From 28cf328a098334b51a3e9d2d56f983fb8c862211 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 23 五月 2020 09:54:38 +0800
Subject: [PATCH] 足迹、收藏订单兼容新需求

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderServiceImpl.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderServiceImpl.java
index 1e585a4..f4ba043 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopOrderServiceImpl.java
@@ -23,6 +23,8 @@
 import com.yeshi.fanli.dao.mybatis.shop.BanLiShopOrderMapper;
 import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
 import com.yeshi.fanli.dto.mq.order.body.BanLiShopOrderMQMsg;
+import com.yeshi.fanli.dto.msg.MsgRedPackUseContentDTO;
+import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum;
 import com.yeshi.fanli.entity.mq.MQUnSendInfo;
 import com.yeshi.fanli.entity.redpack.RedPackDetail;
 import com.yeshi.fanli.entity.shop.BanLiShopGoods;
@@ -35,8 +37,10 @@
 import com.yeshi.fanli.exception.redpack.RedPackBalanceException;
 import com.yeshi.fanli.exception.redpack.RedPackDetailException;
 import com.yeshi.fanli.exception.shop.BanLiShopOrderException;
+import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
 import com.yeshi.fanli.service.inter.mq.MQUnSendInfoService;
 import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
+import com.yeshi.fanli.service.inter.redpack.RedPackForbidService;
 import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsClassService;
 import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsService;
 import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetPayService;
@@ -44,6 +48,7 @@
 import com.yeshi.fanli.service.inter.shop.BanLiShopOrderService;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.factory.RedPackDetailFactory;
+import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
 import com.yeshi.fanli.util.rocketmq.MQTopicName;
 import com.yeshi.fanli.util.shop.BanLiShopOrderUtil;
 import com.yeshi.fanli.util.wx.BanLiShopWXPayUtil;
@@ -84,7 +89,13 @@
 	@Resource(name = "transactionManager")
 	private DataSourceTransactionManager transactionManager;
 
-	@Transactional
+	@Resource
+	private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
+
+	@Resource
+	private RedPackForbidService redPackForbidService;
+
+	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void addOrder(BanLiShopOrder order) throws BanLiShopOrderException {
 		// 鏌ヨ蹇呰鐨勫弬鏁版槸鍚︽坊鍔�
@@ -140,6 +151,10 @@
 		order.setOrderNo(orderNo);
 		banLiShopOrderMapper.updateByPrimaryKeySelective(update);
 
+		// 澧炲姞閿�閲�
+		banLiShopGoodsSetService.addSalesCount(order.getGoodsSet().getId(), 1);
+		banLiShopGoodsService.addSalesCount(order.getGoods().getId(), 1);
+
 		// 璁㈠崟娣诲姞鎴愬姛 ,寤舵椂閫氱煡鍚庣画
 		sendPlaceOrderMsg(order.getId(), order.getUid());
 	}
@@ -160,8 +175,8 @@
 
 	private void sendPlaceOrderMsg(Long orderId, Long uid) {
 
-		Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.banLiShopOrderDelay.name(),
-				new Gson().toJson(new BanLiShopOrderMQMsg(orderId, uid)).getBytes());
+		Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.banLiShopOrderDelay,
+				new BanLiShopOrderMQMsg(orderId, uid));
 		msg.setKey(orderId + "");
 		long delayTime = System.currentTimeMillis() + (Constant.IS_TEST ? 1000 * 30L : 1000 * 60 * 10);// 10鍒嗛挓鍚庨�氱煡
 		msg.setStartDeliverTime(delayTime);
@@ -186,12 +201,12 @@
 	@Override
 	public List<BanLiShopOrder> listByUid(Long uid, int page, int pageSize) {
 
-		return banLiShopOrderMapper.listByUid(null, uid, (page - 1) * pageSize, pageSize);
+		return banLiShopOrderMapper.listByUidAndState(null, uid, (page - 1) * pageSize, pageSize);
 	}
 
 	@Override
 	public long countByUid(Long uid) {
-		return banLiShopOrderMapper.countByUid(null, uid);
+		return banLiShopOrderMapper.countByUidAndState(null, uid);
 	}
 
 	@Override
@@ -208,7 +223,7 @@
 		banLiShopOrderMapper.updateByPrimaryKeySelective(order);
 	}
 
-	@Transactional
+	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void payOrderByHongBao(Long orderId) throws BanLiShopOrderException, RedPackBalanceException {
 		BanLiShopOrder order = banLiShopOrderMapper.selectByPrimaryKeyForUpdate(orderId);
@@ -313,6 +328,7 @@
 		return banLiShopOrderMapper.selectByPrimaryKeyForUpdate(id);
 	}
 
+	@Transactional(rollbackFor = Exception.class)
 	@Override
 	public void invalidOrderByOrderId(Long id, String desc) {
 		// 鍒ゆ柇璁㈠崟鏄惁瀛樺湪
@@ -331,8 +347,8 @@
 					if (isS)// 鏀粯鎴愬姛锛岄噸鏂板彂閫佹敮浠樻垚鍔熸秷鎭�
 					{
 						BanLiShopOrderMQMsg msg = new BanLiShopOrderMQMsg(order.getId(), order.getUid());
-						Message message = new Message(MQTopicName.TOPIC_ORDER.name(),
-								OrderTopicTagEnum.banLiShopOrderPaid.name(), new Gson().toJson(msg).getBytes());
+						Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER,
+								OrderTopicTagEnum.banLiShopOrderPaid, msg);
 						producer.send(message);
 						return;
 					}
@@ -363,8 +379,8 @@
 		if (order.getState() != BanLiShopOrder.STATE_PAID)
 			throw new BanLiShopOrderException(1, "璁㈠崟鏈浜庡緟瀹℃牳鐘舵��");
 
-		Message message = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.banLiShopOrderRefund.name(),
-				new Gson().toJson(new BanLiShopOrderMQMsg(order.getId(), order.getUid())).getBytes());
+		Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.banLiShopOrderRefund,
+				new BanLiShopOrderMQMsg(order.getId(), order.getUid()));
 		try {
 			orderTransactionProducer.send(message, new LocalTransactionExecuter() {
 				@Override
@@ -389,7 +405,17 @@
 			update.setState(BanLiShopOrder.STATE_REJECT);
 			update.setStateDesc(msg);
 			update.setUpdateTime(new Date());
+			update.setRejectTime(new Date());
 			banLiShopOrderMapper.updateByPrimaryKeySelective(update);
+			// 娑堟伅鍙戦��
+			MsgRedPackUseContentDTO dto = new MsgRedPackUseContentDTO();
+			dto.setGoodsSetName(order.getOrderGoods().getSetName());
+			dto.setHongBao(order.getHongBaoPayment());
+			dto.setMoney(order.getMoneyPayment());
+			dto.setReason(msg);
+			dto.setTime(new Date());
+			userMoneyMsgNotificationService.redPackMsg(order.getUid(), MsgTypeMoneyTypeEnum.redPackUseFail,
+					new Gson().toJson(dto), null);
 			transactionManager.commit(transactionStatus);
 		} catch (Exception e) {
 			transactionManager.rollback(transactionStatus);
@@ -413,6 +439,9 @@
 		if (goods == null || goods.getState() == BanLiShopGoods.STATE_OFFLINE) {
 			throw new BanLiShopOrderException(22, "鍟嗗搧宸蹭笅绾�");
 		}
+
+		if (redPackForbidService.verifyForbid(uid))
+			throw new BanLiShopOrderException(25, "绾㈠寘鍔熻兘宸茶灏佺");
 
 		if (pay.getHongBaoPrice() != null && pay.getHongBaoPrice().compareTo(new BigDecimal(0)) > 0) {
 			BigDecimal money = redPackBalanceService.getBalance(uid);
@@ -452,4 +481,14 @@
 		return banLiShopOrderMapper.selectByOrderNo(orderNo);
 	}
 
+	@Override
+	public List<BanLiShopOrder> listByUidAndState(Long uid, List<Integer> stateList, int page, int pageSize) {
+		return banLiShopOrderMapper.listByUidAndState(stateList, uid, (page - 1) * pageSize, pageSize);
+	}
+
+	@Override
+	public long countByUidAndState(Long uid, List<Integer> stateList) {
+		return banLiShopOrderMapper.countByUidAndState(stateList, uid);
+	}
+
 }

--
Gitblit v1.8.0