陶杰
2024-10-22 61299cec43f35a9a8fd6d6a9840fdc44f1c24e9b
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
package com.mzl.flower.service.impl.wallet;
 
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.config.security.SecurityUtils;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.wallet.CreateWalletWithdrawRecordDTO;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
import com.mzl.flower.entity.wallet.WalletDO;
import com.mzl.flower.entity.wallet.WalletWithdrawRecordDO;
import com.mzl.flower.mapper.wallet.WalletWithdrawRecordMapper;
import com.mzl.flower.service.supplier.SupplierService;
import com.mzl.flower.service.wallet.WalletService;
import com.mzl.flower.service.wallet.WalletWithdrawRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author @TaoJie
 * @since 2024-10-22
 */
@Service
public class WalletWithdrawRecordServiceImpl extends ServiceImpl<WalletWithdrawRecordMapper, WalletWithdrawRecordDO> implements WalletWithdrawRecordService {
    @Autowired
    private WalletService walletService;
 
    @Autowired
    private SupplierService supplierService;
 
    @Transactional
    @Override
    public boolean create(CreateWalletWithdrawRecordDTO dto) {
        SupplierDTO supplierDTO=supplierService.getCurrentSupplier();
        if(null==supplierDTO){
            throw new ValidationException("供应商不能为空");
        }
 
        final WalletDO walletDO = walletService.getBySupplierId(supplierDTO.getId());
        if(null==walletDO){
            throw new ValidationException("钱包不能为空");
        }
        // 查看钱包的金额是不是大于要提现的金额
        if(null!=walletDO.getWithdrawableAmount() && null!=dto.getAmount()
                && walletDO.getWithdrawableAmount().compareTo(dto.getAmount())<0){
            throw new ValidationException("钱包金额不足");
        }
        WalletWithdrawRecordDO withdrawRecordDO=new WalletWithdrawRecordDO();
        withdrawRecordDO.setAmount(dto.getAmount());
        withdrawRecordDO.setSupplierId(supplierDTO.getId());
        withdrawRecordDO.setWithdrawState(Constants.WALLET_WITHDRAW_STATE.WAITING.name());
        withdrawRecordDO.setMethod(Constants.WALLET_WITHDRAW_METHOD.WEIXIN.name());
        withdrawRecordDO.create(SecurityUtils.getUserId());
 
        return save(withdrawRecordDO);
 
    }
}