yujian
2019-02-28 70c9043f312a52a922cb15490d90a172b3515060
fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java
@@ -31,7 +31,6 @@
import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail;
import com.yeshi.fanli.entity.bus.user.HongBao;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.Order;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.order.CommonOrder;
@@ -56,6 +55,8 @@
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserNotificationService;
import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
@@ -124,6 +125,12 @@
   @Resource
   private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
   @Resource
   private UserSystemCouponService userSystemCouponService;
   @Resource
   private UserSystemCouponRecordService userSystemCouponRecordService;
   @Override
   public int insert(HongBaoV2 record) {
@@ -505,6 +512,23 @@
      if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
         // 免单处理
         boolean mianDan = false;
         if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) {
            List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
                  commonOrder.getOrderNo());
            if (orderList != null && orderList.size() == 1) {// 只有1个订单才参与免单
               BigDecimal payMent = commonOrder.getPayment();
               if (commonOrder.getState() == CommonOrder.STATE_JS)
                  payMent = commonOrder.getSettlement();
               if (payMent.compareTo(new BigDecimal(10)) < 0) {
                  mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getOrderNo());
                  fanliRate = new BigDecimal(100);
               }
            }
         }
         HongBaoV2 hongBao = new HongBaoV2(hongBaoOrder.getHongBaoV2().getId());
         hongBao.setUpdateTime(new Date());
         // 更改状态与资金
@@ -574,21 +598,21 @@
               hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
               // 加入通知
               if (notificationMap.get(type) == null) {
               if (notificationMap.get(child.getType()) == null) {
                  HongBaoV2 tempHongBao = new HongBaoV2(child.getId());
                  tempHongBao.setUserInfo(child.getUserInfo());
                  tempHongBao.setMoney(child.getMoney());
                  CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                  tempCommonOrder.setPayment(commonOrder.getPayment());
                  notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
                  notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao));
               } else {
                  // 增加付款金额与资金
                  HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
                  HongBaoOrder tempHongBaoOrder = notificationMap.get(child.getType());
                  tempHongBaoOrder.getCommonOrder().setPayment(
                        tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                  tempHongBaoOrder.getHongBaoV2()
                        .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(child.getMoney()));
                  notificationMap.put(type, tempHongBaoOrder);
                  notificationMap.put(child.getType(), tempHongBaoOrder);
               }
            }
@@ -625,7 +649,7 @@
         // 通知
         if (notificationMap.get(type) == null) {
            HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId());
            tempHongBao.setUserInfo(hongBao.getUserInfo());
            tempHongBao.setUserInfo(hongBaoOrder.getHongBaoV2().getUserInfo());
            tempHongBao.setMoney(hongBao.getMoney());
            CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
            tempCommonOrder.setPayment(commonOrder.getPayment());
@@ -685,6 +709,40 @@
         throws HongBaoException {
      if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
         // 查询是否有免单计划
         BigDecimal mianDanMoney = null;
         if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) {
            List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
                  commonOrder.getOrderNo());
            if (orderList != null && orderList.size() == 1) {// 只有1个订单才参与免单
               BigDecimal payMent = commonOrder.getPayment();
               if (commonOrder.getState() == CommonOrder.STATE_JS)
                  payMent = commonOrder.getSettlement();
               CommonOrderGoods goods = commonOrderGoodsMapper
                     .selectByPrimaryKey(commonOrder.getCommonOrderGoods().getId());
               if (goods != null) {
                  try {
                     if (userSystemCouponService.updateCouponRecordUsed(commonOrder.getUserInfo().getId(),
                           commonOrder.getOrderNo(), payMent, Long.parseLong(goods.getGoodsId())))
                        mianDanMoney = payMent;
                  } catch (NumberFormatException e) {
                     throw new HongBaoException(10, "免单商品处理出错");
                  } catch (Exception e) {
                     e.printStackTrace();
                     throw new HongBaoException(11, "免单商品处理出错");
                  }
               }
            }
         } else if (commonOrder.getState() == CommonOrder.STATE_SX) {// 设置免单券失效
            try {
               userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo());
            } catch (Exception e) {
               e.printStackTrace();
            }
         }
         HongBaoV2 hongBao = new HongBaoV2();
         hongBao.setUserInfo(commonOrder.getUserInfo());
         hongBao.setCreateTime(new Date());
@@ -705,6 +763,10 @@
         } else {
            throw new HongBaoException(3, "维权订单不能创建红包");
         }
         if (mianDanMoney != null)
            hongBao.setMoney(mianDanMoney);
         UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
         hongBao.setUrank(user.getRank());
         hongBaoV2Mapper.insertSelective(hongBao);
@@ -733,7 +795,7 @@
         }
         UserInfo boss = threeSaleSerivce.getBoss(user.getId());
         if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO) {// 1级BOSS存在且红包未失效
         if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO && mianDanMoney == null) {// 1级BOSS存在且红包未失效,免单不支持多级分销
            // 插入一级子红包
            BigDecimal firstRate = hongBaoManageService