cloudroam
2024-10-24 9e3c6fa190b1c59b2178ae1823c994684a4d9df3
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
package com.mzl.flower.service.impl.wallet;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.wallet.CreateWalletBillRecordDTO;
import com.mzl.flower.entity.payment.Transfer;
import com.mzl.flower.entity.payment.TransferDetail;
import com.mzl.flower.entity.wallet.WalletBillRecordDO;
import com.mzl.flower.entity.wallet.WalletDO;
import com.mzl.flower.mapper.payment.TransferDetailMapper;
import com.mzl.flower.mapper.payment.TransferMapper;
import com.mzl.flower.mapper.wallet.WalletBillRecordMapper;
import com.mzl.flower.service.wallet.WalletBillRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mzl.flower.service.wallet.WalletService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import javax.annotation.Resource;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author @TaoJie
 * @since 2024-10-22
 */
@Service
public class WalletBillRecordServiceImpl extends ServiceImpl<WalletBillRecordMapper, WalletBillRecordDO> implements WalletBillRecordService {
 
    @Resource
    private TransferMapper transferMapper;
 
    @Resource
    private TransferDetailMapper transferDetailMapper;
 
    @Resource
    private WalletBillRecordMapper walletBillRecordMapper;
 
    @Resource
    private WalletService walletService;
 
    @Override
    public void create(CreateWalletBillRecordDTO dto) {
 
 
    }
 
    public void updateTransferStatus(String transferId) {
        Transfer t = transferMapper.selectById(transferId);
        if ("FINISHED".equals(t.getStatus())) {
            WalletBillRecordDO walletBillRecordDO = walletBillRecordMapper.selectOne(new QueryWrapper<WalletBillRecordDO>().eq("transfer_id", transferId));
            if (walletBillRecordDO == null) {
                return;
            }
            String transferDetailId = walletBillRecordDO.getTransferDetailId();
            TransferDetail td = transferDetailMapper.selectById(transferDetailId);
            if (td == null) {
                log.warn("未找到对应明细");
                return;
            }
            String dStatus = td.getStatus();
            if ("SUCCESS".equals(dStatus)) {
                walletBillRecordDO.setTransferState(Constants.SETTLEMENT_STATUS.COMPLETED.name());
                walletBillRecordDO.update("sys");
                walletBillRecordMapper.updateById(walletBillRecordDO);
                //更新钱包
                WalletDO walletDO = walletService.getBySupplierId(walletBillRecordDO.getWalletId());
                if(!ObjectUtils.isEmpty(walletDO)){
                    //体现中金额
                    walletDO.setWithdrawingAmount(walletDO.getWithdrawingAmount().subtract(walletBillRecordDO.getChangeAmount()));
                    //已提现金额
                    walletDO.setWithdrawnAmount(walletDO.getWithdrawnAmount().add(walletBillRecordDO.getChangeAmount()));
                }
 
            } else if ("FAIL".equals(dStatus)) {
                walletBillRecordDO.setTransferState(Constants.SETTLEMENT_STATUS.FAILED.name());
                walletBillRecordDO.update("sys");
                walletBillRecordMapper.updateById(walletBillRecordDO);
            }
        }
    }
}