From 04f5c3bd20524c97dce07cc03bb24e190303083a Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 22 十月 2019 14:33:11 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div --- fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java | 225 +++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 173 insertions(+), 52 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 9164a50..8ffe63e 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 @@ -18,6 +18,10 @@ 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; @@ -27,10 +31,13 @@ import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper; import com.yeshi.fanli.dto.HongBao; import com.yeshi.fanli.dto.order.CommonOrderAddResultDTO; +import com.yeshi.fanli.dto.order.OrderMQMsgDTO; 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; @@ -48,21 +55,23 @@ import com.yeshi.fanli.exception.order.OrderItemException; import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException; import com.yeshi.fanli.log.LogHelper; +import com.yeshi.fanli.service.inter.elme.ElmeHongBaoOrderMapService; +import com.yeshi.fanli.service.inter.elme.ElmeOrderService; import com.yeshi.fanli.service.inter.hongbao.AccountDetailsHongBaoMapService; -import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service; -import com.yeshi.fanli.service.inter.jd.JDOrderService; 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.OrderProcessService; -import com.yeshi.fanli.service.inter.pdd.PDDOrderService; +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.TaoBaoOrderService; import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; -import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService; import com.yeshi.fanli.service.inter.user.UserSystemCouponService; +import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; import com.yeshi.fanli.util.CMQManager; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.MoneyBigDecimalUtil; @@ -135,6 +144,9 @@ @Resource private PDDOrderService pddOrderService; + + @Resource(name = "orderTransactionProducer") + private TransactionProducer orderTransactionProducer; /** * 鏄惁鏄垎浜鍗� @@ -488,16 +500,7 @@ if (olist != null && olist.size() > 0) { long time = TimeUtil.convertToTimeTemp(olist.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss"); - olist = TaoKeOrderApiUtil.getTaoBaoAllOrder(TimeUtil.getGernalTime(time, "yyyy-MM-dd HH:mm:ss"), - TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, - TaoKeOrderApiUtil.TK_STATUS_ALL); - List<TaoBaoOrder> thirdOList = TaoKeOrderApiUtil.getTaoBaoThirdAllOrder( - TimeUtil.getGernalTime(time, "yyyy-MM-dd HH:mm:ss"), 30, 1, - TaoKeOrderApiUtil.TK_STATUS_ALL, TaoBaoConstant.TAOBAO_AUTH_APPKEY, - TaoBaoConstant.TAOBAO_AUTH_APPSECRET); - if (thirdOList != null && thirdOList.size() > 0) - olist.addAll(thirdOList); - + 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() @@ -991,8 +994,7 @@ 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); @@ -1051,7 +1053,7 @@ // 鐢ㄧ涓�涓瓙璁㈠崟閿佸畾鐢ㄦ埛 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); @@ -1064,8 +1066,6 @@ } } catch (CommonOrderException e) { e.printStackTrace(); - } catch (HongBaoException e1) { - e1.printStackTrace(); } } } @@ -1170,11 +1170,13 @@ 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); @@ -1182,12 +1184,6 @@ } } } 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) { @@ -1206,11 +1202,12 @@ 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); @@ -1218,12 +1215,6 @@ } } } 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) { @@ -1320,11 +1311,12 @@ 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); @@ -1332,12 +1324,6 @@ } } } 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) { @@ -1358,11 +1344,12 @@ 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); @@ -1370,12 +1357,6 @@ } } } catch (CommonOrderException e) { - try { - LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + pddOrder.getOrderId()); - } catch (Exception e1) { - e1.printStackTrace(); - } - } catch (HongBaoException e) { try { LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + pddOrder.getOrderId()); } catch (Exception e1) { @@ -1452,4 +1433,144 @@ 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; + + /** + * 鑾峰彇楗夸簡涔堝彲浠ヨ繑鍒╃殑绾㈠寘 + * + * @return + */ + @Override + public List<HongBaoV2> getCanBalanceElmeFanliHongBao() { + List<Integer> list = new ArrayList<>(); + list.add(HongBaoV2.TYPE_ELME); + return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, 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); + } + // 杩斿埄鍒拌处 + } + + private void addHongBaoWithMQ(List<CommonOrderAddResultDTO> commonOrderList, String orderId, Long uid, + int sourceType, int hongBaoType) { + final List<CommonOrder> coList = convertCommonOrder(commonOrderList); + OrderMQMsgDTO mqMsg = new OrderMQMsgDTO(orderId, sourceType, uid); + Message msg = new Message("TOPIC_ORDER", String.format("orderhongbao-%s-%s", sourceType, hongBaoType), + new Gson().toJson(mqMsg).getBytes()); + orderTransactionProducer.send(msg, new LocalTransactionExecuter() { + @Override + public TransactionStatus execute(Message arg0, Object arg1) { + int resultCode = 0; + try { + resultCode = hongBaoV2Service.addHongBao(coList, hongBaoType); + } catch (HongBaoException e) { + try { + LogHelper.errorDetailInfo(e, "addJDOrder鎴朼ddHongBao鍑洪敊", "璁㈠崟鍙�:" + orderId); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + if (resultCode != 0) + return TransactionStatus.CommitTransaction; + else + return TransactionStatus.RollbackTransaction; + } + }, null); + } + } -- Gitblit v1.8.0