Pu Zhibing
6 天以前 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
package com.stylefeng.guns.modular.system.controller.general;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
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.shiro.ShiroKit;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.core.util.ExcelExportUtil;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.util.Tingg.model.*;
import com.stylefeng.guns.modular.system.model.TDriver;
import com.stylefeng.guns.modular.system.model.TPubWithdrawal;
import com.stylefeng.guns.modular.system.model.TSystemNotice;
import com.stylefeng.guns.modular.system.model.TUser;
import com.stylefeng.guns.modular.system.service.ITDriverService;
import com.stylefeng.guns.modular.system.service.ITPubWithdrawalService;
import com.stylefeng.guns.modular.system.service.ITSystemNoticeService;
import com.stylefeng.guns.modular.system.service.ITUserService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.stylefeng.guns.modular.system.util.Tingg.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * 提现列表控制器
 * @author fengshuonan
 * @Date 2020-06-09 09:30:59
 */
@Controller
@RequestMapping("")
public class TPubWithdrawalController extends BaseController {
 
    private String PREFIX = "/system/tPubWithdrawal/";
 
    @Autowired
    private ITPubWithdrawalService tPubWithdrawalService;
 
    @Autowired
    private ITSystemNoticeService tSystemNoticeService;
 
    @Autowired
    private TinggPayoutUtil tinggPayoutUtil;
 
    @Autowired
    private ITUserService userService;
 
    @Autowired
    private ITDriverService driverService;
 
    @Value("${callbackPath}")
    private String callbackPath;
 
 
 
 
 
    /**
     * 跳转到提现列表首页
     */
    @RequestMapping("/tPubWithdrawal")
    public String index() {
        return PREFIX + "tPubWithdrawal.html";
    }
 
    /**
     * 跳转到查看详情
     */
    @RequestMapping("/tPubWithdrawal/lookDetail/{id}/{type}")
    public String lookDetail(@PathVariable Integer id, @PathVariable Integer type, Model model) {
        TPubWithdrawal tPubWithdrawal = tPubWithdrawalService.selectById(id);
        String str = "";
        if (1 == type){
            str = tPubWithdrawal.getRemark();
        }
        model.addAttribute("str",str);
        return "/system/tComplaint/lookDetail.html";
    }
 
    /**
     * 跳转到立即处理页面
     * ----------改为批量
     */
    @RequestMapping("/tPubWithdrawal/tPubWithdrawal_immediately/{tPubWithdrawalIds}")
    public String tPubWithdrawalUpdate(@PathVariable String tPubWithdrawalIds, Model model) {
        model.addAttribute("tPubWithdrawalIds",tPubWithdrawalIds);
        return PREFIX + "tPubWithdrawal_immediately.html";
    }
 
    /**
     * 获取提现列表列表
     */
    @RequestMapping(value = "/tPubWithdrawal/list")
    @ResponseBody
    public Object list(String insertTime,
                       String name,
                       Integer withdrawalType,
                       Integer userType,
                       Integer type,
                       Integer state) {
        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();
        if (ShiroKit.getUser().getRoleType() != 1){
            page.setRecords(null);
        }else{
            page.setRecords(tPubWithdrawalService.getWithdrawalList(page,beginTime,endTime,name,withdrawalType,userType,type,state));
        }
        return super.packForBT(page);
    }
 
    /**
     * 新增提现列表
     */
    @RequestMapping(value = "/tPubWithdrawal/add")
    @ResponseBody
    public Object add(TPubWithdrawal tPubWithdrawal) {
        tPubWithdrawalService.insert(tPubWithdrawal);
        return SUCCESS_TIP;
    }
 
    /**
     * 立即处理操作
     */
    @RequestMapping(value = "/tPubWithdrawal/immediately")
    @ResponseBody
    public Object immediately(@RequestParam Integer id,@RequestParam Integer state,@RequestParam String remark) {
        TPubWithdrawal tPubWithdrawal = tPubWithdrawalService.selectById(id);
        if (SinataUtil.isNotEmpty(tPubWithdrawal)){
            tPubWithdrawal.setRemark(remark);
            String serviceCode = "";
            String phone = "";
            Integer language = null;
            if(tPubWithdrawal.getUserType() == 1){
                TUser tUser = userService.selectById(tPubWithdrawal.getUserId());
                language = tUser.getLanguage();
                serviceCode = tUser.getPhoneOperator();
                phone = tUser.getPhone();
            }else{
                TDriver tDriver = driverService.selectById(tPubWithdrawal.getUserId());
                language = tDriver.getLanguage();
                serviceCode = tDriver.getPhoneOperator();
                phone = tDriver.getPhone();
            }
            if(2 == state){
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
                String payerTransactionID = sdf.format(new Date()) + tPubWithdrawal.getId();
                PayoutResponse payoutResponse = tinggPayoutUtil.sendPayout(serviceCode, phone, payerTransactionID, tPubWithdrawal.getMoney().doubleValue(), callbackPath + "/base/withdrawalCallback", remark);
                AuthStatus authStatus = payoutResponse.getAuthStatus();
                Results results = payoutResponse.getResults().get(0);
                String statusCode = results.getStatusCode();
                if(!"131".equals(authStatus.getAuthStatusCode())){
                    return ResultUtil.error(authStatus.getAuthStatusDescription());
                }
                if(!"139".equals(statusCode)){
                    return ResultUtil.error(results.getStatusDescription());
                }
                tPubWithdrawal.setSerialNo(results.getBeepTransactionID());
                tPubWithdrawal.setState(4);
            }else{//回退金额
                tPubWithdrawal.setHandleTime(new Date());
                tPubWithdrawal.setState(state);
                if(tPubWithdrawal.getUserType() == 1){
                    TUser tUser = userService.selectById(tPubWithdrawal.getUserId());
                    tUser.setBalance(tUser.getBalance().add(tPubWithdrawal.getMoney()));
                    userService.updateById(tUser);
                }else{
                    TDriver tDriver = driverService.selectById(tPubWithdrawal.getUserId());
                    tDriver.setBalance(tDriver.getBalance().add(tPubWithdrawal.getMoney()));
                    if(tPubWithdrawal.getType() == 1){//活动提现
                        tDriver.setLaveActivityMoney(new BigDecimal(tDriver.getLaveActivityMoney()).add(tPubWithdrawal.getMoney()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
                    }else{//业务提现
                        tDriver.setLaveBusinessMoney(new BigDecimal(tDriver.getLaveBusinessMoney()).add(tPubWithdrawal.getMoney()).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
                    }
                    driverService.updateById(tDriver);
                }
            }
            tPubWithdrawalService.updateById(tPubWithdrawal);
 
 
            //增加系统消息
            TSystemNotice notice = new TSystemNotice();
            notice.setType(2);
            notice.setUserType(tPubWithdrawal.getUserType());
            notice.setContent((language == 1 ? "提现申请反馈" : language == 2 ? "Feedback on withdrawal requests" : "Réponse à la demande de retrait") + ":【" +remark +"】。");
            notice.setUserId(tPubWithdrawal.getUserId());
            notice.setInsertTime(new Date());
            notice.setRead(1);
            tSystemNoticeService.insert(notice);
        }
        return SUCCESS_TIP;
    }
 
 
    @ResponseBody
    @PostMapping("/base/withdrawalCallback")
    public PayoutCallbackResponse tinggPayoutCallback(@RequestBody PayoutCallbackRequest request){
        System.err.println("转账回调>>>>" + JSON.toJSONString(request));
        PayoutCallbackResponse payoutCallbackResponse = new PayoutCallbackResponse();
        AuthStatus authStatus = new AuthStatus();
        authStatus.setAuthStatusCode(131);
        authStatus.setAuthStatusDescription("Authentication was successful");
        payoutCallbackResponse.setAuthStatus(authStatus);
        Results results = new Results();
        PayoutPacket packet = request.getPayload().getPacket();
        String statusCode = packet.getStatusCode();
        String beepTransactionID = packet.getBeepTransactionID();
        String payerTransactionID = packet.getPayerTransactionID();
 
        String id = payerTransactionID.substring(17);
        TPubWithdrawal tPubWithdrawal = tPubWithdrawalService.selectById(id);
        tPubWithdrawal.setState(2);
        tPubWithdrawal.setHandleTime(new Date());
        tPubWithdrawal.setSerialNo(beepTransactionID);
        tPubWithdrawalService.updateById(tPubWithdrawal);
 
        results.setBeepTransactionID(beepTransactionID);
        results.setPayerTransactionID(payerTransactionID);
        results.setStatusCode("188");
        results.setStatusDescription("Response was received");
        payoutCallbackResponse.setResults(results);
        return payoutCallbackResponse;
    }
 
 
 
 
    /**
     * 修改提现列表
     */
    @RequestMapping(value = "/tPubWithdrawal/update")
    @ResponseBody
    public Object update(TPubWithdrawal tPubWithdrawal) {
        tPubWithdrawalService.updateById(tPubWithdrawal);
        return SUCCESS_TIP;
    }
 
    /**
     * 提现列表详情
     */
    @RequestMapping(value = "/tPubWithdrawal/detail/{tPubWithdrawalId}")
    @ResponseBody
    public Object detail(@PathVariable("tPubWithdrawalId") Integer tPubWithdrawalId) {
        return tPubWithdrawalService.selectById(tPubWithdrawalId);
    }
 
    /**
     * 提现列表导出
     * @author yxh
     * @date 2021/4/7 15:59
     * @param insertTime
     * @param name
     * @param withdrawalType
     * @param userType
     * @param type
     * @param state
     */
    @RequestMapping(value = "/tPubWithdrawal/downloadList",method = RequestMethod.GET)
    public void downloadList(String insertTime, String name, Integer withdrawalType, Integer userType, Integer type, Integer state,
                             HttpServletRequest request, HttpServletResponse response){
        String start = null;
        String end = null;
        if(ToolUtil.isNotEmpty(insertTime)){
            start = insertTime.split(" - ")[0];
            end = insertTime.split(" - ")[1];
        }
        List<Map<String, Object>> list =tPubWithdrawalService.getWithdrawalListNoPage(start,end,name,withdrawalType,userType,type,state);
        // 表格数据
        List<List<String>> dataList = new ArrayList<>();
        // 表头行
        List<String> shellList = new ArrayList<String>();
        shellList.add("申请时间");
        shellList.add("提现人");
        shellList.add("提现手机号");
        shellList.add("账户类型");
        shellList.add("提现金额");
        shellList.add("提现类型");
        shellList.add("账户余额");
        shellList.add("联系人");
        shellList.add("联系电话");
        shellList.add("备注");
        shellList.add("状态");
        dataList.add(shellList);
        for (Map<String, Object> map : list) {
            //数据行
            shellList = new ArrayList<String>();
            if(SinataUtil.isNotEmpty(map.get("applyTime"))){
                shellList.add(map.get("applyTime").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(map.get("name"))){
                shellList.add(map.get("name").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(map.get("code"))){
                shellList.add(map.get("code").toString());
            }else{
                shellList.add("-");
            }
            //userType
            if(SinataUtil.isNotEmpty(map.get("userType"))){
                switch (map.get("userType").toString()){
                    case "1":
                        shellList.add("用户");
                        break;
                    case "2":
                        shellList.add("司机");
                        break;
                    default:
                        shellList.add("-");
                }
            }else{
                shellList.add("-");
            }
            //money
            if(SinataUtil.isNotEmpty(map.get("money"))){
                shellList.add(map.get("money").toString());
            }else{
                shellList.add("-");
            }
            //type
            if(SinataUtil.isNotEmpty(map.get("type"))){
                switch (map.get("type").toString()){
                    case "1":
                        shellList.add("活动收入提现");
                        break;
                    case "2":
                        shellList.add("业务收入提现");
                        break;
                    default:
                        shellList.add("-");
                }
            }else{
                shellList.add("-");
            }
            //balance
            if(SinataUtil.isNotEmpty(map.get("balance"))){
                shellList.add(map.get("balance").toString());
            }else{
                shellList.add("-");
            }
            //userName
            if(SinataUtil.isNotEmpty(map.get("userName"))){
                shellList.add(map.get("userName").toString());
            }else{
                shellList.add("-");
            }
            //userPhone
            if(SinataUtil.isNotEmpty(map.get("userPhone"))){
                shellList.add(map.get("userPhone").toString());
            }else{
                shellList.add("-");
            }
            //remark
            if(SinataUtil.isNotEmpty(map.get("remark"))){
                shellList.add(map.get("remark").toString());
            }else{
                shellList.add("-");
            }
            //state
            if(SinataUtil.isNotEmpty(map.get("state"))){
                switch (map.get("state").toString()){
                    case "1":
                        shellList.add("待处理");
                        break;
                    case "2":
                        shellList.add("成功");
                        break;
                    case "3":
                        shellList.add("失败");
                        break;
                    default:
                        shellList.add("-");
                }
            }else{
                shellList.add("-");
            }
            dataList.add(shellList);
        }
        try {
            // 调用工具类进行导出
            ExcelExportUtil.easySheet("提现导出记录"+ DateUtil.formatDate(new Date(), "YYYYMMddHHmmss"), "提现导出记录", dataList,request, response);
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}