|
@@ -2,19 +2,10 @@ package com.qs.mp.user.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.qs.mp.admin.domain.Goods;
|
|
|
-import com.qs.mp.admin.domain.Ticket;
|
|
|
import com.qs.mp.admin.domain.TicketBox;
|
|
|
-import com.qs.mp.admin.domain.TicketBoxGoods;
|
|
|
-import com.qs.mp.admin.domain.param.IndexTicketBoxTopQueryParam;
|
|
|
-import com.qs.mp.admin.domain.param.IndexTicketSiteTopQueryParam;
|
|
|
-import com.qs.mp.admin.domain.param.TicketBoxGrossProfitParam;
|
|
|
import com.qs.mp.admin.domain.vo.*;
|
|
|
import com.qs.mp.admin.service.*;
|
|
|
import com.qs.mp.channel.domain.*;
|
|
@@ -27,9 +18,6 @@ import com.qs.mp.common.enums.*;
|
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
|
import com.qs.mp.common.utils.DateUtils;
|
|
|
import com.qs.mp.common.utils.LogUtil;
|
|
|
-import com.qs.mp.common.utils.RSAUtil;
|
|
|
-import com.qs.mp.common.utils.StringUtils;
|
|
|
-import com.qs.mp.framework.redis.RedisKey;
|
|
|
import com.qs.mp.framework.redis.RedisLockKey;
|
|
|
import com.qs.mp.framework.service.IAsyncTaskService;
|
|
|
import com.qs.mp.pay.domain.PayOrder;
|
|
@@ -39,7 +27,6 @@ import com.qs.mp.system.service.id.BizIdGenerator;
|
|
|
import com.qs.mp.user.domain.*;
|
|
|
import com.qs.mp.user.domain.vo.*;
|
|
|
import com.qs.mp.user.mapper.GroupBuyingOrderMapper;
|
|
|
-import com.qs.mp.user.mapper.UserTicketOrderMapper;
|
|
|
import com.qs.mp.user.service.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -53,7 +40,6 @@ import org.springframework.util.Assert;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
@@ -80,15 +66,6 @@ public class UserGroupOrderServiceImpl extends
|
|
|
@Autowired
|
|
|
private IChannelUserRelService channelUserRelService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private IChannelOrderDetailService channelOrderDetailService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IUserTicketOrderItemService userTicketOrderItemService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ITicketService ticketService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IChannelService channelService;
|
|
|
|
|
@@ -105,24 +82,6 @@ public class UserGroupOrderServiceImpl extends
|
|
|
@Autowired
|
|
|
private DistributedLocker distributedLocker;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ITicketBoxGoodsService ticketBoxGoodsService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IUserPrizeStorageService userPrizeStorageService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IGoodsService goodsService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ICouponService couponService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ICouponPkgService couponPkgService;
|
|
|
-
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IPromoterUserService promoterUserService;
|
|
|
|
|
|
@Autowired
|
|
|
private IGroupBuyingService groupBuyingService;
|
|
@@ -133,6 +92,10 @@ public class UserGroupOrderServiceImpl extends
|
|
|
private IUserAddrService userAddrService;
|
|
|
@Autowired
|
|
|
private ISysUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private IChannelMoneyLogService channelMoneyLogService;
|
|
|
+ @Autowired
|
|
|
+ private IChannelCommissionService channelCommissionService;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -158,6 +121,20 @@ public class UserGroupOrderServiceImpl extends
|
|
|
if (!distributedLocker.tryLock(groupUserKey, 3, -1, TimeUnit.SECONDS)) {
|
|
|
throw new ServiceException("拼团活动太火爆了,请稍后重试!");
|
|
|
}
|
|
|
+
|
|
|
+ if(groupBuyingGroup.getGroupStatus().equals(GroupingStatusEnum.END.getValue())){
|
|
|
+ throw new ServiceException("拼团以开奖!");
|
|
|
+ }
|
|
|
+ if(groupBuyingGroup.getGroupStatus().equals(GroupingStatusEnum.CLOSE.getValue())){
|
|
|
+ throw new ServiceException("拼团以结束!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!checkBuying(groupBuying)) {
|
|
|
+ throw new ServiceException("活动已经过期,下次早点来哦!");
|
|
|
+ }
|
|
|
+ if(groupBuying.getIsPutaway() == 1){
|
|
|
+ throw new ServiceException("活动已下架!");
|
|
|
+ }
|
|
|
if(orderSettleVO.getGroupType() == 1){
|
|
|
if(ObjectUtil.isNotEmpty(redisCache.getCacheObject(key))){
|
|
|
int count = redisCache.getCacheObject(key);
|
|
@@ -216,6 +193,21 @@ public class UserGroupOrderServiceImpl extends
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 校验活动是否过期
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean checkBuying(GroupBuying groupBuying){
|
|
|
+ Date now = new Date();
|
|
|
+ Date start = groupBuying.getStartTime();
|
|
|
+ Date end = groupBuying.getEndTime();
|
|
|
+ if(now.compareTo(start) >= 0 || now.compareTo(end) <= 0){
|
|
|
+ return true;
|
|
|
+ }else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean batchCancelOrder(String boxId, List<String> orderIds) {
|
|
|
return false;
|
|
@@ -252,6 +244,7 @@ public class UserGroupOrderServiceImpl extends
|
|
|
groupBuyingOrder.setPrizeQuantity(orderSettleVO.getPrizeQuantity());
|
|
|
groupBuyingOrder.setPrizeType(orderSettleVO.getPrizeType());
|
|
|
groupBuyingOrder.setPayAmt(orderSettleVO.getOrderAmt());
|
|
|
+ groupBuyingOrder.setGroupType(orderSettleVO.getGroupType());
|
|
|
|
|
|
if (orderSettleVO.getOrderAmt() == 0) {
|
|
|
groupBuyingOrder.setCommStatus(CommStatusEnum.YES.getValue()); // 无需结佣,直接置为已结佣
|
|
@@ -315,11 +308,189 @@ public class UserGroupOrderServiceImpl extends
|
|
|
|
|
|
@Override
|
|
|
public boolean paySuccess(PayOrder payOrder) {
|
|
|
- return false;
|
|
|
+ GroupBuyingOrder buyingOrder = getOne(new LambdaQueryWrapper<GroupBuyingOrder>()
|
|
|
+ .eq(GroupBuyingOrder::getOrderId,payOrder.getBizId())
|
|
|
+ );
|
|
|
+ if (null == buyingOrder || buyingOrder.getStatus() != UserTicketOrderStatusEnum.NOT_PAY.getValue()) {
|
|
|
+ LogUtil.error(logger, "支付回调用户购票订单处理,订单状态异常,不是待支付。payOrder:{0}, ticketOrder:{1}",
|
|
|
+ JSONObject.toJSONString(payOrder), JSONObject.toJSONString(buyingOrder));
|
|
|
+ //回退次数
|
|
|
+ backGroup(buyingOrder);
|
|
|
+ throw new ServiceException("支付回调用户购票订单处理,订单状态异常,不是待支付。orderId:" + payOrder.getBizId());
|
|
|
+
|
|
|
+ }
|
|
|
+ buyingOrder.setPayTime(DateUtils.parseDate(payOrder.getCompleteDate()));
|
|
|
+ buyingOrder.setPayType(payOrder.getPayResource());
|
|
|
+
|
|
|
+ // 插入异步任务
|
|
|
+ Assert.isTrue(asyncTaskService.insertAsyncTask(AsyncTaskTypeEnum.TICKET_PAY, payOrder.getBizId()),
|
|
|
+ "创建支付成功异步任务失败. orderId:" + payOrder.getOrderId());
|
|
|
+ //todo 处理开团发奖逻辑
|
|
|
+ //return processTicketOrder(ticketOrder);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付回调失败,回退锁定次数
|
|
|
+ */
|
|
|
+ public boolean backGroup(GroupBuyingOrder buyingOrder){
|
|
|
+ String key = RedisLockKey.build(RedisLockKey.USER_INITIATE_GROUP_LOCK,buyingOrder.getGroupbuyingId(),buyingOrder.getUserId());
|
|
|
+ String groupUserKey = RedisLockKey.build(RedisLockKey.USER_JOIN_GROUP_LOCK,buyingOrder.getGroupbuyingId(),buyingOrder.getUserId());
|
|
|
+ if (!distributedLocker.tryLock(key, 3, -1, TimeUnit.SECONDS)) {
|
|
|
+ throw new ServiceException("拼团活动太火爆了,请稍后重试!");
|
|
|
+ }
|
|
|
+ if (!distributedLocker.tryLock(groupUserKey, 3, -1, TimeUnit.SECONDS)) {
|
|
|
+ throw new ServiceException("拼团活动太火爆了,请稍后重试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //发起拼团,更新用户剩余拼团次数
|
|
|
+ if(buyingOrder.getGroupType() == 1){
|
|
|
+ redisCache.increment(key,1);
|
|
|
+ redisCache.increment(groupUserKey,1);
|
|
|
+ }
|
|
|
+ //参与拼团,更新用户参团次数
|
|
|
+ if(buyingOrder.getGroupType() == 2){
|
|
|
+ redisCache.increment(groupUserKey,1);
|
|
|
+ }
|
|
|
+ }finally {
|
|
|
+ distributedLocker.unlock(key);
|
|
|
+ distributedLocker.unlock(groupUserKey);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean commToChannel(String orderId, Integer resource) {
|
|
|
- return false;
|
|
|
+ ChannelCommParam channelCommParam = new ChannelCommParam();
|
|
|
+ GroupBuyingOrder buyingOrder = getOne(new LambdaQueryWrapper<GroupBuyingOrder>()
|
|
|
+ .eq(GroupBuyingOrder::getOrderId,orderId)
|
|
|
+ );
|
|
|
+ if (ChannelCommissionResourceEnum.USER.getValue().equals(resource)) {
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(buyingOrder, channelCommParam);
|
|
|
+ Assert.isTrue(channelCommParam.getCommStatus() != CommStatusEnum.YES,
|
|
|
+ "结佣处理,结佣状态异常,不是结佣中或未结佣。orderId=" + orderId);
|
|
|
+
|
|
|
+ // 判断线上票判断渠道商是否打标,打标则不分佣
|
|
|
+ if (TicketTypeEnum.ONLINE.equals(buyingOrder.getResource())) {
|
|
|
+ if (buyingOrder.getChannelId() != null) {
|
|
|
+ Channel channel = channelService.getById(buyingOrder.getChannelId());
|
|
|
+ if (channel.getCommFlag() == 1) {
|
|
|
+ // 不分佣,更新订单状态
|
|
|
+ boolean rst = update(
|
|
|
+ new LambdaUpdateWrapper<GroupBuyingOrder>().set(GroupBuyingOrder::getCommStatus,
|
|
|
+ CommStatusEnum.NO_COMM)
|
|
|
+ .eq(GroupBuyingOrder::getOrderId, orderId)
|
|
|
+ .in(GroupBuyingOrder::getCommStatus, CommStatusEnum.DOING, CommStatusEnum.NO));
|
|
|
+ Assert.isTrue(rst, "定制渠道不结佣,更新订单状态失败。orderId:" + orderId);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (channelCommParam.getPayAmt() == 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (null != channelCommParam.getChannelId()) {
|
|
|
+ // 推广员的分佣
|
|
|
+ int promoterCommAmt = 0;
|
|
|
+ // 如果有推广员则先给推广员分佣
|
|
|
+ if (channelCommParam.getPromoterId() != null && channelCommParam.getPromoterId() > 0) {
|
|
|
+ Channel promoter = channelService.getById(channelCommParam.getPromoterId());
|
|
|
+ if (promoter != null) {
|
|
|
+ ChannelCommission siteCommission = saveSiteCommAmt(channelCommParam, buyingOrder, promoter, promoterCommAmt);
|
|
|
+ promoterCommAmt = siteCommission.getCommAmt();
|
|
|
+ // 推广员账户余额增加
|
|
|
+ changeMoney(promoter, siteCommission);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 给门店分佣
|
|
|
+ Channel channel = channelService.getById(channelCommParam.getChannelId());
|
|
|
+ ChannelCommission siteCommission = saveSiteCommAmt(channelCommParam, buyingOrder, channel, promoterCommAmt);
|
|
|
+ // 经销商账户余额增加
|
|
|
+ changeMoney(channel, siteCommission);
|
|
|
+
|
|
|
+ int sumCommAmt = siteCommission.getCommAmt() + promoterCommAmt;
|
|
|
+ // 渠道分润
|
|
|
+ while (channel.getParentId() > 0) {
|
|
|
+ channel = channelService.getById(channel.getParentId());
|
|
|
+ ChannelCommission channelCommission = new ChannelCommission();
|
|
|
+ channelCommission.setChannelId(channel.getChannelId());
|
|
|
+ channelCommission.setOrderId(siteCommission.getOrderId());
|
|
|
+ channelCommission.setResource(resource);
|
|
|
+ channelCommission.setBoxId(siteCommission.getBoxId());
|
|
|
+ channelCommission.setSaleAmt(siteCommission.getSaleAmt());
|
|
|
+ channelCommission.setSaleCommRate(siteCommission.getSaleCommRate());
|
|
|
+ channelCommission.setSaleCommAmt(siteCommission.getSaleCommAmt());
|
|
|
+ channelCommission.setCommRate(channel.getCommRate());
|
|
|
+ channelCommission.setCommAmt(new BigDecimal(channelCommission.getSaleCommAmt()).multiply(
|
|
|
+ channelCommission.getCommRate()).divide(new BigDecimal(100), 0, RoundingMode.DOWN)
|
|
|
+ .intValue() - sumCommAmt);
|
|
|
+ channelCommissionService.save(channelCommission);
|
|
|
+ sumCommAmt += channelCommission.getCommAmt();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LogUtil.info(logger, "渠道结佣时,订单对应的渠道不存在,无需结佣。orderId:{0}",
|
|
|
+ channelCommParam.getOrderId());
|
|
|
+ }
|
|
|
+ if (ChannelCommissionResourceEnum.USER.getValue().equals(resource)) {
|
|
|
+ boolean rst = update(
|
|
|
+ new LambdaUpdateWrapper<GroupBuyingOrder>().set(GroupBuyingOrder::getCommStatus,
|
|
|
+ CommStatusEnum.YES)
|
|
|
+ .eq(GroupBuyingOrder::getOrderId, orderId)
|
|
|
+ .in(GroupBuyingOrder::getCommStatus, CommStatusEnum.DOING, CommStatusEnum.NO));
|
|
|
+ Assert.isTrue(rst, "渠道结佣完成,更新订单状态失败。orderId:" + orderId);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changeMoney(Channel channel, ChannelCommission siteCommission) {
|
|
|
+ ChannelMoneyLog moneyLog = new ChannelMoneyLog();
|
|
|
+ moneyLog.setChannelId(channel.getChannelId());
|
|
|
+ moneyLog.setType(ChannelMoneyEnum.COMMISSION);
|
|
|
+ moneyLog.setLogMoney(siteCommission.getCommAmt());
|
|
|
+ moneyLog.setBizTime(new Date());
|
|
|
+ moneyLog.setRefId(String.valueOf(siteCommission.getId()));
|
|
|
+ channelMoneyLogService.changeMoney(moneyLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ChannelCommission saveSiteCommAmt(ChannelCommParam channelCommParam, TicketBox ticketBox,
|
|
|
+ Channel channel, int sumCommAmt) {
|
|
|
+ ChannelCommission siteCommission = new ChannelCommission();
|
|
|
+ siteCommission.setChannelId(channel.getChannelId());
|
|
|
+ siteCommission.setOrderId(channelCommParam.getOrderId());
|
|
|
+ siteCommission.setBoxId(channelCommParam.getBoxId());
|
|
|
+ siteCommission.setSaleAmt(channelCommParam.getPayAmt());
|
|
|
+ siteCommission.setSaleCommRate(ticketBox.getSaleCommRate());
|
|
|
+ siteCommission.setSaleCommAmt(new BigDecimal(siteCommission.getSaleAmt()).multiply(
|
|
|
+ siteCommission.getSaleCommRate()).divide(new BigDecimal(100), 0, RoundingMode.DOWN)
|
|
|
+ .intValue());
|
|
|
+ siteCommission.setCommRate(channel.getCommRate());
|
|
|
+ siteCommission.setCommAmt(new BigDecimal(siteCommission.getSaleCommAmt()).multiply(
|
|
|
+ siteCommission.getCommRate()).divide(new BigDecimal(100), 0, RoundingMode.DOWN).intValue() - sumCommAmt);
|
|
|
+ channelCommissionService.save(siteCommission);
|
|
|
+ return siteCommission;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ChannelCommission saveSiteCommAmt(ChannelCommParam channelCommParam, GroupBuyingOrder groupBuyingOrder,
|
|
|
+ Channel channel, int sumCommAmt) {
|
|
|
+ ChannelCommission siteCommission = new ChannelCommission();
|
|
|
+ siteCommission.setChannelId(channel.getChannelId());
|
|
|
+ siteCommission.setOrderId(channelCommParam.getOrderId());
|
|
|
+ siteCommission.setBoxId(channelCommParam.getBoxId());
|
|
|
+ siteCommission.setSaleAmt(channelCommParam.getPayAmt());
|
|
|
+ siteCommission.setSaleCommRate(groupBuyingOrder.getSaleCommRate());
|
|
|
+ siteCommission.setSaleCommAmt(new BigDecimal(siteCommission.getSaleAmt()).multiply(
|
|
|
+ siteCommission.getSaleCommRate()).divide(new BigDecimal(100), 0, RoundingMode.DOWN)
|
|
|
+ .intValue());
|
|
|
+ siteCommission.setCommRate(channel.getCommRate());
|
|
|
+ siteCommission.setCommAmt(new BigDecimal(siteCommission.getSaleCommAmt()).multiply(
|
|
|
+ siteCommission.getCommRate()).divide(new BigDecimal(100), 0, RoundingMode.DOWN).intValue() - sumCommAmt);
|
|
|
+ channelCommissionService.save(siteCommission);
|
|
|
+ return siteCommission;
|
|
|
}
|
|
|
}
|