bug
jiangqs
2023-09-11 3adbcc42d5f84c3c83d220543189361add81e04d
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
package com.ruoyi.order.service.impl.account;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.binarywang.wxpay.bean.ecommerce.ProfitSharingResult;
import com.ruoyi.order.domain.pojo.account.ProfitSharing;
import com.ruoyi.order.mapper.account.ProfitSharingMapper;
import com.ruoyi.order.service.account.ProfitSharingService;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
 
/**
 * <p>
 * 分账 服务实现类
 * </p>
 *
 * @author jqs
 * @since 2023-06-02
 */
@Service
public class ProfitSharingServiceImpl extends ServiceImpl<ProfitSharingMapper, ProfitSharing> implements ProfitSharingService {
 
    @Override
    public void saveProfitSharing(Long shopId, String orderId, BigDecimal orderMoney, ProfitSharingResult result) {
        ProfitSharing profitSharing = new ProfitSharing();
        profitSharing.setShareId(result.getOutOrderNo());
        profitSharing.setDelFlag(0);
        profitSharing.setShareStatus("FINISHED".equals(result.getStatus()) ? 2 : 1);
        profitSharing.setShopId(shopId);
        profitSharing.setOrderId(orderId);
        profitSharing.setOrderMoney(orderMoney);
 
        List<ProfitSharingResult.Receiver> receivers = result.getReceivers();
        if(null != receivers && !receivers.isEmpty()){
            ProfitSharingResult.Receiver receiver = receivers.get(0);
            profitSharing.setReceiverAccount(receiver.getReceiverMchid());
            BigDecimal receiverAmount = new BigDecimal(receiver.getAmount());
            receiverAmount = receiverAmount.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
            profitSharing.setReceiverAmount(receiverAmount);
            profitSharing.setSurpMoney(orderMoney.subtract(receiverAmount));
            profitSharing.setReceiverDescription(receiver.getDescription());
            profitSharing.setFinishFlag(0);
            profitSharing.setFailReason(receiver.getFailReason());
            profitSharing.setDetailId(receiver.getDetailId());
        }
        profitSharing.setCreateTime(new Date());
 
        this.saveOrUpdate(profitSharing);
    }
 
    /**
     * @description  通过订单id获取
     * @author  jqs
     * @date    2023/9/8 10:34
     * @param orderId
     * @return  ProfitSharing
     */
    @Override
    public ProfitSharing getByOrderId(String orderId){
        LambdaQueryWrapper<ProfitSharing> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProfitSharing::getDelFlag,0);
        queryWrapper.eq(ProfitSharing::getOrderId,orderId);
        return this.getOne(queryWrapper,false);
    }
}