xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
package com.stylefeng.guns.modular.system.controller.general;
 
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.SinataUtil;
import com.stylefeng.guns.modular.cloudPayment.example.AllocationExample;
import com.stylefeng.guns.modular.cloudPayment.example.WithdrawalExample;
import com.stylefeng.guns.modular.cloudPayment.req.WithdrawalReq;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.HttpRequestUtil;
import com.stylefeng.guns.modular.system.util.PushURL;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.resp.AllocationResp;
import com.unionpay.upyzt.resp.WithdrawalResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
 
/**
 * 提现列表控制器
 *
 * @author fengshuonan
 * @Date 2020-06-09 09:30:59
 */
@Controller
@Slf4j
@RequestMapping("/tPubWithdrawal")
public class TPubWithdrawalController extends BaseController {
 
    private String PREFIX = "/system/tPubWithdrawal/";
 
    @Autowired
    private ITPubWithdrawalService tPubWithdrawalService;
 
    @Autowired
    private ITSystemNoticeService tSystemNoticeService;
    @Resource
    private IUserWithdrawalService userWithdrawalService;
 
    /**
     * 跳转到提现列表首页
     */
    @RequestMapping("")
    public String index(Model model) {
        model.addAttribute("id",ShiroKit.getUser().getObjectId());
        return PREFIX + "tPubWithdrawal.html";
    }
 
    /**
     * 跳转到查看详情
     */
    @RequestMapping("/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_immediately/{tPubWithdrawalId}")
    public String tPubWithdrawalUpdate(@PathVariable Integer tPubWithdrawalId, Model model) {
        model.addAttribute("tPubWithdrawalId",tPubWithdrawalId);
        return PREFIX + "tPubWithdrawal_immediately.html";
    }
 
    /**
     * 获取提现列表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String insertTime,
                       String name,
                       Integer withdrawalType) {
        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 (false){
            page.setRecords(null);
        }else{
            List<Map<String, Object>> withdrawalList = tPubWithdrawalService.getWithdrawalList(page, beginTime, endTime, name, withdrawalType);
            for (Map<String, Object> map : withdrawalList) {
                String money = map.get("money").toString();
                String realGetMoney = map.get("realGetMoney").toString();
                map.put("overMoeny",new BigDecimal(money).subtract(new BigDecimal(realGetMoney)));
            }
            page.setRecords(withdrawalList);
        }
        return super.packForBT(page);
    }
 
    /**
     * 新增提现列表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TPubWithdrawal tPubWithdrawal) {
        tPubWithdrawalService.insert(tPubWithdrawal);
        return SUCCESS_TIP;
    }
 
    @Resource
    private ITDriverService driverService;
 
    @Resource
    private ITUserService userService;
    /**
     * 立即处理操作
     */
    @RequestMapping(value = "/immediately")
    @ResponseBody
    @Transactional(rollbackFor = UpyztException.class,propagation = Propagation.REQUIRES_NEW)
    public synchronized Object immediately(@RequestParam Integer id,@RequestParam Integer state,@RequestParam String remark) {
        TPubWithdrawal tPubWithdrawal = tPubWithdrawalService.selectById(id);
        if(tPubWithdrawal.getState()!=1){
            return SUCCESS_TIP;
        }
        tPubWithdrawal.setRemark(remark);
        tPubWithdrawal.setHandleTime(new Date());
        if (SinataUtil.isNotEmpty(tPubWithdrawal)){
//            tPubWithdrawal.setState(state);  //调用接口修改状态
 
 
 
 
            Integer stateObj = 1;
            if (2 == state){   //同意提现
                stateObj = 1;
            }else if (3 == state){  //拒绝提现
                stateObj = 2;
            }
 
            Integer objectId = ShiroKit.getUser().getObjectId();
            // 获取手续费
            Double poundage = tPubWithdrawalService.getPoundage(objectId);
            if(poundage!=null && poundage>0){
                BigDecimal money = tPubWithdrawal.getMoney();
                if(money.doubleValue()>=1){
                    BigDecimal divide = new BigDecimal(poundage).divide(new BigDecimal(100));
                    tPubWithdrawal.setMoney(money.subtract(money.multiply(divide)));
                }
            }
            Integer userType = tPubWithdrawal.getUserType();
            if(stateObj==1){
                if(userType==1){
                    TUser tUser1 = userService.selectById(tPubWithdrawal.getUserId());
                    // 用户
                    List<UserWithdrawal> userWithdrawals = userWithdrawalService.selectList(new EntityWrapper<UserWithdrawal>().eq("phone", tUser1.getPhone()).eq("applicationStatus","succeeded"));
                    if(userWithdrawals.size()>0){
                        System.out.println("用户:"+userWithdrawals);
                        System.out.println("用户:"+userWithdrawals.get(0));
                        try {
                            log.info("用户提现创建=========");
                            WithdrawalResp withdrawalResp = WithdrawalExample.create(userWithdrawalService.createInfo(userWithdrawals.get(0), tPubWithdrawal));
                            tPubWithdrawal.setWithdrawId(withdrawalResp.getWithdrawalId());
                            tPubWithdrawalService.updateById(tPubWithdrawal);
                            log.info("用户提现创建信息========="+withdrawalResp.toString());
                            log.info("用户提现创建成功=========");
                        } catch (UpyztException e) {
                            log.info("用户提现创建失败=========");
                            e.printStackTrace();
                            if(userType==1){
                                TUser tUser = userService.selectById(tPubWithdrawal.getUserId());
                                BigDecimal balance = tUser.getBalance();
                                BigDecimal money = balance.add(tPubWithdrawal.getMoney());
                                tUser.setBalance(money);
                                userService.updateById(tUser);
 
                            }else {
                                TDriver tDriver = driverService.selectById(tPubWithdrawal.getUserId());
                                BigDecimal balance = tDriver.getBalance();
                                BigDecimal money = balance.add(tPubWithdrawal.getMoney());
                                tDriver.setBalance(money);
                                driverService.updateById(tDriver);
                            }
                            tPubWithdrawal.setState(3);
                            tPubWithdrawalService.updateById(tPubWithdrawal);
                            return e.getMessage();
                        }
                    }else {
                        return "该用户未进件";
                    }
                }else {
                    // 司机.
                    // 查询当前操作电子用户
                    TDriver tUser1 = driverService.selectById(tPubWithdrawal.getUserId());
                    UserWithdrawal userWithdrawal = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>()
                            .eq("phone", tUser1.getPhone())
                            .last("LIMIT 1"));
                    // 先从平台进行分账到用户电子账簿
                    if(userWithdrawal==null){
                        return "该司机未进件";
                    }
                    try {
                        log.info("司机提现创建=========");
                        WithdrawalResp withdrawalResp = WithdrawalExample.create(userWithdrawalService.createInfo(userWithdrawal, tPubWithdrawal));
                        tPubWithdrawal.setWithdrawId(withdrawalResp.getWithdrawalId());
                        tPubWithdrawalService.updateById(tPubWithdrawal);
                        log.info("司机提现创建信息========="+withdrawalResp.toString());
                        log.info("司机提现创建成功=========");
                    } catch (UpyztException e) {
                        log.info("司机提现创建失败=========");
                        e.printStackTrace();
                        if(userType==1){
                            TUser tUser = userService.selectById(tPubWithdrawal.getUserId());
                            BigDecimal balance = tUser.getBalance();
                            BigDecimal money = balance.add(tPubWithdrawal.getMoney());
                            tUser.setBalance(money);
                            userService.updateById(tUser);
                        }else {
                            TDriver tDriver = driverService.selectById(tPubWithdrawal.getUserId());
                            if(tPubWithdrawal.getType()==2){
                                BigDecimal balance = new BigDecimal(tDriver.getLaveBusinessMoney());
                                BigDecimal money = balance.add(tPubWithdrawal.getMoney());
                                tDriver.setLaveBusinessMoney(money.doubleValue());
                            }else
                            {
                                BigDecimal balance = new BigDecimal(tDriver.getLaveActivityMoney());
                                BigDecimal money = balance.add(tPubWithdrawal.getMoney());
                                tDriver.setLaveActivityMoney(money.doubleValue());
                            }
 
                            driverService.updateById(tDriver);
                        }
                        tPubWithdrawal.setState(3);
                        tPubWithdrawalService.updateById(tPubWithdrawal);
                        return e.getMessage();
                    }
                }
            }else {
                tPubWithdrawal.setState(state);
                tPubWithdrawalService.updateById(tPubWithdrawal);
                // 拒绝  返回余额
                if(userType==1){
                    TUser tUser = userService.selectById(tPubWithdrawal.getUserId());
                    BigDecimal balance = tUser.getBalance();
                    BigDecimal money = balance.add(tPubWithdrawal.getMoney());
                    tUser.setBalance(money);
                    userService.updateById(tUser);
                }else {
                    TDriver tDriver = driverService.selectById(tPubWithdrawal.getUserId());
                    if(tPubWithdrawal.getType()==2){
                        BigDecimal balance = new BigDecimal(tDriver.getLaveBusinessMoney());
                        BigDecimal money = balance.add(tPubWithdrawal.getMoney());
                        tDriver.setLaveBusinessMoney(money.doubleValue());
                    }else
                    {
                        BigDecimal balance = new BigDecimal(tDriver.getLaveActivityMoney());
                        BigDecimal money = balance.add(tPubWithdrawal.getMoney());
                        tDriver.setLaveActivityMoney(money.doubleValue());
                    }
 
                    driverService.updateById(tDriver);
                }
            }
//            Map<String,String> map = new HashMap<>();
//            map.put("id", String.valueOf(tPubWithdrawal.getId()));
//            map.put("state", String.valueOf(stateObj));
//            String result = HttpRequestUtil.postRequest(PushURL.withdraw_auth_url, map);
//            System.out.println("提现审核接口 :【recordId="+tPubWithdrawal.getId().toString()+"】,调用接口:"+result);
            //增加系统消息
            TSystemNotice notice = new TSystemNotice();
            notice.setType(2);
            notice.setUserType(tPubWithdrawal.getUserType());
            notice.setContent("提现处理结果:【"+remark+"】。");
            notice.setUserId(tPubWithdrawal.getUserId());
            notice.setInsertTime(new Date());
            notice.setRead(1);
            tSystemNoticeService.insert(notice);
 
        }
        return SUCCESS_TIP;
    }
 
    /**
     * 修改提现列表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TPubWithdrawal tPubWithdrawal) {
        tPubWithdrawalService.updateById(tPubWithdrawal);
        return SUCCESS_TIP;
    }
 
 
    /**
     * 提现列表详情
     */
    @RequestMapping(value = "/detail/{tPubWithdrawalId}")
    @ResponseBody
    public Object detail(@PathVariable("tPubWithdrawalId") Integer tPubWithdrawalId) {
        return tPubWithdrawalService.selectById(tPubWithdrawalId);
    }
 
 
 
}