admin
2019-09-22 b9f8ef2c4737b6e6be4b12fc8f7bafb033bfcfe5
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -20,6 +20,7 @@
import com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper;
import com.yeshi.fanli.dao.mybatis.order.CommonOrderTradeIdMapMapper;
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
import com.yeshi.fanli.dto.order.CommonOrderAddResultDTO;
import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
@@ -45,9 +46,9 @@
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemCouponService;
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.order.HongBaoV2Service;
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.util.Constant;
@@ -216,9 +217,9 @@
   }
   @Override
   public Map<String, BigDecimal> countByUidAndOrderState(Long uid, Integer type, String startTime, String endTime,
         Integer day, Integer source) {
      return commonOrderMapper.countByUidAndOrderState(uid, type, startTime, endTime, day, source);
   public Long countUserOrderToApp(Long uid, Integer type, String startTime, String endTime,
         Integer day, Integer source, Integer state, Integer stateOrder) {
      return commonOrderMapper.countUserOrderToApp(uid, type, startTime, endTime, day, source, state, stateOrder);
   }
   private BigDecimal getWeiQuanMoney(List<TaoBaoWeiQuanOrder> listWQ, int sourceType, Long uid) {
@@ -234,9 +235,11 @@
            if (hongBaoList != null && hongBaoList.size() > 0) {
               CommonOrder commonOrder = commonOrderMapper.selectBySourceTypeAndTradeId(sourceType, tradeId);
               if (commonOrder != null && commonOrder.getSettlement().compareTo(new BigDecimal(0)) > 0) {
                  BigDecimal wqMoney =
                        MoneyBigDecimalUtil.mul(hongBaoList.get(0).getMoney(), weiQuanOrder.getMoney())
                              .divide(commonOrder.getSettlement(), 2, BigDecimal.ROUND_UP);
                  BigDecimal wqMoney = MoneyBigDecimalUtil
                        .mul(hongBaoList.get(0).getMoney(), weiQuanOrder.getMoney())
                        .divide(commonOrder.getSettlement(), 2, BigDecimal.ROUND_UP);
                  if (wqMoney.compareTo(hongBaoList.get(0).getMoney()) > 0)
                     wqMoney = hongBaoList.get(0).getMoney();
                  weiQuanMoney = weiQuanMoney.add(wqMoney);
               }
            }
@@ -448,15 +451,17 @@
                     orderStateContent = "维权成功";
                     WeiQuanInfo weiQuanInfo = new WeiQuanInfo();
                     weiQuanInfo.setOldHongBao("¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN).toString());
//                     if (isPart) {
                        weiQuanInfo.setWqHongBao(
                              "维权:-¥" + weiQuanMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
                        hongBao = MoneyBigDecimalUtil.sub(hongBao, weiQuanMoney);
//                     } else {
//                        weiQuanInfo
//                              .setWqHongBao("维权:-¥" + weiQuanMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
//                        hongBao = MoneyBigDecimalUtil.sub(hongBao, weiQuanMoney);
//                     }
                     // if (isPart) {
                     weiQuanInfo
                           .setWqHongBao("维权:-¥" + weiQuanMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
                     hongBao = MoneyBigDecimalUtil.sub(hongBao, weiQuanMoney);
                     // } else {
                     // weiQuanInfo
                     // .setWqHongBao("维权:-¥" + weiQuanMoney.setScale(2,
                     // BigDecimal.ROUND_DOWN).toString());
                     // hongBao = MoneyBigDecimalUtil.sub(hongBao,
                     // weiQuanMoney);
                     // }
                     order.setWeiQuanInfo(weiQuanInfo);
                  }
               }
@@ -641,9 +646,9 @@
      // 1.6.5 是否存在新兑换的券
      if (!hasRewardCoupon && exchangeCoupon) {
         try {
            String downTime = order.getDownTime();
            if (!StringUtil.isNullOrEmpty(downTime)) {
               long downOrderTime = TimeUtil.convertDateToTemp2(downTime);
            Date thirdCreateTime = order.getThirdCreateTime();
            if (thirdCreateTime != null) {
               long downOrderTime = thirdCreateTime.getTime();
               long limitDate = TimeUtil.convertDateToTemp("2019-09-05");
               if (downOrderTime > limitDate)
                  hasRewardCoupon = true;
@@ -676,7 +681,7 @@
         Map<String, Object> jumpLink = new HashMap<String, Object>();
         jumpLink.put("orderNo", order.getOrderNo());
         if (VersionUtil.greaterThan_1_6_0(acceptData.getPlatform(), acceptData.getVersion())) {
            jumpLink.put("goodsType", order.getSourceType());
            jumpLink.put("goodsType", order.getSourceType()+"");
         }
         Map<String, Object> jump = new HashMap<String, Object>();
@@ -701,7 +706,7 @@
         Map<String, Object> jumpLink = new HashMap<String, Object>();
         jumpLink.put("orderNo", order.getOrderNo());
         if (VersionUtil.greaterThan_1_6_0(acceptData.getPlatform(), acceptData.getVersion())) {
            jumpLink.put("goodsType", order.getSourceType());
            jumpLink.put("goodsType", order.getSourceType()+"");
         }
         Map<String, Object> jump = new HashMap<String, Object>();
@@ -724,8 +729,9 @@
   @Transactional
   @Override
   public List<CommonOrder> addTaoBaoOrder(List<TaoBaoOrder> taoBaoOrders, Long uid) throws CommonOrderException {
      List<CommonOrder> commonOrderList = new ArrayList<>();
   public List<CommonOrderAddResultDTO> addTaoBaoOrder(List<TaoBaoOrder> taoBaoOrders, Long uid)
         throws CommonOrderException {
      List<CommonOrderAddResultDTO> commonOrderList = new ArrayList<>();
      // 判断所有的订单状态
      int invalidCount = 0;
      for (TaoBaoOrder tb : taoBaoOrders) {
@@ -785,8 +791,9 @@
   @Transactional
   @Override
   public List<CommonOrder> addPDDOrder(List<PDDOrder> pddOrderList, Long uid) throws CommonOrderException {
      List<CommonOrder> commonOrderList = new ArrayList<>();
   public List<CommonOrderAddResultDTO> addPDDOrder(List<PDDOrder> pddOrderList, Long uid)
         throws CommonOrderException {
      List<CommonOrderAddResultDTO> commonOrderList = new ArrayList<>();
      // 判断所有的订单状态
      int invalidCount = 0;
      for (PDDOrder order : pddOrderList) {
@@ -834,8 +841,8 @@
   @Transactional
   @Override
   public List<CommonOrder> addJDOrder(JDOrder jdOrder, Long uid) throws CommonOrderException {
      List<CommonOrder> commonOrderList = new ArrayList<>();
   public List<CommonOrderAddResultDTO> addJDOrder(JDOrder jdOrder, Long uid) throws CommonOrderException {
      List<CommonOrderAddResultDTO> commonOrderList = new ArrayList<>();
      // 判断所有的订单状态
      int invalidCount = 0;
      for (JDOrderItem tb : jdOrder.getOrderItemList()) {
@@ -903,7 +910,7 @@
    * @param commonOrder
    */
   @Transactional
   private CommonOrder addCommonOrder(CommonOrder commonOrder) throws CommonOrderException {
   private CommonOrderAddResultDTO addCommonOrder(CommonOrder commonOrder) throws CommonOrderException {
      // 判断商品是否存在
      if (commonOrder == null)
         throw new CommonOrderException(1, "订单为空");
@@ -946,13 +953,13 @@
         // 插入映射,保证交易ID的完整性
         commonOrderTradeIdMapMapper.insertSelective(new CommonOrderTradeIdMap(commonOrder.getId(),
               commonOrder.getTradeId(), new Date(), commonOrder.getSourceType()));
         return commonOrder;
         return new CommonOrderAddResultDTO(commonOrder, CommonOrderAddResultDTO.TYPE_ADD);
      } else {// 修改
         // 已经结算,已经失效,状态未改变的订单不处理
         if (oldCommonOrder.getState() == CommonOrder.STATE_JS || oldCommonOrder.getState() == CommonOrder.STATE_SX
               || oldCommonOrder.getState() == CommonOrder.STATE_WQ
               || (oldCommonOrder.getState().intValue() == commonOrder.getState())) {
            return oldCommonOrder;
            return new CommonOrderAddResultDTO(oldCommonOrder, CommonOrderAddResultDTO.TYPE_NOUPDATE);
         }
         // 交易ID一致才修改
         if (commonOrder.getTradeId() != null
@@ -968,9 +975,10 @@
            updateCommonOrder.setUpdateTime(new Date());
            updateCommonOrder.setTradeId(commonOrder.getTradeId());
            commonOrderMapper.updateByPrimaryKeySelective(updateCommonOrder);
            return commonOrderMapper.selectByPrimaryKey(updateCommonOrder.getId());
            return new CommonOrderAddResultDTO(commonOrderMapper.selectByPrimaryKey(updateCommonOrder.getId()),
                  CommonOrderAddResultDTO.TYPE_UPDATE);
         } else
            return oldCommonOrder;
            return new CommonOrderAddResultDTO(oldCommonOrder, CommonOrderAddResultDTO.TYPE_NOUPDATE);
      }
   }
@@ -1364,7 +1372,7 @@
   }
   @Override
   public JSONObject getRewardJumpInfo(String orderNo) {
   public JSONObject getRewardJumpInfo(String orderNo, Integer goodsType) {
      JSONObject map = new JSONObject();
      // 订单标识
@@ -1381,6 +1389,7 @@
      Map<String, Object> jumpLink = new HashMap<String, Object>();
      jumpLink.put("orderNo", orderNo);
      jumpLink.put("goodsType", goodsType == null? goodsType: goodsType +"");
      Map<String, Object> jump = new HashMap<String, Object>();
      jump.put("type", 1);
@@ -1447,4 +1456,15 @@
      return commonOrderMapper.getByOrderNo(uid, orderNO);
   }
   @Override
   public CommonOrder selectLatestValidByUid(Long uid) {
      List<Integer> stateList = new ArrayList<>();
      stateList.add(CommonOrder.STATE_FK);
      stateList.add(CommonOrder.STATE_JS);
      List<CommonOrder> commonOrderList = commonOrderMapper.listByUid(uid, stateList, 0, 1);
      if (commonOrderList == null || commonOrderList.size() == 0)
         return null;
      return commonOrderList.get(0);
   }
}