Ver Fonte

提交订单-优惠券计算

chao há 3 anos atrás
pai
commit
4f0c716b23

+ 0 - 2
src/main/java/com/caimei365/order/controller/OrderSubmitApi.java

@@ -76,8 +76,6 @@ public class OrderSubmitApi {
      *                              "bankAccountNo": "987987465465464"
      *                          }
      *              }
-     * @return {code: -1=(用户账户异常,数据异常,操作异常等),1提交成功(支付完成),2提交成功(未支付),
-     *              code为1和2时:data{orderNo:订单号,orderID:订单ID,payTotalFee:订单金额,orderMark:订单标识}
      */
     @ApiOperation("提交订单(旧:/order/submit)(/seller/order/submit)")
     @PostMapping("/generate")

+ 1 - 0
src/main/java/com/caimei365/order/model/dto/SubmitDto.java

@@ -109,6 +109,7 @@ public class SubmitDto implements Serializable {
                 ", orderSource=" + orderSource +
                 ", cartType=" + cartType +
                 ", serviceProviderId=" + serviceProviderId +
+                ", clubCouponId=" + clubCouponId +
                 ", orderInfo='" + orderInfo + '\'' +
                 ", payInfo='" + payInfo + '\'' +
                 ", orderInvoice='" + orderInvoice + '\'' +

+ 16 - 9
src/main/java/com/caimei365/order/service/impl/SubmitServiceImpl.java

@@ -107,9 +107,8 @@ public class SubmitServiceImpl implements SubmitService {
      *                              "bankAccountNo": "987987465465464"
      *                          }
      *              }
-     * @return {code: -1=(用户账户异常,数据异常,操作异常等),1提交成功(支付完成),2提交成功(未支付),
-     *              code为1和2时:data{orderNo:订单号,orderId:订单Id,payTotalFee:订单金额,orderMark:订单标识}
      */
+    @Transactional(rollbackFor = Exception.class)
     @Override
     public ResponseJson<Map<String, Object>> generateOrder(SubmitDto submitDto) {
         // 获取机构用户Id
@@ -270,7 +269,6 @@ public class SubmitServiceImpl implements SubmitService {
         return saveOrder(orderParamBo);
     }
 
-    @Transactional(rollbackFor = Exception.class)
     public ResponseJson<Map<String, Object>> saveOrder(OrderParamBo orderParamBo) {
         log.info("******************** 提交订单逻辑处理 start *******************");
         /*
@@ -576,6 +574,9 @@ public class SubmitServiceImpl implements SubmitService {
                             promotionPrice.setProductId(productId);
                             promotionPrice.setNumber(productNum);
                             promotionPrice.setPrice(discountPrice);
+                            if (null == promotions.getProductList()){
+                                promotions.setProductList(new ArrayList<>());
+                            }
                             promotions.getProductList().add(promotionPrice);
                             if (!promotionsIds.contains(promotions.getId())) {
                                 promotionsIds.add(promotions.getId());
@@ -781,8 +782,6 @@ public class SubmitServiceImpl implements SubmitService {
             couponAmount = coupon.getCouponAmount();
         }
         mainOrder.setCouponAmount(couponAmount);
-        // 订单总额 = 商品费 - 优惠券金额
-        payTotalFee.set(MathUtil.sub(productTotalFee.get(), couponAmount).doubleValue());
         /*
          * 计算运费
          */
@@ -804,8 +803,11 @@ public class SubmitServiceImpl implements SubmitService {
         // 运费标志:0包邮 -1到付 1遵循运费规则
         mainOrder.setPostageFlag(orderParamBo.getPostageFlag());
         if (1 == orderParamBo.getPostageFlag() && orderParamBo.getOffsetBeans() > 0) {
-            // 采美豆抵扣运费,订单总额 = 商品费
-            payTotalFee.set(productTotalFee.get());
+            // 订单总额 = 商品费 - 优惠券金额
+            payTotalFee.set(MathUtil.sub(productTotalFee.get(), couponAmount).doubleValue());
+        } else {
+            // 订单总额 -= 优惠券金额
+            payTotalFee.set(MathUtil.sub(payTotalFee.get(), couponAmount).doubleValue());
         }
         // 商品总额
         mainOrder.setProductTotalFee(productTotalFee.get());
@@ -861,6 +863,8 @@ public class SubmitServiceImpl implements SubmitService {
             log.info("【提交订单】>>>>>更新用户余额,抵扣后剩余:[userMoney:" + lastUserMoney + "] ,ableUserMoney:" + lastAbleUserMoney);
             // 支付时间
             mainOrder.setPayTime(curDateStr);
+        } else {
+            payableAmount.set(payTotalFee.get());
         }
         // 余额支付金额
         mainOrder.setBalancePayFee(balancePayFee.get());
@@ -1260,11 +1264,14 @@ public class SubmitServiceImpl implements SubmitService {
         info.put("payableAmount", mainOrder.getPayableAmount());
         if (isPaySuccessFlag) {
             // 1提交成功(支付完成)
-            return ResponseJson.success(1,"提交成功且已支付完成!", info);
+            info.put("code", 1);
+            info.put("msg", "提交成功且已支付完成!");
         } else {
             //2提交成功(未支付)
-            return ResponseJson.success(2,"提交成功但未支付!", info);
+            info.put("code", 2);
+            info.put("msg", "提交成功但未支付!");
         }
+        return ResponseJson.success("操作成功!", info);
     }
 
     /**