From c113e8b7e11a52bf1eeaf1ced7324db7ee4305fa Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期三, 24 六月 2020 09:36:22 +0800
Subject: [PATCH] 发圈零点关键词调整
---
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java | 1231 +++++++++++++++++++++++++++++++++-------------------------
1 files changed, 695 insertions(+), 536 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 c2b3dc3..3ff3530 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
@@ -2,7 +2,6 @@
import java.math.BigDecimal;
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -10,6 +9,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import javax.annotation.Resource;
@@ -18,6 +18,11 @@
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;
@@ -25,8 +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.HongBao;
+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;
@@ -39,18 +48,26 @@
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.hongbao.AccountDetailsHongBaoMapService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
@@ -59,26 +76,32 @@
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.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.HongBaoRecieveCMQManager;
-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.taobao.TaoKeOrderApiUtil;
+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 {
@@ -117,6 +140,9 @@
private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
@Resource
+ private UserOrderMsgNotificationService userOrderMsgNotificationService;
+
+ @Resource
private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
@Resource
@@ -139,6 +165,18 @@
@Resource
private PDDOrderService pddOrderService;
+
+ @Resource(name = "orderTransactionProducer")
+ private TransactionProducer orderTransactionProducer;
+
+ @Resource(name = "producer")
+ private Producer producer;
+
+ @Resource
+ private OrderMoneySettleService orderMoneySettleService;
+
+ @Resource
+ private HongBaoV2AddManager hongBaoV2AddManager;
/**
* 鏄惁鏄垎浜鍗�
@@ -179,6 +217,7 @@
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();
@@ -186,26 +225,39 @@
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 (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId())
- || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 璁剧疆娓犻亾ID褰撳仛浼氬憳杩愯惀ID鐨勪綅缃甀D
- 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;
- }
+ 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);
+ } 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);
+ }
}
}
}
@@ -214,6 +266,54 @@
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
@@ -322,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);
@@ -337,10 +438,15 @@
private HongBaoOrderMapper hongBaoOrderMapper;
@Override
- @Transactional
+ @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;
+
// 姝e父鐢ㄦ埛鎵嶈兘鍒拌处
UserInfo mainUser = userInfoMapper.selectAvailableByPrimaryKey(hb1.getUserInfo().getId());
if (mainUser == null || mainUser.getState() != UserInfo.STATE_NORMAL) {
@@ -353,12 +459,7 @@
return;
}
- if (hongBaoOrder.getCommonOrder() == null) {// ||
- // hongBaoOrder.getCommonOrder().getSourceType()
- // ==
- // Constant.SOURCE_TYPE_JD
- // || hongBaoOrder.getCommonOrder().getSourceType() ==
- // Constant.SOURCE_TYPE_PDD
+ if (hongBaoOrder.getCommonOrder() == null) {
return;
}
@@ -382,134 +483,57 @@
return;
}
- // 鏌ヨ鍚屼竴璁㈠崟鍙风殑绾㈠寘
- List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(
- hongBaoOrder.getCommonOrder().getSourceType(), hongBaoOrder.getCommonOrder().getOrderNo());
- List<HongBaoV2> hongBaoList = new ArrayList<>();
- Map<Long, BigDecimal> userMoney = new HashMap<>();
- Map<Long, List<HongBaoV2>> userHongBao = new HashMap<>();
- Map<Long, Integer> userGoodsCount = new HashMap<>();
- // Map<Long, BigDecimal> userPayMent = new HashMap<>();
- for (CommonOrder co : orderList) {
- hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(co.getId());
- hongBaoList.add(hongBaoOrder.getHongBaoV2());
- Long uid = co.getUserInfo().getId();
- if (userGoodsCount.get(uid) == null)
- userGoodsCount.put(uid, co.getCount());
- else
- userGoodsCount.put(uid, Integer.valueOf(co.getCount() + userGoodsCount.get(uid)));
- // if (userPayMent.get(uid) == null)
- // userPayMent.put(uid, new BigDecimal(0));
- // if (co.getState() == CommonOrder.STATE_JS)
- // userPayMent.put(uid,
- // userPayMent.get(uid).add(co.getSettlement()));
- // else
- // userPayMent.put(uid, userPayMent.get(uid).add(co.getPayment()));
- }
-
- for (HongBaoV2 hb : hongBaoList) {
- long currentTimeMillis = System.currentTimeMillis();
- if (hb.getState() != HongBao.STATE_SHIXIAO) {
- // 璁剧疆涓哄凡杩斿埄
- // 澶勭悊涓荤孩鍖�
- if (hb.getState() != HongBaoV2.STATE_SHIXIAO && hb.getState() != HongBaoV2.STATE_YILINGQU
- && hb.getType() == HongBaoV2.TYPE_ZIGOU) {
- // 濡傛灉绾㈠寘娌¤棰嗗彇
- Long uid = hb.getUserInfo().getId();
- HongBaoV2 updateHongBao = new HongBaoV2();
- updateHongBao.setId(hb.getId());
- updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
- updateHongBao.setGetTime(new Date(currentTimeMillis));
- hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
- if (userMoney.get(uid) == null)
- userMoney.put(uid, hb.getMoney());
- else
- userMoney.put(uid, userMoney.get(uid).add(hb.getMoney()));
-
- // 娣诲姞绾㈠寘鍒扮敤鎴�
- if (userHongBao.get(uid) == null)
- userHongBao.put(uid, new ArrayList<>());
- userHongBao.get(uid).add(hb);
- }
+ // 鏌ヨ璇ヨ鍗曚箣鍓嶆槸鍚︽湁鍒拌处
+ 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());
}
}
- Iterator<Long> its = userMoney.keySet().iterator();
-
- while (its.hasNext()) {
- // 灏嗚嚜宸辨坊鍔犲埌鐢ㄦ埛
- Long uid = its.next();
- BigDecimal money = userMoney.get(uid);
- UserMoneyDetail userMoneyDetail = null;
- // 鎻掑叆鏂扮増璧勯噾鏄庣粏
- try {
- // 姝ゅ涓嶇敤璁㈠崟鍙峰仛鍞竴鎬х储寮�
- userMoneyDetail = UserMoneyDetailFactory.createFanLi(uid, hongBaoOrder.getCommonOrder().getOrderNo(),
- hongBaoOrder.getCommonOrder().getSourceType(), null, money);
- } catch (UserMoneyDetailException e1) {
- try {
- LogHelper.errorDetailInfo(e1, "璁㈠崟鍙�:" + hongBaoOrder.getCommonOrder().getOrderNo(), "");
- } catch (Exception e2) {
- e2.printStackTrace();
- }
+ List<HongBaoV2> allHongBaoList = hongBaoV2Mapper.listByIds(hongBaoIdList);
+ boolean first = true;
+ for (HongBaoV2 v2 : allHongBaoList)
+ if (v2.getState() == HongBaoV2.STATE_YILINGQU) {
+ first = false;
+ break;
}
- userMoneyService.addUserMoney(uid, money, userMoneyDetail);
- // 娣诲姞璧勯噾鏄庣粏涓庣孩鍖呯殑鏄犲皠鍏崇郴
- for (HongBaoV2 v2 : userHongBao.get(uid)) {
- accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(v2.getId(), userMoneyDetail.getId());
- try {
- HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(v2.getId());
- } catch (Exception e) {
- LogHelper.errorDetailInfo(e);
- }
- }
-
- // 绔欏唴淇�+鎺ㄩ��
- UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
-
- // 鏂扮増閫氱煡
- userMoneyMsgNotificationService.fanliOrderReceived(uid, hongBaoOrder.getCommonOrder().getOrderNo(),
- hongBaoOrder.getCommonOrder().getSourceType(), userGoodsCount.get(uid), money, user.getMyHongBao());
- }
- // 閫氱煡鍏嶅崟鍒拌处
+ // 鑷喘鍒拌处浜嬪姟娑堟伅
+ 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 {
- userSystemCouponService.updateStateByArrivalAccount(hongBaoOrder.getCommonOrder().getOrderNo());
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- // 缁存潈鎵f锛�2018-08-05鍚庡紑濮嬪疄琛岋級
- if (hongBaoOrder.getCommonOrder().getSettleTime() != null && hongBaoOrder.getCommonOrder().getSettleTime()
- .getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
- try {
- if (hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_TAOBAO)
- taoBaoWeiQuanDrawBackService.doWeiQuanFanli(hongBaoOrder.getCommonOrder().getOrderNo());
- } catch (TaoBaoWeiQuanException e) {
- if (e.getCode() == TaoBaoWeiQuanException.CODE_NEDD_UPDATE_ORDER) {
- List<TaoBaoOrder> olist = taoBaoOrderService
- .getTaoBaoOrderByOrderId(hongBaoOrder.getCommonOrder().getOrderNo());
-
- if (olist != null && olist.size() > 0) {
- long time = TimeUtil.convertToTimeTemp(olist.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss");
- olist = TaoKeOrderApiUtil.getTaoBaoCommonOrderList(time, time + 1000 * 2L, 1);
- if (olist != null && olist.size() > 0) {
- for (int i = 0; i < olist.size(); i++) {
- if (!olist.get(i).getOrderId()
- .equalsIgnoreCase(hongBaoOrder.getCommonOrder().getOrderNo())) {// 鍒犻櫎鏃犲叧璁㈠崟
- olist.remove(i);
- i--;
- }
- }
-
- taoBaoOrderService.addTaoBaoOrderList(olist);
+ 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;
}
}
- } else
- throw new TaoBaoWeiQuanException(e.getCode(), e.getMsg());
+ }, 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
@@ -518,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);
@@ -535,13 +560,8 @@
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("2018-08-05", "yyyy-MM-dd")) {
- // return;
- // }
- // TODO 澶勭悊缁存潈鎴愬姛浣嗘槸宸插埌璐︾殑璁㈠崟
-
+ // 澶勭悊缁存潈鎴愬姛浣嗘槸宸插埌璐︾殑璁㈠崟
if (order.getJieSuanTime().getTime() > TimeUtil.convertToTimeTemp("2019-01-01", "yyyy-MM-dd")) {// 缁撶畻鏃堕棿鍦�2鏈�1鍙风殑寮�濮嬪鐞嗗凡鍒拌处浣嗘槸缁存潈鐨�
CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
order.getOrderItemId());
@@ -552,15 +572,34 @@
TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackService
.selectByOrderItemId(order.getOrderItemId());
if (drawBack == null) {// 杩樻湭鎵f
+ OrderLogHelper.taoBaoWeiQuan("宸插埌璐︽湭鎵f澶勭悊:瀛愯鍗曞彿:" + order.getOrderItemId());
try {
- taoBaoWeiQuanDrawBackService.doWeiQuanFanli(order.getOrderId());
+ taoBaoWeiQuanDrawBackService.doWeiQuanFanli(order.getOrderId(), true);
taoBaoWeiQuanDrawBackService.doWeiQuanShare(order.getOrderId());
taoBaoWeiQuanDrawBackService.doWeiQuanInvite(order.getOrderId());
} catch (TaoBaoWeiQuanException e) {
try {
- LogHelper.errorDetailInfo(e, null, "璁㈠崟鍙�:" + order.getOrderId());
+ 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;
}
}
}
@@ -570,317 +609,120 @@
}
@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)
- 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);
}
}
- }
- private HongBaoV2 filterWeiQuanINGHongBao(HongBaoV2 hongBao) {
-
- long hbId = hongBao.getId();
- if (hongBao.getParent() != null) {
- hbId = hongBao.getParent().getId();
- }
-
- HongBaoOrder hongbaoOrder = hongBaoOrderMapper.selectByHongBaoId(hbId);
-
- if (hongbaoOrder == null)
- return null;
-
- List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
- .selectListByOrderIdAndState(hongbaoOrder.getCommonOrder().getOrderNo(), "缁存潈鍒涘缓");
-
- List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList1 = taoBaoWeiQuanOrderMapper
- .selectListByOrderIdAndState(hongbaoOrder.getCommonOrder().getOrderNo(), "绛夊緟澶勭悊");
- if ((taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
- || (taoBaoWeiQuanList1 != null && taoBaoWeiQuanList1.size() > 0)) {
- return null;
- }
- return hongBao;
}
@Override
- @Transactional
- public void fanliInvaiteAndShare(Long uid) throws TaoBaoWeiQuanException {
- List<Long> recieveHongBaoIds = new ArrayList<>();
- /**
- * 澶勭悊閭�璇疯禋璁㈠崟
- */
- // 鏌ヨUID鐨勯個璇疯禋璁㈠崟
- List<Integer> types = new ArrayList<>();
- types.add(HongBaoV2.TYPE_YIJI);
- types.add(HongBaoV2.TYPE_ERJI);
- long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid);
- List<HongBaoV2> hongBaoList = new ArrayList<>();
- // 1000鏉℃暟鎹负1椤�
- int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
+ 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<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, i * 1000,
- 1000);
- if (tempHongBaoList != null && tempHongBaoList.size() > 0)
- hongBaoList.addAll(tempHongBaoList);
- }
- // 鐏板害娴嬭瘯涓紝浜笢/鎷煎澶氳鍗曞垎浜�/閭�璇疯鍗曚笉杩斿埄
- for (int i = 0; i < hongBaoList.size(); i++) {
- HongBaoV2 item = hongBaoList.get(i);
- if (item.getType() == HongBaoV2.TYPE_SHARE_GOODS) {
- } else {
- item = item.getParent();
- }
- if (item != null) {
- HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(item.getId());
- if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {
- CommonOrder co = hongBaoOrder.getCommonOrder();
- // 涓婄骇鐢ㄦ埛涓嶆槸姝e父鐢ㄦ埛锛岃鍗曞潎涓嶈兘鍒拌处
- UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
- if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
- hongBaoList.remove(i);
- 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);
}
- }
}
-
- List<Long> hbIdList = new ArrayList<>();
-
- BigDecimal invitemoney = new BigDecimal(0);
- Set<String> inviteOrders = new HashSet<>();
- int inviteGoodsCount = 0;
-
- // 闇�瑕佸垽鏂��娆剧殑璁㈠崟鍙�
- Set<String> drawBackOrders = new HashSet<String>();
- for (HongBaoV2 hongBao : hongBaoList) {
- hongBao = filterWeiQuanINGHongBao(hongBao);
- if (hongBao == null)
- continue;
-
- hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
- if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
- invitemoney = invitemoney.add(hongBao.getMoney());
- HongBaoV2 updateHongBao = new HongBaoV2();
- updateHongBao.setId(hongBao.getId());
- updateHongBao.setGetTime(new Date());
- updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
- updateHongBao.setUpdateTime(new Date());
- hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
- // 娣诲姞鍒扮孩鍖呰繑鍒╄褰曢泦鍚�
- hbIdList.add(hongBao.getId());
-
- // 2018-08-05 杩囧悗鐨勮鍗曟墠澶勭悊缁存潈
-
- HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getParent().getId());
- inviteGoodsCount += hongBaoOrder.getCommonOrder().getCount();
- inviteOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
-
- Date balanceTime = hongBaoOrder.getCommonOrder().getSettleTime();
- if (balanceTime != null
- && balanceTime.getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
- if (!StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getOrderNo()))
- drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
- }
- }
- }
-
- /**
- * 澶勭悊涓�绾т簩绾у垎浜禋(灞炰簬閭�璇疯禋绫诲瀷)
- */
-
- List<HongBaoV2> totalHongBaoList = new ArrayList<>();
- // 鏌ヨUID鐨勪簩绾ф垨鑰呬笁绾у垎浜禋璁㈠崟
- // TODO 鏆傛椂鏌ヨ10000鏉℃暟鎹紝鍚庨潰鍐嶅仛鍒嗛〉
- types.clear();
- types.add(HongBaoV2.TYPE_SHARE_YIJI);
- types.add(HongBaoV2.TYPE_SHARE_ERJI);
- // TODO 闇�瑕佸鐞嗚秴杩�1w鏉℃暟鎹殑璁㈠崟
- List<HongBaoV2> hbList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 0, 10000);
-
- if (hbList != null && hbList.size() > 0)
- totalHongBaoList.addAll(hbList);
-
- for (HongBaoV2 hb : totalHongBaoList) {
- if (hb.getState() == HongBaoV2.STATE_BUKELINGQU || hb.getState() == HongBaoV2.STATE_KELINGQU) {
- hb = filterWeiQuanINGHongBao(hb);
- if (hb == null)
- continue;
- invitemoney = invitemoney.add(hb.getMoney());
- HongBaoV2 updateHongBao = new HongBaoV2();
- updateHongBao.setId(hb.getId());
- updateHongBao.setGetTime(new Date());
- updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
- updateHongBao.setUpdateTime(new Date());
- hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
- // 娣诲姞鍒扮孩鍖呰繑鍒╄褰曢泦鍚�
- hbIdList.add(hb.getId());
-
- HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hb.getParent().getId());
- inviteGoodsCount += hongBaoOrder.getCommonOrder().getCount();
- inviteOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
- if (!StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getOrderNo()))
- drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
- }
- }
-
- // 閭�璇疯禋鍒拌处
- if (invitemoney.compareTo(new BigDecimal(0)) > 0) {
-
- // 娣诲姞鏂扮増璇︽儏璁板綍
+ // 鏍规嵁鐢ㄦ埛ID
+ Iterator<Long> its = uidSets.iterator();
+ while (its.hasNext()) {
+ Long uid = its.next();
try {
- // 鏌ヨ閭�璇疯禋鐨勬湁鏁堣鍗曪紝澶辨晥璁㈠崟锛岀淮鏉冭鍗�
- Calendar ca = Calendar.getInstance();
- Date maxDate = new Date(TimeUtil
- .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
- ca.add(Calendar.MONTH, -1);
-
- Date minDate = new Date(TimeUtil
- .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
- long validCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
- minDate, maxDate);
- long weiQuanCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
- minDate, maxDate);
-
- UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createInvite(uid, Constant.SOURCE_TYPE_TAOBAO,
- (int) validCount, (int) weiQuanCount, invitemoney, new Date());
-
- // 澧炲姞璧勯噾
- userMoneyService.addUserMoney(uid, invitemoney, userMoneyDetail);
- // 娣诲姞鍒扮孩鍖呰繑鍒╄褰曢泦鍚�
- accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(hbIdList, userMoneyDetail.getId());
- } catch (UserMoneyDetailException e) {
- try {
- LogHelper.errorDetailInfo(e);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
-
- // 鏂扮増閫氱煡
- userMoneyMsgNotificationService.inviteOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, inviteOrders.size(),
- inviteGoodsCount, invitemoney, userInfoMapper.selectByPrimaryKey(uid).getMyHongBao());
-
- for (String orderId : drawBackOrders)
- taoBaoWeiQuanDrawBackService.doWeiQuanInvite(orderId);
- }
- if (hbIdList.size() > 0)
- recieveHongBaoIds.addAll(hbIdList);
- hbIdList.clear();
- drawBackOrders.clear();
-
- /**
- * 澶勭悊鍒嗕韩璧�
- */
-
- int shareGoodsCount = 0;
- Set<String> shareOrders = new HashSet<>();
- BigDecimal sharemoney = new BigDecimal(0);
- // 鏌ヨUID鐨勫垎浜禋璁㈠崟
- types.clear();
- types.add(HongBaoV2.TYPE_SHARE_GOODS);
- // TODO 闇�瑕佸鐞嗚秴杩�10000鏉℃暟鎹殑璁㈠崟
- List<HongBaoV2> hongBaoShareList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 0, 10000);
- for (HongBaoV2 hongBao : hongBaoShareList) {
- hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
- hongBao = filterWeiQuanINGHongBao(hongBao);
- if (hongBao == null)
- continue;
- if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
- sharemoney = sharemoney.add(hongBao.getMoney());
- HongBaoV2 updateHongBao = new HongBaoV2();
- updateHongBao.setId(hongBao.getId());
- updateHongBao.setGetTime(new Date());
- updateHongBao.setState(HongBao.STATE_YILINGQU);
- updateHongBao.setUpdateTime(new Date());
- hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
- // 娣诲姞鍒扮孩鍖呰繑鍒╄褰曢泦鍚�
- hbIdList.add(hongBao.getId());
- // 2018-08-05 杩囧悗鐨勮鍗曟墠澶勭悊缁存潈
- Date balanceTime = null;
- HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getId());
- if (hongBaoOrder != null) {
- balanceTime = hongBaoOrder.getCommonOrder().getSettleTime();
- shareGoodsCount += hongBaoOrder.getCommonOrder().getCount();
- }
- shareOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
- if (balanceTime != null
- && balanceTime.getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
- drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
- }
- }
- }
-
- /**
- * 鍒嗕韩璧氬埌璐�
- */
-
- if (sharemoney.compareTo(new BigDecimal(0)) > 0) {
- // 娣诲姞鏂扮増璇︽儏璁板綍
- try {
- // 璁$畻鏈湀鐨勬湁鏁堣鍗曪紝澶辨晥璁㈠崟锛岀淮鏉冭鍗�
- Calendar ca = Calendar.getInstance();
-
- Date maxDate = new Date(TimeUtil
- .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
- ca.add(Calendar.MONTH, -1);
-
- Date minDate = new Date(TimeUtil
- .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
- long validCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
- minDate, maxDate);
- long weiQuanCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
- minDate, maxDate);
- long invalidCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_SX,
- minDate, maxDate);
-
- UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, Constant.SOURCE_TYPE_TAOBAO,
- (int) validCount, (int) weiQuanCount, sharemoney, new Date());
- // 娣诲姞璧勯噾
- userMoneyService.addUserMoney(uid, sharemoney, userMoneyDetail);
-
- // 娣诲姞鍒扮孩鍖呰繑鍒╄褰曢泦鍚�
- accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(hbIdList, userMoneyDetail.getId());
- if (hbIdList.size() > 0)
- recieveHongBaoIds.addAll(hbIdList);
- } catch (UserMoneyDetailException e) {
- try {
- LogHelper.errorDetailInfo(e);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
-
- // 鏂扮増閫氱煡
- userMoneyMsgNotificationService.shareOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, shareOrders.size(),
- shareGoodsCount, sharemoney, userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao());
-
- for (String orderId : drawBackOrders)
- taoBaoWeiQuanDrawBackService.doWeiQuanShare(orderId);
- }
-
- // 鎵�鏈夌殑杩斿埄鍒拌处绾㈠寘ID
- for (Long hongBaoId : recieveHongBaoIds) {
- try {
- HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
+ if (Constant.ENABLE_MQ)
+ CMQManager.getInstance().addFanLiShareMsg(new UidDateDTO(uid, maxTime));
} catch (Exception e) {
- LogHelper.errorDetailInfo(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 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();
+ }
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
@@ -902,10 +744,28 @@
// 鍘熸潵涓嶅瓨鍦ㄨ鍗�
Long uid = null;
if (oldOrder == null) {
- PidUser pidUser = null;// pidUserMapper.selectByPid(pid);
- if (pidUser != null) {
- uid = pidUser.getUid();
+ 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 ((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());
+ if (info != null && info.getUser() != null)
+ targetUid = info.getUser().getId();
+ }
+
+ if (targetUid != null) {
+ uid = targetUid;
// 鎻掑叆鍒癘rder涓�
// 娣诲姞鍒拌鍗曚腑鍘�
Order order = new Order();
@@ -919,36 +779,8 @@
// 鍔犲叆鍒拌鍗曡〃
orderMapper.insertSelective(order);
oldOrder = order;
- } else {
- 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;
- // 鎻掑叆鍒癘rder涓�
- // 娣诲姞鍒拌鍗曚腑鍘�
- 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();
}
@@ -986,15 +818,15 @@
List<CommonOrderAddResultDTO> commonOrderList = null;
try {
commonOrderList = commonOrderService.addTaoBaoOrder(orderList, uid);
- hongBaoV2Service.addHongBao(convertCommonOrder(commonOrderList), HongBaoV2.TYPE_ZIGOU);
-
+ 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);
+ if (Constant.ENABLE_MQ)
+ PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
} catch (Exception e) {
}
}
@@ -1010,21 +842,12 @@
@Override
public void processShareGoodsOrderNew(String orderId, List<TaoBaoOrder> orderList) {
- 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());
// 鍘熸潵涓嶅瓨鍦ㄨ鍗�
Long uid = null;
- PidUser pidUser = null; // pidUserMapper.selectByPid(pid);-PID鏈哄埗绉婚櫎
- if (pidUser != null)
- uid = pidUser.getUid();
- else {
- UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService.getByRelationId(orderList.get(0).getRelationId());
- if (info != null && info.getUser() != null)
- uid = info.getUser().getId();
- }
-
+ UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService.getByRelationId(orderList.get(0).getRelationId());
+ if (info != null && info.getUser() != null)
+ uid = info.getUser().getId();
// 灏氭湭鎵惧埌鍜孭ID瀵瑰簲鐨勭敤鎴�
if (uid == null) {
// 閫氳繃绾㈠寘鏌ヨ
@@ -1046,21 +869,20 @@
// 鐢ㄧ涓�涓瓙璁㈠崟閿佸畾鐢ㄦ埛
try {
List<CommonOrderAddResultDTO> commonOrders = commonOrderService.addTaoBaoOrder(orderList, uid);
- hongBaoV2Service.addHongBao(convertCommonOrder(commonOrders), HongBaoV2.TYPE_SHARE_GOODS);
+ 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);
+ if (Constant.ENABLE_MQ)
+ PlaceOrderCMQManager.getInstance().addPlaceOrderMsg(order);
} catch (Exception e) {
}
}
} catch (CommonOrderException e) {
e.printStackTrace();
- } catch (HongBaoException e1) {
- e1.printStackTrace();
}
}
}
@@ -1085,12 +907,15 @@
public void processJDOrder(JDOrder order) {
if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0)
return;
-
// 鎷嗗崟鐨勪笉鍋氬鐞�
if (order.getValidCode() == 2)
return;
+ // 鏍规嵁ext1涓巗ubUnionId璺熷崟
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);
@@ -1165,24 +990,21 @@
try {
List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addJDOrder(jdOrder, uid);
- hongBaoV2Service.addHongBao(convertCommonOrder(commonOrderList), HongBaoV2.TYPE_ZIGOU);
+ 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_TAOBAO);
+ 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) {
}
}
} catch (CommonOrderException e) {
- try {
- LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + jdOrder.getOrderId());
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- } catch (HongBaoException e) {
try {
LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + jdOrder.getOrderId());
} catch (Exception e1) {
@@ -1201,24 +1023,20 @@
private void processShareJDOrder(JDOrder jdOrder, Long uid) {
try {
List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addJDOrder(jdOrder, uid);
- hongBaoV2Service.addHongBao(convertCommonOrder(commonOrderList), HongBaoV2.TYPE_SHARE_GOODS);
+ 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_TAOBAO);
+ 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) {
}
}
} catch (CommonOrderException e) {
- try {
- LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + jdOrder.getOrderId());
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- } catch (HongBaoException e) {
try {
LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + jdOrder.getOrderId());
} catch (Exception e1) {
@@ -1315,24 +1133,20 @@
List<PDDOrder> pddOrderList = new ArrayList<>();
pddOrderList.add(pddOrder);
List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addPDDOrder(pddOrderList, uid);
- hongBaoV2Service.addHongBao(convertCommonOrder(commonOrderList), HongBaoV2.TYPE_ZIGOU);
+ 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_TAOBAO);
+ 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, "addPDDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + pddOrder.getOrderSn());
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- } catch (HongBaoException e) {
try {
LogHelper.errorDetailInfo(e, "addPDDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + pddOrder.getOrderSn());
} catch (Exception e1) {
@@ -1353,14 +1167,16 @@
List<PDDOrder> pddOrderList = new ArrayList<>();
pddOrderList.add(pddOrder);
List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addPDDOrder(pddOrderList, uid);
- hongBaoV2Service.addHongBao(convertCommonOrder(commonOrderList), HongBaoV2.TYPE_SHARE_GOODS);
+ 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_TAOBAO);
+ 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) {
}
}
@@ -1370,9 +1186,275 @@
} catch (Exception e1) {
e1.printStackTrace();
}
- } catch (HongBaoException e) {
+ }
+ }
+
+ @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, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + pddOrder.getOrderId());
+ 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();
}
@@ -1450,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);
@@ -1464,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
@@ -1481,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(), "璁㈠崟鎴愬姛锛屽晢瀹舵湭鎵撴");
@@ -1507,6 +1609,9 @@
@Resource
private ElmeOrderService elmeOrderService;
+ @Resource
+ private ElmeOrderProcessService elmeOrderProcessService;
+
/**
* 鑾峰彇楗夸簡涔堝彲浠ヨ繑鍒╃殑绾㈠寘
*
@@ -1516,7 +1621,7 @@
public List<HongBaoV2> getCanBalanceElmeFanliHongBao() {
List<Integer> list = new ArrayList<>();
list.add(HongBaoV2.TYPE_ELME);
- return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, 0, 1000);
+ return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, null, new Date(), 0, 1000);
}
@Override
@@ -1553,11 +1658,65 @@
}
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);
+ 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) {
+ try {
+ LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + orderId);
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ } catch (UserAccountException e) {
+
+ }
+ 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());
+ 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;
+ }
+
}
--
Gitblit v1.8.0