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));
|
}
|
}
|
|
|
}
|