From 4bf96fb425e655e1a099aa750bb4bd6c9e158261 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期四, 16 四月 2020 17:34:35 +0800
Subject: [PATCH] 奖励券使用限制

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java |   38 +++++++++++++++++++++++++++++++-------
 1 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
index b5801de..8dc4b6e 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/CommonOrderServiceImpl.java
@@ -36,6 +36,7 @@
 import com.yeshi.fanli.entity.jd.JDGoods;
 import com.yeshi.fanli.entity.jd.JDOrder;
 import com.yeshi.fanli.entity.jd.JDOrderItem;
+import com.yeshi.fanli.entity.money.InviteOrderSubsidyDebt;
 import com.yeshi.fanli.entity.order.CommonOrder;
 import com.yeshi.fanli.entity.order.CommonOrderGoods;
 import com.yeshi.fanli.entity.order.CommonOrderTradeIdMap;
@@ -57,6 +58,7 @@
 import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.config.SystemCouponService;
 import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
+import com.yeshi.fanli.service.inter.money.InviteOrderSubsidyDebtService;
 import com.yeshi.fanli.service.inter.order.CommonOrderService;
 import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
 import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
@@ -133,6 +135,9 @@
 
 	@Resource
 	private InviteOrderSubsidyService inviteOrderSubsidyService;
+	
+	@Resource
+	private InviteOrderSubsidyDebtService inviteOrderSubsidyDebtService;
 
 	@Resource
 	private UserVIPInfoService userVIPInfoService;
@@ -585,16 +590,16 @@
 			if (HongBaoV2.TYPE_ZIGOU == hongBaoType) {
 				// 濂栧姳璁㈠崟銆佸厤鍗� 浣跨敤璁板綍
 				if (sourceType == null) {
-					couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, null, uid, vip, acceptData);
+					couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, null, uid, vip, acceptData, hongBao);
 				} else if (sourceType == Constant.SOURCE_TYPE_TAOBAO) {
 					couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordTB, uid, vip,
-							acceptData);
+							acceptData, hongBao);
 				} else if (sourceType == Constant.SOURCE_TYPE_JD) {
 					couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordJD, uid, vip,
-							acceptData);
+							acceptData, hongBao);
 				} else if (sourceType == Constant.SOURCE_TYPE_PDD) {
 					couponFactory(order, hasRewardCoupon, hongBaoState, hongBaoType, listRecordPDD, uid, vip,
-							acceptData);
+							acceptData, hongBao);
 				}
 			}
 
@@ -617,7 +622,7 @@
 	 * @param signList
 	 */
 	private void couponFactory(CommonOrderVO order, boolean hasRewardCoupon, Integer hongBaoState, Integer hongBaoType,
-			List<UserSystemCouponRecord> list, Long uid, boolean vip, AcceptData acceptData) throws Exception {
+			List<UserSystemCouponRecord> list, Long uid, boolean vip, AcceptData acceptData, BigDecimal hongBao) throws Exception {
 
 		// 鏄惁鍏嶅崟鍟嗗搧
 		boolean freeOrder = false;
@@ -715,6 +720,11 @@
 			order.setRewardDetail(rewardMap);
 		}
 
+		// 浣跨敤濂栧姳鍒� 閲戦棰濋檺鍒�
+		if (hongBao.compareTo(Constant.REWARD_COUPON_LIMIT_MONEY) > 0){
+			return;
+		}
+		
 		// 鏄惁鍙娇鐢ㄥ鍔卞埜
 		if (!rewardSuccess && !freeOrder && HongBaoV2.TYPE_ZIGOU == hongBaoType
 				&& HongBaoV2.STATE_YILINGQU == hongBaoState && !vip && CommonOrder.STATE_WQ != order.getState()) {
@@ -2062,6 +2072,21 @@
 				order.setOrderOrigin("3");
 				order.setHongBaoTypePic(CommonOrder.TYPE_INVITE);
 				signList.add(CommonOrder.TYPE_INVITE);
+				
+				// 绾㈠寘鍔犱笂琛ヨ创閲戦
+				InviteOrderSubsidy orderSubsidy = inviteOrderSubsidyService.getByOrderNoAndType(uid, orderNo, sourceType);
+				if (orderSubsidy != null && orderSubsidy.getMoney() != null) {
+					BigDecimal subsidyMoney = orderSubsidy.getMoney();
+					// 缁存潈閲戦
+					InviteOrderSubsidyDebt subsidyDebt = inviteOrderSubsidyDebtService.getBySourceId(orderSubsidy.getId());
+					if (subsidyDebt != null && subsidyDebt.getOriginMoney() != null) {
+						subsidyMoney = subsidyMoney.subtract(subsidyDebt.getOriginMoney());
+					} 
+					//  鏈�缁堣ˉ璐�
+					if (subsidyMoney.compareTo(new BigDecimal(0)) > 0) {
+						hongBao = hongBao.add(subsidyMoney);
+					}
+				}
 			} 
 			order.setSignList(signList);
 
@@ -2104,9 +2129,8 @@
 			stateMap.put("content", stateContent);
 			stateMap.put("fontColor", stateFontColor);
 			order.setAccountState(stateMap);
-
 			hongbaoInfo = hongBaoState_Str + hongbaoInfo;
-
+			
 			Map<String, String> hongBaoMap = new HashMap<String, String>();
 			hongBaoMap.put("content", hongbaoInfo + " 楼" + hongBao.setScale(2, BigDecimal.ROUND_DOWN).toString());
 			hongBaoMap.put("fontColor", hongbaoInfoFontColor);

--
Gitblit v1.8.0