admin
2019-08-26 d28bed1a1275131a5ca37f7da37961e2b518ac07
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -1,6 +1,7 @@
package com.yeshi.fanli.service.impl.order;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -52,6 +53,8 @@
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.factory.CommonOrderGoodsFactory;
import com.yeshi.fanli.util.factory.goods.CommonOrderFactory;
@@ -64,6 +67,7 @@
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
import com.yeshi.fanli.vo.order.CommonOrderGoodsVO;
import com.yeshi.fanli.vo.order.CommonOrderVO;
import com.yeshi.fanli.vo.order.WeiQuanInfo;
import net.sf.json.JSONObject;
@@ -327,6 +331,14 @@
      // 是否存在奖励券
      boolean hasRewardCoupon = userSystemCouponService.hasRewardCoupon(uid);
      // 2019.8.1开始返回维权信息
      Date august = null;
      try {
         august = TimeUtil.parse("2019-08-01");
      } catch (ParseException e) {
         e.printStackTrace();
      }
      /* 组织订单状态 等信息 */
      for (CommonOrderVO order : listOrder) {
@@ -374,6 +386,11 @@
            }
         }
         BigDecimal hongBao = order.getHongBao();
         if (hongBao == null) {
            hongBao = new BigDecimal(0);
         }
         if (CommonOrder.STATE_FK == orderState) {
            orderStateContent = "已付款";
         } else if (CommonOrder.STATE_JS == orderState) {
@@ -390,7 +407,7 @@
                     .selectListByOrderIdAndState(order.getOrderNo(), "维权成功");
               boolean isPart = false;// 默认失效
               BigDecimal weiQuanMoney = new BigDecimal(0);
               if (listWQ != null && listWQ.size() > 0) {
                  BigDecimal fanTotalMoney = new BigDecimal(0);
                  for (TaoBaoWeiQuanOrder weiQuanOrder : listWQ) {
@@ -398,17 +415,41 @@
                     if (fanMoney != null) {
                        fanTotalMoney = MoneyBigDecimalUtil.add(fanTotalMoney, fanMoney);
                     }
                     weiQuanMoney = MoneyBigDecimalUtil.add(weiQuanOrder.getMoney(), weiQuanMoney);
                  }
                  if (fanTotalMoney.compareTo(order.getHongBao()) < 0) {
                  if (fanTotalMoney.compareTo(hongBao) < 0) {
                     isPart = true;
                  }
               }
               if (isPart) {
                  hongBaoState = HongBaoV2.STATE_BUFENSHIXIAO; // 部分失效
               if (!VersionUtil.greaterThan_1_6_0(acceptData.getPlatform(), acceptData.getVersion())) {
                  if (isPart) {
                     hongBaoState = HongBaoV2.STATE_BUFENSHIXIAO; // 部分失效
                  } else {
                     hongBaoState = HongBaoV2.STATE_SHIXIAO; // 全部失效
                  }
               } else {
                  hongBaoState = HongBaoV2.STATE_SHIXIAO; // 全部失效
                  // 2019.8.1 返回维权信息
                  if (settleTime != null && august != null && settleTime.getTime() > august.getTime()) {
                     orderStateContent = "维权成功";
                     WeiQuanInfo weiQuanInfo = new WeiQuanInfo();
                     weiQuanInfo.setOldHongBao("¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN).toString());
                     if (isPart) {
                        // 维权失效金额=维权的金额*获得的红包/结算金额
                        BigDecimal settlement = order.getSettlement();
                        BigDecimal wqHongbao = MoneyBigDecimalUtil
                              .div(MoneyBigDecimalUtil.mul(hongBao, settlement), settlement);
                        weiQuanInfo.setWqHongBao(
                              "维权:-¥" + wqHongbao.setScale(2, BigDecimal.ROUND_DOWN).toString());
                        hongBao = MoneyBigDecimalUtil.sub(hongBao, wqHongbao);
                     } else {
                        weiQuanInfo
                              .setWqHongBao("维权:-¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN).toString());
                        hongBao = new BigDecimal(0);
                     }
                     order.setWeiQuanInfo(weiQuanInfo);
                  }
               }
            }
         }
@@ -495,10 +536,6 @@
         hongbaoInfo = hongBaoState_Str + hongbaoInfo;
         BigDecimal hongBao = order.getHongBao();
         if (hongBao == null) {
            hongBao = new BigDecimal(0);
         }
         Map<String, String> hongBaoMap = new HashMap<String, String>();
         hongBaoMap.put("content", hongbaoInfo + " ¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN).toString());
         hongBaoMap.put("fontColor", hongbaoInfoFontColor);
@@ -522,9 +559,9 @@
         }
         // 分享、邀请 隐藏订单号
         if (HongBaoV2.TYPE_SHARE_GOODS == hongBaoType || HongBaoV2.TYPE_YAOQING == hongBaoType || HongBaoV2.TYPE_YIJI == hongBaoType
               || HongBaoV2.TYPE_ERJI == hongBaoType || HongBaoV2.TYPE_SHARE_YIJI == hongBaoType
               || HongBaoV2.TYPE_SHARE_ERJI == hongBaoType) {
         if (HongBaoV2.TYPE_SHARE_GOODS == hongBaoType || HongBaoV2.TYPE_YAOQING == hongBaoType
               || HongBaoV2.TYPE_YIJI == hongBaoType || HongBaoV2.TYPE_ERJI == hongBaoType
               || HongBaoV2.TYPE_SHARE_YIJI == hongBaoType || HongBaoV2.TYPE_SHARE_ERJI == hongBaoType) {
            order.setOrderNo(UserUtil.filterOrderId(order.getOrderNo()));
         }
      }
@@ -752,16 +789,6 @@
            commonOrderGoodsMapper.insertSelective(cog);
            newCommonOrder.setCommonOrderGoods(cog);
         } else {
            if (!Constant.IS_OUTNET) {
               PDDGoodsDetail pddGoods = null;
               pddGoods = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(cog.getGoodsId()));
               if (pddGoods != null) {
                  cog = CommonOrderGoodsFactory.create(pddGoods);
                  commonGoodsList.get(0).setPicture(cog.getPicture());
                  commonOrderGoodsMapper.updateByPrimaryKeySelective(commonGoodsList.get(0));
               }
            }
         }
         newCommonOrder.setUserInfo(new UserInfo(uid));
         commonOrderList.add(addCommonOrder(newCommonOrder));
@@ -807,22 +834,26 @@
         if (commonGoodsList.size() <= 0)// 不存在就插入商品
         {
            JDGoods goods = JDApiUtil.getGoodsDetail(itemOrder.getSkuId());
            if (goods == null) {
               goods = JDUtil.getGoodsFromWeb(itemOrder.getSkuId());
            }
            if (goods == null) {
               goods = new JDGoods();
               goods.setSkuName(itemOrder.getSkuName());
               goods.setPrice(itemOrder.getPrice());
               goods.setSkuId(itemOrder.getSkuId());
            }
            if (goods != null) {
               cog = CommonOrderGoodsFactory.create(goods);
            }
            cog.setCreateTime(new Date());
            cog.setUpdateTime(new Date());
            commonOrderGoodsMapper.insertSelective(cog);
         } else {
            if (!Constant.IS_OUTNET) {
               JDGoods goods = JDApiUtil.getGoodsDetail(itemOrder.getSkuId());
               if(goods==null)
                  goods=JDUtil.getGoodsFromWeb(itemOrder.getSkuId());
               commonGoodsList.get(0).setTitle(goods.getSkuName());
               commonGoodsList.get(0).setPicture(goods.getPicUrl());
               commonOrderGoodsMapper.updateByPrimaryKeySelective(commonGoodsList.get(0));
            }
         }
         newCommonOrder.setUserInfo(new UserInfo(uid));
         commonOrderList.add(addCommonOrder(newCommonOrder));
@@ -869,10 +900,9 @@
      if (!StringUtil.isNullOrEmpty(commonOrder.getTradeId()))
         oldCommonOrder = commonOrderMapper.selectBySourceTypeAndTradeId(commonOrder.getSourceType(),
               commonOrder.getTradeId());
      else
         oldCommonOrder = commonOrderMapper.selectByOrderNoAndOrderTypeAndOrderBy(commonOrder.getOrderNo(),
               commonOrder.getSourceType(), commonOrder.getOrderBy());
      else {
         throw new CommonOrderException(10, "交易ID为空");
      }
      if (oldCommonOrder == null)// 新增
      {
         commonOrder.setCreateTime(new Date());
@@ -884,6 +914,7 @@
      } else {// 修改
         // 已经结算,已经失效,状态未改变的订单不处理
         if (oldCommonOrder.getState() == CommonOrder.STATE_JS || oldCommonOrder.getState() == CommonOrder.STATE_SX
               || oldCommonOrder.getState() == CommonOrder.STATE_WQ
               || (oldCommonOrder.getState().intValue() == commonOrder.getState())) {
            return oldCommonOrder;
         }
@@ -999,8 +1030,14 @@
         Integer type, Integer orderState, String startTime, String endTime, Integer source)
         throws CommonOrderException {
      List<CommonOrderVO> list = commonOrderMapper.listQuery(start, count, keyType, key, state, type, orderState,
            startTime, endTime, source);
      List<CommonOrderVO> list = null;
      if (StringUtil.isNullOrEmpty(key) || keyType == 1) {// 搜索框无值或者按订单号搜索时都只搜索主订单
         list = commonOrderMapper.listQueryWithNoChild(start, count, keyType, key, state, type, orderState,
               startTime, endTime, source);
      } else
         list = commonOrderMapper.listQuery(start, count, keyType, key, state, type, orderState, startTime, endTime,
               source);
      if (list == null) {
         list = new ArrayList<CommonOrderVO>();
@@ -1131,6 +1168,8 @@
                        || CouponTypeEnum.welfareFreeCoupon.name().equals(systemCouponType)) {
                     if (UserSystemCouponRecord.STATE_SUCCESS == couponState) {
                        // 免单成功
                        order.setOtherState(2);
                     } else if (UserSystemCouponRecord.STATE_FREE_ON == couponState) {
                        order.setOtherState(1);
                     }
                  }
@@ -1146,6 +1185,8 @@
                        || CouponTypeEnum.welfareFreeCoupon.name().equals(systemCouponType)) {
                     if (UserSystemCouponRecord.STATE_SUCCESS == couponState) {
                        // 免单成功
                        order.setOtherState(2);
                     } else if (UserSystemCouponRecord.STATE_FREE_ON == couponState) {
                        order.setOtherState(1);
                     }
                  }
@@ -1161,6 +1202,8 @@
                        || CouponTypeEnum.welfareFreeCoupon.name().equals(systemCouponType)) {
                     if (UserSystemCouponRecord.STATE_SUCCESS == couponState) {
                        // 免单成功
                        order.setOtherState(2);
                     } else if (UserSystemCouponRecord.STATE_FREE_ON == couponState) {
                        order.setOtherState(1);
                     }
                  }
@@ -1177,7 +1220,11 @@
   @Override
   public long countQuery(Integer keyType, String key, Integer state, Integer type, Integer orderState,
         String startTime, String endTime, Integer source) throws CommonOrderException {
      return commonOrderMapper.countQuery(keyType, key, state, type, orderState, startTime, endTime, source);
      if (StringUtil.isNullOrEmpty(key) || keyType == 1) {// 搜索框无值或者按订单号搜索时都只搜索主订单
         return commonOrderMapper.countQueryWithNoChild(keyType, key, state, type, orderState, startTime, endTime,
               source);
      } else
         return commonOrderMapper.countQuery(keyType, key, state, type, orderState, startTime, endTime, source);
   }
   @Override
@@ -1355,5 +1402,4 @@
      return commonOrderMapper.listBySourceTypeAndStateAndThirdCrateTime(sourceType, state, minTime, maxTime,
            (page - 1) * pageSize, pageSize);
   }
}