yujian
2019-07-11 1180be99c94b80d5fe9fea2877558fb29aa97427
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -20,6 +20,7 @@
import com.yeshi.fanli.dao.mybatis.order.CommonOrderTradeIdMapMapper;
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord;
@@ -30,6 +31,7 @@
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.CommonOrderGoods;
import com.yeshi.fanli.entity.order.CommonOrderTradeIdMap;
import com.yeshi.fanli.entity.order.HongBaoOrder;
import com.yeshi.fanli.entity.pdd.PDDOrder;
import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
@@ -44,11 +46,13 @@
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
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;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.factory.CommonOrderGoodsFactory;
import com.yeshi.fanli.util.factory.goods.CommonOrderFactory;
import com.yeshi.fanli.util.jd.JDApiUtil;
@@ -98,6 +102,9 @@
   @Resource
   private CommonGoodsService commonGoodsService;
   @Resource
   private HongBaoOrderService hongBaoOrderService;
   // 奖励订单图片
   public final static String PIC_REWARD = "http://img.flqapp.com/resource/order/order_state_reward.png";
@@ -138,26 +145,26 @@
   @Override
   public List<CommonOrderVO> listGroupOrderNoByUid(long start, int count, Long uid, Integer state, Integer type,
         Integer orderState, String orderNo, String startTime, String endTime, Integer dateType)
         Integer orderState, String orderNo, String startTime, String endTime, Integer dateType, Integer source)
         throws CommonOrderException {
      return commonOrderMapper.listUserOrder(start, count, uid, state, type, orderState, orderNo, startTime, endTime,
            dateType);
            dateType, source);
   }
   @Override
   public long countGroupOrderNoByUid(Long uid, Integer state, Integer type, Integer orderState, String orderNo,
         String startTime, String endTime, Integer dateType) throws CommonOrderException {
      return commonOrderMapper.countUserOrder(uid, state, type, orderState, orderNo, startTime, endTime, dateType);
         String startTime, String endTime, Integer dateType, Integer source) throws CommonOrderException {
      return commonOrderMapper.countUserOrder(uid, state, type, orderState, orderNo, startTime, endTime, dateType, source);
   }
   @Override
   public List<CommonOrderVO> getOrderByUid(Integer page, Long uid, Integer state, Integer type, Integer orderState,
         String orderNo, String startTime, String endTime, Integer dateType) throws CommonOrderException {
   public List<CommonOrderVO> getOrderByUid(AcceptData acceptData,Integer page, Long uid, Integer state, Integer type, Integer orderState,
         String orderNo, String startTime, String endTime, Integer dateType, Integer source) throws CommonOrderException {
      int pageSize = Constant.PAGE_SIZE;
      List<CommonOrderVO> listOrder = listGroupOrderNoByUid((page - 1) * pageSize, pageSize, uid, state, type,
            orderState, orderNo, startTime, endTime, dateType);
            orderState, orderNo, startTime, endTime, dateType, source);
      // 订单信息为空
      if (listOrder == null || listOrder.size() == 0) {
@@ -173,24 +180,24 @@
      }
      // 数据加工重新组织
      listDataFactory(listOrder, listGoods, uid);
      listDataFactory(acceptData, listOrder, listGoods, uid);
      return listOrder;
   }
   @Override
   public Map<String, BigDecimal> countHistoryOrder(Long uid, Integer day) {
      return commonOrderMapper.countHistoryOrder(uid, day);
   public Map<String, BigDecimal> countHistoryOrder(Long uid, Integer day, Integer source) {
      return commonOrderMapper.countHistoryOrder(uid, day, source);
   }
   @Override
   public long countBonusOrderNumber(Long uid, Integer type, Integer day, String startTime, String endTime) {
      return commonOrderMapper.countBonusOrderNumber(uid, type, day, startTime, endTime);
   public long countBonusOrderNumber(Long uid, Integer type, Integer day, String startTime, String endTime, Integer source) {
      return commonOrderMapper.countBonusOrderNumber(uid, type, day, startTime, endTime, source);
   }
   @Override
   public BigDecimal countBonusOrderMoney(Long uid, Integer type, Integer day, String startTime, String endTime) {
      return commonOrderMapper.countBonusOrderMoney(uid, type, day, startTime, endTime);
   public BigDecimal countBonusOrderMoney(Long uid, Integer type, Integer day, String startTime, String endTime, Integer source) {
      return commonOrderMapper.countBonusOrderMoney(uid, type, day, startTime, endTime, source);
   }
   @Override
@@ -201,11 +208,11 @@
   @Override
   public Map<String, BigDecimal> countByUidAndOrderState(Long uid, Integer type, String startTime, String endTime,
         Integer day) {
      return commonOrderMapper.countByUidAndOrderState(uid, type, startTime, endTime, day);
         Integer day, Integer source) {
      return commonOrderMapper.countByUidAndOrderState(uid, type, startTime, endTime, day, source);
   }
   public void listDataFactory(List<CommonOrderVO> listOrder, List<CommonOrderVO> listGoods, Long uid) {
   public void listDataFactory(AcceptData acceptData, List<CommonOrderVO> listOrder, List<CommonOrderVO> listGoods, Long uid) {
      List<String> listNo = new ArrayList<String>();
      for (CommonOrderVO commonOrderVO : listOrder) {
@@ -272,13 +279,19 @@
               listOrderGoods.add(commonGoodsVO);
               Integer orderType = commonOrder.getOrderType();
               Integer orderType = order.getOrderType();
               if (orderType == null) {
                  String shopType = commonGoodsVO.getShopType();
                  if (CommonOrderGoodsVO.TYPE_TAOBAO.equalsIgnoreCase(shopType)) {
                     commonOrder.setOrderType(1);
                     order.setOrderType(1);
                  } else if (CommonOrderGoodsVO.TYPE_TMALL.equalsIgnoreCase(shopType)) {
                     commonOrder.setOrderType(2);
                     order.setOrderType(2);
                  }
                  if (Constant.SOURCE_TYPE_JD == sourceType2) {
                     order.setOrderType(3);
                  } else if (Constant.SOURCE_TYPE_PDD == sourceType2) {
                     order.setOrderType(4);
                  }
               }
@@ -684,6 +697,7 @@
      return commonOrderList;
   }
   @Transactional
   @Override
   public List<CommonOrder> addJDOrder(JDOrder jdOrder, Long uid) throws CommonOrderException {
      List<CommonOrder> commonOrderList = new ArrayList<>();
@@ -782,7 +796,8 @@
         return commonOrder;
      } else {// 修改
         // 已经结算或者已经失效的订单不处理
         if (oldCommonOrder.getState() == CommonOrder.STATE_JS || oldCommonOrder.getState() == CommonOrder.STATE_SX) {
         if (oldCommonOrder.getState() == CommonOrder.STATE_JS
               || oldCommonOrder.getState() == CommonOrder.STATE_SX) {
            return oldCommonOrder;
         }
         // 交易ID一致才修改
@@ -996,15 +1011,6 @@
      return commonOrderMapper.countQuery(keyType, key, state, type, orderState, startTime, endTime);
   }
   @Override
   public CommonOrderVO getInfoByOrderNo(Long uid, String orderNo) throws CommonOrderException {
      List<CommonOrderVO> list = getOrderByUid(1, uid, null, null, null, orderNo, null, null, null);
      if (list == null || list.size() == 0) {
         return null;
      } else {
         return list.get(0);
      }
   }
   @Override
   public CommonOrderVO getCommonOrderByOrderNo(Long uid, String orderNo, Integer orderState)
@@ -1099,30 +1105,6 @@
      return commonOrderVO;
   }
   @Override
   public List<CommonOrderVO> getCouponHongbaoByOrderNo(Long uid, Integer hongBaoState, String orderNo)
         throws CommonOrderException {
      List<CommonOrderVO> listOrder = commonOrderMapper.getCouponHongbaoByOrderNo(uid, hongBaoState, orderNo);
      // 订单信息为空
      if (listOrder == null || listOrder.size() == 0) {
         listOrder = new ArrayList<CommonOrderVO>();
         return listOrder;
      }
      // 商品信息
      List<CommonOrderVO> listGoods = commonOrderMapper.listOrderGoodsInfo(listOrder);
      // 订单商品为空
      if (listGoods == null || listGoods.size() == 0) {
         return listOrder;
      }
      // 数据加工重新组织
      listDataFactory(listOrder, listGoods, uid);
      return listOrder;
   }
   @Override
   public JSONObject getRewardJumpInfo(String orderNo) {
@@ -1163,4 +1145,38 @@
      return commonOrderMapper.selectBySourceTypeAndTradeId(sourceType, tradeId);
   }
   @Transactional
   @Override
   public void deleteErrorCommonOrder(Long coId) {
      // 查询是否返利到账
      HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(coId);
      if (hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_YILINGQU)
         return;
      List<HongBaoV2> hongBaoList = hongBaoV2Service.listChildrenById(hongBaoOrder.getHongBaoV2().getId());
      boolean canDelete = true;
      for (HongBaoV2 child : hongBaoList)
         if (child.getState() == HongBaoV2.STATE_YILINGQU) {
            canDelete = false;
            break;
         }
      // 不能删除
      if (!canDelete)
         return;
      // 删除child
      for (HongBaoV2 child : hongBaoList)
         hongBaoV2Service.deleteByPrimaryKey(child.getId());
      // 删除主红包
      hongBaoV2Service.deleteByPrimaryKey(hongBaoOrder.getHongBaoV2().getId());
      // 删除hongbaoOrder
      hongBaoOrderService.deleteByPrimaryKey(hongBaoOrder.getId());
      // 删除CommonOrder
      commonOrderMapper.deleteByPrimaryKey(hongBaoOrder.getCommonOrder().getId());
   }
   @Override
   public List<CommonOrder> listBySourceTypeAndTradeId(int sourceType, String tradeId) {
      return commonOrderMapper.listBySourceTypeAndTradeId(sourceType, tradeId);
   }
}