yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java
@@ -5,7 +5,12 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
@@ -13,6 +18,7 @@
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
import com.yeshi.fanli.dao.mybatis.PidOrderMapper;
import com.yeshi.fanli.dao.mybatis.hongbao.HongBaoMapper;
import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper;
import com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper;
@@ -21,20 +27,28 @@
import com.yeshi.fanli.dao.mybatis.order.OrderMapper;
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoOrderMapper;
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
import com.yeshi.fanli.dto.HongBaoDTO;
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.UserInfo;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.CommonOrderGoods;
import com.yeshi.fanli.entity.order.HongBaoOrder;
import com.yeshi.fanli.entity.taobao.PidOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
import com.yeshi.fanli.exception.HongBaoException;
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.msg.UserOrderMsgNotificationService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
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.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.TimeUtil;
@@ -75,6 +89,24 @@
   @Resource
   private TaoBaoWeiQuanOrderMapper taoBaoWeiQuanOrderMapper;
   @Resource
   private UserShareGoodsGroupService userShareGoodsGroupService;
   @Resource
   private PidOrderMapper pidOrderMapper;
   @Resource
   private HongBaoManageService hongBaoManageService;
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Resource
   private UserNotificationService userNotificationService;
   @Resource
   private UserOrderMsgNotificationService userOrderMsgNotificationService;
   @Override
   public int insert(HongBaoV2 record) {
@@ -119,12 +151,22 @@
      if (hb.getParent() != null)
         v2.setParent(new HongBaoV2(hb.getParent().getId()));
      if (hb.getPreGettime() == null || hb.getPreGettime() == 0)
         v2.setPreGetTime(null);
      else
         v2.setPreGetTime(new Date(hb.getPreGettime()));
      if (hb.getType() == HongBao.TYPE_SHARE_GOODS) {
         if (hb.getBalanceTime() != null)
            v2.setPreGetTime(new Date(hb.getPreGettime()));
         else
            v2.setPreGetTime(null);
      } else {
         if (hb.getPreGettime() == null || hb.getPreGettime() == 0)
            v2.setPreGetTime(null);
         else
            v2.setPreGetTime(new Date(hb.getPreGettime()));
      }
      v2.setState(hb.getState());
      if (hb.getState() == 1 && hb.getBalanceTime() != null) {
         v2.setState(HongBaoV2.STATE_KELINGQU);
      }
      v2.setType(type);
      v2.setUpdateTime(new Date(hb.getCreatetime()));
      v2.setUrank(hb.getUrank());
@@ -192,6 +234,14 @@
            if (list.size() <= 0)
               return;
            if (list.get(0).getType() == 20)
               for (HongBao hb1 : list) {
                  PidOrder pidOrder = pidOrderMapper.getPidOrderByHongBaoId(hb1.getId());
                  if (pidOrder != null)
                     hb1.setAuctionId(pidOrder.getAuctionId());
               }
            List<TaoBaoOrder> orderList = taoBaoOrderMapper.selectTaoBaoOrderByOrderId(orderId);
            if (orderList == null || orderList.size() < list.size()) {
@@ -206,12 +256,24 @@
            // 按照auctionId,payMoney排序
            Comparator<HongBao> cm = new Comparator<HongBao>() {
               @Override
               public int compare(HongBao o1, HongBao o2) {
                  return o1.getAuctionId() == o2.getAuctionId()
                        ? (o1.getPayMoney().subtract(o2.getPayMoney()).compareTo(new BigDecimal(0)))
                        : (int) (o1.getAuctionId() - o2.getAuctionId());
                  if (o1.getAuctionId().longValue() < o2.getAuctionId().longValue())
                     return -3;
                  else if (o1.getAuctionId().longValue() > o2.getAuctionId().longValue()) {
                     return 3;
                  } else {
                     if (o1.getState() - o2.getState() > 0)
                        return 2;
                     else if (o1.getState() - o2.getState() < 0)
                        return -2;
                     else {
                        if (o1.getPayMoney().compareTo(o2.getPayMoney()) >= 0)
                           return 1;
                        else
                           return -1;
                     }
                  }
               }
            };
@@ -221,13 +283,24 @@
               @Override
               public int compare(TaoBaoOrder o1, TaoBaoOrder o2) {
                  return o1.getAuctionId() == o2.getAuctionId()
                        ? (o1.getPayment().subtract(o2.getPayment()).compareTo(new BigDecimal(0)))
                        : (int) (o1.getAuctionId() - o2.getAuctionId());
                  if (o1.getAuctionId().longValue() < o2.getAuctionId().longValue())
                     return -3;
                  else if (o1.getAuctionId().longValue() > o2.getAuctionId().longValue()) {
                     return 3;
                  } else {
                     if (o1.getPayment().compareTo(o2.getPayment()) < 0)
                        return 2;
                     else
                        return -2;
                  }
               }
            };
            Collections.sort(orderList, cmOrder);
            for (TaoBaoOrder t : orderList)
               System.out.println(t.getAuctionId());
            for (int i = 0; i < list.size(); i++) {
               CommonOrder commonOrder = TaoBaoOrderUtil.convert(orderList.get(i));
@@ -289,28 +362,122 @@
   }
   @Resource
   private HongBaoManageService hongBaoManageService;
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Transactional
   @Override
   public void addHongBao(CommonOrder commonOrder, int type) throws HongBaoException {
      if (commonOrder == null || commonOrder.getId() == null || commonOrder.getUserInfo() == null)
         throw new HongBaoException(1, "订单信息不完整");
      HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
      if (hongBaoOrder == null) {
         saveHongBao(commonOrder, type);
      } else {
         updateHongBao(hongBaoOrder, commonOrder, type);
   public void addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException {
      Set<Integer> stateSet = new HashSet<>();// 订单状态Set
      if (commonOrderList != null && commonOrderList.size() > 0) {
         Map<Integer, HongBaoOrder> notificationMap = new HashMap<>();
         int goodsCount = 0;
         boolean hasAdd = false;
         for (CommonOrder commonOrder : commonOrderList) {
            stateSet.add(commonOrder.getState());
            goodsCount += commonOrder.getCount();
            if (commonOrder == null || commonOrder.getId() == null || commonOrder.getUserInfo() == null)
               throw new HongBaoException(1, "订单信息不完整");
            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
            if (hongBaoOrder == null) {
               saveHongBao(commonOrder, type, notificationMap);
               hasAdd = true;
            } else {
               updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
            }
         }
         /**
          * 通知用户的返利情况
          */
         int state = getOrderState(stateSet);
         if (hasAdd) {
            Iterator<Integer> its = notificationMap.keySet().iterator();
            while (its.hasNext()) {
               Integer t = its.next();
               HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
               CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
               String orderId = commonOrderList.get(0).getOrderNo();
               Long uid = notify.getUserInfo().getId();
               BigDecimal money = notify.getMoney();
               switch (t) {
               case HongBaoV2.TYPE_ZIGOU:
                  userNotificationService.orderFanliStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK,
                        null, money);
                  userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, commonOrder.getPayment(),
                        money, goodsCount, state);
                  break;
               case HongBaoV2.TYPE_SHARE_GOODS:
                  userNotificationService.orderShareStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK,
                        null, money);
                  userOrderMsgNotificationService.orderShareStatistic(uid, orderId, commonOrder.getPayment(),
                        money, goodsCount, state);
                  break;
               case HongBaoV2.TYPE_YIJI:
                  userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount,
                        MsgOrderDetail.STATE_FK, null, money);
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(),
                        money, goodsCount, state);
                  break;
               case HongBaoV2.TYPE_ERJI:
                  userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount,
                        MsgOrderDetail.STATE_FK, null, money);
                  userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(),
                        money, goodsCount, state);
                  break;
               }
            }
         }
         // 添加新版本通知
         if (!hasAdd) {
            Iterator<Integer> its = notificationMap.keySet().iterator();
            while (its.hasNext()) {
               Integer t = its.next();
               HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
               CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
               String orderId = commonOrderList.get(0).getOrderNo();
               Long uid = notify.getUserInfo().getId();
               BigDecimal money = notify.getMoney();
               switch (t) {
               case HongBaoV2.TYPE_ZIGOU:
                  userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId, commonOrder.getPayment(),
                        money, state);
                  break;
               case HongBaoV2.TYPE_SHARE_GOODS:
                  userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, commonOrder.getPayment(),
                        money, state);
                  break;
               case HongBaoV2.TYPE_YIJI:
                  userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(),
                        money, state);
                  break;
               case HongBaoV2.TYPE_ERJI:
                  userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(),
                        money, state);
                  break;
               }
            }
         }
      }
   }
   private int getOrderState(Set<Integer> states) {
      if (states.size() == 1)
         return states.iterator().next();
      Iterator<Integer> its = states.iterator();
      while (its.hasNext()) {
         int tempState = its.next();
         if (tempState == CommonOrder.STATE_FK)
            return CommonOrder.STATE_FK;
         else if (tempState == CommonOrder.STATE_JS)
            return CommonOrder.STATE_JS;
      }
      return CommonOrder.STATE_SX;
   }
   @Transactional
   private void updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type) throws HongBaoException {
   private void updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type,
         Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException {
      System.out.println(commonOrder.getOrderNo());
      HongBaoV2 oldHongBao = hongBaoV2Mapper.selectByPrimaryKey(hongBaoOrder.getHongBaoV2().getId());
      if (oldHongBao == null)
@@ -339,6 +506,24 @@
         }
         hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao);
         // 加入通知
         if (notificationMap.get(type) == null) {
            HongBaoV2 tempHongBao = new HongBaoV2(oldHongBao.getId());
            tempHongBao.setUserInfo(oldHongBao.getUserInfo());
            tempHongBao.setMoney(hongBao.getMoney());
            CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
            tempCommonOrder.setPayment(commonOrder.getPayment());
            notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
         } else {
            // 增加付款金额与资金
            HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
            tempHongBaoOrder.getCommonOrder()
                  .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
            tempHongBaoOrder.getHongBaoV2()
                  .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
            notificationMap.put(type, tempHongBaoOrder);
         }
         // 获取子红包
         List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
         if (children != null)
@@ -358,7 +543,7 @@
               // 以实际收入为准计算预估收益
               if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
                  childUpdate.setMoney(
                        MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), rate.divide(new BigDecimal(100))));
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))));
                  Calendar calendar = Calendar.getInstance();
                  calendar.setTime(commonOrder.getSettleTime());
                  calendar.add(Calendar.MONTH, 1);
@@ -367,9 +552,28 @@
                        "yyyy-M-dd")));
               } else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) {
                  childUpdate.setMoney(
                        MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), rate.divide(new BigDecimal(100))));
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))));
               }
               hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
               // 加入通知
               if (notificationMap.get(type) == 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));
               } else {
                  // 增加付款金额与资金
                  HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
                  tempHongBaoOrder.getCommonOrder().setPayment(
                        tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                  tempHongBaoOrder.getHongBaoV2()
                        .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(child.getMoney()));
                  notificationMap.put(type, tempHongBaoOrder);
               }
            }
      } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
@@ -395,6 +599,23 @@
            hongBao.setMoney(new BigDecimal(0));
         }
         hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao);
         // 通知
         if (notificationMap.get(type) == null) {
            HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId());
            tempHongBao.setUserInfo(hongBao.getUserInfo());
            tempHongBao.setMoney(hongBao.getMoney());
            CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
            tempCommonOrder.setPayment(commonOrder.getPayment());
            notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
         } else {
            // 增加付款金额与资金
            HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
            tempHongBaoOrder.getCommonOrder()
                  .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
            tempHongBaoOrder.getHongBaoV2()
                  .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
            notificationMap.put(type, tempHongBaoOrder);
         }
         // 获取子红包
         List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId());
@@ -416,7 +637,7 @@
               // 以实际收入为准计算预估收益
               if (CommonOrder.STATE_JS == commonOrder.getState()) {
                  childUpdate.setMoney(
                        MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), rate.divide(new BigDecimal(100))));
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))));
                  Calendar calendar = Calendar.getInstance();
                  calendar.setTime(commonOrder.getSettleTime());
                  calendar.add(Calendar.MONTH, 1);
@@ -428,7 +649,7 @@
                     System.out.println("");
                  childUpdate.setMoney(
                        MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), rate.divide(new BigDecimal(100))));
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100))));
               }
               hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate);
            }
@@ -437,7 +658,8 @@
   }
   @Transactional
   private void saveHongBao(CommonOrder commonOrder, int type) throws HongBaoException {
   private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
         throws HongBaoException {
      if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
         BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
         HongBaoV2 hongBao = new HongBaoV2();
@@ -469,6 +691,23 @@
         hongBaoOrder.setCreateTime(new Date());
         hongBaoOrder.setHongBaoV2(hongBao);
         hongBaoOrderMapper.insertSelective(hongBaoOrder);
         // 加入通知
         if (notificationMap.get(type) == null) {
            HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId());
            tempHongBao.setUserInfo(hongBao.getUserInfo());
            tempHongBao.setMoney(hongBao.getMoney());
            CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
            tempCommonOrder.setPayment(commonOrder.getPayment());
            notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
         } else {
            // 增加付款金额与资金
            HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
            tempHongBaoOrder.getCommonOrder()
                  .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
            tempHongBaoOrder.getHongBaoV2()
                  .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
            notificationMap.put(type, tempHongBaoOrder);
         }
         UserInfo boss = threeSaleSerivce.getBoss(user.getId());
         if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO) {// 1级BOSS存在且红包未失效
@@ -489,7 +728,7 @@
            if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
               firstHongbao.setMoney(
                     MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), firstRate.divide(new BigDecimal(100))));
                     MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
               Calendar calendar = Calendar.getInstance();
               calendar.setTime(commonOrder.getSettleTime());
               calendar.add(Calendar.MONTH, 1);
@@ -498,9 +737,26 @@
                     "yyyy-M-dd")));
            } else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) {
               firstHongbao.setMoney(
                     MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), firstRate.divide(new BigDecimal(100))));
                     MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
            }
            hongBaoV2Mapper.insertSelective(firstHongbao);
            // 用户通知
            if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) {
               HongBaoV2 tempHongBao = new HongBaoV2(firstHongbao.getId());
               tempHongBao.setUserInfo(firstHongbao.getUserInfo());
               tempHongBao.setMoney(firstHongbao.getMoney());
               CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
               tempCommonOrder.setPayment(commonOrder.getPayment());
               notificationMap.put(HongBaoV2.TYPE_YIJI, new HongBaoOrder(tempCommonOrder, tempHongBao));
            } else {
               // 增加付款金额与资金
               HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_YIJI);
               tempHongBaoOrder.getCommonOrder()
                     .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
               tempHongBaoOrder.getHongBaoV2()
                     .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(firstHongbao.getMoney()));
               notificationMap.put(HongBaoV2.TYPE_YIJI, tempHongBaoOrder);
            }
            // 插入二级子红包
            boss = threeSaleSerivce.getBoss(boss.getId());
@@ -518,8 +774,8 @@
               secondHongbao.setVersion(2);
               secondHongbao.setState(hongBao.getState());
               if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
                  firstHongbao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(),
                        secondRate.divide(new BigDecimal(100))));
                  secondHongbao.setMoney(
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
                  Calendar calendar = Calendar.getInstance();
                  calendar.setTime(commonOrder.getSettleTime());
                  calendar.add(Calendar.MONTH, 1);
@@ -527,10 +783,28 @@
                        calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25",
                        "yyyy-M-dd")));
               } else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) {
                  secondHongbao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(),
                        secondRate.divide(new BigDecimal(100))));
                  secondHongbao.setMoney(
                        MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
               }
               hongBaoV2Mapper.insertSelective(secondHongbao);
               // 用户通知
               if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null) {
                  HongBaoV2 tempHongBao = new HongBaoV2(secondHongbao.getId());
                  tempHongBao.setUserInfo(secondHongbao.getUserInfo());
                  tempHongBao.setMoney(secondHongbao.getMoney());
                  CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
                  tempCommonOrder.setPayment(commonOrder.getPayment());
                  notificationMap.put(HongBaoV2.TYPE_ERJI, new HongBaoOrder(tempCommonOrder, tempHongBao));
               } else {
                  // 增加付款金额与资金
                  HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_ERJI);
                  tempHongBaoOrder.getCommonOrder().setPayment(
                        tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
                  tempHongBaoOrder.getHongBaoV2()
                        .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(secondHongbao.getMoney()));
                  notificationMap.put(HongBaoV2.TYPE_ERJI, tempHongBaoOrder);
               }
            }
         }
@@ -569,7 +843,103 @@
         hongBaoOrder.setCreateTime(new Date());
         hongBaoOrder.setHongBaoV2(hongBao);
         hongBaoOrderMapper.insertSelective(hongBaoOrder);
         if (notificationMap.get(type) == null) {
            HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId());
            tempHongBao.setUserInfo(hongBao.getUserInfo());
            tempHongBao.setMoney(hongBao.getMoney());
            CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId());
            tempCommonOrder.setPayment(commonOrder.getPayment());
            notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao));
         } else {
            // 增加付款金额与资金
            HongBaoOrder tempHongBaoOrder = notificationMap.get(type);
            tempHongBaoOrder.getCommonOrder()
                  .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment()));
            tempHongBaoOrder.getHongBaoV2()
                  .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney()));
            notificationMap.put(type, tempHongBaoOrder);
         }
         // 修改统计数据
         Long goodsId = commonOrder.getCommonOrderGoods().getId();
         // 查询商品
         CommonOrderGoods goods = commonOrderGoodsMapper.selectByPrimaryKey(goodsId);
         HongBao hb = new HongBao();
         if (goods != null)
            hb.setAuctionId(Long.parseLong(goods.getGoodsId()));
         hb.setUserInfo(hongBao.getUserInfo());
         hb.setMoney(hongBao.getMoney());
         try {
            userShareGoodsGroupService.updateOrderRecord(hb);
         } catch (UserShareGoodsRecordException e) {
            try {
               LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
               e1.printStackTrace();
            }
         }
      } else
         throw new HongBaoException(2, "type错误");
   }
   @Override
   public List<HongBaoDTO> listJiangJinByUid(Long uid, int page, int pageSize) {
      return hongBaoV2Mapper.listJiangJinByUid(uid, (page - 1) * pageSize, pageSize);
   }
   @Override
   public long countJiangJinByUid(Long uid) {
      Long count = hongBaoV2Mapper.countJiangJinByUid(uid);
      return count == null ? 0 : count;
   }
   @Override
   public BigDecimal getTotalTiChengMoney(Long uid) {
      return hongBaoV2Mapper.getTotalTiChengMoney(uid);
   }
   @Override
   public int getTotalTiChengCount(Long uid) {
      return hongBaoV2Mapper.getTotalTiChengCount(uid);
   }
   @Override
   public BigDecimal getUnGetTiChengMoney(Long uid) {
      return hongBaoV2Mapper.getUnGetTiChengMoney(uid);
   }
   @Override
   public BigDecimal getTotalFanLiMoney(Long uid) {
      BigDecimal money = hongBaoV2Mapper.getTotalFanLiMoney(uid);
      return money == null ? new BigDecimal(0) : money;
   }
   @Override
   public BigDecimal getUnRecievedFanLiMoney(Long uid) {
      BigDecimal money = hongBaoV2Mapper.getUnRecievedFanLiMoney(uid);
      return money == null ? new BigDecimal(0) : money;
   }
   @Override
   public BigDecimal getUnRecievedMoneyWithCreateTime(Long uid, Date minDate, Date maxDate) {
      BigDecimal money = hongBaoV2Mapper.getUnRecievedMoneyWithCreateTime(uid, minDate, maxDate);
      if (money == null)
         return new BigDecimal(0);
      else
         return money;
   }
   @Override
   public BigDecimal getUnRecievedMoneyWithPreGetTime(Long uid, Date minDate, Date maxDate) {
      BigDecimal money = hongBaoV2Mapper.getUnRecievedMoneyWithPreGetTime(uid, minDate, maxDate);
      if (money == null)
         return new BigDecimal(0);
      else
         return money;
   }
}