瀏覽代碼

feature: 分佣

liufeng 1 年之前
父節點
當前提交
aa1f02ead1

+ 1 - 1
mp-common/src/main/java/com/qs/mp/common/enums/GroupingStatusEnum.java

@@ -19,7 +19,7 @@ public enum GroupingStatusEnum implements IEnum<Integer> {
 
     START(0,"进行中"),
 
-    END(1,"已结束");
+    END(1,"已完成");
 
     private Integer value;
     private String desc;

+ 4 - 0
mp-service/src/main/java/com/qs/mp/admin/domain/vo/GroupBuyingOrder.java

@@ -91,6 +91,10 @@ public class GroupBuyingOrder implements Serializable {
     @TableId(value = "pay_type")
     private String payType;
 
+    @ApiModelProperty("拼团类型,1: 发起拼团,2:参与拼团")
+    @TableId(value = "pay_type")
+    private int groupType;
+
     @ApiModelProperty("支付时间")
     @TableId(value = "pay_time")
     private Date payTime;

+ 6 - 0
mp-service/src/main/java/com/qs/mp/framework/service/IAsyncTaskService.java

@@ -34,6 +34,12 @@ public interface IAsyncTaskService extends IService<AsyncTask> {
      */
     void ticketPay(AsyncTask asyncTask);
 
+    /**
+     * 拼团支付相关任务处理
+     * @param asyncTask
+     */
+    void groupPay(AsyncTask asyncTask);
+
     /**
      * 盲票生成相关任务处理
      * @param asyncTask

+ 65 - 12
mp-service/src/main/java/com/qs/mp/framework/service/impl/AsyncTaskServiceImpl.java

@@ -5,6 +5,9 @@ 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.qs.mp.admin.domain.*;
+import com.qs.mp.admin.domain.vo.GroupBuying;
+import com.qs.mp.admin.domain.vo.GroupBuyingGroup;
+import com.qs.mp.admin.domain.vo.GroupBuyingOrder;
 import com.qs.mp.admin.service.*;
 import com.qs.mp.channel.domain.ChannelOrder;
 import com.qs.mp.channel.service.IChannelOrderService;
@@ -24,15 +27,10 @@ import com.qs.mp.user.domain.UserDeliverOrderItem;
 import com.qs.mp.user.domain.UserDeliverOrderItemCard;
 import com.qs.mp.user.domain.UserTicketOrder;
 import com.qs.mp.user.domain.UserTicketOrderItem;
-import com.qs.mp.user.service.IUserDeliverOrderItemCardService;
-import com.qs.mp.user.service.IUserDeliverOrderItemService;
-import com.qs.mp.user.service.IUserDeliverOrderService;
-import com.qs.mp.user.service.IUserHitPrizeService;
-import com.qs.mp.user.service.IUserPrizeStorageService;
-import com.qs.mp.user.service.IUserTicketOrderItemService;
-import com.qs.mp.user.service.IUserTicketOrderService;
-import java.util.ArrayList;
-import java.util.Date;
+import com.qs.mp.user.service.*;
+
+import java.time.LocalDateTime;
+import java.util.*;
 import java.util.stream.Collectors;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,9 +38,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.List;
-import java.util.Objects;
-
 /**
  * <p>
  *  服务实现类
@@ -114,6 +109,14 @@ public class AsyncTaskServiceImpl extends ServiceImpl<AsyncTaskMapper, AsyncTask
     @Autowired
     private ICdKeyGroupService  cdKeyGroupService;
 
+    @Autowired
+    private IUserGroupOrderService userGroupOrderService;
+
+    @Autowired
+    private IGroupBuyingService groupBuyingService;
+    @Autowired
+    private IGroupBuyingGroupService groupBuyingGroupService;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean insertAsyncTask(AsyncTaskTypeEnum taskType, String bizId) {
@@ -186,6 +189,56 @@ public class AsyncTaskServiceImpl extends ServiceImpl<AsyncTaskMapper, AsyncTask
 
     }
 
+    @Override
+    public void groupPay(AsyncTask asyncTask) {
+        String orderId = asyncTask.getBizId();
+        GroupBuyingOrder buyingOrder = userGroupOrderService.getOne(new LambdaQueryWrapper<GroupBuyingOrder>()
+                .eq(GroupBuyingOrder::getOrderId,orderId)
+        );
+        GroupBuying groupBuying = groupBuyingService.getById(buyingOrder.getGroupbuyingId());
+
+        SysUser sysUser = sysUserService.getById(buyingOrder.getUserId());
+        //1: 发起拼团,2:参与拼团
+        //生成开团信息
+        if(buyingOrder.getGroupType() == 1){
+            //生成开团信息
+            GroupBuyingGroup groupBuyingGroup = new GroupBuyingGroup();
+            groupBuyingGroup.setGroupbuyingId(groupBuying.getId());
+            groupBuyingGroup.setGroupStatus(GroupingStatusEnum.START.getValue());
+            groupBuyingGroup.setStartgroupuser(buyingOrder.getUserId());
+            groupBuyingGroup.setStartGroupUserMobile(Long.valueOf(sysUser.getPhonenumber()));
+            groupBuyingGroup.setPartinIds(String.valueOf(sysUser.getUserId()));
+            groupBuyingGroup.setPartinNum(1);
+            Integer effectiveTime = groupBuying.getGroupEffectiveTime();
+            //获取当前时间
+            LocalDateTime now = LocalDateTime.now();
+            //当前时间+加上拼团有效期
+            now.plusSeconds(effectiveTime);
+            groupBuyingGroup.setGroupEndTime(DateUtils.localDateTime2Date(now));
+            groupBuyingGroupService.save(groupBuyingGroup);
+        }else {
+            //更新团信息
+            GroupBuyingGroup groupBuyingGroup = groupBuyingGroupService.getById(buyingOrder.getGroupId());
+            List<String> ids = Arrays.asList(groupBuyingGroup.getPartinIds().split(","));
+            ids.add(String.valueOf(buyingOrder.getUserId()));
+            groupBuyingGroup.setPartinIds(String.join(",",ids));
+            groupBuyingGroup.setPartinNum(groupBuyingGroup.getPartinNum()+1);
+            // todo 已成团,完成成团后逻辑
+            if(groupBuyingGroup.getPartinNum() == groupBuying.getGroupSize()){
+                groupBuyingGroup.setGroupStatus(GroupingStatusEnum.END.getValue());
+            }
+            groupBuyingGroupService.updateById(groupBuyingGroup);
+        }
+        // 用户关系绑定
+        channelUserRelService.bindUser(buyingOrder.getUserId(), buyingOrder.getChannelId());
+
+        if (buyingOrder.getCommStatus() != CommStatusEnum.NO.getValue()) {
+            LogUtil.warn(logger, "收到拼团支付成功任务,订单结佣状态不是未结佣,忽略任务。orderId=" + orderId);
+            return;
+        }
+        userGroupOrderService.commToChannel(orderId, ChannelCommissionResourceEnum.USER.getValue());
+    }
+
 
     @Override
     public void ticketGenerate(AsyncTask asyncTask) {

+ 5 - 0
mp-service/src/main/java/com/qs/mp/pay/service/impl/WalletServiceImpl.java

@@ -31,6 +31,7 @@ import com.qs.mp.pay.service.IWalletService;
 import com.qs.mp.system.service.id.BizIdGenerator;
 import com.qs.mp.user.domain.UserTicketOrder;
 import com.qs.mp.user.service.IUserDeliverOrderService;
+import com.qs.mp.user.service.IUserGroupOrderService;
 import com.qs.mp.user.service.IUserTicketOrderService;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -84,6 +85,8 @@ public class WalletServiceImpl implements IWalletService {
 
   @Autowired
   private IChannelGoodsSettleOrderService settleOrderService;
+  @Autowired
+  private IUserGroupOrderService userGroupOrderService;
 
   @Value("${pay.notifyUrl}")
   private String notifyUrl;  //支付成功前端跳转地址
@@ -363,6 +366,8 @@ public class WalletServiceImpl implements IWalletService {
     } else if (BizTypeEnum.DELIVER_ORDER == payOrder.getBizType()) {
       // 用户提货订单支付成功,调用业务订单服务处理
       userDeliverOrderService.paySuccess(payOrder);
+    }else if(BizTypeEnum.GROUP_ORDER == payOrder.getBizType()){
+      userGroupOrderService.paySuccess(payOrder);
     } else {
       //数据结构异常,告警
       LogUtil.error(logger, "该业务单据类型未支持,orderNo:" + orderNo);

+ 2 - 0
mp-service/src/main/java/com/qs/mp/user/service/IUserGroupOrderService.java

@@ -59,6 +59,8 @@ public interface IUserGroupOrderService extends IService<GroupBuyingOrder> {
    */
   boolean paySuccess(PayOrder payOrder);
 
+  boolean backGroup(GroupBuyingOrder buyingOrder);
+
   /**
    * 给渠道分润
    * @param orderId

+ 214 - 43
mp-service/src/main/java/com/qs/mp/user/service/impl/UserGroupOrderServiceImpl.java

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