| | |
| | | package com.yeshi.fanli.service.impl.order;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.UUID;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Propagation;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | |
|
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.Producer;
|
| | | import com.aliyun.openservices.ons.api.transaction.LocalTransactionExecuter;
|
| | | import com.aliyun.openservices.ons.api.transaction.TransactionProducer;
|
| | | import com.aliyun.openservices.ons.api.transaction.TransactionStatus;
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.OrderMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
|
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
|
| | | import com.yeshi.fanli.dto.order.CommonOrderAddResultDTO;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | 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;
|
| | | import com.yeshi.fanli.entity.order.CommonOrder;
|
| | | import com.yeshi.fanli.entity.order.HongBaoOrder;
|
| | | import com.yeshi.fanli.entity.pdd.PDDOrder;
|
| | | import com.yeshi.fanli.entity.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
|
| | | import com.yeshi.fanli.exception.elme.ElmeOrderException;
|
| | | import com.yeshi.fanli.exception.money.OrderMoneySettleException;
|
| | | import com.yeshi.fanli.exception.money.UserMoneyDetailException;
|
| | | import com.yeshi.fanli.exception.order.CommonOrderException;
|
| | | import com.yeshi.fanli.exception.order.HongBaoException;
|
| | | import com.yeshi.fanli.exception.order.OrderItemException;
|
| | | import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException;
|
| | | import com.yeshi.fanli.exception.user.UserAccountException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.log.OrderLogHelper;
|
| | | import com.yeshi.fanli.service.inter.elme.ElmeHongBaoOrderMapService;
|
| | | import com.yeshi.fanli.service.inter.elme.ElmeOrderProcessService;
|
| | | 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;
|
| | | import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
|
| | | import com.yeshi.fanli.service.inter.order.LostOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderMoneySettleService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderProcessService;
|
| | | import com.yeshi.fanli.service.inter.order.jd.JDOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.pdd.PDDOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.service.manger.order.HongBaoV2AddManager;
|
| | | import com.yeshi.fanli.util.CMQManager;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TaoBaoConstant;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.cmq.PlaceOrderCMQManager;
|
| | | import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
|
| | | import com.yeshi.fanli.util.jd.JDApiUtil;
|
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
|
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | @Service
|
| | | public class OrderProcessServiceImpl implements OrderProcessService {
|
| | |
|
| | | @Resource
|
| | | private OrderMapper orderMapper;
|
| | |
|
| | | @Resource
|
| | | private UserInfoMapper userInfoMapper;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoWeiQuanDrawBackService taoBaoWeiQuanDrawBackService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoOrderService taoBaoOrderService;
|
| | |
|
| | | @Resource
|
| | | private LostOrderService lostOrderService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoWeiQuanOrderMapper taoBaoWeiQuanOrderMapper;
|
| | |
|
| | | @Resource
|
| | | private AccountDetailsHongBaoMapService accountDetailsHongBaoMapService;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyDetailMapper userMoneyDetailMapper;
|
| | |
|
| | | @Resource
|
| | | private HongBaoV2Mapper hongBaoV2Mapper;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
|
| | |
|
| | | @Resource
|
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserSystemCouponService userSystemCouponService;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyService userMoneyService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
|
| | |
|
| | | @Resource
|
| | | private CommonOrderService commonOrderService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoV2Service hongBaoV2Service;
|
| | |
|
| | | @Resource
|
| | | private JDOrderService jdOrderService;
|
| | |
|
| | | @Resource
|
| | | private PDDOrderService pddOrderService;
|
| | |
|
| | | @Resource(name = "orderTransactionProducer")
|
| | | private TransactionProducer orderTransactionProducer;
|
| | |
|
| | | @Resource(name = "producer")
|
| | | private Producer producer;
|
| | |
|
| | | @Resource
|
| | | private OrderMoneySettleService orderMoneySettleService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoV2AddManager hongBaoV2AddManager;
|
| | |
|
| | | /**
|
| | | * 是否是分享订单
|
| | | * |
| | | * @param order
|
| | | * @return
|
| | | */
|
| | | private boolean isShareOrder(TaoBaoOrder order) {
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), order.getSourceMediaId(),
|
| | | order.getAdPositionId());
|
| | | if (!StringUtil.isNullOrEmpty(order.getSpecialId())
|
| | | || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 设置渠道ID当做会员运营ID的位置ID
|
| | | return false;
|
| | | } else if (!StringUtil.isNullOrEmpty(order.getRelationId())) {
|
| | | return true;
|
| | | } else {
|
| | | // 通过红包查询
|
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | order.getTradeId());
|
| | |
|
| | | if (commonOrder != null) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null
|
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public synchronized void processOrder(Map<String, List<TaoBaoOrder>> orders) {
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | |
|
| | | // 分离出返利订单与分享赚订单
|
| | | Iterator<String> its = orders.keySet().iterator();
|
| | | Map<String, List<TaoBaoOrder>> fanliOrderMap = new HashMap<>();
|
| | | Map<String, List<TaoBaoOrder>> shareOrderMap = new HashMap<>();
|
| | | Map<String, List<TaoBaoOrder>> elmeOrderMap = new HashMap<>();
|
| | | while (its.hasNext()) {
|
| | | String orderId = its.next();
|
| | |
|
| | | if (orders.get(orderId) != null && orders.get(orderId).size() > 0) {
|
| | | List<TaoBaoOrder> list = orders.get(orderId);
|
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(),
|
| | | list.get(0).getSourceMediaId(), list.get(0).getAdPositionId());
|
| | | if ("饿了么".equalsIgnoreCase(list.get(0).getOrderType())) {
|
| | | // 处理饿了么订单
|
| | | elmeOrderMap.put(orderId, list);
|
| | | }
|
| | |
|
| | | else {
|
| | | if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId())
|
| | | || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 设置渠道ID当做会员运营ID的位置ID
|
| | | fanliOrderMap.put(orderId, list);
|
| | | } else if (!StringUtil.isNullOrEmpty(list.get(0).getRelationId())) {
|
| | | shareOrderMap.put(orderId, list);
|
| | | } else {
|
| | | // 通过红包查询
|
| | | CommonOrder commonOrder = commonOrderService
|
| | | .selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, list.get(0).getTradeId());
|
| | |
|
| | | if (commonOrder != null) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null
|
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) {
|
| | | shareOrderMap.put(orderId, list);
|
| | | continue;
|
| | | }
|
| | | }
|
| | | fanliOrderMap.put(orderId, list);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 处理返利订单
|
| | | processShopingFanliOrder(fanliOrderMap);
|
| | | // 处理分享赚订单
|
| | | processShareGoodsOrder(shareOrderMap);
|
| | | // 处理饿了么订单
|
| | | processElemeOrder(elmeOrderMap);
|
| | | }
|
| | |
|
| | | private ElmeOrder createElmeOrder(TaoBaoOrder taoBaoOrder) {
|
| | | ElmeOrder elmeOrder = new ElmeOrder();
|
| | | elmeOrder.setChannelId("");
|
| | | elmeOrder.setCreateTime(new Date());
|
| | | elmeOrder
|
| | | .setOrderDate(new Date(TimeUtil.convertToTimeTemp(taoBaoOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss")));
|
| | | elmeOrder.setOrderId(taoBaoOrder.getOrderId());
|
| | | elmeOrder.setPayMoney(taoBaoOrder.getPayment());
|
| | | elmeOrder.setRid(taoBaoOrder.getRelationId());
|
| | | if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单结算"))
|
| | | elmeOrder.setIsSettle(true);
|
| | | else
|
| | | elmeOrder.setIsSettle(false);
|
| | |
|
| | | if (!taoBaoOrder.getOrderState().equalsIgnoreCase("订单失效"))
|
| | | elmeOrder.setState(1);
|
| | | else {
|
| | | elmeOrder.setState(0);
|
| | | elmeOrder.setPayMoney(new BigDecimal(0));
|
| | | }
|
| | | elmeOrder.setTrackPid(
|
| | | String.format("mm_124933865_%s_%s", taoBaoOrder.getSourceMediaId(), taoBaoOrder.getAdPositionId()));
|
| | | if (!StringUtil.isNullOrEmpty(taoBaoOrder.getRelationId())) {
|
| | | UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByRelationId(taoBaoOrder.getRelationId());
|
| | | if (extraInfo != null)
|
| | | elmeOrder.setUid(extraInfo.getUser().getId());
|
| | | }
|
| | | return elmeOrder;
|
| | | }
|
| | |
|
| | | private void processElemeOrder(Map<String, List<TaoBaoOrder>> orders) {
|
| | | for (Iterator<String> its = orders.keySet().iterator(); its.hasNext();) {
|
| | | String orderId = its.next();
|
| | | List<TaoBaoOrder> orderList = orders.get(orderId);
|
| | | for (TaoBaoOrder taoBaoOrder : orderList) {
|
| | | ElmeOrder elmeOrder = createElmeOrder(taoBaoOrder);
|
| | | try {
|
| | | elmeOrderProcessService.processOrder(elmeOrder);
|
| | | } catch (ElmeOrderException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void processShopingFanliOrder(Map<String, List<TaoBaoOrder>> orders) {
|
| | | // 查询在Order中是否存在该订单号
|
| | | Iterator<String> its = orders.keySet().iterator();
|
| | | String tempOrderId = "";
|
| | | while (its.hasNext()) {
|
| | | try {
|
| | | String orderId = its.next();
|
| | | tempOrderId = orderId;
|
| | | // 处理红包与子红包
|
| | | // if (isRedisLockOrder(orderId))
|
| | | // continue;
|
| | | // redisLockOrder(orderId);
|
| | | processShopingFanliOrderNew(orderId, orders.get(orderId));
|
| | | // redisUnlockOrder(orderId);
|
| | | // 出错了就不处理该订单了,需要定期检查
|
| | |
|
| | | // 更改丢失订单的状态
|
| | | lostOrderService.processSuceess(orderId, Constant.SOURCE_TYPE_TAOBAO);
|
| | |
|
| | | } catch (HongBaoException e1) {
|
| | | e1.printStackTrace();
|
| | | } catch (OrderItemException e2) {
|
| | | e2.printStackTrace();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, null, tempOrderId);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void processShareGoodsOrder(Map<String, List<TaoBaoOrder>> orders) {
|
| | | // pidOrderService.addPidOrderFromTaoBao(orders);
|
| | | if (orders != null) {
|
| | | Iterator<String> its = orders.keySet().iterator();
|
| | | while (its.hasNext()) {
|
| | | String orderId = its.next();
|
| | | try {
|
| | | processShareGoodsOrderNew(orderId, orders.get(orderId));
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "processShareGoodsOrderNew出错", "订单号:" + orderId);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void fanli() {
|
| | | LogHelper.test("处理返利到账");
|
| | | // 获取主红包
|
| | | List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByType(HongBaoV2.TYPE_ZIGOU, 1000);
|
| | | //
|
| | | // /**
|
| | | // * 需要实时更新待返利的订单
|
| | | // */
|
| | | //
|
| | | // // 计算最大的创建时间与最小的创建时间
|
| | | // Map<String, Long> map = getMaxAndMinCreateTime(hongBaoList);
|
| | | // if (map != null) {
|
| | | // long max = map.get("max");
|
| | | // long min = map.get("min");
|
| | | // // 最小时间提前10分钟
|
| | | // min = min - 1000 * 60 * 10L;
|
| | | // // 更新该段时间的订单
|
| | | // List<TaoBaoOrder> orderList = new ArrayList<>();
|
| | | // try {
|
| | | // orderList = TaoBaoOrderUtil.getOrderList(min, max);
|
| | | // } catch (TaoBaoOrderException e) {
|
| | | // e.printStackTrace();
|
| | | // }
|
| | | // // try {
|
| | | // if (orderList != null)
|
| | | // processOrder(TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(orderList));
|
| | | // // } catch (Exception e) {
|
| | | // // e.printStackTrace();
|
| | | // // try {
|
| | | // // LogHelper.errorDetailInfo(e);
|
| | | // // } catch (Exception e1) {
|
| | | // // e1.printStackTrace();
|
| | | // // }
|
| | | // // }
|
| | | // }
|
| | |
|
| | | /**
|
| | | * 开始返利
|
| | | */
|
| | | for (HongBaoV2 hb : hongBaoList) {
|
| | | //
|
| | | if (hb.getState() == HongBaoV2.STATE_SHIXIAO || hb.getState() == HongBaoV2.STATE_YILINGQU)
|
| | | continue;
|
| | |
|
| | | if (hb.getPreGetTime() == null || hb.getPreGetTime().getTime() == 0
|
| | | || hb.getPreGetTime().getTime() > System.currentTimeMillis())
|
| | | continue;
|
| | | try {
|
| | | CMQManager.getInstance().addFanLiMsgNew(hb);
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Resource
|
| | | private HongBaoOrderMapper hongBaoOrderMapper;
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void fanli(HongBaoV2 hb1) throws TaoBaoWeiQuanException {
|
| | | // 查询最新的红包数据
|
| | | hb1 = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hb1.getId());
|
| | | // 正常用户才能到账
|
| | | UserInfo mainUser = userInfoMapper.selectAvailableByPrimaryKey(hb1.getUserInfo().getId());
|
| | | if (mainUser == null || mainUser.getState() != UserInfo.STATE_NORMAL) {
|
| | | return;
|
| | | }
|
| | | // 查询红包相关联的订单
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hb1.getId());
|
| | | if (hongBaoOrder == null) {
|
| | | LogHelper.error("返利失败:" + hb1.getId());
|
| | | return;
|
| | | }
|
| | |
|
| | | if (hongBaoOrder.getCommonOrder() == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // 如果是拼多多/京东维权则返回,不需要返利
|
| | | if ((hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_PDD
|
| | | || hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_JD)
|
| | | && hongBaoOrder.getCommonOrder().getState() == CommonOrder.STATE_WQ)
|
| | | return;
|
| | |
|
| | | if (hongBaoOrder.getCommonOrder() != null
|
| | | && hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_TAOBAO) {
|
| | | // 维权中的不返利
|
| | | List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
|
| | | .selectListByOrderIdAndState(hongBaoOrder.getCommonOrder().getOrderNo(), "维权创建");
|
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
|
| | | return;
|
| | |
|
| | | taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
|
| | | .selectListByOrderIdAndState(hongBaoOrder.getCommonOrder().getOrderNo(), "等待处理");
|
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
|
| | | return;
|
| | | }
|
| | |
|
| | | // 查询该订单之前是否有到账
|
| | | List<HongBaoOrder> list = hongBaoOrderMapper.listByOrderIdAndSourceType(
|
| | | hongBaoOrder.getCommonOrder().getOrderNo(), hongBaoOrder.getCommonOrder().getSourceType());
|
| | | List<Long> hongBaoIdList = new ArrayList<>();
|
| | | if (list != null) {
|
| | | for (HongBaoOrder ho : list) {
|
| | | hongBaoIdList.add(ho.getHongBaoV2().getId());
|
| | | }
|
| | | }
|
| | |
|
| | | List<HongBaoV2> allHongBaoList = hongBaoV2Mapper.listByIds(hongBaoIdList);
|
| | | boolean first = true;
|
| | | for (HongBaoV2 v2 : allHongBaoList)
|
| | | if (v2.getState() == HongBaoV2.STATE_YILINGQU) {
|
| | | first = false;
|
| | | break;
|
| | | }
|
| | |
|
| | | // 自购到账事务消息
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_ZIGOU,
|
| | | mainUser.getId(), hongBaoOrder.getCommonOrder().getSourceType(),
|
| | | hongBaoOrder.getCommonOrder().getOrderNo(), null, new Date(), 0);
|
| | | mqMsg.setOrderFirst(first);
|
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
|
| | | String key = mainUser.getId() + "-" + UUID.randomUUID().toString();
|
| | | msg.setKey(key);
|
| | | try {
|
| | | if (!Constant.IS_TEST)
|
| | | orderTransactionProducer.send(msg, new LocalTransactionExecuter() {
|
| | | @Override
|
| | | public TransactionStatus execute(Message arg0, Object arg1) {
|
| | | try {
|
| | | orderMoneySettleService.ziGouSettle(hongBaoOrder.getCommonOrder().getOrderNo(),
|
| | | hongBaoOrder.getCommonOrder().getSourceType(), key);
|
| | | return TransactionStatus.CommitTransaction;
|
| | | } catch (Exception e) {
|
| | | return TransactionStatus.RollbackTransaction;
|
| | | }
|
| | | }
|
| | | }, null);
|
| | | else {
|
| | | try {
|
| | | orderMoneySettleService.ziGouSettle(hongBaoOrder.getCommonOrder().getOrderNo(),
|
| | | hongBaoOrder.getCommonOrder().getSourceType(), key);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg));
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void weiQuanOrder(List<TaoBaoWeiQuanOrder> orderList) {
|
| | | if (orderList != null)
|
| | | for (TaoBaoWeiQuanOrder order : orderList) {
|
| | | try {
|
| | | if (order.getState().contains("维权成功")) {
|
| | | CMQManager.getInstance().addWeiQuanOrderMsg(order);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.error("维权订单加入到队列出错:" + order != null ? new Gson().toJson(order) : null);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void weiQuanOrder(TaoBaoWeiQuanOrder order) {
|
| | | // 订单结算时间在2018-08-05后就不处理维权了
|
| | |
|
| | | List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(order.getOrderId());
|
| | | if (orderList != null && orderList.size() > 0 & !StringUtil.isNullOrEmpty(orderList.get(0).getSettlementTime()))
|
| | | order.setJieSuanTime(
|
| | | new Date(TimeUtil.convertToTimeTemp(orderList.get(0).getSettlementTime(), "yyyy-MM-dd HH:mm:ss")));
|
| | |
|
| | | // 处理维权成功但是已到账的订单
|
| | | if (order.getJieSuanTime().getTime() > TimeUtil.convertToTimeTemp("2019-01-01", "yyyy-MM-dd")) {// 结算时间在2月1号的开始处理已到账但是维权的
|
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | order.getOrderItemId());
|
| | | if (commonOrder != null && !StringUtil.isNullOrEmpty(commonOrder.getTradeId())) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null
|
| | | && hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_YILINGQU) {// 已经到账的看是否需要扣款
|
| | | TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackService
|
| | | .selectByOrderItemId(order.getOrderItemId());
|
| | | if (drawBack == null) {// 还未扣款
|
| | | OrderLogHelper.taoBaoWeiQuan("已到账未扣款处理:子订单号:" + order.getOrderItemId());
|
| | | try {
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanFanli(order.getOrderId(),true);
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanShare(order.getOrderId());
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanInvite(order.getOrderId());
|
| | | } catch (TaoBaoWeiQuanException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "到账后处理维权扣款出错", "订单号:" + order.getOrderId());
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | } else {
|
| | | // 查询子红包是否已到账
|
| | | List<HongBaoV2> children = hongBaoV2Service
|
| | | .listChildrenById(hongBaoOrder.getHongBaoV2().getId());
|
| | | for (HongBaoV2 hongBaoV2 : children) {
|
| | | if (hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU) {
|
| | | try {
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanInvite(order.getOrderId());
|
| | | } catch (TaoBaoWeiQuanException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "到账后处理维权扣款出错", "订单号:" + order.getOrderId());
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void fanliInvaiteAndShare() {
|
| | | // 查出邀请赚与分享赚该返利的用户ID
|
| | | List<Long> inviteAndShareUids = hongBaoV2Mapper.listUidCanBanlanceShareAndInvite(1000);
|
| | | Set<Long> uidSets = new HashSet<>();
|
| | | if (inviteAndShareUids != null)
|
| | | for (Long uid : inviteAndShareUids) {
|
| | | if (userInfoMapper.selectAvailableByPrimaryKey(uid) != null)
|
| | | uidSets.add(uid);
|
| | | }
|
| | | // 根据用户ID
|
| | | Iterator<Long> its = uidSets.iterator();
|
| | | while (its.hasNext()) {
|
| | | Long uid = its.next();
|
| | | try {
|
| | | CMQManager.getInstance().addFanLiTiChengMsg(uid);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.error(e);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void fanliInvaiteAndShare(Long uid) throws TaoBaoWeiQuanException {
|
| | | // 邀请赚到账
|
| | | try {
|
| | | orderMoneySettleService.inviteSettleTB(uid);
|
| | | } catch (OrderMoneySettleException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | try {
|
| | | orderMoneySettleService.inviteSettleJD(uid);
|
| | | } catch (OrderMoneySettleException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | //
|
| | | try {
|
| | | orderMoneySettleService.inviteSettlePDD(uid);
|
| | | } catch (OrderMoneySettleException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | // 分享赚到账
|
| | | try {
|
| | | orderMoneySettleService.shareSettleTB(uid);
|
| | | } catch (OrderMoneySettleException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | try {
|
| | | orderMoneySettleService.shareSettleJD(uid);
|
| | | } catch (OrderMoneySettleException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | //
|
| | | try {
|
| | | orderMoneySettleService.shareSettlePDD(uid);
|
| | | } catch (OrderMoneySettleException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void processShopingFanliOrderNew(String orderId, List<TaoBaoOrder> orderList)
|
| | | throws HongBaoException, OrderItemException {
|
| | |
|
| | | LogHelper.test(String.format("订单处理:订单号-%s 订单数量-%s", orderId, orderList.size() + ""));
|
| | | if (orderList.size() == 1)
|
| | | LogHelper.test("订单排序值:" + orderList.get(0).getOrderBy());
|
| | |
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | |
|
| | | if (orderList != null && orderList.size() > 0) {
|
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(),
|
| | | orderList.get(0).getSourceMediaId(), orderList.get(0).getAdPositionId());
|
| | |
|
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(orderId, Constant.SOURCE_TYPE_TAOBAO);
|
| | | // 原来不存在订单
|
| | | Long uid = null;
|
| | | if (oldOrder == null) {
|
| | | Long targetUid = null;
|
| | | if (pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)
|
| | | && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {
|
| | | targetUid = taoBaoBuyRelationMapService.selectUidByRelationId(orderList.get(0).getRelationId());
|
| | |
|
| | | } else if (!StringUtil.isNullOrEmpty(orderList.get(0).getSpecialId())) {
|
| | | UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService
|
| | | .getBySpecialId(orderList.get(0).getSpecialId());
|
| | | if (info != null && info.getUser() != null)
|
| | | targetUid = info.getUser().getId();
|
| | | }
|
| | |
|
| | | if (targetUid != null) {
|
| | | uid = targetUid;
|
| | | // 插入到Order中
|
| | | // 添加到订单中去
|
| | | Order order = new Order();
|
| | | order.setBeizhu("PID返利订单");
|
| | | order.setCreatetime(System.currentTimeMillis());
|
| | | order.setOrderId(orderId);
|
| | | order.setOrderType(1);
|
| | | order.setState(Order.STATE_YIZHIFU);
|
| | | order.setUserInfo(new UserInfo(uid));
|
| | | order.setVersion(2);
|
| | | // 加入到订单表
|
| | | orderMapper.insertSelective(order);
|
| | | oldOrder = order;
|
| | | }
|
| | |
|
| | | } else {
|
| | | uid = oldOrder.getUserInfo().getId();
|
| | | }
|
| | | // 尚未找到和PID对应的用户
|
| | | if (uid == null)
|
| | | return;
|
| | |
|
| | | // 计算订单总额度
|
| | | Order updateOrder = new Order();
|
| | | updateOrder.setId(oldOrder.getId());
|
| | | BigDecimal money = new BigDecimal(0);
|
| | | for (TaoBaoOrder o : orderList) {
|
| | | if (o.getOrderState().equalsIgnoreCase("订单结算"))
|
| | | money = money.add(o.getSettlement());
|
| | | else {
|
| | | money = money.add(o.getPayment());
|
| | | }
|
| | | }
|
| | | updateOrder.setMoney(money);
|
| | | String thirdState = null;
|
| | | for (TaoBaoOrder o : orderList)
|
| | | if (!o.getOrderState().equalsIgnoreCase("订单失效")) {
|
| | | thirdState = o.getOrderState();
|
| | | break;
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(thirdState))
|
| | | thirdState = "订单失效";
|
| | | updateOrder.setThirdState(thirdState);
|
| | | updateOrder.setThirdCreateTime(
|
| | | new Date(TimeUtil.convertToTimeTemp(orderList.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss")));
|
| | | orderMapper.updateByPrimaryKeySelective(updateOrder);
|
| | |
|
| | | // 用第一个子订单锁定用户
|
| | | List<CommonOrderAddResultDTO> commonOrderList = null;
|
| | | try {
|
| | | commonOrderList = commonOrderService.addTaoBaoOrder(orderList, uid);
|
| | | addHongBaoWithMQ(commonOrderList, orderId, uid, Constant.SOURCE_TYPE_TAOBAO, HongBaoV2.TYPE_ZIGOU);
|
| | | if (isCommonOrderAllAdd(commonOrderList)) {
|
| | | Order order = new Order();
|
| | | order.setOrderId(orderId);
|
| | | order.setOrderType(Constant.SOURCE_TYPE_TAOBAO);
|
| | | order.setUserInfo(new UserInfo(uid));
|
| | | try {
|
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | }
|
| | | } catch (CommonOrderException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "addTaoBaoOrder或addHongBao出错", "订单号:" + orderId);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void processShareGoodsOrderNew(String orderId, List<TaoBaoOrder> orderList) {
|
| | | if (orderList != null && orderList.size() > 0) {
|
| | | // 原来不存在订单
|
| | | Long uid = null;
|
| | | UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService.getByRelationId(orderList.get(0).getRelationId());
|
| | | if (info != null && info.getUser() != null)
|
| | | uid = info.getUser().getId();
|
| | | // 尚未找到和PID对应的用户
|
| | | if (uid == null) {
|
| | | // 通过红包查询
|
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | orderList.get(0).getTradeId());
|
| | |
|
| | | if (commonOrder != null) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null
|
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) {
|
| | | uid = hongBaoOrder.getHongBaoV2().getUserInfo().getId();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (uid == null)
|
| | | return;
|
| | |
|
| | | // 用第一个子订单锁定用户
|
| | | try {
|
| | | List<CommonOrderAddResultDTO> commonOrders = commonOrderService.addTaoBaoOrder(orderList, uid);
|
| | | addHongBaoWithMQ(commonOrders, orderId, uid, Constant.SOURCE_TYPE_TAOBAO, HongBaoV2.TYPE_SHARE_GOODS);
|
| | | if (isCommonOrderAllAdd(commonOrders)) {
|
| | | Order order = new Order();
|
| | | order.setOrderId(orderId);
|
| | | order.setOrderType(Constant.SOURCE_TYPE_TAOBAO);
|
| | | order.setUserInfo(new UserInfo(uid));
|
| | | try {
|
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | }
|
| | | } catch (CommonOrderException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 是否为分享订单
|
| | | * |
| | | * @param order
|
| | | * @return
|
| | | */
|
| | | private boolean isShareOrder(JDOrder order) {
|
| | | if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0)
|
| | | return false;
|
| | | Long positionId = order.getOrderItemList().get(0).getPositionId();
|
| | | if (positionId == JDApiUtil.POSITION_SHARE) {// 分享订单
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void processJDOrder(JDOrder order) {
|
| | | if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0)
|
| | | return;
|
| | | // 拆单的不做处理
|
| | | if (order.getValidCode() == 2)
|
| | | return;
|
| | |
|
| | | // 根据ext1与subUnionId跟单
|
| | | String uidStr = order.getExt1();
|
| | | if (StringUtil.isNullOrEmpty(uidStr))
|
| | | uidStr = order.getOrderItemList().get(0).getSubUnionId();
|
| | |
|
| | | Long uid = null;
|
| | | if (!StringUtil.isNullOrEmpty(uidStr) && NumberUtil.isNumeric(uidStr))
|
| | | uid = Long.parseLong(uidStr);
|
| | | Long positionId = order.getOrderItemList().get(0).getPositionId();
|
| | | if (positionId == JDApiUtil.POSITION_FANLI)// 返利订单
|
| | | {
|
| | | processFanLiJDOrder(order, uid);
|
| | | lostOrderService.processSuceess(order.getOrderId() + "", Constant.SOURCE_TYPE_JD);
|
| | | } else if (positionId == JDApiUtil.POSITION_SHARE) {// 分享订单
|
| | | if (uid == null)// 分享订单不允许找回
|
| | | return;
|
| | | processShareJDOrder(order, uid);
|
| | | } else {// 处理是否有订单找回的状态
|
| | | processFanLiJDOrder(order, null);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 处理京东返利订单
|
| | | * |
| | | * @param jdOrder
|
| | | * @param uid
|
| | | */
|
| | | @Transactional
|
| | | private void processFanLiJDOrder(JDOrder jdOrder, Long uid) {
|
| | | int invalidCount = 0;
|
| | | BigDecimal totalMoney = new BigDecimal(0);
|
| | | // 订单状态判断
|
| | | for (JDOrderItem item : jdOrder.getOrderItemList()) {
|
| | | if (item.getEstimateCosPrice() != null)
|
| | | totalMoney = totalMoney.add(item.getEstimateCosPrice());
|
| | |
|
| | | if (item.getValidCode() == 16 || item.getValidCode() == 17 || item.getValidCode() == 18) {// 已付款
|
| | |
|
| | | } else if (item.getValidCode() == 15) {// 未支付
|
| | |
|
| | | } else {
|
| | | invalidCount++;
|
| | | }
|
| | | }
|
| | |
|
| | | // 加入订单
|
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(jdOrder.getOrderId() + "",
|
| | | Constant.SOURCE_TYPE_JD);
|
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单"))
|
| | | uid = oldOrder.getUserInfo().getId();
|
| | |
|
| | | if (uid == null)
|
| | | return;
|
| | |
|
| | | if (oldOrder == null)// 新增
|
| | | {
|
| | | Order order = new Order();
|
| | | order.setBeizhu("京东返利订单");
|
| | | order.setCreatetime(System.currentTimeMillis());
|
| | | order.setOrderId(jdOrder.getOrderId() + "");
|
| | | order.setOrderType(Constant.SOURCE_TYPE_JD);
|
| | | order.setState(
|
| | | invalidCount == jdOrder.getOrderItemList().size() ? Order.STATE_SHIXIAO : Order.STATE_YIZHIFU);
|
| | | order.setUserInfo(new UserInfo(uid));
|
| | | order.setVersion(2);
|
| | | order.setThirdCreateTime(new Date(jdOrder.getOrderTime()));
|
| | | order.setMoney(totalMoney);
|
| | | // 加入到订单表
|
| | | orderMapper.insertSelective(order);
|
| | | } else {
|
| | | Order updateOrder = new Order();
|
| | | updateOrder.setId(oldOrder.getId());
|
| | | updateOrder.setMoney(totalMoney);
|
| | | orderMapper.updateByPrimaryKeySelective(updateOrder);
|
| | | }
|
| | |
|
| | | try {
|
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addJDOrder(jdOrder, uid);
|
| | | addHongBaoWithMQ(commonOrderList, jdOrder.getOrderId() + "", uid, Constant.SOURCE_TYPE_JD,
|
| | | HongBaoV2.TYPE_ZIGOU);
|
| | |
|
| | | if (isCommonOrderAllAdd(commonOrderList)) {
|
| | | Order order = new Order();
|
| | | order.setOrderId(jdOrder.getOrderId() + "");
|
| | | order.setOrderType(Constant.SOURCE_TYPE_JD);
|
| | | order.setUserInfo(new UserInfo(uid));
|
| | | try {
|
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | }
|
| | | } catch (CommonOrderException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + jdOrder.getOrderId());
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 处理京东分享订单
|
| | | * |
| | | * @param order
|
| | | * @param uid
|
| | | */
|
| | | @Transactional
|
| | | private void processShareJDOrder(JDOrder jdOrder, Long uid) {
|
| | | try {
|
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addJDOrder(jdOrder, uid);
|
| | | addHongBaoWithMQ(commonOrderList, jdOrder.getOrderId() + "", uid, Constant.SOURCE_TYPE_JD,
|
| | | HongBaoV2.TYPE_SHARE_GOODS);
|
| | | if (isCommonOrderAllAdd(commonOrderList)) {
|
| | | Order order = new Order();
|
| | | order.setOrderId(jdOrder.getOrderId() + "");
|
| | | order.setOrderType(Constant.SOURCE_TYPE_JD);
|
| | | order.setUserInfo(new UserInfo(uid));
|
| | | try {
|
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | }
|
| | | } catch (CommonOrderException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + jdOrder.getOrderId());
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 是否是分享赚订单
|
| | | * |
| | | * @param order
|
| | | * @return
|
| | | */
|
| | | private boolean isShareOrder(PDDOrder pddOrder) {
|
| | | String positionId = pddOrder.getpId();
|
| | | if (PinDuoDuoApiUtil.PID_SHARE.equalsIgnoreCase(positionId))
|
| | | return true;
|
| | | else
|
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 处理拼多多订单
|
| | | */
|
| | | @Override
|
| | | public void processPDDOrder(PDDOrder pddOrder) {
|
| | | if (pddOrder == null)
|
| | | return;
|
| | | String uidStr = pddOrder.getCustomParameters();
|
| | | Long uid = null;
|
| | | if (!StringUtil.isNullOrEmpty(uidStr))
|
| | | uid = Long.parseLong(uidStr);
|
| | | String positionId = pddOrder.getpId();
|
| | | if (PinDuoDuoApiUtil.PID_FANLI.equalsIgnoreCase(positionId))// 返利订单
|
| | | {
|
| | | processFanLiPDDOrder(pddOrder, uid);
|
| | | lostOrderService.processSuceess(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD);
|
| | | } else if (PinDuoDuoApiUtil.PID_SHARE.equalsIgnoreCase(positionId)) {// 分享订单
|
| | | if (uid == null)// 分享订单不允许找回
|
| | | return;
|
| | | processSharePDDOrder(pddOrder, uid);
|
| | | } else {// 处理是否有订单找回的状态
|
| | | processFanLiPDDOrder(pddOrder, null);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 处理拼多多自购返利订单
|
| | | * |
| | | * @param pddOrder
|
| | | * @param uid
|
| | | */
|
| | | @Transactional
|
| | | private void processFanLiPDDOrder(PDDOrder pddOrder, Long uid) {
|
| | | int orderState = 0;
|
| | | if (pddOrder.getOrderStatus() == -1 || pddOrder.getOrderStatus() == 8)
|
| | | orderState = Order.STATE_SHIXIAO;
|
| | | else
|
| | | orderState = Order.STATE_YIZHIFU;
|
| | |
|
| | | BigDecimal totalMoney = MoneyBigDecimalUtil.div(new BigDecimal(pddOrder.getOrderAmount()), new BigDecimal(100));
|
| | |
|
| | | // 加入订单
|
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD);
|
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单"))
|
| | | uid = oldOrder.getUserInfo().getId();
|
| | |
|
| | | if (uid == null)
|
| | | return;
|
| | |
|
| | | if (oldOrder == null)// 新增
|
| | | {
|
| | | Order order = new Order();
|
| | | order.setBeizhu("拼多多返利订单");
|
| | | order.setCreatetime(System.currentTimeMillis());
|
| | | order.setOrderId(pddOrder.getOrderSn());
|
| | | order.setOrderType(Constant.SOURCE_TYPE_PDD);
|
| | | order.setState(orderState);
|
| | | order.setUserInfo(new UserInfo(uid));
|
| | | order.setVersion(2);
|
| | | order.setThirdCreateTime(new Date(pddOrder.getOrderCreateTime() * 1000));
|
| | | order.setMoney(totalMoney);
|
| | | // 加入到订单表
|
| | | orderMapper.insertSelective(order);
|
| | | } else {
|
| | | Order updateOrder = new Order();
|
| | | updateOrder.setId(oldOrder.getId());
|
| | | updateOrder.setMoney(totalMoney);
|
| | | orderMapper.updateByPrimaryKeySelective(updateOrder);
|
| | | }
|
| | |
|
| | | try {
|
| | | List<PDDOrder> pddOrderList = new ArrayList<>();
|
| | | pddOrderList.add(pddOrder);
|
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addPDDOrder(pddOrderList, uid);
|
| | | addHongBaoWithMQ(commonOrderList, pddOrder.getOrderSn(), uid, Constant.SOURCE_TYPE_PDD,
|
| | | HongBaoV2.TYPE_ZIGOU);
|
| | | if (isCommonOrderAllAdd(commonOrderList)) {
|
| | | Order order = new Order();
|
| | | order.setOrderId(pddOrder.getOrderSn());
|
| | | order.setOrderType(Constant.SOURCE_TYPE_PDD);
|
| | | order.setUserInfo(new UserInfo(uid));
|
| | | try {
|
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | }
|
| | | } catch (CommonOrderException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "addPDDOrder或addHongBao出错", "订单号:" + pddOrder.getOrderSn());
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 处理拼多多分享订单
|
| | | * |
| | | * @param order
|
| | | * @param uid
|
| | | */
|
| | | @Transactional
|
| | | private void processSharePDDOrder(PDDOrder pddOrder, Long uid) {
|
| | | try {
|
| | | List<PDDOrder> pddOrderList = new ArrayList<>();
|
| | | pddOrderList.add(pddOrder);
|
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addPDDOrder(pddOrderList, uid);
|
| | | addHongBaoWithMQ(commonOrderList, pddOrder.getOrderSn(), uid, Constant.SOURCE_TYPE_PDD,
|
| | | HongBaoV2.TYPE_SHARE_GOODS);
|
| | | if (isCommonOrderAllAdd(commonOrderList)) {
|
| | | Order order = new Order();
|
| | | order.setOrderId(pddOrder.getOrderSn());
|
| | | order.setOrderType(Constant.SOURCE_TYPE_PDD);
|
| | | order.setUserInfo(new UserInfo(uid));
|
| | | try {
|
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | }
|
| | | } catch (CommonOrderException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + pddOrder.getOrderId());
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void repairCommonOrderByByTaoBaoOrder(String orderId) {
|
| | | // 根据订单号查询淘宝订单
|
| | | List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId);
|
| | | if (orderList != null)
|
| | | for (TaoBaoOrder order : orderList) {
|
| | | // 根据交易ID查询常规订单
|
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | order.getTradeId());
|
| | | // 修复orderby
|
| | | if (commonOrder != null) {
|
| | | CommonOrder update = new CommonOrder(commonOrder.getId());
|
| | | update.setOrderBy(order.getOrderBy());
|
| | | update.setUpdateTime(new Date());
|
| | | commonOrderService.updateByPrimaryKeySelective(update);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public boolean isShareOrder(CommonOrder commonOrder) {
|
| | | switch (commonOrder.getSourceType()) {
|
| | | case Constant.SOURCE_TYPE_TAOBAO:
|
| | | return isShareOrder(taoBaoOrderService.selectByTradeId(commonOrder.getTradeId()));
|
| | | case Constant.SOURCE_TYPE_JD:
|
| | | return isShareOrder(jdOrderService.selectDetailByOrderId(Long.parseLong(commonOrder.getOrderNo())));
|
| | | case Constant.SOURCE_TYPE_PDD:
|
| | | return isShareOrder(pddOrderService.selectByOrderSn(commonOrder.getOrderNo()).get(0));
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 转为普通订单
|
| | | * |
| | | * @param dtoList
|
| | | * @return
|
| | | */
|
| | | private List<CommonOrder> convertCommonOrder(List<CommonOrderAddResultDTO> dtoList) {
|
| | | List<CommonOrder> commonOrderList = new ArrayList<>();
|
| | | if (dtoList != null)
|
| | | for (CommonOrderAddResultDTO dto : dtoList)
|
| | | commonOrderList.add(dto.getCommonOrder());
|
| | | return commonOrderList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 是否全是增加
|
| | | * |
| | | * @param list
|
| | | * @return
|
| | | */
|
| | | private boolean isCommonOrderAllAdd(List<CommonOrderAddResultDTO> list) {
|
| | | if (list == null || list.size() == 0)
|
| | | return false;
|
| | | int addCount = 0;
|
| | | if (list != null)
|
| | | for (CommonOrderAddResultDTO dto : list) {
|
| | | if (dto.getType() == CommonOrderAddResultDTO.TYPE_ADD)
|
| | | addCount++;
|
| | | }
|
| | | if (addCount == list.size())
|
| | | return true;
|
| | | else
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void invalidHongBaoV2AndGiveGodenCorn(Long hongBaoId, Long uid, String orderId, int sourceType,
|
| | | String beiZhu) throws Exception {
|
| | | HongBaoV2 v2 = new HongBaoV2(hongBaoId);
|
| | | v2.setState(HongBaoV2.STATE_SHIXIAO);
|
| | | v2.setBeizhu(beiZhu);
|
| | | v2.setUpdateTime(new Date());
|
| | | hongBaoV2Service.updateByPrimaryKeySelective(v2);
|
| | | List<HongBaoV2> children = hongBaoV2Service.listChildrenById(hongBaoId);
|
| | | if (children != null)
|
| | | for (HongBaoV2 child : children) {
|
| | | HongBaoV2 update = new HongBaoV2(child.getId());
|
| | | update.setState(HongBaoV2.STATE_SHIXIAO);
|
| | | update.setBeizhu(beiZhu);
|
| | | update.setUpdateTime(new Date());
|
| | | hongBaoV2Service.updateByPrimaryKeySelective(update);
|
| | | }
|
| | | userSystemCouponService.systemGiveRewardCoupon(uid, 1, orderId, sourceType, "因商家违约未能结算返利或商家已经关店");
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void doTaoBaoSellerNotPaid(TaoBaoOrder order) {
|
| | |
|
| | | // 根据交易ID查询
|
| | | if (!StringUtil.isNullOrEmpty(order.getTradeId())) {
|
| | | List<CommonOrder> commonOrderList = commonOrderService
|
| | | .listBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, order.getTradeId());
|
| | | if (commonOrderList != null)
|
| | | // 查询主订单
|
| | | for (CommonOrder commonOrder : commonOrderList) {
|
| | | // 查询主红包
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null) {
|
| | | if (hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_BUKELINGQU) {
|
| | | // 订单失效,赠送金币
|
| | | try {
|
| | | invalidHongBaoV2AndGiveGodenCorn(hongBaoOrder.getHongBaoV2().getId(), hongBaoOrder.getHongBaoV2().getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType(), "订单成功,商家未打款");
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public void elmeFanli() {
|
| | |
|
| | | }
|
| | |
|
| | | // 饿了么订单
|
| | | @Resource
|
| | | private ElmeHongBaoOrderMapService elmeHongBaoOrderMapService;
|
| | |
|
| | | @Resource
|
| | | private ElmeOrderService elmeOrderService;
|
| | |
|
| | | @Resource
|
| | | private ElmeOrderProcessService elmeOrderProcessService;
|
| | |
|
| | | /**
|
| | | * 获取饿了么可以返利的红包
|
| | | * |
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public List<HongBaoV2> getCanBalanceElmeFanliHongBao() {
|
| | | List<Integer> list = new ArrayList<>();
|
| | | list.add(HongBaoV2.TYPE_ELME);
|
| | | return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, 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);
|
| | | }
|
| | | // 返利到账
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加红包与事务消息
|
| | | * |
| | | * @param commonOrderList
|
| | | * @param orderId
|
| | | * @param uid
|
| | | * @param sourceType
|
| | | * @param hongBaoType
|
| | | */
|
| | | @Transactional
|
| | | private void addHongBaoWithMQ(List<CommonOrderAddResultDTO> commonOrderList, String orderId, Long uid,
|
| | | int sourceType, int hongBaoType) {
|
| | | final List<CommonOrder> coList = convertCommonOrder(commonOrderList);
|
| | | int resultCode = 0;
|
| | | try {
|
| | | long time = TimeUtil.convertToTimeTemp("2019-12-06", "yyyy-MM-dd");
|
| | | if (!Constant.IS_TEST)
|
| | | time = TimeUtil.convertToTimeTemp("2019-12-20", "yyyy-MM-dd");
|
| | |
|
| | | if (coList.get(0).getThirdCreateTime().getTime() < time)
|
| | | resultCode = hongBaoV2Service.addHongBao(coList, hongBaoType);
|
| | | else
|
| | | resultCode = hongBaoV2AddManager.addHongBao(coList, hongBaoType);
|
| | | } catch (HongBaoException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + orderId);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | } catch (UserAccountException e) {
|
| | |
|
| | | }
|
| | | if (!Constant.IS_TEST)
|
| | | if (resultCode == 1) {// 只发送新增消息
|
| | | OrderMQMsg mqMsg = new OrderMQMsg(orderId, sourceType, uid, OrderMQMsg.HANDLE_TYPE_ADD,
|
| | | isCommonOrderValid(coList), 0, new Date());
|
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderStatistic, mqMsg);
|
| | | producer.send(msg);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 订单是否有效
|
| | | * |
| | | * @param coList
|
| | | * @return
|
| | | */
|
| | | private boolean isCommonOrderValid(List<CommonOrder> coList) {
|
| | | for (CommonOrder commonOrder : coList) {
|
| | | if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK
|
| | | || commonOrder.getState() == CommonOrder.STATE_WQ) {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.order; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.UUID; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.SystemPIDInfo; |
| | | import com.yeshi.fanli.entity.dy.DYOrder; |
| | | import com.yeshi.fanli.service.manger.PIDManager; |
| | | import com.yeshi.fanli.service.manger.order.TeamRewardManager; |
| | | import com.yeshi.fanli.util.goods.douyin.DYUtil; |
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.NumberUtil; |
| | | |
| | | import com.aliyun.openservices.ons.api.Message; |
| | | import com.aliyun.openservices.ons.api.transaction.LocalTransactionExecuter; |
| | | import com.aliyun.openservices.ons.api.transaction.TransactionProducer; |
| | | import com.aliyun.openservices.ons.api.transaction.TransactionStatus; |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper; |
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper; |
| | | import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper; |
| | | import com.yeshi.fanli.dao.mybatis.order.OrderMapper; |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper; |
| | | import com.yeshi.fanli.dto.mq.UidDateDTO; |
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMQMsg; |
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg; |
| | | import com.yeshi.fanli.dto.order.CommonOrderAddResultDTO; |
| | | import com.yeshi.fanli.dto.order.HongBaoAddResult; |
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2; |
| | | 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; |
| | | import com.yeshi.fanli.entity.order.CommonOrder; |
| | | import com.yeshi.fanli.entity.order.HongBaoOrder; |
| | | import com.yeshi.fanli.entity.pdd.PDDOrder; |
| | | import com.yeshi.fanli.entity.suning.SuningOrderInfo; |
| | | import com.yeshi.fanli.entity.taobao.PidUser; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder; |
| | | import com.yeshi.fanli.entity.vipshop.VipShopOrder; |
| | | import com.yeshi.fanli.entity.vipshop.VipShopOrderDetail; |
| | | import com.yeshi.fanli.exception.elme.ElmeOrderException; |
| | | import com.yeshi.fanli.exception.money.OrderMoneySettleException; |
| | | import com.yeshi.fanli.exception.money.UserMoneyDetailException; |
| | | import com.yeshi.fanli.exception.order.CommonOrderException; |
| | | import com.yeshi.fanli.exception.order.HongBaoException; |
| | | import com.yeshi.fanli.exception.order.OrderItemException; |
| | | import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException; |
| | | import com.yeshi.fanli.exception.user.UserAccountException; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.log.OrderLogHelper; |
| | | import com.yeshi.fanli.service.inter.elme.ElmeHongBaoOrderMapService; |
| | | import com.yeshi.fanli.service.inter.elme.ElmeOrderProcessService; |
| | | import com.yeshi.fanli.service.inter.elme.ElmeOrderService; |
| | | import com.yeshi.fanli.service.inter.money.UserMoneyService; |
| | | import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService; |
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService; |
| | | import com.yeshi.fanli.service.inter.order.HongBaoV2Service; |
| | | import com.yeshi.fanli.service.inter.order.LostOrderService; |
| | | import com.yeshi.fanli.service.inter.order.OrderMoneySettleService; |
| | | import com.yeshi.fanli.service.inter.order.OrderProcessService; |
| | | import com.yeshi.fanli.service.inter.order.jd.JDOrderService; |
| | | import com.yeshi.fanli.service.inter.order.msg.UserOrderMsgNotificationService; |
| | | import com.yeshi.fanli.service.inter.order.pdd.PDDOrderService; |
| | | import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; |
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; |
| | | import com.yeshi.fanli.service.manger.msg.RocketMQManager; |
| | | import com.yeshi.fanli.service.manger.order.HongBaoV2AddManager; |
| | | import com.yeshi.fanli.util.CMQManager; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import org.yeshi.utils.MoneyBigDecimalUtil; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.TaoBaoConstant; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.fanli.util.factory.UserMoneyDetailFactory; |
| | | import com.yeshi.fanli.util.jd.JDApiUtil; |
| | | import com.yeshi.fanli.util.mq.cmq.order.PlaceOrderCMQManager; |
| | | import com.yeshi.fanli.util.mq.cmq.order.TeamOrderCMQManager; |
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; |
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | import com.yeshi.fanli.util.suning.SuningApiUtil; |
| | | import com.yeshi.fanli.util.vipshop.VipShopUtil; |
| | | |
| | | @Service |
| | | public class OrderProcessServiceImpl implements OrderProcessService { |
| | | |
| | | @Resource |
| | | private OrderMapper orderMapper; |
| | | |
| | | @Resource |
| | | private UserInfoMapper userInfoMapper; |
| | | |
| | | @Resource |
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService; |
| | | |
| | | @Resource |
| | | private TaoBaoWeiQuanDrawBackService taoBaoWeiQuanDrawBackService; |
| | | |
| | | @Resource |
| | | private TaoBaoOrderService taoBaoOrderService; |
| | | |
| | | @Resource |
| | | private LostOrderService lostOrderService; |
| | | |
| | | @Resource |
| | | private TaoBaoWeiQuanOrderMapper taoBaoWeiQuanOrderMapper; |
| | | |
| | | @Resource |
| | | private HongBaoV2Mapper hongBaoV2Mapper; |
| | | |
| | | @Resource |
| | | private UserOrderMsgNotificationService userOrderMsgNotificationService; |
| | | |
| | | @Resource |
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; |
| | | |
| | | @Resource |
| | | private UserMoneyService userMoneyService; |
| | | |
| | | @Resource |
| | | private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService; |
| | | |
| | | @Resource |
| | | private CommonOrderService commonOrderService; |
| | | |
| | | @Resource |
| | | private HongBaoV2Service hongBaoV2Service; |
| | | |
| | | @Resource |
| | | private JDOrderService jdOrderService; |
| | | |
| | | @Resource |
| | | private PDDOrderService pddOrderService; |
| | | |
| | | @Resource(name = "orderTransactionProducer") |
| | | private TransactionProducer orderTransactionProducer; |
| | | |
| | | @Resource |
| | | private RocketMQManager rocketMQManager; |
| | | |
| | | @Resource |
| | | private OrderMoneySettleService orderMoneySettleService; |
| | | |
| | | @Resource |
| | | private HongBaoV2AddManager hongBaoV2AddManager; |
| | | |
| | | @Resource |
| | | private TeamRewardManager teamRewardManager; |
| | | |
| | | @Resource |
| | | private PIDManager pidManager; |
| | | |
| | | /** |
| | | * 是否是分享订单 |
| | | * |
| | | * @param order |
| | | * @return |
| | | */ |
| | | private boolean isShareOrder(SystemEnum system, TaoBaoOrder order) { |
| | | |
| | | String specialRelationId = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel); |
| | | |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), order.getSourceMediaId(), |
| | | order.getAdPositionId()); |
| | | if (!StringUtil.isNullOrEmpty(order.getSpecialId()) |
| | | || pid.equalsIgnoreCase(specialRelationId)) {// 设置渠道ID当做会员运营ID的位置ID |
| | | return false; |
| | | } else if (!StringUtil.isNullOrEmpty(order.getRelationId())) { |
| | | return true; |
| | | } else { |
| | | // 通过红包查询 |
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, |
| | | order.getTradeId()); |
| | | |
| | | if (commonOrder != null) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | //获取推广位类型 |
| | | private SystemPIDInfo.PidType getPidType(int sourceType, String pid) { |
| | | List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, sourceType); |
| | | if ((pidInfoList == null || pidInfoList.size() == 0) && sourceType == Constant.SOURCE_TYPE_TAOBAO) { |
| | | pidInfoList = pidManager.listPidInfoByPidCache(pid, Constant.SOURCE_TYPE_ELME); |
| | | } |
| | | |
| | | SystemPIDInfo.PidType pidType = null; |
| | | if (pidInfoList != null && pidInfoList.size() > 0) { |
| | | pidType = pidInfoList.get(0).getPidType(); |
| | | } |
| | | return pidType; |
| | | } |
| | | |
| | | //根据PID获取系统 |
| | | private List<SystemEnum> getPidSystems(String pid) { |
| | | List<SystemEnum> systemList = new ArrayList<>(); |
| | | List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, null); |
| | | |
| | | if (pidInfoList != null) { |
| | | for (SystemPIDInfo pidInfo : pidInfoList) { |
| | | systemList.add(pidInfo.getSystem()); |
| | | } |
| | | } |
| | | return systemList; |
| | | } |
| | | |
| | | private Set<Integer> getPidSourceTypes(String pid) { |
| | | Set<Integer> sourceTypes = new HashSet<>(); |
| | | List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, null); |
| | | if (pidInfoList != null) { |
| | | for (SystemPIDInfo pidInfo : pidInfoList) { |
| | | sourceTypes.add(pidInfo.getSourceType()); |
| | | } |
| | | } |
| | | return sourceTypes; |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void processOrder(Map<String, List<TaoBaoOrder>> orders) { |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | |
| | | // 分离出返利订单与分享赚订单 |
| | | Iterator<String> its = orders.keySet().iterator(); |
| | | Map<String, List<TaoBaoOrder>> fanliOrderMap = new HashMap<>(); |
| | | Map<String, List<TaoBaoOrder>> shareOrderMap = new HashMap<>(); |
| | | Map<String, List<TaoBaoOrder>> elmeOrderMap = new HashMap<>(); |
| | | while (its.hasNext()) { |
| | | String orderId = its.next(); |
| | | |
| | | if (orders.get(orderId) != null && orders.get(orderId).size() > 0) { |
| | | List<TaoBaoOrder> list = orders.get(orderId); |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), |
| | | list.get(0).getSourceMediaId(), list.get(0).getAdPositionId()); |
| | | |
| | | |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_TAOBAO, pid); |
| | | |
| | | //--------分离自购,分享,饿了么订单类型------- |
| | | if (pidType != null) { |
| | | if ("饿了么".equalsIgnoreCase(list.get(0).getOrderType()) |
| | | && pidType != SystemPIDInfo.PidType.share) { |
| | | // 饿了么订单开始归入到淘宝订单 |
| | | if (TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), |
| | | "yyyy-MM-dd HH:mm:ss") >= Constant.NEW_ORDER_FANLI_RULE_TIME) { |
| | | fanliOrderMap.put(orderId, list); |
| | | } else { |
| | | elmeOrderMap.put(orderId, list); |
| | | } |
| | | } else { |
| | | if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId()) |
| | | || pidType == SystemPIDInfo.PidType.fanliChannel) {// 设置渠道ID当做会员运营ID的位置ID |
| | | fanliOrderMap.put(orderId, list); |
| | | } else if (!StringUtil.isNullOrEmpty(list.get(0).getRelationId())) { |
| | | shareOrderMap.put(orderId, list); |
| | | } else { |
| | | // 通过红包查询 |
| | | CommonOrder commonOrder = commonOrderService |
| | | .selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, list.get(0).getTradeId()); |
| | | |
| | | if (commonOrder != null) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | shareOrderMap.put(orderId, list); |
| | | continue; |
| | | } |
| | | } |
| | | fanliOrderMap.put(orderId, list); |
| | | } |
| | | } |
| | | } else { |
| | | if ("口碑".equalsIgnoreCase(list.get(0).getOrderType()) |
| | | && pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) {// 口碑自购 |
| | | fanliOrderMap.put(orderId, list); |
| | | } else { |
| | | fanliOrderMap.put(orderId, list); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 处理返利订单 |
| | | processShopingFanliOrder(fanliOrderMap); |
| | | // 处理分享赚订单 |
| | | processShareGoodsOrder(shareOrderMap); |
| | | // 处理饿了么订单 |
| | | processElemeOrder(elmeOrderMap); |
| | | } |
| | | |
| | | private ElmeOrder createElmeOrder(TaoBaoOrder taoBaoOrder) { |
| | | ElmeOrder elmeOrder = new ElmeOrder(); |
| | | elmeOrder.setChannelId(""); |
| | | elmeOrder.setCreateTime(new Date()); |
| | | elmeOrder |
| | | .setOrderDate(new Date(TimeUtil.convertToTimeTemp(taoBaoOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss"))); |
| | | elmeOrder.setOrderId(taoBaoOrder.getOrderId()); |
| | | elmeOrder.setPayMoney(taoBaoOrder.getPayment()); |
| | | elmeOrder.setRid(taoBaoOrder.getRelationId()); |
| | | if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单结算")) |
| | | elmeOrder.setIsSettle(true); |
| | | else |
| | | elmeOrder.setIsSettle(false); |
| | | |
| | | if (!taoBaoOrder.getOrderState().equalsIgnoreCase("订单失效")) |
| | | elmeOrder.setState(1); |
| | | else { |
| | | elmeOrder.setState(0); |
| | | elmeOrder.setPayMoney(new BigDecimal(0)); |
| | | } |
| | | elmeOrder.setTrackPid( |
| | | String.format("mm_124933865_%s_%s", taoBaoOrder.getSourceMediaId(), taoBaoOrder.getAdPositionId())); |
| | | if (!StringUtil.isNullOrEmpty(taoBaoOrder.getRelationId())) { |
| | | UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByRelationId(taoBaoOrder.getRelationId(), null); |
| | | if (extraInfo != null) |
| | | elmeOrder.setUid(extraInfo.getUser().getId()); |
| | | } |
| | | return elmeOrder; |
| | | } |
| | | |
| | | private void processElemeOrder(Map<String, List<TaoBaoOrder>> orders) { |
| | | for (Iterator<String> its = orders.keySet().iterator(); its.hasNext(); ) { |
| | | String orderId = its.next(); |
| | | List<TaoBaoOrder> orderList = orders.get(orderId); |
| | | for (TaoBaoOrder taoBaoOrder : orderList) { |
| | | ElmeOrder elmeOrder = createElmeOrder(taoBaoOrder); |
| | | try { |
| | | elmeOrderProcessService.processOrder(elmeOrder); |
| | | } catch (ElmeOrderException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void processShopingFanliOrder(Map<String, List<TaoBaoOrder>> orders) { |
| | | // 查询在Order中是否存在该订单号 |
| | | Iterator<String> its = orders.keySet().iterator(); |
| | | String tempOrderId = ""; |
| | | while (its.hasNext()) { |
| | | try { |
| | | String orderId = its.next(); |
| | | tempOrderId = orderId; |
| | | // 处理红包与子红包 |
| | | // if (isRedisLockOrder(orderId)) |
| | | // continue; |
| | | // redisLockOrder(orderId); |
| | | processShopingFanliOrderNew(orderId, orders.get(orderId)); |
| | | // redisUnlockOrder(orderId); |
| | | // 出错了就不处理该订单了,需要定期检查 |
| | | |
| | | // 更改丢失订单的状态 |
| | | lostOrderService.processSuceess(orderId, Constant.SOURCE_TYPE_TAOBAO); |
| | | |
| | | } catch (HongBaoException e1) { |
| | | e1.printStackTrace(); |
| | | } catch (OrderItemException e2) { |
| | | e2.printStackTrace(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | try { |
| | | LogHelper.errorDetailInfo(e, null, tempOrderId); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void processShareGoodsOrder(Map<String, List<TaoBaoOrder>> orders) { |
| | | // pidOrderService.addPidOrderFromTaoBao(orders); |
| | | if (orders != null) { |
| | | Iterator<String> its = orders.keySet().iterator(); |
| | | while (its.hasNext()) { |
| | | String orderId = its.next(); |
| | | try { |
| | | processShareGoodsOrderNew(orderId, orders.get(orderId)); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "processShareGoodsOrderNew出错", "订单号:" + orderId); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void fanli() { |
| | | LogHelper.test("处理返利到账"); |
| | | // 获取主红包 |
| | | List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByType(HongBaoV2.TYPE_ZIGOU, 1000); |
| | | // |
| | | // /** |
| | | // * 需要实时更新待返利的订单 |
| | | // */ |
| | | // |
| | | // // 计算最大的创建时间与最小的创建时间 |
| | | // Map<String, Long> map = getMaxAndMinCreateTime(hongBaoList); |
| | | // if (map != null) { |
| | | // long max = map.get("max"); |
| | | // long min = map.get("min"); |
| | | // // 最小时间提前10分钟 |
| | | // min = min - 1000 * 60 * 10L; |
| | | // // 更新该段时间的订单 |
| | | // List<TaoBaoOrder> orderList = new ArrayList<>(); |
| | | // try { |
| | | // orderList = TaoBaoOrderUtil.getOrderList(min, max); |
| | | // } catch (TaoBaoOrderException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // // try { |
| | | // if (orderList != null) |
| | | // processOrder(TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(orderList)); |
| | | // // } catch (Exception e) { |
| | | // // e.printStackTrace(); |
| | | // // try { |
| | | // // LogHelper.errorDetailInfo(e); |
| | | // // } catch (Exception e1) { |
| | | // // e1.printStackTrace(); |
| | | // // } |
| | | // // } |
| | | // } |
| | | |
| | | /** |
| | | * 开始返利 |
| | | */ |
| | | for (HongBaoV2 hb : hongBaoList) { |
| | | // |
| | | if (hb.getState() == HongBaoV2.STATE_SHIXIAO || hb.getState() == HongBaoV2.STATE_YILINGQU) |
| | | continue; |
| | | |
| | | if (hb.getPreGetTime() == null || hb.getPreGetTime().getTime() == 0 |
| | | || hb.getPreGetTime().getTime() > System.currentTimeMillis()) |
| | | continue; |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | CMQManager.getInstance().addFanLiMsgNew(hb); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Resource |
| | | private HongBaoOrderMapper hongBaoOrderMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void fanli(HongBaoV2 hb1) throws TaoBaoWeiQuanException { |
| | | // 查询最新的红包数据 |
| | | hb1 = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hb1.getId()); |
| | | |
| | | if (hb1 == null || hb1.getState() != HongBaoV2.STATE_KELINGQU || hb1.getPreGetTime() == null |
| | | || hb1.getPreGetTime().getTime() > System.currentTimeMillis()) |
| | | return; |
| | | |
| | | // 正常用户才能到账 |
| | | UserInfo mainUser = userInfoMapper.selectAvailableByPrimaryKey(hb1.getUserInfo().getId()); |
| | | if (mainUser == null || mainUser.getState() != UserInfo.STATE_NORMAL) { |
| | | return; |
| | | } |
| | | // 查询红包相关联的订单 |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hb1.getId()); |
| | | if (hongBaoOrder == null) { |
| | | LogHelper.error("返利失败:" + hb1.getId()); |
| | | return; |
| | | } |
| | | |
| | | if (hongBaoOrder.getCommonOrder() == null) { |
| | | return; |
| | | } |
| | | |
| | | // 如果是拼多多/京东维权则返回,不需要返利 |
| | | if ((hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_PDD |
| | | || hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_JD) |
| | | && hongBaoOrder.getCommonOrder().getState() == CommonOrder.STATE_WQ) |
| | | return; |
| | | |
| | | if (hongBaoOrder.getCommonOrder() != null |
| | | && hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_TAOBAO) { |
| | | // 维权中的不返利 |
| | | List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper |
| | | .selectListByOrderIdAndState(hongBaoOrder.getCommonOrder().getOrderNo(), "维权创建"); |
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0) |
| | | return; |
| | | |
| | | taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper |
| | | .selectListByOrderIdAndState(hongBaoOrder.getCommonOrder().getOrderNo(), "等待处理"); |
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0) |
| | | return; |
| | | } |
| | | |
| | | // 查询该订单之前是否有到账 |
| | | List<HongBaoOrder> list = hongBaoOrderMapper.listByOrderIdAndSourceType( |
| | | hongBaoOrder.getCommonOrder().getOrderNo(), hongBaoOrder.getCommonOrder().getSourceType()); |
| | | List<Long> hongBaoIdList = new ArrayList<>(); |
| | | if (list != null) { |
| | | for (HongBaoOrder ho : list) { |
| | | hongBaoIdList.add(ho.getHongBaoV2().getId()); |
| | | } |
| | | } |
| | | |
| | | List<HongBaoV2> allHongBaoList = hongBaoV2Mapper.listByIds(hongBaoIdList); |
| | | boolean first = true; |
| | | for (HongBaoV2 v2 : allHongBaoList) |
| | | if (v2.getState() == HongBaoV2.STATE_YILINGQU) { |
| | | first = false; |
| | | break; |
| | | } |
| | | |
| | | // 自购到账事务消息 |
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_ZIGOU, |
| | | mainUser.getId(), hongBaoOrder.getCommonOrder().getSourceType(), |
| | | hongBaoOrder.getCommonOrder().getOrderNo(), null, new Date(), 0); |
| | | mqMsg.setOrderFirst(first); |
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg); |
| | | String key = mainUser.getId() + "-" + UUID.randomUUID().toString(); |
| | | msg.setKey(key); |
| | | try { |
| | | if (!Constant.IS_TEST) |
| | | orderTransactionProducer.send(msg, new LocalTransactionExecuter() { |
| | | @Override |
| | | public TransactionStatus execute(Message arg0, Object arg1) { |
| | | try { |
| | | orderMoneySettleService.ziGouSettle(hongBaoOrder.getCommonOrder().getOrderNo(), |
| | | hongBaoOrder.getCommonOrder().getSourceType(), key); |
| | | return TransactionStatus.CommitTransaction; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return TransactionStatus.RollbackTransaction; |
| | | } |
| | | } |
| | | }, null); |
| | | else { |
| | | try { |
| | | orderMoneySettleService.ziGouSettle(hongBaoOrder.getCommonOrder().getOrderNo(), |
| | | hongBaoOrder.getCommonOrder().getSourceType(), key); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void weiQuanOrder(List<TaoBaoWeiQuanOrder> orderList) { |
| | | if (orderList != null) |
| | | for (TaoBaoWeiQuanOrder order : orderList) { |
| | | try { |
| | | if (order.getState().contains("维权成功")) { |
| | | if (Constant.ENABLE_MQ) |
| | | CMQManager.getInstance().addWeiQuanOrderMsg(order); |
| | | } |
| | | } catch (Exception e) { |
| | | LogHelper.error("维权订单加入到队列出错:" + order != null ? new Gson().toJson(order) : null); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void weiQuanOrder(TaoBaoWeiQuanOrder order) { |
| | | // 订单结算时间在2018-08-05后就不处理维权了 |
| | | |
| | | List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(order.getOrderId()); |
| | | if (orderList != null && orderList.size() > 0 & !StringUtil.isNullOrEmpty(orderList.get(0).getSettlementTime())) |
| | | order.setJieSuanTime( |
| | | new Date(TimeUtil.convertToTimeTemp(orderList.get(0).getSettlementTime(), "yyyy-MM-dd HH:mm:ss"))); |
| | | |
| | | // 处理维权成功但是已到账的订单 |
| | | if (order.getJieSuanTime().getTime() > TimeUtil.convertToTimeTemp("2019-01-01", "yyyy-MM-dd")) {// 结算时间在1月1号的开始处理已到账但是维权的 |
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, |
| | | order.getOrderItemId()); |
| | | if (commonOrder != null && !StringUtil.isNullOrEmpty(commonOrder.getTradeId())) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_YILINGQU) {// 已经到账的看是否需要扣款 |
| | | TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackService |
| | | .selectByOrderItemId(order.getOrderItemId()); |
| | | if (drawBack == null) {// 还未扣款 |
| | | OrderLogHelper.taoBaoWeiQuan("已到账未扣款处理:子订单号:" + order.getOrderItemId()); |
| | | try { |
| | | taoBaoWeiQuanDrawBackService.doWeiQuanFanli(order.getOrderId(), true); |
| | | taoBaoWeiQuanDrawBackService.doWeiQuanShare(order.getOrderId()); |
| | | teamRewardManager.weiQuan(order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, order.getOrderItemId()); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "到账后处理维权扣款出错", "订单号:" + order.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } else { |
| | | try { |
| | | // taoBaoWeiQuanDrawBackService.doWeiQuanInvite(order.getOrderId()); |
| | | teamRewardManager.weiQuan(order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, order.getOrderItemId()); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "到账后处理维权扣款出错", "订单号:" + order.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void fanliPreInvaite(Date maxTime) { |
| | | // 查出邀请赚的用户ID |
| | | List<Integer> typeList = new ArrayList<>(); |
| | | typeList.add(HongBaoV2.TYPE_YIJI); |
| | | typeList.add(HongBaoV2.TYPE_ERJI); |
| | | typeList.add(HongBaoV2.TYPE_SHARE_YIJI); |
| | | typeList.add(HongBaoV2.TYPE_SHARE_ERJI); |
| | | |
| | | long count = hongBaoV2Mapper.countUidCanBanlanceByTypeAndMaxTime(typeList, maxTime); |
| | | int pageSize = 1000; |
| | | int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); |
| | | Set<Long> uidSets = new HashSet<>(); |
| | | for (int i = 0; i < page; i++) { |
| | | List<Long> inviteAndShareUids = hongBaoV2Mapper.listUidCanBanlanceByTypeAndMaxTime(typeList, maxTime, |
| | | i * pageSize, pageSize); |
| | | if (inviteAndShareUids != null) |
| | | for (Long uid : inviteAndShareUids) { |
| | | if (userInfoMapper.selectAvailableByPrimaryKey(uid) != null) |
| | | uidSets.add(uid); |
| | | } |
| | | } |
| | | // 根据用户ID |
| | | Iterator<Long> its = uidSets.iterator(); |
| | | while (its.hasNext()) { |
| | | Long uid = its.next(); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | TeamOrderCMQManager.getInstance().addFanLiTeamIncomePreMsg(new UidDateDTO(uid, maxTime)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | LogHelper.error(e); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public int fanliShare(Date maxTime) { |
| | | // 查出邀请赚的用户ID |
| | | List<Integer> typeList = new ArrayList<>(); |
| | | typeList.add(HongBaoV2.TYPE_SHARE_GOODS); |
| | | |
| | | long count = hongBaoV2Mapper.countUidCanBanlanceByTypeAndMaxTime(typeList, maxTime); |
| | | int pageSize = 1000; |
| | | int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); |
| | | Set<Long> uidSets = new HashSet<>(); |
| | | for (int i = 0; i < page; i++) { |
| | | List<Long> inviteAndShareUids = hongBaoV2Mapper.listUidCanBanlanceByTypeAndMaxTime(typeList, maxTime, |
| | | i * pageSize, pageSize); |
| | | if (inviteAndShareUids != null) |
| | | for (Long uid : inviteAndShareUids) { |
| | | if (userInfoMapper.selectAvailableByPrimaryKey(uid) != null) |
| | | uidSets.add(uid); |
| | | } |
| | | } |
| | | // 根据用户ID |
| | | Iterator<Long> its = uidSets.iterator(); |
| | | while (its.hasNext()) { |
| | | Long uid = its.next(); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | CMQManager.getInstance().addFanLiShareMsg(new UidDateDTO(uid, maxTime)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | LogHelper.error(e); |
| | | } |
| | | } |
| | | |
| | | return uidSets.size(); |
| | | } |
| | | |
| | | @Override |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | public void fanliPreInvaite(Long uid, Date maxPreGetTime) { |
| | | // 邀请赚到账 |
| | | try { |
| | | orderMoneySettleService.inviteSettleTB(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettleJD(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettlePDD(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettleVipShop(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettleSuning(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettleDY(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void fanliShare(Long uid, Date maxPreGetTime) { |
| | | // 邀请赚到账 |
| | | try { |
| | | orderMoneySettleService.shareSettleTB(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettleJD(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettlePDD(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettleVipShop(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettleSuning(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettleDY(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
| | | @Override |
| | | public void processShopingFanliOrderNew(String orderId, List<TaoBaoOrder> orderList) |
| | | throws HongBaoException, OrderItemException { |
| | | |
| | | LogHelper.test(String.format("订单处理:订单号-%s 订单数量-%s", orderId, orderList.size() + "")); |
| | | if (orderList.size() == 1) |
| | | LogHelper.test("订单排序值:" + orderList.get(0).getOrderBy()); |
| | | |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | |
| | | if (orderList != null && orderList.size() > 0) { |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), |
| | | orderList.get(0).getSourceMediaId(), orderList.get(0).getAdPositionId()); |
| | | |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_TAOBAO, pid); |
| | | List<SystemEnum> systemList = getPidSystems(pid); |
| | | Set<Integer> sourceTypes = getPidSourceTypes(pid); |
| | | |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(orderId, Constant.SOURCE_TYPE_TAOBAO); |
| | | // 原来不存在订单 |
| | | Long uid = null; |
| | | if (oldOrder == null) { |
| | | Long targetUid = null; |
| | | if (pidType != null && pidType == SystemPIDInfo.PidType.fanliChannel |
| | | && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 处理非返利商品库的商品 |
| | | targetUid = taoBaoBuyRelationMapService.selectUidByRelationId(orderList.get(0).getRelationId()); |
| | | |
| | | } else if ((sourceTypes.contains(Constant.SOURCE_TYPE_ELME) |
| | | || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) |
| | | && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 处理饿了么,口碑的订单 |
| | | UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService |
| | | .getByRelationId(orderList.get(0).getRelationId(), systemList); |
| | | if (extraInfo != null) { |
| | | targetUid = extraInfo.getUser().getId(); |
| | | } |
| | | } else if (!StringUtil.isNullOrEmpty(orderList.get(0).getSpecialId())) { |
| | | UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService |
| | | .getBySpecialId(orderList.get(0).getSpecialId(), systemList); |
| | | if (info != null && info.getUser() != null) |
| | | targetUid = info.getUser().getId(); |
| | | } |
| | | |
| | | if (targetUid != null) { |
| | | uid = targetUid; |
| | | // 插入到Order中 |
| | | // 添加到订单中去 |
| | | Order order = new Order(); |
| | | order.setBeizhu("PID返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(orderId); |
| | | order.setOrderType(1); |
| | | order.setState(Order.STATE_YIZHIFU); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | oldOrder = order; |
| | | } |
| | | |
| | | } else { |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | } |
| | | // 尚未找到和PID对应的用户 |
| | | if (uid == null) |
| | | return; |
| | | |
| | | // 计算订单总额度 |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | BigDecimal money = new BigDecimal(0); |
| | | for (TaoBaoOrder o : orderList) { |
| | | if (o.getOrderState().equalsIgnoreCase("订单结算")) |
| | | money = money.add(o.getSettlement()); |
| | | else { |
| | | money = money.add(o.getPayment()); |
| | | } |
| | | } |
| | | updateOrder.setMoney(money); |
| | | String thirdState = null; |
| | | for (TaoBaoOrder o : orderList) |
| | | if (!o.getOrderState().equalsIgnoreCase("订单失效")) { |
| | | thirdState = o.getOrderState(); |
| | | break; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(thirdState)) |
| | | thirdState = "订单失效"; |
| | | updateOrder.setThirdState(thirdState); |
| | | updateOrder.setThirdCreateTime( |
| | | new Date(TimeUtil.convertToTimeTemp(orderList.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss"))); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | |
| | | // 用第一个子订单锁定用户 |
| | | List<CommonOrderAddResultDTO> commonOrderList = null; |
| | | try { |
| | | commonOrderList = commonOrderService.addTaoBaoOrder(orderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, orderId, uid, Constant.SOURCE_TYPE_TAOBAO, HongBaoV2.TYPE_ZIGOU); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(orderId); |
| | | order.setOrderType(Constant.SOURCE_TYPE_TAOBAO); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addTaoBaoOrder或addHongBao出错", "订单号:" + orderId); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void processShareGoodsOrderNew(String orderId, List<TaoBaoOrder> orderList) { |
| | | if (orderList != null && orderList.size() > 0) { |
| | | // 原来不存在订单 |
| | | Long uid = null; |
| | | UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService.getByRelationId(orderList.get(0).getRelationId(), null); |
| | | if (info != null && info.getUser() != null) |
| | | uid = info.getUser().getId(); |
| | | // 尚未找到和PID对应的用户 |
| | | if (uid == null) { |
| | | // 通过红包查询 |
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, |
| | | orderList.get(0).getTradeId()); |
| | | |
| | | if (commonOrder != null) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | uid = hongBaoOrder.getHongBaoV2().getUserInfo().getId(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | // 用第一个子订单锁定用户 |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrders = commonOrderService.addTaoBaoOrder(orderList, uid); |
| | | addHongBaoWithMQ(commonOrders, orderId, uid, Constant.SOURCE_TYPE_TAOBAO, HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrders)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(orderId); |
| | | order.setOrderType(Constant.SOURCE_TYPE_TAOBAO); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 是否为分享订单 |
| | | * |
| | | * @param order |
| | | * @return |
| | | */ |
| | | private boolean isShareOrder(JDOrder order) { |
| | | if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0) |
| | | return false; |
| | | Long positionId = order.getOrderItemList().get(0).getPositionId(); |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_JD, positionId + ""); |
| | | if (pidType != null && pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public void processJDOrder(JDOrder order) { |
| | | if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0) |
| | | return; |
| | | // 拆单且不在commonorder中的不做处理 |
| | | if (order.getValidCode() == 2) { |
| | | List<CommonOrder> list= commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_JD,order.getOrderId()+""); |
| | | if(list==null||list.size()==0) { |
| | | return; |
| | | } |
| | | } |
| | | // 根据ext1与subUnionId跟单 |
| | | String uidStr = order.getExt1(); |
| | | if (StringUtil.isNullOrEmpty(uidStr)) |
| | | uidStr = order.getOrderItemList().get(0).getSubUnionId(); |
| | | |
| | | Long uid = null; |
| | | if (!StringUtil.isNullOrEmpty(uidStr) && NumberUtil.isNumeric(uidStr)) |
| | | uid = Long.parseLong(uidStr); |
| | | Long positionId = order.getOrderItemList().get(0).getPositionId(); |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_JD, positionId + ""); |
| | | |
| | | if (pidType != null) { |
| | | if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单 |
| | | { |
| | | processFanLiJDOrder(order, uid); |
| | | lostOrderService.processSuceess(order.getOrderId() + "", Constant.SOURCE_TYPE_JD); |
| | | } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareJDOrder(order, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiJDOrder(order, null); |
| | | } |
| | | } else { |
| | | processFanLiJDOrder(order, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理京东返利订单 |
| | | * |
| | | * @param jdOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiJDOrder(JDOrder jdOrder, Long uid) { |
| | | int invalidCount = 0; |
| | | BigDecimal totalMoney = new BigDecimal(0); |
| | | // 订单状态判断 |
| | | for (JDOrderItem item : jdOrder.getOrderItemList()) { |
| | | if (item.getEstimateCosPrice() != null) |
| | | totalMoney = totalMoney.add(item.getEstimateCosPrice()); |
| | | |
| | | if (item.getValidCode() == 16 || item.getValidCode() == 17 || item.getValidCode() == 18) {// 已付款 |
| | | |
| | | } else if (item.getValidCode() == 15) {// 未支付 |
| | | |
| | | } else { |
| | | invalidCount++; |
| | | } |
| | | } |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(jdOrder.getOrderId() + "", |
| | | Constant.SOURCE_TYPE_JD); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("京东返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(jdOrder.getOrderId() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_JD); |
| | | order.setState( |
| | | invalidCount == jdOrder.getOrderItemList().size() ? Order.STATE_SHIXIAO : Order.STATE_YIZHIFU); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | order.setThirdCreateTime(new Date(jdOrder.getOrderTime())); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addJDOrder(jdOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, jdOrder.getOrderId() + "", uid, Constant.SOURCE_TYPE_JD, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(jdOrder.getOrderId() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_JD); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + jdOrder.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理京东分享订单 |
| | | * |
| | | * @param jdOrder |
| | | * @param uid |
| | | */ |
| | | private void processShareJDOrder(JDOrder jdOrder, Long uid) { |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addJDOrder(jdOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, jdOrder.getOrderId() + "", uid, Constant.SOURCE_TYPE_JD, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(jdOrder.getOrderId() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_JD); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + jdOrder.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 是否是分享赚订单 |
| | | * |
| | | * @param pddOrder |
| | | * @return |
| | | */ |
| | | private boolean isShareOrder(PDDOrder pddOrder) { |
| | | String positionId = pddOrder.getpId(); |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_PDD, positionId); |
| | | |
| | | if (pidType != null && pidType == SystemPIDInfo.PidType.share) |
| | | return true; |
| | | else |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 处理拼多多订单 |
| | | */ |
| | | @Override |
| | | public void processPDDOrder(PDDOrder pddOrder) { |
| | | if (pddOrder == null) |
| | | return; |
| | | String customParameters = pddOrder.getCustomParameters(); |
| | | Long uid = null; |
| | | if (!StringUtil.isNullOrEmpty(customParameters)) |
| | | uid = Long.parseLong(PinDuoDuoUtil.getUidFromCustomParams(customParameters)); |
| | | String positionId = pddOrder.getpId(); |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_PDD, positionId); |
| | | if (pidType != null) { |
| | | if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单 |
| | | { |
| | | processFanLiPDDOrder(pddOrder, uid); |
| | | lostOrderService.processSuceess(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD); |
| | | } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processSharePDDOrder(pddOrder, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiPDDOrder(pddOrder, null); |
| | | } |
| | | } else { |
| | | processFanLiPDDOrder(pddOrder, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理拼多多自购返利订单 |
| | | * |
| | | * @param pddOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiPDDOrder(PDDOrder pddOrder, Long uid) { |
| | | int orderState = 0; |
| | | if (pddOrder.getOrderStatus() == -1 || pddOrder.getOrderStatus() == 8) |
| | | orderState = Order.STATE_SHIXIAO; |
| | | else |
| | | orderState = Order.STATE_YIZHIFU; |
| | | |
| | | BigDecimal totalMoney = MoneyBigDecimalUtil.div(new BigDecimal(pddOrder.getOrderAmount()), new BigDecimal(100)); |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("拼多多返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(pddOrder.getOrderSn()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_PDD); |
| | | order.setState(orderState); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | if (pddOrder.getFailReason() != null && pddOrder.getFailReason().contains("比价")) |
| | | order.setStateDesc("比价订单"); |
| | | order.setThirdCreateTime(new Date(pddOrder.getOrderCreateTime() * 1000)); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | if (pddOrder.getFailReason() != null && pddOrder.getFailReason().contains("比价")) |
| | | updateOrder.setStateDesc("比价订单"); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<PDDOrder> pddOrderList = new ArrayList<>(); |
| | | pddOrderList.add(pddOrder); |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addPDDOrder(pddOrderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, pddOrder.getOrderSn(), uid, Constant.SOURCE_TYPE_PDD, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(pddOrder.getOrderSn()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_PDD); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addPDDOrder或addHongBao出错", "订单号:" + pddOrder.getOrderSn()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理拼多多分享订单 |
| | | * |
| | | * @param pddOrder |
| | | * @param uid |
| | | */ |
| | | private void processSharePDDOrder(PDDOrder pddOrder, Long uid) { |
| | | try { |
| | | List<PDDOrder> pddOrderList = new ArrayList<>(); |
| | | pddOrderList.add(pddOrder); |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addPDDOrder(pddOrderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, pddOrder.getOrderSn(), uid, Constant.SOURCE_TYPE_PDD, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(pddOrder.getOrderSn()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_PDD); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + pddOrder.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void processVipShopOrder(VipShopOrder order) { |
| | | |
| | | if (order == null || order.getDetailList() == null || order.getDetailList().size() == 0) |
| | | return; |
| | | |
| | | |
| | | // 根据ext1与subUnionId跟单 |
| | | String channelTag = order.getChannelTag(); |
| | | |
| | | String uidStr = VipShopUtil.getUidFromChanTag(channelTag); |
| | | |
| | | Long uid = null; |
| | | if (!StringUtil.isNullOrEmpty(uidStr) && NumberUtil.isNumeric(uidStr)) |
| | | uid = Long.parseLong(uidStr); |
| | | String type = VipShopUtil.getTypeFromChanTag(channelTag); |
| | | if ("buy".equalsIgnoreCase(type))// 返利订单 |
| | | { |
| | | processFanLiVipShopOrder(order, uid); |
| | | lostOrderService.processSuceess(order.getOrderSn() + "", Constant.SOURCE_TYPE_VIP); |
| | | } else if ("share".equalsIgnoreCase(type)) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareVipShopOrder(order, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiVipShopOrder(order, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理唯品会返利订单 |
| | | * |
| | | * @param vipShopOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiVipShopOrder(VipShopOrder vipShopOrder, Long uid) { |
| | | int invalidCount = 0; |
| | | BigDecimal totalMoney = new BigDecimal(0); |
| | | // 订单状态判断 |
| | | for (VipShopOrderDetail item : vipShopOrder.getDetailList()) { |
| | | if (item.getCommissionTotalCost() != null) |
| | | totalMoney = totalMoney.add(item.getCommissionTotalCost()); |
| | | if (item.getStatus() == VipShopOrderDetail.STATUS_INVALID) { |
| | | invalidCount++; |
| | | } |
| | | } |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(vipShopOrder.getOrderSn() + "", |
| | | Constant.SOURCE_TYPE_VIP); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("唯品会返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(vipShopOrder.getOrderSn() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_VIP); |
| | | order.setState( |
| | | invalidCount == vipShopOrder.getDetailList().size() ? Order.STATE_SHIXIAO : Order.STATE_YIZHIFU); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | order.setThirdCreateTime(new Date(vipShopOrder.getOrderTime())); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addVipShopOrder(vipShopOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, vipShopOrder.getOrderSn() + "", uid, Constant.SOURCE_TYPE_VIP, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(vipShopOrder.getOrderSn() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_VIP); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addVipShopOrder或addHongBao出错", "订单号:" + vipShopOrder.getOrderSn()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理京东分享订单 |
| | | * |
| | | * @param jdOrder |
| | | * @param uid |
| | | */ |
| | | private void processShareVipShopOrder(VipShopOrder jdOrder, Long uid) { |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addVipShopOrder(jdOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, jdOrder.getOrderSn() + "", uid, Constant.SOURCE_TYPE_VIP, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(jdOrder.getOrderSn() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_VIP); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + jdOrder.getOrderSn()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理苏宁订单 |
| | | */ |
| | | @Override |
| | | public void processSuningOrder(SuningOrderInfo suningOrder) { |
| | | if (suningOrder == null) |
| | | return; |
| | | String uidStr = suningOrder.getChildAccountId(); |
| | | Long uid = null; |
| | | if (!StringUtil.isNullOrEmpty(uidStr)) |
| | | uid = Long.parseLong(uidStr); |
| | | String positionId = suningOrder.getPositionId(); |
| | | |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_SUNING, positionId); |
| | | |
| | | if (pidType != null) { |
| | | if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单 |
| | | { |
| | | processFanLiSuningOrder(suningOrder, uid); |
| | | lostOrderService.processSuceess(suningOrder.getOrderCode(), Constant.SOURCE_TYPE_SUNING); |
| | | } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareSuningOrder(suningOrder, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiSuningOrder(suningOrder, null); |
| | | } |
| | | } else { |
| | | processFanLiSuningOrder(suningOrder, null); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 处理苏宁自购返利订单 |
| | | * |
| | | * @param suningOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiSuningOrder(SuningOrderInfo suningOrder, Long uid) { |
| | | int orderState = 0; |
| | | |
| | | // 等待付款;支付完成;退款;订单已取消;确认收货 |
| | | |
| | | if ("订单已取消".equalsIgnoreCase(suningOrder.getOrderLineStatusDesc()) |
| | | || "退款".equalsIgnoreCase(suningOrder.getOrderLineStatusDesc())) |
| | | orderState = Order.STATE_SHIXIAO; |
| | | else |
| | | orderState = Order.STATE_YIZHIFU; |
| | | |
| | | BigDecimal totalMoney = new BigDecimal(suningOrder.getPayAmount()); |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(suningOrder.getOrderCode(), |
| | | Constant.SOURCE_TYPE_SUNING); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("苏宁返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(suningOrder.getOrderCode()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_SUNING); |
| | | order.setState(orderState); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | order.setThirdCreateTime( |
| | | new Date(TimeUtil.convertToTimeTemp(suningOrder.getOrderSubmitTime(), "yyyy-MM-dd HH:mm:ss"))); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<SuningOrderInfo> pddOrderList = new ArrayList<>(); |
| | | pddOrderList.add(suningOrder); |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addSuningOrder(pddOrderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, suningOrder.getOrderCode(), uid, Constant.SOURCE_TYPE_SUNING, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(suningOrder.getOrderCode()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_SUNING); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addPDDOrder或addHongBao出错", "订单号:" + suningOrder.getOrderCode()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理苏宁分享订单 |
| | | * |
| | | * @param suningOrder |
| | | * @param uid |
| | | */ |
| | | private void processShareSuningOrder(SuningOrderInfo suningOrder, Long uid) { |
| | | try { |
| | | List<SuningOrderInfo> suningOrderList = new ArrayList<>(); |
| | | suningOrderList.add(suningOrder); |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addSuningOrder(suningOrderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, suningOrder.getOrderCode(), uid, Constant.SOURCE_TYPE_SUNING, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(suningOrder.getOrderCode()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_SUNING); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + suningOrder.getOrderCode()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void processDYOrder(DYOrder order) { |
| | | if (order == null) |
| | | return; |
| | | |
| | | |
| | | // 根据ext1与subUnionId跟单 |
| | | String extra_info = order.getExternal_info(); |
| | | |
| | | Long uid = DYUtil.getUid(extra_info); |
| | | String type = DYUtil.getTypeFromExtraInfo(extra_info); |
| | | if ("buy".equalsIgnoreCase(type))// 返利订单 |
| | | { |
| | | processFanLiDYOrder(order, uid); |
| | | lostOrderService.processSuceess(order.getOrder_id() + "", Constant.SOURCE_TYPE_DY); |
| | | } else if ("share".equalsIgnoreCase(type)) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareDYOrder(order, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiDYOrder(order, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理抖音返利订单 |
| | | * |
| | | * @param dyOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiDYOrder(DYOrder dyOrder, Long uid) { |
| | | |
| | | BigDecimal totalMoney = new BigDecimal(dyOrder.getTotal_pay_amount()).divide(new BigDecimal(100),2, RoundingMode.FLOOR); |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(dyOrder.getOrder_id() + "", |
| | | Constant.SOURCE_TYPE_DY); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("抖音返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(dyOrder.getOrder_id() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_DY); |
| | | order.setState( |
| | | (dyOrder.getFlow_point().equalsIgnoreCase(DYOrder.FLOW_POINT_REFUND)) ? Order.STATE_SHIXIAO : Order.STATE_YIZHIFU); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | order.setThirdCreateTime(new Date(TimeUtil.convertToTimeTemp(dyOrder.getPay_success_time(),"yyyy-MM-dd HH:mm:ss"))); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addDYOrder(dyOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, dyOrder.getOrder_id() + "", uid, Constant.SOURCE_TYPE_DY, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(dyOrder.getOrder_id()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_DY); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addDYOrder或addHongBao出错", "订单号:" + dyOrder.getOrder_id()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理抖音分享订单 |
| | | * |
| | | * @param dyOrder |
| | | * @param uid |
| | | */ |
| | | private void processShareDYOrder(DYOrder dyOrder, Long uid) { |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addDYOrder(dyOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, dyOrder.getOrder_id() + "", uid, Constant.SOURCE_TYPE_DY, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(dyOrder.getOrder_id()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_DY); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addDYOrder或addHongBao出错", "订单号:" + dyOrder.getOrder_id()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void repairCommonOrderByByTaoBaoOrder(String orderId) { |
| | | // 根据订单号查询淘宝订单 |
| | | List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId); |
| | | if (orderList != null) |
| | | for (TaoBaoOrder order : orderList) { |
| | | // 根据交易ID查询常规订单 |
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, |
| | | order.getTradeId()); |
| | | // 修复orderby |
| | | if (commonOrder != null) { |
| | | CommonOrder update = new CommonOrder(commonOrder.getId()); |
| | | update.setOrderBy(order.getOrderBy()); |
| | | update.setUpdateTime(new Date()); |
| | | commonOrderService.updateByPrimaryKeySelective(update); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public boolean isShareOrder(CommonOrder commonOrder) { |
| | | //获取系统 |
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(commonOrder.getUserInfo().getId()); |
| | | SystemEnum system = user.getSystem(); |
| | | switch (commonOrder.getSourceType()) { |
| | | case Constant.SOURCE_TYPE_TAOBAO: |
| | | return isShareOrder(system, taoBaoOrderService.selectByTradeId(commonOrder.getTradeId())); |
| | | case Constant.SOURCE_TYPE_JD: |
| | | return isShareOrder(jdOrderService.selectDetailByOrderId(Long.parseLong(commonOrder.getOrderNo()))); |
| | | case Constant.SOURCE_TYPE_PDD: |
| | | return isShareOrder(pddOrderService.selectByOrderSn(commonOrder.getOrderNo()).get(0)); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 转为普通订单 |
| | | * |
| | | * @param dtoList |
| | | * @return |
| | | */ |
| | | private List<CommonOrder> convertCommonOrder(List<CommonOrderAddResultDTO> dtoList) { |
| | | List<CommonOrder> commonOrderList = new ArrayList<>(); |
| | | if (dtoList != null) |
| | | for (CommonOrderAddResultDTO dto : dtoList) |
| | | commonOrderList.add(dto.getCommonOrder()); |
| | | return commonOrderList; |
| | | } |
| | | |
| | | /** |
| | | * 是否全是增加 |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | private boolean isCommonOrderAllAdd(List<CommonOrderAddResultDTO> list) { |
| | | if (list == null || list.size() == 0) |
| | | return false; |
| | | int addCount = 0; |
| | | if (list != null) |
| | | for (CommonOrderAddResultDTO dto : list) { |
| | | if (dto.getType() == CommonOrderAddResultDTO.TYPE_ADD) |
| | | addCount++; |
| | | } |
| | | if (addCount == list.size()) |
| | | return true; |
| | | else |
| | | return false; |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void invalidHongBaoV2AndGiveGodenCorn(Long hongBaoId, Long uid, String orderId, int sourceType, |
| | | String beiZhu) throws Exception { |
| | | HongBaoOrder hongbaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBaoId); |
| | | if (hongbaoOrder != null) { |
| | | CommonOrder commonOrder = commonOrderService.selectByPrimaryKey(hongbaoOrder.getCommonOrder().getId()); |
| | | if (commonOrder != null) { |
| | | if (commonOrder.getState() == CommonOrder.STATE_FK) { |
| | | CommonOrder updateOrder = new CommonOrder(commonOrder.getId()); |
| | | updateOrder.setState(CommonOrder.STATE_SX); |
| | | updateOrder.setUpdateTime(new Date()); |
| | | commonOrderService.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | } |
| | | } |
| | | |
| | | HongBaoV2 hongBao = hongBaoV2Service.selectByPrimaryKey(hongBaoId); |
| | | if (hongBao == null || hongBao.getState() == HongBaoV2.STATE_SHIXIAO) |
| | | return; |
| | | |
| | | HongBaoV2 v2 = new HongBaoV2(hongBaoId); |
| | | v2.setState(HongBaoV2.STATE_SHIXIAO); |
| | | v2.setBeizhu(beiZhu); |
| | | v2.setUpdateTime(new Date()); |
| | | hongBaoV2Service.updateByPrimaryKeySelective(v2); |
| | | List<HongBaoV2> children = hongBaoV2Service.listChildrenById(hongBaoId); |
| | | if (children != null) |
| | | for (HongBaoV2 child : children) { |
| | | HongBaoV2 update = new HongBaoV2(child.getId()); |
| | | update.setState(HongBaoV2.STATE_SHIXIAO); |
| | | update.setBeizhu(beiZhu); |
| | | update.setUpdateTime(new Date()); |
| | | hongBaoV2Service.updateByPrimaryKeySelective(update); |
| | | } |
| | | |
| | | if (hongBao.getType() == HongBaoV2.TYPE_ZIGOU || hongBao.getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | userOrderMsgNotificationService.orderInvalidToBusinessRunning(uid, orderId, sourceType, hongBao.getType()); |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void doTaoBaoSellerNotPaid(TaoBaoOrder order) { |
| | | |
| | | // 根据交易ID查询 |
| | | if (!StringUtil.isNullOrEmpty(order.getTradeId())) { |
| | | List<CommonOrder> commonOrderList = commonOrderService |
| | | .listBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, order.getTradeId()); |
| | | if (commonOrderList != null) |
| | | // 查询主订单 |
| | | for (CommonOrder commonOrder : commonOrderList) { |
| | | // 查询主红包 |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null) { |
| | | if (hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_BUKELINGQU || hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_SHIXIAO) { |
| | | // 订单失效,赠送金币 |
| | | try { |
| | | invalidHongBaoV2AndGiveGodenCorn(hongBaoOrder.getHongBaoV2().getId(), hongBaoOrder.getHongBaoV2().getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType(), "订单成功,商家未打款"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void elmeFanli() { |
| | | |
| | | } |
| | | |
| | | // 饿了么订单 |
| | | @Resource |
| | | private ElmeHongBaoOrderMapService elmeHongBaoOrderMapService; |
| | | |
| | | @Resource |
| | | private ElmeOrderService elmeOrderService; |
| | | |
| | | @Resource |
| | | private ElmeOrderProcessService elmeOrderProcessService; |
| | | |
| | | /** |
| | | * 获取饿了么可以返利的红包 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<HongBaoV2> getCanBalanceElmeFanliHongBao() { |
| | | List<Integer> list = new ArrayList<>(); |
| | | list.add(HongBaoV2.TYPE_ELME); |
| | | return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, null, new Date(), 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(); |
| | | } |
| | | // 返利到账 |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加红包与事务消息 |
| | | * |
| | | * @param commonOrderList |
| | | * @param orderId |
| | | * @param uid |
| | | * @param sourceType |
| | | * @param hongBaoType |
| | | */ |
| | | private void addHongBaoWithMQ(List<CommonOrderAddResultDTO> commonOrderList, String orderId, Long uid, |
| | | int sourceType, int hongBaoType) { |
| | | final List<CommonOrder> coList = convertCommonOrder(commonOrderList); |
| | | HongBaoAddResult result = null; |
| | | try { |
| | | long time = TimeUtil.convertToTimeTemp("2019-12-06", "yyyy-MM-dd"); |
| | | if (!Constant.IS_TEST) |
| | | time = TimeUtil.convertToTimeTemp("2019-12-20", "yyyy-MM-dd"); |
| | | |
| | | if (coList.get(0).getThirdCreateTime().getTime() < time) |
| | | result = hongBaoV2Service.addHongBao(coList, hongBaoType); |
| | | else |
| | | result = hongBaoV2AddManager.addHongBao(coList, hongBaoType); |
| | | } catch (HongBaoException e) { |
| | | if (e.getCode() != HongBaoException.CODE_ORDER_WEIQUAN) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + orderId); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } catch (UserAccountException e) { |
| | | |
| | | } |
| | | if (result == null) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | if (!Constant.IS_TEST) |
| | | if (result.getResultCode() == HongBaoAddResult.CODE_ADD) {// 只发送新增消息 |
| | | OrderMQMsg mqMsg = new OrderMQMsg(orderId, sourceType, uid, OrderMQMsg.HANDLE_TYPE_ADD, |
| | | isCommonOrderValid(coList), 0, new Date(), result.isMiandan(), coList.get(0).getThirdCreateTime()); |
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderStatistic, mqMsg); |
| | | rocketMQManager.sendNormalMsg(msg, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 订单是否有效 |
| | | * |
| | | * @param coList |
| | | * @return |
| | | */ |
| | | private boolean isCommonOrderValid(List<CommonOrder> coList) { |
| | | for (CommonOrder commonOrder : coList) { |
| | | if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK |
| | | || commonOrder.getState() == CommonOrder.STATE_WQ) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void invalidTaoBaoOrder(String tradeId) { |
| | | TaoBaoOrder taoBaoOrder = taoBaoOrderService.selectByTradeId(tradeId); |
| | | //订单付款和订单成功的状态才允许失效 |
| | | if (taoBaoOrder != null && ("订单付款".equalsIgnoreCase(taoBaoOrder.getOrderState()) || "订单成功".equalsIgnoreCase(taoBaoOrder.getOrderState()))) { |
| | | TaoBaoOrder update = new TaoBaoOrder(); |
| | | update.setId(taoBaoOrder.getId()); |
| | | update.setLatestUpdateTime(new Date()); |
| | | update.setOrderState("订单失效"); |
| | | taoBaoOrderService.updateSelectiveByPrimaryKey(update); |
| | | CMQManager.getInstance().addTaoBaoOrderMsg(taoBaoOrder.getOrderId()); |
| | | } |
| | | } |
| | | |
| | | } |