yujian
2019-10-21 d085ca89e39b4cda025a9a53d3797fbe8b242ae7
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -31,6 +31,8 @@
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.elme.ElmeHongBaoOrderMap;
import com.yeshi.fanli.entity.elme.ElmeOrder;
import com.yeshi.fanli.entity.jd.JDOrder;
import com.yeshi.fanli.entity.jd.JDOrderItem;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
@@ -48,6 +50,8 @@
import com.yeshi.fanli.exception.order.OrderItemException;
import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.elme.ElmeHongBaoOrderMapService;
import com.yeshi.fanli.service.inter.elme.ElmeOrderService;
import com.yeshi.fanli.service.inter.hongbao.AccountDetailsHongBaoMapService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
@@ -1443,4 +1447,117 @@
         return false;
   }
   @Transactional(rollbackFor = Exception.class)
   public void invalidHongBaoV2AndGiveGodenCorn(Long hongBaoId, Long uid, String orderId, int sourceType,
         String beiZhu) throws Exception {
      HongBaoV2 v2 = new HongBaoV2(hongBaoId);
      v2.setState(HongBaoV2.STATE_SHIXIAO);
      v2.setBeizhu(beiZhu);
      v2.setUpdateTime(new Date());
      hongBaoV2Service.updateByPrimaryKeySelective(v2);
      List<HongBaoV2> children = hongBaoV2Service.listChildrenById(hongBaoId);
      if (children != null)
         for (HongBaoV2 child : children) {
            HongBaoV2 update = new HongBaoV2(child.getId());
            update.setState(HongBaoV2.STATE_SHIXIAO);
            update.setBeizhu(beiZhu);
            update.setUpdateTime(new Date());
            hongBaoV2Service.updateByPrimaryKeySelective(update);
         }
      userSystemCouponService.systemGiveRewardCoupon(uid, 1, orderId, sourceType, "因商家违约未能结算返利或商家已经关店");
   }
   @Transactional
   @Override
   public void doTaoBaoSellerNotPaid(TaoBaoOrder order) {
      // 根据交易ID查询
      if (!StringUtil.isNullOrEmpty(order.getTradeId())) {
         List<CommonOrder> commonOrderList = commonOrderService
               .listBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, order.getTradeId());
         if (commonOrderList != null)
            // 查询主订单
            for (CommonOrder commonOrder : commonOrderList) {
            // 查询主红包
            HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
            if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null) {
            if (hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_BUKELINGQU) {
            // 订单失效,赠送金币
            try {
            invalidHongBaoV2AndGiveGodenCorn(hongBaoOrder.getHongBaoV2().getId(), hongBaoOrder.getHongBaoV2().getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType(), "订单成功,商家未打款");
            } catch (Exception e) {
            e.printStackTrace();
            }
            }
            }
            }
      }
   }
   public void elmeFanli() {
   }
   // 饿了么订单
   @Resource
   private ElmeHongBaoOrderMapService elmeHongBaoOrderMapService;
   @Resource
   private ElmeOrderService elmeOrderService;
   /**
    * 获取饿了么可以返利的红包
    *
    * @return
    */
   @Override
   public List<HongBaoV2> getCanBalanceElmeFanliHongBao() {
      List<Integer> list = new ArrayList<>();
      list.add(HongBaoV2.TYPE_ELME);
      return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, 0, 1000);
   }
   @Override
   @Transactional
   public void elmeFanli(Long hongBaoId) {
      // 查询详情
      HongBaoV2 hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBaoId);
      if (hongBao.getType() == HongBaoV2.TYPE_ELME && hongBao.getState() == HongBaoV2.STATE_KELINGQU
            && hongBao.getPreGetTime() != null && System.currentTimeMillis() > hongBao.getPreGetTime().getTime()) {// 可以到账了
         // 判断用户状态
         UserInfo user = userInfoMapper.selectByPrimaryKey(hongBao.getUserInfo().getId());
         if (user == null || user.getState() != UserInfo.STATE_NORMAL)
            return;
         ElmeHongBaoOrderMap map = elmeHongBaoOrderMapService.selectByHongBaoId(hongBaoId);
         if (map == null)
            return;
         ElmeOrder order = elmeOrderService.selectByPrimaryKey(map.getElmeOrder().getId());
         if (order == null)
            return;
         // 到账,加数据
         HongBaoV2 update = new HongBaoV2(hongBao.getId());
         update.setUpdateTime(new Date());
         update.setGetTime(new Date());
         update.setState(HongBaoV2.STATE_YILINGQU);
         hongBaoV2Mapper.updateByPrimaryKeySelective(update);
         // 增加资金
         UserMoneyDetail detail = null;
         try {
            detail = UserMoneyDetailFactory.createElmeFanLi(hongBao.getUserInfo().getId(), order.getOrderId(),
                  hongBao.getId(), hongBao.getMoney());
         } catch (UserMoneyDetailException e) {
            e.printStackTrace();
         }
         userMoneyService.addUserMoney(hongBao.getUserInfo().getId(), hongBao.getMoney(), detail);
         BigDecimal balance = userInfoMapper.selectByPrimaryKey(hongBao.getUserInfo().getId()).getMyHongBao();
         // 添加消息
         userMoneyMsgNotificationService.elmeFanli(hongBao.getUserInfo().getId(), order.getOrderId(),
               hongBao.getMoney(), balance);
      }
      // 返利到账
   }
}