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
package com.stylefeng.guns.modular.system.controller.general;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.cloudPayment.example.BalanceAcctExample;
import com.stylefeng.guns.modular.cloudPayment.example.WithdrawalExample;
import com.stylefeng.guns.modular.cloudPayment.req.BalanceAcctReq;
import com.stylefeng.guns.modular.cloudPayment.req.WithdrawalReq;
import com.stylefeng.guns.modular.system.controller.util.Base64Util;
import com.stylefeng.guns.modular.system.model.TEnterpriseWithdrawal;
import com.stylefeng.guns.modular.system.model.User;
import com.stylefeng.guns.modular.system.service.ITEnterpriseWithdrawalService;
import com.stylefeng.guns.modular.system.service.IUserService;
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.resp.BalanceAcctListResp;
import com.unionpay.upyzt.resp.BalanceAcctResp;
import com.unionpay.upyzt.resp.WithdrawalResp;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.TCompanyWithdraw;
import com.stylefeng.guns.modular.system.service.ITCompanyWithdrawService;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-03-17 14:18:09
 */
@Controller
@RequestMapping("/tCompanyWithdraw")
public class TCompanyWithdrawController extends BaseController {
 
    private String PREFIX = "/system/tCompanyWithdraw/";
 
    @Autowired
    private ITCompanyWithdrawService tCompanyWithdrawService;
 
    @Resource
    private ITEnterpriseWithdrawalService enterpriseWithdrawalService;
 
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index(Model model) {
        Integer id = ShiroKit.getUser().getObjectId();
        List<TEnterpriseWithdrawal> companyId = enterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", id));
        if(companyId.size()>0){
            try {
                BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
                balanceAcctReq.setMchId(companyId.get(0).getMchId());
                BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
                Long settledAmount = balanceAcctListResp.getBalanceAccts().get(0).getSettledAmount();
                String money = settledAmount.toString();
                model.addAttribute("money",new BigDecimal(money).divide(new BigDecimal(100)).toString());
            } catch (UpyztException e) {
                e.printStackTrace();
                model.addAttribute("money",0);
            }
 
        }else {
            model.addAttribute("money",0);
        }
        return PREFIX + "tCompanyWithdraw.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tCompanyWithdraw_add")
    public String tCompanyWithdrawAdd() {
        return PREFIX + "tCompanyWithdraw_add.html";
    }
 
    /**
     * 跳转到修改
     */
    @RequestMapping("/tCompanyWithdraw_update/{tCompanyWithdrawId}")
    public String tCompanyWithdrawUpdate(@PathVariable Integer tCompanyWithdrawId, Model model) {
        TCompanyWithdraw tCompanyWithdraw = tCompanyWithdrawService.selectById(tCompanyWithdrawId);
        model.addAttribute("item",tCompanyWithdraw);
        LogObjectHolder.me().set(tCompanyWithdraw);
        return PREFIX + "tCompanyWithdraw_edit.html";
    }
@Autowired
private IUserService userService;
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String createTime,Integer state) {
        Integer id = ShiroKit.getUser().getObjectId();
        EntityWrapper<TCompanyWithdraw> withdrawEntityWrapper = new EntityWrapper<>();
        String sTime=null;
        String eTime=null;
        if(ToolUtil.isNotEmpty(state)){
            withdrawEntityWrapper.eq("status",state);
        }
        withdrawEntityWrapper.eq("companyId",id);
        if(ToolUtil.isNotEmpty(createTime)){
            sTime=createTime.split(" - ")[0]+" 00:00:01";
            eTime=createTime.split(" - ")[1]+" 23:59:59";
            withdrawEntityWrapper.between("createTime",sTime,eTime);
        }
        List<TCompanyWithdraw> tCompanyWithdraws = tCompanyWithdrawService.selectList(withdrawEntityWrapper);
        for (TCompanyWithdraw tCompanyWithdraw : tCompanyWithdraws) {
            Integer createId = tCompanyWithdraw.getCreateId();
            User user = userService.selectById(createId);
            tCompanyWithdraw.setCreateUserName(user.getName());
        }
        return tCompanyWithdraws;
    }
 
    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
    public Object add(Double money,String type,String remark) {
        List<TEnterpriseWithdrawal> companyId = enterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", ShiroKit.getUser().getObjectId()));
        if(companyId.size()>0){
            try {
                BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
                balanceAcctReq.setMchId(companyId.get(0).getMchId());
                BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
                Long settledAmount = balanceAcctListResp.getBalanceAccts().get(0).getSettledAmount();
                if(settledAmount<money){
                    return "5001";
                }
            } catch (UpyztException e) {
                e.printStackTrace();
            }
 
        }
        TCompanyWithdraw tCompanyWithdraw = new TCompanyWithdraw();
        tCompanyWithdraw.setWithdrawMoney(new BigDecimal(money));
        tCompanyWithdraw.setCompanyId(ShiroKit.getUser().getObjectId());
        tCompanyWithdraw.setCreateId(ShiroKit.getUser().getId());
        tCompanyWithdraw.setCreateTime(new Date());
        if("提现".equals(type)){
            tCompanyWithdraw.setType(1);
        }
        tCompanyWithdraw.setRemark(remark);
        tCompanyWithdraw.setStatus(0);
        // TODO 创建提现  需要回调进行提现状态查询
 
        try {
            WithdrawalReq withdrawalReq = new WithdrawalReq();
            if(companyId.size()>0){
                TEnterpriseWithdrawal enterpriseWithdrawal = companyId.get(0);
                withdrawalReq.setOutOrderNo(ToolUtil.getRandomString(32));
                int total = new BigDecimal(money).multiply(new BigDecimal(100)).intValue();
                withdrawalReq.setAmount(total);
                withdrawalReq.setBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId());
                withdrawalReq.setBankAcctNo(enterpriseWithdrawal.getBankAccount());
                withdrawalReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode()));
 
            }
            WithdrawalResp withdrawalResp = WithdrawalExample.create(withdrawalReq);
 
            System.out.println("公司添加提现:"+withdrawalResp);
            tCompanyWithdraw.setWithdrawId(withdrawalResp.getWithdrawalId());
 
        } catch (UpyztException e) {
            e.printStackTrace();
            System.out.println("公司添加提现失败:"+e.getIssue());
        }
        tCompanyWithdrawService.insert(tCompanyWithdraw);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tCompanyWithdrawId) {
        tCompanyWithdrawService.deleteById(tCompanyWithdrawId);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TCompanyWithdraw tCompanyWithdraw) {
        tCompanyWithdrawService.updateById(tCompanyWithdraw);
        return SUCCESS_TIP;
    }
 
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{tCompanyWithdrawId}")
    @ResponseBody
    public Object detail(@PathVariable("tCompanyWithdrawId") Integer tCompanyWithdrawId) {
        return tCompanyWithdrawService.selectById(tCompanyWithdrawId);
    }
}