无关风月
2025-03-21 0f8dce61fdc6cc174ab891e9867934324df2e489
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package com.stylefeng.guns.modular.system.controller.general;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
import com.stylefeng.guns.modular.system.controller.util.HttpUtils;
import com.stylefeng.guns.modular.system.model.TDriver;
import com.stylefeng.guns.modular.system.model.TWithdrawal;
import com.stylefeng.guns.modular.system.service.ITDriverService;
import com.stylefeng.guns.modular.system.service.ITWithdrawalService;
import com.stylefeng.guns.modular.system.util.DateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 提现相关控制器
 */
@Controller
@RequestMapping("/withdrawal")
public class TWithdrawalController extends BaseController {
 
    @Autowired
    private ITWithdrawalService withdrawalService;
 
    @Autowired
    private ITDriverService driverService;
 
    private String PREFIX = "/system/tWithdrawal/";
 
    /**
     * 跳转到提现首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tWithdrawal.html";
    }
 
    /**
     * 跳转到添加提现
     */
    @RequestMapping("/tWithdrawal_add")
    public String tWithdrawalAdd(Model model) {
        return PREFIX + "tWithdrawal_add.html";
    }
 
    /**
     * 跳转到修改提现
     */
    @RequestMapping("/tWithdrawal_update/{tWithdrawalId}")
    public String tWithdrawalUpdate(@PathVariable Integer tWithdrawalId, Model model) {
        TWithdrawal tWithdrawal = withdrawalService.selectById(tWithdrawalId);
        tWithdrawal.setWithdrawalTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(tWithdrawal.getWithdrawalTime()));
        tWithdrawal.setWithdrawalTypeStr(tWithdrawal.getWithdrawalType()==1?"支付宝":"银行卡");
        model.addAttribute("item",tWithdrawal);
        LogObjectHolder.me().set(tWithdrawal);
        if(tWithdrawal.getStatus() == 1){
            return PREFIX + "tWithdrawal_edit.html";
        }else {
            return PREFIX + "tWithdrawal_detail.html";
        }
 
    }
 
    /**
     * 获取提现列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String insertTime,
                       String driverName,
                       Integer status) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(insertTime)){
            String[] timeArray = insertTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(withdrawalService.getWithdrawalList(page,beginTime,endTime,driverName,status));
        return super.packForBT(page);
    }
 
    /**
     * 新增提现
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TWithdrawal withdrawal) {
        withdrawalService.insert(withdrawal);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除提现
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tWithdrawalId) {
        withdrawalService.deleteById(tWithdrawalId);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改提现
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TWithdrawal withdrawal) {
 
        withdrawal.setStatus(withdrawal.getStatus());
 
        if(withdrawal.getStatus() == 2){
            withdrawal.setReceiptVoucher(withdrawal.getReceiptVoucher());
        }
 
        if(withdrawal.getStatus() == 3){
            withdrawal.setRemark(withdrawal.getRemark());
            TWithdrawal tWithdrawal = withdrawalService.selectById(withdrawal.getId());
            TDriver driver = driverService.selectById(tWithdrawal.getDriverId());
            BigDecimal balance = driver.getBalance();
            BigDecimal withdrawalMoney = tWithdrawal.getWithdrawalMoney();
            driver.setBalance(balance.add(withdrawalMoney));
            driverService.updateById(driver);
        }
 
        withdrawalService.updateById(withdrawal);
        return SUCCESS_TIP;
    }
 
    @RequestMapping(value = "/excel")
    @ResponseBody
    public Object excel(String insertTime,
                        String driverName,
                        Integer status,
                        HttpServletResponse response) {
            String beginTime = null;
            String endTime = null;
            if (SinataUtil.isNotEmpty(insertTime)){
                String[] timeArray = insertTime.split(" - ");
                beginTime = timeArray[0];
                endTime = timeArray[1];
            }
        List<Map<String, Object>> list = withdrawalService.excel1(beginTime, endTime, driverName, status);
        try {
            String fileName = "提现管理" + System.currentTimeMillis() + ".xls"; // 文件名
            String sheetName = "提现管理";// sheet名
            Map<String,Object> object = null;
            String[] title = new String[] {
                    "下单时间",
                    "提现人",
                    "提现方式",
                    "收款人信息",
                    "账户余额",
                    "提现金额",
                    "联系电话",
                    "备注",
                    "状态"
            };// 标题
            String[][] values = new String[list.size()][];
            for (int i = 0; i < list.size(); i++) {
                values[i] = new String[title.length];
                // 将对象内容转换成string
                object = list.get(i);
                values[i][0] = new SimpleDateFormat("yyyy-MM-dd HH:mm").format((Date) object.get("withdrawalTime"));
                values[i][1] = object.get("driverName").toString();
                values[i][2] = "银行卡";
                values[i][3] = "开户行:"+object.get("openBank").toString()+"/n"+"收款人:"+object.get("receivePaymentName").toString()+"/n"+"银行卡号:"+object.get("receivePaymentAccount").toString();
                values[i][4] = new BigDecimal(object.get("driverBalance").toString()).setScale(2, RoundingMode.HALF_UP).toString();
                values[i][5] = object.get("withdrawalMoney").toString();
                values[i][6] = object.get("driverPhone").toString();
                values[i][7] = object.get("remark")!=null?object.get("remark").toString():"-";
                values[i][8] = (Integer)object.get("status")==1?"待处理":(Integer)object.get("status")==2?"成功":"失败";
            }
            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName, title, values, null);
 
            this.setResponseHeader(response, fileName);
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS_TIP;
    }
 
    /**
     * 设置相应头部信息
     * @param response
     * @param fileName
     * @return
     */
    public void setResponseHeader(HttpServletResponse response, String fileName) {
        try {
            try {
                fileName = new String(fileName.getBytes(), "ISO8859-1");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            response.setContentType("application/octet-stream;charset=ISO8859-1");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.addHeader("Pargam", "no-cache");
            response.addHeader("Cache-Control", "no-cache");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
 
}