From c952838555e557097f84a47624bc2860e0a2d9a8 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期二, 30 六月 2020 15:50:46 +0800
Subject: [PATCH] 云发单异步 + 首单
---
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java | 526 ++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 439 insertions(+), 87 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
index 81fc96c..3395cec 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -30,10 +30,12 @@
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;
@@ -46,11 +48,14 @@
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;
@@ -73,8 +78,8 @@
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.OrderTeamRewardService;
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;
@@ -88,12 +93,15 @@
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.cmq.order.PlaceOrderCMQManager;
+import com.yeshi.fanli.util.cmq.order.TeamOrderCMQManager;
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;
+import com.yeshi.fanli.util.suning.SuningApiUtil;
+import com.yeshi.fanli.util.vipshop.VipShopUtil;
@Service
public class OrderProcessServiceImpl implements OrderProcessService {
@@ -132,6 +140,9 @@
private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
@Resource
+ private UserOrderMsgNotificationService userOrderMsgNotificationService;
+
+ @Resource
private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
@Resource
@@ -166,9 +177,6 @@
@Resource
private HongBaoV2AddManager hongBaoV2AddManager;
-
- @Resource
- private OrderTeamRewardService orderTeamRewardService;
/**
* 鏄惁鏄垎浜鍗�
@@ -217,12 +225,19 @@
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 ("楗夸簡涔�".equalsIgnoreCase(list.get(0).getOrderType())
+ && !pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT)) {
+ // 楗夸簡涔堣鍗曞紑濮嬪綊鍏ュ埌娣樺疂璁㈠崟
+ 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 ("鍙g".equalsIgnoreCase(list.get(0).getOrderType())
+ && pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) {// 鍙g鑷喘
+ fanliOrderMap.put(orderId, list);
+ } else {
if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId())
|| pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 璁剧疆娓犻亾ID褰撳仛浼氬憳杩愯惀ID鐨勪綅缃甀D
fanliOrderMap.put(orderId, list);
@@ -407,7 +422,8 @@
|| hb.getPreGetTime().getTime() > System.currentTimeMillis())
continue;
try {
- CMQManager.getInstance().addFanLiMsgNew(hb);
+ if (Constant.ENABLE_MQ)
+ CMQManager.getInstance().addFanLiMsgNew(hb);
} catch (Exception e) {
try {
LogHelper.errorDetailInfo(e);
@@ -426,6 +442,11 @@
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;
+
// 姝e父鐢ㄦ埛鎵嶈兘鍒拌处
UserInfo mainUser = userInfoMapper.selectAvailableByPrimaryKey(hb1.getUserInfo().getId());
if (mainUser == null || mainUser.getState() != UserInfo.STATE_NORMAL) {
@@ -521,7 +542,8 @@
for (TaoBaoWeiQuanOrder order : orderList) {
try {
if (order.getState().contains("缁存潈鎴愬姛")) {
- CMQManager.getInstance().addWeiQuanOrderMsg(order);
+ if (Constant.ENABLE_MQ)
+ CMQManager.getInstance().addWeiQuanOrderMsg(order);
}
} catch (Exception e) {
LogHelper.error("缁存潈璁㈠崟鍔犲叆鍒伴槦鍒楀嚭閿�:" + order != null ? new Gson().toJson(order) : null);
@@ -587,65 +609,117 @@
}
@Override
- public void fanliInvaiteAndShare() {
- // 鏌ュ嚭閭�璇疯禋涓庡垎浜禋璇ヨ繑鍒╃殑鐢ㄦ埛ID
- List<Long> inviteAndShareUids = hongBaoV2Mapper.listUidCanBanlanceShareAndInvite(1000);
+ public void fanliPreInvaite(Date maxTime) {
+ // 鏌ュ嚭閭�璇疯禋鐨勭敤鎴稩D
+ 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<>();
- if (inviteAndShareUids != null)
- for (Long uid : inviteAndShareUids) {
- if (userInfoMapper.selectAvailableByPrimaryKey(uid) != null)
- uidSets.add(uid);
- }
+ 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 {
- CMQManager.getInstance().addFanLiTiChengMsg(uid);
+ if (Constant.ENABLE_MQ)
+ TeamOrderCMQManager.getInstance().addFanLiTeamIncomePreMsg(new UidDateDTO(uid, maxTime));
} catch (Exception e) {
e.printStackTrace();
LogHelper.error(e);
}
}
+
+ }
+
+ @Override
+ public void fanliShare(Date maxTime) {
+ // 鏌ュ嚭閭�璇疯禋鐨勭敤鎴稩D
+ 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);
+ }
+ }
+
+ }
+
+ @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();
+ }
}
@Override
@Transactional(rollbackFor = Exception.class)
- public void fanliInvaiteAndShare(Long uid) throws TaoBaoWeiQuanException {
+ public void fanliShare(Long uid, Date maxPreGetTime) {
// 閭�璇疯禋鍒拌处
try {
- orderMoneySettleService.inviteSettleTB(uid);
+ orderMoneySettleService.shareSettleTB(uid, maxPreGetTime);
} 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);
+ orderMoneySettleService.shareSettleJD(uid, maxPreGetTime);
} catch (OrderMoneySettleException e) {
e.printStackTrace();
}
try {
- orderMoneySettleService.shareSettleJD(uid);
- } catch (OrderMoneySettleException e) {
- e.printStackTrace();
- }
- //
- try {
- orderMoneySettleService.shareSettlePDD(uid);
+ orderMoneySettleService.shareSettlePDD(uid, maxPreGetTime);
} catch (OrderMoneySettleException e) {
e.printStackTrace();
}
@@ -672,9 +746,17 @@
if (oldOrder == null) {
Long targetUid = null;
if (pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)
- && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {
+ && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 澶勭悊闈炶繑鍒╁晢鍝佸簱鐨勫晢鍝�
targetUid = taoBaoBuyRelationMapService.selectUidByRelationId(orderList.get(0).getRelationId());
+ } else if ((pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_ELEME_PID)
+ || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID))
+ && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 澶勭悊楗夸簡涔�,鍙g鐨勮鍗�
+ UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService
+ .getByRelationId(orderList.get(0).getRelationId());
+ if (extraInfo != null) {
+ targetUid = extraInfo.getUser().getId();
+ }
} else if (!StringUtil.isNullOrEmpty(orderList.get(0).getSpecialId())) {
UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService
.getBySpecialId(orderList.get(0).getSpecialId());
@@ -743,7 +825,7 @@
order.setOrderType(Constant.SOURCE_TYPE_TAOBAO);
order.setUserInfo(new UserInfo(uid));
try {
- if (!Constant.IS_TEST)
+ if (Constant.ENABLE_MQ)
PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
} catch (Exception e) {
}
@@ -794,7 +876,8 @@
order.setOrderType(Constant.SOURCE_TYPE_TAOBAO);
order.setUserInfo(new UserInfo(uid));
try {
- PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
+ if (Constant.ENABLE_MQ)
+ PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
} catch (Exception e) {
}
}
@@ -916,7 +999,8 @@
order.setOrderType(Constant.SOURCE_TYPE_JD);
order.setUserInfo(new UserInfo(uid));
try {
- PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
+ if (Constant.ENABLE_MQ)
+ PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
} catch (Exception e) {
}
}
@@ -947,7 +1031,8 @@
order.setOrderType(Constant.SOURCE_TYPE_JD);
order.setUserInfo(new UserInfo(uid));
try {
- PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
+ if (Constant.ENABLE_MQ)
+ PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
} catch (Exception e) {
}
}
@@ -1056,7 +1141,8 @@
order.setOrderType(Constant.SOURCE_TYPE_PDD);
order.setUserInfo(new UserInfo(uid));
try {
- PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
+ if (Constant.ENABLE_MQ)
+ PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
} catch (Exception e) {
}
}
@@ -1089,13 +1175,286 @@
order.setOrderType(Constant.SOURCE_TYPE_PDD);
order.setUserInfo(new UserInfo(uid));
try {
- PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
+ if (Constant.ENABLE_MQ)
+ PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
} catch (Exception e) {
}
}
} catch (CommonOrderException e) {
try {
LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + 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涓巗ubUnionId璺熷崟
+ 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 jdOrder
+ * @param uid
+ */
+ @Transactional
+ 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鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + vipShopOrder.getOrderSn());
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 澶勭悊浜笢鍒嗕韩璁㈠崟
+ *
+ * @param order
+ * @param uid
+ */
+ @Transactional
+ 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鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + 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();
+ if (SuningApiUtil.PID_BUY.equalsIgnoreCase(positionId))// 杩斿埄璁㈠崟
+ {
+ processFanLiSuningOrder(suningOrder, uid);
+ lostOrderService.processSuceess(suningOrder.getOrderCode(), Constant.SOURCE_TYPE_SUNING);
+ } else if (PinDuoDuoApiUtil.PID_SHARE.equalsIgnoreCase(positionId)) {// 鍒嗕韩璁㈠崟
+ if (uid == null)// 鍒嗕韩璁㈠崟涓嶅厑璁告壘鍥�
+ return;
+ processShareSuningOrder(suningOrder, uid);
+ } else {// 澶勭悊鏄惁鏈夎鍗曟壘鍥炵殑鐘舵��
+ processFanLiSuningOrder(suningOrder, null);
+ }
+ }
+
+ /**
+ * 澶勭悊鎷煎澶氳嚜璐繑鍒╄鍗�
+ *
+ * @param pddOrder
+ * @param uid
+ */
+ @Transactional
+ 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鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + suningOrder.getOrderCode());
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * 澶勭悊鎷煎澶氬垎浜鍗�
+ *
+ * @param order
+ * @param uid
+ */
+ @Transactional
+ 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鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + suningOrder.getOrderCode());
} catch (Exception e1) {
e1.printStackTrace();
}
@@ -1173,6 +1532,23 @@
@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);
@@ -1187,7 +1563,10 @@
update.setUpdateTime(new Date());
hongBaoV2Service.updateByPrimaryKeySelective(update);
}
- userSystemCouponService.systemGiveRewardCoupon(uid, 1, orderId, sourceType, "鍥犲晢瀹惰繚绾︽湭鑳界粨绠楄繑鍒╂垨鍟嗗宸茬粡鍏冲簵");
+
+ if (hongBao.getType() == HongBaoV2.TYPE_ZIGOU || hongBao.getType() == HongBaoV2.TYPE_SHARE_GOODS) {
+ userOrderMsgNotificationService.orderInvalidToBusinessRunning(uid, orderId, sourceType, hongBao.getType());
+ }
}
@Transactional
@@ -1204,7 +1583,7 @@
// 鏌ヨ涓荤孩鍖�
HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null) {
- if (hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_BUKELINGQU) {
+ 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(), "璁㈠崟鎴愬姛锛屽晢瀹舵湭鎵撴");
@@ -1242,7 +1621,7 @@
public List<HongBaoV2> getCanBalanceElmeFanliHongBao() {
List<Integer> list = new ArrayList<>();
list.add(HongBaoV2.TYPE_ELME);
- return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, null, 0, 1000);
+ return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, null, new Date(), 0, 1000);
}
@Override
@@ -1279,9 +1658,6 @@
}
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);
}
// 杩斿埄鍒拌处
}
@@ -1299,16 +1675,16 @@
private void addHongBaoWithMQ(List<CommonOrderAddResultDTO> commonOrderList, String orderId, Long uid,
int sourceType, int hongBaoType) {
final List<CommonOrder> coList = convertCommonOrder(commonOrderList);
- int resultCode = 0;
+ 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)
- resultCode = hongBaoV2Service.addHongBao(coList, hongBaoType);
+ result = hongBaoV2Service.addHongBao(coList, hongBaoType);
else
- resultCode = hongBaoV2AddManager.addHongBao(coList, hongBaoType);
+ result = hongBaoV2AddManager.addHongBao(coList, hongBaoType);
} catch (HongBaoException e) {
try {
LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + orderId);
@@ -1319,9 +1695,9 @@
}
if (!Constant.IS_TEST)
- if (resultCode == 1) {// 鍙彂閫佹柊澧炴秷鎭�
+ if (result.getResultCode() == HongBaoAddResult.CODE_ADD) {// 鍙彂閫佹柊澧炴秷鎭�
OrderMQMsg mqMsg = new OrderMQMsg(orderId, sourceType, uid, OrderMQMsg.HANDLE_TYPE_ADD,
- isCommonOrderValid(coList), 0, new Date());
+ isCommonOrderValid(coList), 0, new Date(), result.isMiandan(),coList.get(0).getThirdCreateTime());
Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderStatistic, mqMsg);
producer.send(msg);
}
@@ -1341,30 +1717,6 @@
}
}
return false;
- }
-
- @Override
- public void fanliOrderTeamReward() {
- Date time = new Date();
- long count = orderTeamRewardService.countCanSettleUid(time);
- int pageSize = 500;
- int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
- List<Long> uidList = new ArrayList<>();
- for (int i = 0; i < page; i++) {
- List<Long> list = orderTeamRewardService.listCanSettleUid(time, i + 1, pageSize);
- if (list != null && list.size() > 0)
- uidList.addAll(list);
- }
- // 娣诲姞鍒伴槦鍒�
- if (uidList != null)
- for (Long uid : uidList)
- if (!Constant.IS_TEST)
- CMQManager.getInstance().addFanLiOrderTeamRewardMsg(uid);
- }
-
- @Override
- public void fanliOrderTeamReward(Long uid) throws OrderMoneySettleException {
- orderMoneySettleService.orderTeamRewardSettle(uid);
}
}
--
Gitblit v1.8.0