...
|
...
|
@@ -38,10 +38,12 @@ import com.yoho.core.redis.YHValueOperations; |
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.lottery.dal.LotteryMapper;
|
|
|
import com.yoho.lottery.dal.LotteryPrizeMapper;
|
|
|
import com.yoho.lottery.dal.LotteryRecordMapper;
|
|
|
import com.yoho.lottery.dal.PrizeMapper;
|
|
|
import com.yoho.lottery.dal.WeixinBindPrizeMapper;
|
|
|
import com.yoho.lottery.dal.model.Lottery;
|
|
|
import com.yoho.lottery.dal.model.LotteryPrize;
|
|
|
import com.yoho.lottery.dal.model.LotteryRecord;
|
|
|
import com.yoho.lottery.dal.model.Prize;
|
|
|
import com.yoho.lottery.dal.model.WeixinBindPrize;
|
...
|
...
|
@@ -52,6 +54,8 @@ import com.yoho.service.model.order.response.OrderInfoResponse; |
|
|
import com.yoho.service.model.order.response.OrderQueryForLotteryResponse;
|
|
|
import com.yoho.service.model.order.response.Orders;
|
|
|
import com.yoho.service.model.order.response.OrdersGoods;
|
|
|
import com.yoho.service.model.request.UserBaseReqBO;
|
|
|
import com.yoho.service.model.response.UserBaseRspBO;
|
|
|
|
|
|
@Service
|
|
|
public class LotteryServiceImpl implements ILotteryService , ApplicationContextAware {
|
...
|
...
|
@@ -98,6 +102,9 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA |
|
|
|
|
|
@Resource
|
|
|
private WeixinBindPrizeMapper weixinBindPrizeMapper;
|
|
|
|
|
|
@Resource
|
|
|
private LotteryPrizeMapper lotteryPrizeMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SendCouponHelper sendCouponHelper;
|
...
|
...
|
@@ -134,6 +141,18 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA |
|
|
data.setPrizes(prize);
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Cacheable(expireTime = CacheKeyAndTime.LOTTERY_PRIZE_INTO)
|
|
|
public LotteryRespData getLotteryPrizeInfo(Integer lotteryId, int startIndex, int length) {
|
|
|
|
|
|
LotteryRespData data = new LotteryRespData();
|
|
|
Lottery lottery = lotteryMapper.selectByPrimaryKey(lotteryId);
|
|
|
checkLottery(lotteryId, lottery);
|
|
|
List<LotteryPrize> prize = lotteryPrizeMapper.selectPrize(lotteryId, startIndex, length);
|
|
|
data.setLotteryPrize(prize);
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public LotteryRespData getOrderLotteryState(Integer lotteryId, Integer userId, String orderCode) {
|
...
|
...
|
@@ -198,7 +217,8 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA |
|
|
state.setOrderLotteryMessage(MSG_MULTI);
|
|
|
return state;
|
|
|
}
|
|
|
|
|
|
// 设置过期时间:4秒防止发生异常情况后永久阻塞
|
|
|
yhRedisTemplate.expire(lockKey, 4, TimeUnit.SECONDS);
|
|
|
|
|
|
// 查询抽奖统计信息
|
|
|
/*List<LotteryPrizeInfo> lotteryPrizeInfo = lotteryRecordMapper.selectLotteryPrizeInfo(lotteryId, userId % 10);
|
...
|
...
|
@@ -277,6 +297,24 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA |
|
|
logger.warn("错误的奖品id:活动id{} 奖品id{}", lotteryId, prizeId);
|
|
|
return savePrizeAndGetResp(lotteryId, userId, orderCode, null);
|
|
|
}
|
|
|
|
|
|
// 订单金额
|
|
|
BigDecimal orderMoney = getOrderMoney(userId, orderCode);
|
|
|
// 异常情况
|
|
|
if (orderMoney.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
logger.warn("订单金额异常为0,设置未中奖!");
|
|
|
return savePrizeAndGetResp(lotteryId, userId, orderCode, null);
|
|
|
}
|
|
|
|
|
|
// 金额大于300的不可以抽中面单奖
|
|
|
if (StringUtils.equals(prize.getPrizeType(), "orderyohocoin")) {
|
|
|
BigDecimal maxMoney = new BigDecimal("300");
|
|
|
if (orderMoney.compareTo(maxMoney) > 0) {
|
|
|
logger.warn("订单金额为{},大于300不可以中免单奖,设置未中奖!", orderMoney);
|
|
|
return savePrizeAndGetResp(lotteryId, userId, orderCode, null);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int update = 0;
|
|
|
if (prize.getRemain() > 0) {
|
|
|
// 更新剩余奖品
|
...
|
...
|
@@ -350,6 +388,20 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA |
|
|
logger.info("用户{}的订单{}抽到奖项{},进行发奖!", userId, orderCode, prize);
|
|
|
executor.execute(() -> {
|
|
|
try {
|
|
|
UserBaseRspBO userInfo = lotteryService.getUserInfo(userId);
|
|
|
|
|
|
// 记录中奖统计记录
|
|
|
LotteryPrize bean = new LotteryPrize();
|
|
|
bean.setLotteryId(prize.getLotteryId());
|
|
|
bean.setUserId(userId);
|
|
|
bean.setUserName(userInfo.getNickname());
|
|
|
bean.setOrderCode(orderCode);
|
|
|
bean.setPrizeId(prize.getId());
|
|
|
bean.setPrizeName(prize.getName());
|
|
|
bean.setPrizeRemark(prize.getRemark());
|
|
|
bean.setCreateTime((int) (System.currentTimeMillis() / 1000));
|
|
|
lotteryPrizeMapper.insert(bean);
|
|
|
|
|
|
if ("coupons".equals(prize.getPrizeType())) {
|
|
|
sendCouponHelper.sendCoupon(prize.getPrizeValue(), userId);
|
|
|
}
|
...
|
...
|
@@ -487,6 +539,20 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA |
|
|
throw e;
|
|
|
}
|
|
|
}
|
|
|
@Override
|
|
|
@Cacheable(expireTime = CacheKeyAndTime.LOTTERY_USER_INFO)
|
|
|
public UserBaseRspBO getUserInfo(Integer userId) {
|
|
|
try {
|
|
|
UserBaseReqBO req = new UserBaseReqBO();
|
|
|
req.setUid(userId);
|
|
|
UserBaseRspBO rsp = serviceCaller.call("users.selectUserBaseInfo", req, UserBaseRspBO.class);
|
|
|
logger.info("获得用户信息:{}", rsp);
|
|
|
return rsp;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("获取用户信息失败!uid={} orderCode={}! msg={}", userId, e.getMessage());
|
|
|
throw e;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<LotteryOrderVO> setLotteryOrderStatus(List<LotteryOrderVO> orderVOList, List<LotteryRecord> recordList){
|
|
|
for (LotteryOrderVO orderVO : orderVOList) {
|
...
|
...
|
|