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;
@@ -1490,7 +1494,70 @@
            }
      }
   }
   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);
      }
      // 返利到账
   }
}