admin
2024-01-23 81da61b828e29b7745e1382dfbbaeb685dc083ef
fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -7,8 +7,13 @@
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.dy.DYOrder;
import com.yeshi.fanli.service.inter.order.pdd.PDDOrderService;
import com.yeshi.fanli.util.goods.douyin.CSJCPSApiUtil;
import com.yeshi.fanli.util.goods.douyin.vo.DYGoodsDetail;
import org.apache.commons.beanutils.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -104,6 +109,9 @@
@Service
public class CommonOrderServiceImpl implements CommonOrderService {
    private Logger logger = LoggerFactory.getLogger(CommonOrderService.class);
    @Resource
    private CommonOrderMapper commonOrderMapper;
@@ -368,7 +376,7 @@
                    CommonOrderGoodsVO commonGoodsVO = new CommonOrderGoodsVO();
                    PropertyUtils.copyProperties(commonGoodsVO, goods);
                    commonGoodsVO.setGoodsType(sourceType);
                    commonGoodsVO.setPlaceOrderTime(TimeUtil.getGernalTime(order.getThirdCreateTime().getTime(),"yyyy.MM.dd HH:mm"));
                    commonGoodsVO.setPlaceOrderTime(TimeUtil.getGernalTime(order.getThirdCreateTime().getTime(), "yyyy.MM.dd HH:mm"));
                    // 淘宝商品图片处理
@@ -386,7 +394,7 @@
                    if (totalSettlement == null || totalSettlement.compareTo(new BigDecimal(0)) <= 0) {
                        totalSettlement = commonOrder.getTotalPayment();
                    }
                    if (totalSettlement== null || totalSettlement.compareTo(new BigDecimal(0)) <= 0)
                    if (totalSettlement == null || totalSettlement.compareTo(new BigDecimal(0)) <= 0)
                        commonGoodsVO.setPayState("未付款/已退款");
                    else
                        commonGoodsVO.setPayState("已付款");
@@ -728,7 +736,7 @@
            Map<String, Object> jump = new HashMap<String, Object>();
            jump.put("type", 1); // 页面跳转
            jump.put("params", jumpLink);
            jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("freeCouponDetail"));
            jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("freeCouponDetail", acceptData.getSystem()));
            Map<String, Object> rewardMap = new HashMap<String, Object>();
            rewardMap.put("text", rewardStyleVO);
@@ -757,7 +765,7 @@
            Map<String, Object> jump = new HashMap<String, Object>();
            jump.put("type", 1); // 1 常规跳转页面
            jump.put("params", jumpLink);
            jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail"));
            jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail", acceptData.getSystem()));
            rewardMap.put("jump", jump);
            order.setRewardDetail(rewardMap);
        }
@@ -782,7 +790,7 @@
            long limitDate = TimeUtil.convertDateToTemp(Constant.VIP_ONLINE_TIME);
            if (downOrderTime > limitDate) {
                // 2.1 开始新版
                rewardCounponLimitTime(order, accountTime);
                rewardCounponLimitTime(order, accountTime, acceptData.getSystem());
            } else if (hasRewardCoupon) {
                // 在2.1新版上线之前订单-存在则显示奖励券可使用
                ClientTextStyleVO rewardStyleVO = new ClientTextStyleVO();
@@ -797,7 +805,7 @@
                Map<String, Object> jump = new HashMap<String, Object>();
                jump.put("type", 2); // 弹框
                jump.put("params", jumpLink);
                jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail"));
                jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail", acceptData.getSystem()));
                Map<String, Object> rewardMap = new HashMap<String, Object>();
                rewardMap.put("text", rewardStyleVO);
@@ -807,7 +815,7 @@
        }
    }
    private void rewardCounponLimitTime(CommonOrderVO order, Date accountTime) throws Exception {
    private void rewardCounponLimitTime(CommonOrderVO order, Date accountTime, SystemEnum system) throws Exception {
        // 倒计时验证
        Date endDay = DateUtil.plusDayDate(Constant.COUPON_REWARD_LIMIT_DAY, accountTime);
        long currentTime = java.lang.System.currentTimeMillis();
@@ -882,7 +890,7 @@
        Map<String, Object> jump = new HashMap<String, Object>();
        jump.put("type", 2); // 弹出框使用券
        jump.put("params", jumpLink);
        jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail"));
        jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail", system));
        rewardMap.put("jump", jump);
        order.setRewardDetail(rewardMap);
    }
@@ -994,6 +1002,7 @@
            } else {
                cog.setGoodsId(taoBaoOrder.getAuctionId() + "");
                cog.setGoodsType(Constant.SOURCE_TYPE_TAOBAO);
                cog.setTitle(taoBaoOrder.getTitle());
                newCommonOrder.setCommonOrderGoods(cog);
            }
            newCommonOrder.setStateWholeOrder(wholeOrderState);
@@ -1011,11 +1020,10 @@
                                        taoBaoGoods.getRootCategoryName(), taoBaoGoods.getLeafName()));
                    } catch (TaobaoGoodsDownException e) {
                        e.printStackTrace();
                        LogHelper.errorDetailInfo(e, "AUCTIONID:" + taoBaoOrder.getAuctionId(), "");
                        logger.warn("淘宝商品下架:{}", taoBaoOrder.getAuctionId(), e);
                        try {
                            taoBaoGoods = TaoBaoUtil.getSimpleGoodsBrief(taoBaoOrder.getAuctionId());
                            // 记录商品分类
                        } catch (Exception e1) {
                            CommonGoods commonGoods = commonGoodsService.getCommonGoodsByGoodsIdAndGoodsType(
                                    taoBaoOrder.getAuctionId(), Constant.SOURCE_TYPE_TAOBAO);
@@ -1029,6 +1037,8 @@
                }
                cog.setCreateTime(new Date());
                cog.setUpdateTime(new Date());
                //覆盖原来的商品ID
                cog.setGoodsId(newCommonOrder.getCommonOrderGoods().getGoodsId());
                commonOrderGoodsMapper.insertSelective(cog);
            }
            newCommonOrder.setUserInfo(new UserInfo(uid));
@@ -1300,7 +1310,7 @@
            {
                SuningGoodsInfo pddGoods = null;
                // TODO 需要获取
                pddGoods = SuningApiUtil.getGoodsDetail(suningOrderInfo.getGoodsNum(), suningOrderInfo.getSellerCode());
                pddGoods = SuningApiUtil.getGoodsDetail(suningOrderInfo.getGoodsNum(), "0000000000");
                if (pddGoods != null) {
                    cog = CommonOrderGoodsFactory.create(pddGoods);
                }
@@ -1315,6 +1325,71 @@
        }
        addConfirmMQMsg(commonOrderList);
        return commonOrderList;
    }
    @Override
    public List<CommonOrderAddResultDTO> addDYOrder(DYOrder order, Long uid) throws CommonOrderException {
        List<CommonOrderAddResultDTO> commonOrderList = new ArrayList<>();
            CommonOrder newCommonOrder = CommonOrderFactory.create(order);
            CommonOrderGoods cog = new CommonOrderGoods();
            cog.setGoodsId(order.getProduct_id());
            cog.setGoodsType(Constant.SOURCE_TYPE_DY);
            newCommonOrder.setCommonOrderGoods(cog);
            newCommonOrder.setStateWholeOrder(newCommonOrder.getState());
            // 订单商品插入
            List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper.listByGoodsIdAndGoodsType(cog.getGoodsId(),
                    cog.getGoodsType());
            if (commonGoodsList.size() <= 0)// 不存在就插入商品
            {
                DYGoodsDetail goods = CSJCPSApiUtil.goodsDetail(Long.parseLong(order.getProduct_id()));
                if (goods == null) {
                    goods = new DYGoodsDetail();
                    goods.setTitle(order.getProduct_name());
                    goods.setPrice(0);
                    goods.setProduct_id(Long.parseLong(order.getProduct_id()));
                    goods.setCover(order.getProduct_img());
                }
                if (goods != null) {
                    cog = CommonOrderGoodsFactory.create(goods);
                }
                cog.setCreateTime(new Date());
                cog.setUpdateTime(new Date());
                commonOrderGoodsMapper.insertSelective(cog);
            } else {
            }
            newCommonOrder.setUserInfo(new UserInfo(uid));
            commonOrderList.add(addCommonOrder(newCommonOrder));
        addConfirmMQMsg(commonOrderList);
        return commonOrderList;
    }
    private boolean needUpdateCommonOrder(CommonOrder oldCommonOrder, CommonOrder newCommonOrder) {
        // 非京东已经结算,已经失效,状态未改变的订单不处理
        if ((oldCommonOrder.getState() == CommonOrder.STATE_JS
                && oldCommonOrder.getSourceType() != Constant.SOURCE_TYPE_JD)
                || oldCommonOrder.getState() == CommonOrder.STATE_SX
                || oldCommonOrder.getState() == CommonOrder.STATE_WQ) {
            return false;
        }
        //状态相同且付款金额,结算金额一致时才不需要更新
        if (oldCommonOrder.getState().intValue() == newCommonOrder.getState()) {
            if (oldCommonOrder.getPayment().compareTo(newCommonOrder.getPayment()) == 0) {
                if (oldCommonOrder.getSettlement() == null && newCommonOrder.getSettlement() == null) {
                    return false;
                } else if (oldCommonOrder.getSettlement() != null && newCommonOrder.getSettlement() != null && oldCommonOrder.getSettlement().compareTo(newCommonOrder.getSettlement()) == 0) {
                    return false;
                }
            }
        }
        return true;
    }
    /**
@@ -1378,12 +1453,8 @@
                    commonOrder.getTradeId(), new Date(), commonOrder.getSourceType()));
            return new CommonOrderAddResultDTO(commonOrder, CommonOrderAddResultDTO.TYPE_ADD);
        } else {// 修改
            // 非京东已经结算,已经失效,状态未改变的订单不处理
            if ((oldCommonOrder.getState() == CommonOrder.STATE_JS
                    && oldCommonOrder.getSourceType() != Constant.SOURCE_TYPE_JD)
                    || oldCommonOrder.getState() == CommonOrder.STATE_SX
                    || oldCommonOrder.getState() == CommonOrder.STATE_WQ
                    || (oldCommonOrder.getState().intValue() == commonOrder.getState()&&oldCommonOrder.getPayment().compareTo(commonOrder.getPayment())==0)) {
            if (!needUpdateCommonOrder(oldCommonOrder, commonOrder)) {
                return new CommonOrderAddResultDTO(oldCommonOrder, CommonOrderAddResultDTO.TYPE_NOUPDATE);
            }
            // 交易ID一致才修改
@@ -1752,7 +1823,7 @@
                } catch (Exception e) {
                    e.printStackTrace();
                }
                commonGoodsVO.setPlaceOrderTime(TimeUtil.getGernalTime(commonOrder.getThirdCreateTime().getTime(),"yyyy.MM.dd HH:mm"));
                commonGoodsVO.setPlaceOrderTime(TimeUtil.getGernalTime(commonOrder.getThirdCreateTime().getTime(), "yyyy.MM.dd HH:mm"));
                String picture = commonGoodsVO.getPicture();
                if (!StringUtil.isNullOrEmpty(picture) && !picture.contains("320x320")) {
@@ -1779,7 +1850,7 @@
                if (totalSettlement == null || totalSettlement.compareTo(new BigDecimal(0)) <= 0) {
                    totalSettlement = commonOrder.getTotalPayment();
                }
                if (totalSettlement== null || totalSettlement.compareTo(new BigDecimal(0)) <= 0)
                if (totalSettlement == null || totalSettlement.compareTo(new BigDecimal(0)) <= 0)
                    commonGoodsVO.setPayState("未付款/已退款");
                else
                    commonGoodsVO.setPayState("已付款");
@@ -1806,7 +1877,7 @@
    }
    @Override
    public JSONObject getRewardJumpInfo(String orderNo, Integer goodsType) {
    public JSONObject getRewardJumpInfo(String orderNo, Integer goodsType, SystemEnum system) {
        JSONObject map = new JSONObject();
        // 订单标识
@@ -1828,7 +1899,7 @@
        Map<String, Object> jump = new HashMap<String, Object>();
        jump.put("type", 1);
        jump.put("params", jumpLink);
        jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail"));
        jump.put("jumpDetail", jumpDetailV2Service.getByTypeCache("rewardCouponDetail", system));
        Map<String, Object> rewardMap = new HashMap<String, Object>();
        rewardMap.put("text", rewardStyleVO);
@@ -1885,7 +1956,13 @@
    @Override
    public List<CommonOrder> getByOrderNo(Long uid, String orderNO) {
        return commonOrderMapper.getByOrderNo(uid, orderNO);
        if(uid!=null) {
            return commonOrderMapper.getByOrderNo(uid, orderNO);
        }else{
            CommonOrderMapper.DaoQuery daoQuery=new CommonOrderMapper.DaoQuery();
            daoQuery.orderId = orderNO;
            return  commonOrderMapper.list(daoQuery,0,100);
        }
    }
@@ -2122,7 +2199,7 @@
                    if (commonGoodsVO.getGoodsType() == null) {
                        commonGoodsVO.setGoodsType(sourceType);
                    }
                    commonGoodsVO.setPlaceOrderTime(TimeUtil.getGernalTime(order.getThirdCreateTime().getTime(),"yyyy.MM.dd HH:mm"));
                    commonGoodsVO.setPlaceOrderTime(TimeUtil.getGernalTime(order.getThirdCreateTime().getTime(), "yyyy.MM.dd HH:mm"));
                    // 淘宝商品图片处理
                    String picture = commonGoodsVO.getPicture();
@@ -2139,7 +2216,7 @@
                    if (totalSettlement == null || totalSettlement.compareTo(new BigDecimal(0)) <= 0) {
                        totalSettlement = commonOrder.getTotalPayment();
                    }
                    if (totalSettlement== null || totalSettlement.compareTo(new BigDecimal(0)) <= 0)
                    if (totalSettlement == null || totalSettlement.compareTo(new BigDecimal(0)) <= 0)
                        commonGoodsVO.setPayState("未付款/已退款");
                    else
                        commonGoodsVO.setPayState("已付款");
@@ -2449,4 +2526,15 @@
        return commonOrderMapper.listByGoodsIdAndUidAndMinThirdCreateTime(goodsId, uid, minThirdCreateTime, 0, 1000);
    }
    @Override
    public List<CommonOrder> listPayStateOrder(Integer sourceType, Date minThirdCreateTime, Date maxThirdCreateTime,int page,int pageSize) {
        CommonOrderMapper.DaoQuery daoQuery = new CommonOrderMapper.DaoQuery();
        daoQuery.minThirdCreateTime = minThirdCreateTime;
        daoQuery.maxThirdCreateTime = maxThirdCreateTime;
        daoQuery.state = CommonOrder.STATE_FK;
        daoQuery.sourceType = sourceType;
        daoQuery.sortList = Arrays.asList(new String[]{"co_third_create_time ASC"});
        return commonOrderMapper.list(daoQuery, (page-1)*pageSize, pageSize);
    }
}