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
package com.stylefeng.guns.modular.account.service.impl;
 
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.account.dao.UserWithdrawalMapper;
import com.stylefeng.guns.modular.account.service.UserWithdrawalService;
import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
import com.stylefeng.guns.modular.cloudPayment.req.WithdrawalReq;
import com.stylefeng.guns.modular.system.model.UserWithdrawal;
import com.unionpay.upyzt.resp.CusApplicationResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
@Slf4j
@Service
public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalMapper, UserWithdrawal> implements UserWithdrawalService {
 
    @Override
    public void cusApplicationRespToUserWithdrawal(UserWithdrawal userWithdrawal,CusApplicationResp cusApplicationResp) {
        userWithdrawal.setApplicationStatus(cusApplicationResp.getApplicationStatus());
        userWithdrawal.setCusId(cusApplicationResp.getCusId());
        userWithdrawal.setSucceededAt(cusApplicationResp.getSucceededAt());
        if(!CollectionUtils.isEmpty(cusApplicationResp.getFailureMsgs())){
            userWithdrawal.setFailureMsgsReason(cusApplicationResp.getFailureMsgs().get(0).getReason());
        }
        userWithdrawal.setRelAcctNo(cusApplicationResp.getRelAcctNo());
        userWithdrawal.setBindAcctName(cusApplicationResp.getBindAcctName());
        userWithdrawal.setBalanceAcctId(cusApplicationResp.getBalanceAcctId());
        userWithdrawal.setSettleAcctId(cusApplicationResp.getSettleAcctId());
        userWithdrawal.setCusApplicationId(cusApplicationResp.getCusApplicationId());
        // 审核通过
    }
 
    @Override
    public AllocationReq createAllocationReq(String balanceAcctId, String companyBalanceAcctId, Integer amount,String password) {
        AllocationReq allocationReq = new AllocationReq();
        allocationReq.setOutOrderNo(ToolUtil.getRandomString(32));
        allocationReq.setPayBalanceAcctId(companyBalanceAcctId);
        allocationReq.setRecvBalanceAcctId(balanceAcctId);
        allocationReq.setAmount(amount*100);
        allocationReq.setOrderNo(ToolUtil.getRandomString(32));
        allocationReq.setPassword(password);
        allocationReq.setOrderAmount(Long.valueOf(amount));
        allocationReq.setProductName("司机提现");
        allocationReq.setProductCount(1);
        return allocationReq;
    }
 
    @Override
    public WithdrawalReq createWithdrawalReq(String balanceAcctId, Integer amount, String password, String code) {
        WithdrawalReq withdrawalReq = new WithdrawalReq();
        withdrawalReq.setOutOrderNo(ToolUtil.getRandomString(32));
        withdrawalReq.setBalanceAcctId(balanceAcctId);
        withdrawalReq.setAmount(amount*100);
        withdrawalReq.setBankAcctNo(code);
        withdrawalReq.setPassword(password);
        return withdrawalReq;
    }
 
    @Override
    public Boolean withdrawDeposit(Integer amount, String bankAcctNo, String withdrawPassword) {
        // 查询当前操作电子用户
        /*UserWithdrawal userWithdrawal = this.selectOne(new EntityWrapper<UserWithdrawal>()
                .eq("userId", Objects.requireNonNull(ShiroKit.getUser()).getId())
                .eq("userType", 2)
                .last("LIMIT 1"));
 
        // 先从平台进行分账到用户电子账簿
        // 查询平台账户
        Company company = companyService.selectOne(new EntityWrapper<Company>()
                .eq("type", 1));
        // 查询平台开户信息
        ElectronicLedger electronicLedger = electronicLedgerService.selectOne(new EntityWrapper<ElectronicLedger>()
                .eq("userId", company.getId())
                .eq("userType", 3)
                .last("LIMIT 1"));
        try {
            // 进行平台分账到司机电子账簿
            log.info("平台分账到司机电子账簿=========");
            AllocationReq allocationReq = this.createAllocationReq(userWithdrawal.getBalanceAcctId(), electronicLedger.getBalanceAcctId(), amount,withdrawPassword);
            AllocationResp allocationResp = AllocationExample.create(allocationReq);
            log.info("平台分账到司机电子账簿完成=========:{}",allocationResp);
 
            // 用户电子账簿进行提现操作
            WithdrawalResp withdrawalResp = WithdrawalExample.create(this.createWithdrawalReq(userWithdrawal.getBalanceAcctId(), amount, withdrawPassword, bankAcctNo));
            log.info("司机电子账簿提现完成=========:{}",withdrawalResp);
            return true;
        }catch (Exception e){
            log.info("司机提现失败=========:{}",e.getMessage());
            e.printStackTrace();
            return false;
        }*/
        return null;
    }
}