| 
					
				 | 
			
			
				@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.github.pagehelper.PageHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.api.feign.AdminFeignService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.api.feign.dto.CouponInfoApi; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.entity.HttpResponseResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.entity.MallOrderItemDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.enums.PostStatusEnum; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -148,6 +149,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public Map<String, Object> generateOrder(OrderParam orderParam) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (orderParam.getOrderAmount() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new BizException("订单金额校验不通过"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<OmsOrderItem> orderItemList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //获取购物车及优惠信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         UmsMember currentMember = memberService.getCurrentMember(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -179,19 +183,27 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Asserts.fail("库存不足,无法下单"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //判断使用使用了优惠券 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (orderParam.getCouponId() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtil.isEmpty(orderParam.getCouponId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //不用优惠券 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (OmsOrderItem orderItem : orderItemList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 orderItem.setCouponAmount(new BigDecimal(0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //使用优惠券 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            SmsCouponHistoryDetail couponHistoryDetail = getUseCoupon(cartPromotionItemList, orderParam.getCouponId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (couponHistoryDetail == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                Asserts.fail("该优惠券不可用"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // todo 使用优惠券 远程调用获取优惠券金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // SmsCouponHistoryDetail couponHistoryDetail = getUseCoupon(cartPromotionItemList, orderParam.getCouponId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //     if (couponHistoryDetail == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //         Asserts.fail("该优惠券不可用"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //对下单商品的优惠券进行处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            handleCouponAmount(orderItemList, couponHistoryDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            HttpResponseResult<CouponInfoApi> couponInfoApiHttpResponseResult = adminFeignService.queryCouponOrderPageInfo( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    currentMember.getId(), orderParam.getCouponId(), orderParam.getOrderAmount(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    orderParam.getPlatformType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CouponInfoApi data = couponInfoApiHttpResponseResult.getData(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal couponAmount = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(data != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                couponAmount = data.getDiscountedPrices(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            handleCouponAmount(orderItemList, couponAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //判断是否使用积分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (orderParam.getUseIntegration() == null || orderParam.getUseIntegration().equals(0)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -234,7 +246,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         order.setPromotionAmount(calcPromotionAmount(orderItemList)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         order.setPromotionInfo(getOrderPromotionInfo(orderItemList)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         order.setPlatformType(orderParam.getPlatformType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (orderParam.getCouponId() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtil.isEmpty(orderParam.getCouponId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             order.setCouponAmount(new BigDecimal(0)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             order.setCouponId(orderParam.getCouponId()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -247,7 +259,11 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             order.setIntegration(orderParam.getUseIntegration()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             order.setIntegrationAmount(calcIntegrationAmount(orderItemList)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        order.setPayAmount(calcPayAmount(order)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        BigDecimal payAmount = calcPayAmount(order); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (payAmount.compareTo(orderParam.getOrderAmount()) != 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new BizException("订单金额校验不通过"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        order.setPayAmount(payAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //转化为订单信息并插入数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         order.setMemberId(currentMember.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         order.setCreateTime(new Date()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -292,7 +308,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         orderItemDao.insertList(orderItemList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //如使用优惠券更新优惠券使用状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (orderParam.getCouponId() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            updateCouponStatus(orderParam.getCouponId(), currentMember.getId(), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // updateCouponStatus(orderParam.getCouponId(), currentMember.getId(), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // todo 远程调用更新优惠券使用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminFeignService.updateCouponOrderInfo(orderParam.getCouponId(),false,order.getOrderSn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //如使用积分需要扣除积分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (orderParam.getUseIntegration() != null) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -474,7 +492,10 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 portalOrderDao.releaseProductStockLock(orderItemList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //修改优惠券使用状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            updateCouponStatus(cancelOrder.getCouponId(), cancelOrder.getMemberId(), 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // updateCouponStatus(cancelOrder.getCouponId(), cancelOrder.getMemberId(), 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // todo 退回优惠券 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            adminFeignService.updateCouponOrderInfo(cancelOrder.getCouponId(),true,cancelOrder.getOrderSn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //返还使用积分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (cancelOrder.getUseIntegration() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 UmsMember member = memberService.getById(cancelOrder.getMemberId()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1259,22 +1280,22 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param orderItemList       order_item列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param couponHistoryDetail 可用优惠券详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void handleCouponAmount(List<OmsOrderItem> orderItemList, SmsCouponHistoryDetail couponHistoryDetail) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        SmsCoupon coupon = couponHistoryDetail.getCoupon(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (coupon.getUseType().equals(0)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void handleCouponAmount(List<OmsOrderItem> orderItemList, BigDecimal couponAmount) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // SmsCoupon coupon = couponHistoryDetail.getCoupon(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // if (coupon.getUseType().equals(0)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //全场通用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            calcPerCouponAmount(orderItemList, coupon); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else if (coupon.getUseType().equals(1)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //指定分类 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            List<OmsOrderItem> couponOrderItemList = getCouponOrderItemByRelation(couponHistoryDetail, orderItemList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                                                  0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            calcPerCouponAmount(couponOrderItemList, coupon); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else if (coupon.getUseType().equals(2)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //指定商品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            List<OmsOrderItem> couponOrderItemList = getCouponOrderItemByRelation(couponHistoryDetail, orderItemList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                                                  1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            calcPerCouponAmount(couponOrderItemList, coupon); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            calcPerCouponAmount(orderItemList, couponAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // } else if (coupon.getUseType().equals(1)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     //指定分类 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     List<OmsOrderItem> couponOrderItemList = getCouponOrderItemByRelation(couponHistoryDetail, orderItemList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //                                                                           0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     calcPerCouponAmount(couponOrderItemList, coupon); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // } else if (coupon.getUseType().equals(2)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     //指定商品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     List<OmsOrderItem> couponOrderItemList = getCouponOrderItemByRelation(couponHistoryDetail, orderItemList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //                                                                           1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     calcPerCouponAmount(couponOrderItemList, coupon); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1282,13 +1303,13 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param orderItemList 可用优惠券的下单商品商品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void calcPerCouponAmount(List<OmsOrderItem> orderItemList, SmsCoupon coupon) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void calcPerCouponAmount(List<OmsOrderItem> orderItemList, BigDecimal coupon) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         BigDecimal totalAmount = calcTotalAmount(orderItemList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (OmsOrderItem orderItem : orderItemList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //(商品价格/可用商品总价)*优惠券面额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             BigDecimal couponAmount = orderItem.getProductPrice() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                                .divide(totalAmount, 3, RoundingMode.HALF_EVEN) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                               .multiply(coupon.getAmount()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                               .multiply(coupon); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             orderItem.setCouponAmount(couponAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 |