puzhibing
2023-11-06 029d0af8d3e0d32dbfff8dc47fb5e997332bc01d
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
package com.ruoyi.order.service.impl.account;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.utils.uuid.IdUtils;
import com.ruoyi.order.domain.pojo.account.OrderPayment;
import com.ruoyi.order.mapper.account.OrderPaymentMapper;
import com.ruoyi.order.service.account.OrderPaymentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.Date;
 
/**
 * <p>
 * 订单支付 服务实现类
 * </p>
 *
 * @author jqs
 * @since 2023-06-02
 */
@Service
public class OrderPaymentServiceImpl extends ServiceImpl<OrderPaymentMapper, OrderPayment> implements OrderPaymentService {
 
    @Override
    public void saveOrderPayment(Long userId, Long shopId, String subMchId, String orderId, String outTradeNo, BigDecimal payMoney, Date endTime,
                                 String profitSharing, String openid, String goodsNames, String prepayId) {
        OrderPayment payment = new OrderPayment();
        payment.setPaymentId(IdUtils.simpleUUID());
        payment.setUserId(userId);
        payment.setShopId(shopId);
        payment.setOrderId(orderId);
        payment.setPayMoney(payMoney);
        payment.setTimeExpire(endTime);
        payment.setSubMchId(subMchId);
        payment.setOutTradeNo(outTradeNo);
        payment.setPayStatus(1);
        // 0 否 1、是
        payment.setProfitSharing("Y".equals(profitSharing) ? 1 : 0);
        payment.setUserOpenId(openid);
        payment.setGoodsNames(goodsNames);
        payment.setPrepayId(prepayId);
        payment.setCreateTime(new Date());
        payment.setDelFlag(0);
        this.saveOrUpdate(payment);
    }
 
    @Override
    public OrderPayment getByOrderId(String orderId) {
        LambdaQueryWrapper<OrderPayment> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(OrderPayment::getOrderId, orderId)
                .eq(OrderPayment::getDelFlag, 0)
                .eq(OrderPayment::getPayStatus, 2)
                .last(" limit 1 ");
        return this.getOne(queryWrapper);
    }
 
    @Override
    public OrderPayment getByUnpaidOrderId(String orderId) {
        LambdaQueryWrapper<OrderPayment> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(OrderPayment::getOrderId, orderId)
                .eq(OrderPayment::getDelFlag, 0)
                .eq(OrderPayment::getPayStatus, 1)
                .last(" limit 1 ");
        return this.getOne(queryWrapper);
    }
 
    @Override
    public void updatePaySuccess(String outTradeNo, BigDecimal feeAmount, String transactionId) {
        LambdaUpdateWrapper<OrderPayment> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(OrderPayment::getOutTradeNo, outTradeNo)
                .set(OrderPayment::getPayStatus, 2)
                .set(OrderPayment::getTransactionId, transactionId)
                .set(OrderPayment::getFeeAmount, feeAmount)
                .set(OrderPayment::getBackTime, new Date());
        this.update(updateWrapper);
    }
}