Administrator
2025-02-09 696a46908ba2e824dacb115377ed14d44857b307
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
package com.taoke.autopay.manager;
 
import com.taoke.autopay.entity.OrderChannelEnum;
import com.taoke.autopay.entity.OrderCountTypeEnum;
import com.taoke.autopay.exception.KeyOrderException;
import com.taoke.autopay.service.UserSettingService;
import com.taoke.autopay.service.WxUserOrderCountService;
import com.taoke.autopay.utils.Constant;
import com.taoke.autopay.utils.TimeUtil;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * 支付次数管理器
 */
@Component
public class PayCountVerifyManager {
 
    @Resource
    private WxUserOrderCountService wxUserOrderCountService;
 
    @Resource
    private UserSettingService userSettingService;
 
    /**
     *  验证支付次数
     * @param uid
     * @param orderType
     * @param orderChannel
     * @throws Exception
     */
    public void verifyPayCount(long uid, int orderType, OrderChannelEnum orderChannel) throws KeyOrderException {
        OrderCountTypeEnum orderCountType=null;
        if(orderType== Constant.ORDER_TYPE_DY){
            orderCountType=OrderCountTypeEnum.DY_ORDER_PAY;
        }else if(orderType==Constant.ORDER_TYPE_KS){
            orderCountType=OrderCountTypeEnum.KS_ORDER_PAY;
        }
        long todayCount = wxUserOrderCountService.sum(uid, orderCountType, orderChannel, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT));
        long totalCount = wxUserOrderCountService.sum(uid, orderCountType, null, null);
        int maxPayCount = userSettingService.getLimitCountByTotalCount(orderType, totalCount, orderChannel);
        if (todayCount >= maxPayCount) {
            throw new KeyOrderException(String.format("老铁今日已达支付次数(%s)上限:%s", orderChannel.getName(), maxPayCount));
        }
    }
 
 
}