Browse Source

机构商品结算优惠券

chao 3 years ago
parent
commit
555528e4b7

+ 5 - 3
src/main/java/com/caimei365/order/controller/CartClubApi.java

@@ -133,17 +133,18 @@ public class CartClubApi {
     @ApiOperation("购物车结算(旧:/order/confirm)")
     @ApiImplicitParams({
             @ApiImplicitParam(required = false, name = "userId", value = "用户Id"),
-            @ApiImplicitParam(required = false, name = "productIds", value = "商品ids,逗号隔开")
+            @ApiImplicitParam(required = false, name = "productIds", value = "商品ids,逗号隔开"),
+            @ApiImplicitParam(required = false, name = "source", value = "来源 : 1 网站 ; 2 小程序")
     })
     @GetMapping("/cart/settlement")
-    public ResponseJson<Map<String, Object>> settlementShoppingCart(Integer userId, String productIds) {
+    public ResponseJson<Map<String, Object>> settlementShoppingCart(Integer userId, String productIds, Integer source) {
         if (null == userId) {
             return ResponseJson.error("用户Id不能为空!", null);
         }
         if (StringUtils.isEmpty(productIds)) {
             return ResponseJson.error("商品Id集合不能为空!", null);
         }
-        return cartClubService.settlementShoppingCart(userId, productIds);
+        return cartClubService.settlementShoppingCart(userId, productIds, source);
     }
 
     /**
@@ -153,6 +154,7 @@ public class CartClubApi {
      *                userId       用户ID
      *                productId    商品id
      *                productCount 商品数量
+     *                source       来源 : 1 网站 ; 2 小程序
      * }
      */
     @ApiOperation("立即购买(旧:/order/confirm)")

+ 5 - 1
src/main/java/com/caimei365/order/model/dto/CartDto.java

@@ -34,5 +34,9 @@ public class CartDto implements Serializable {
      */
     @ApiModelProperty("商品ids,删除购物车用,逗号分隔")
     private String productIds;
-
+    /**
+     * 来源 : 1 网站 ; 2 小程序
+     */
+    @ApiModelProperty("来源 : 1 网站 ; 2 小程序")
+    private Integer source;
 }

+ 3 - 1
src/main/java/com/caimei365/order/service/CartClubService.java

@@ -63,8 +63,9 @@ public interface CartClubService {
      *
      * @param  userId       用户ID
      * @param  productIds   商品ids,逗号隔开
+     * @param source 来源 : 1 网站 ; 2 小程序
      */
-    ResponseJson<Map<String, Object>> settlementShoppingCart(Integer userId, String productIds);
+    ResponseJson<Map<String, Object>> settlementShoppingCart(Integer userId, String productIds, Integer source);
 
     /**
      * 立即购买
@@ -73,6 +74,7 @@ public interface CartClubService {
      *                userId       用户ID
      *                productId    商品id
      *                productCount 商品数量
+     *                source       来源 : 1 网站 ; 2 小程序
      * }
      */
     ResponseJson<Map<String, Object>> buyNowProduct(CartDto cartDto);

+ 61 - 3
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -595,9 +595,10 @@ public class CartClubServiceImpl implements CartClubService {
      *
      * @param userId     用户ID
      * @param productIds 商品ids,逗号隔开
+     * @param source     来源 : 1 网站 ; 2 小程序
      */
     @Override
-    public ResponseJson<Map<String, Object>> settlementShoppingCart(Integer userId, String productIds) {
+    public ResponseJson<Map<String, Object>> settlementShoppingCart(Integer userId, String productIds, Integer source) {
         log.info("¥¥¥¥¥¥¥¥¥¥ > 商品结算");
         // 商品种类
         AtomicInteger kindCount = new AtomicInteger(0);
@@ -613,7 +614,8 @@ public class CartClubServiceImpl implements CartClubService {
         List<PromotionsVo> totalPromotions = new ArrayList<>();
         // 是否包含充值商品,默认false
         AtomicBoolean includeRecharge = new AtomicBoolean(false);
-
+        //所有的商品数据
+        List<CartItemVo> totalProductList = new ArrayList<>();
         // 促销活动Id集合,用于合并促销活动
         List<Integer> promotionsIds = new ArrayList<>();
         // 供应商Id集合,用户判断赠品供应商是否在当前供应商中
@@ -762,6 +764,7 @@ public class CartClubServiceImpl implements CartClubService {
                         // 商品种类
                         kindCount.updateAndGet(v -> v + shopKindCount.get());
                     }
+                    totalProductList.addAll(productList);
                 }
                 // 供应商下商品种类
                 shop.setCount(shopKindCount.get());
@@ -803,6 +806,59 @@ public class CartClubServiceImpl implements CartClubService {
                 });
             }
         });
+
+        // 用户可用优惠券(总)
+        List<CouponVo> couponList = cartClubMapper.getClubCouponList(userId);
+        Iterator<CouponVo> iterator = couponList.iterator();
+        while (iterator.hasNext()) {
+            CouponVo coupon = iterator.next();
+            BigDecimal totalAmount = BigDecimal.ZERO;
+            Integer couponType = coupon.getCouponType();
+            for (CartItemVo item : totalProductList) {
+                if (couponType == 0) {
+                    if (coupon.getProductType() == 1) {
+                        //活动券-全商城商品
+                        BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
+                        totalAmount = MathUtil.add(price, totalAmount);
+                    } else if (coupon.getProductType() == 2) {
+                        //活动券-指定商品
+                        List<Integer> couponProductIds = cartClubMapper.getCouponProductIds(coupon.getCouponId(), source);
+                        if (couponProductIds.contains(item.getProductId())) {
+                            BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
+                            totalAmount = MathUtil.add(price, totalAmount);
+                        }
+                    }
+                } else if (couponType == 1) {
+                    //品类券
+                    if (coupon.getCategoryType().equals(item.getCommodityType())) {
+                        BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
+                        totalAmount = MathUtil.add(price, totalAmount);
+                    }
+                } else if (couponType == 2 || couponType == 4) {
+                    //用户专享券或新用户券
+                    BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
+                    totalAmount = MathUtil.add(price, totalAmount);
+                } else if (coupon.getCouponType() == 3 && coupon.getShopId() != null) {
+                    //店铺券
+                    String shopName = baseMapper.getShopNameById(coupon.getShopId());
+                    if (StringUtils.isNotBlank(shopName)) {
+                        if (shopName.length() > 7) {
+                            shopName = shopName.substring(0, 6) + "...";
+                        }
+                        coupon.setShopName(shopName);
+                    }
+                    if (coupon.getShopId().equals(item.getShopId())) {
+                        BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
+                        totalAmount = MathUtil.add(price, totalAmount);
+                    }
+                }
+            }
+            if (MathUtil.compare(totalAmount, coupon.getTouchPrice()) < 0) {
+                iterator.remove();
+            }
+        }
+        couponList.sort((o1, o2) -> o2.getCouponAmount().compareTo(o1.getCouponAmount()));
+
         // 发票信息
         InvoiceVo invoice = baseMapper.getUserInvoice(userId);
         // 可用余额
@@ -822,6 +878,7 @@ public class CartClubServiceImpl implements CartClubService {
         resultData.put("userMoney", availableMoney);
         resultData.put("userBeans", userBeans);
         resultData.put("includeRecharge", includeRecharge);
+        resultData.put("couponList", couponList);
         return ResponseJson.success(resultData);
     }
 
@@ -832,6 +889,7 @@ public class CartClubServiceImpl implements CartClubService {
      *                userId       用户ID
      *                productId    商品id
      *                productCount 商品数量
+     *                source       来源 : 1 网站 ; 2 小程序
      *                }
      */
     @Override
@@ -860,7 +918,7 @@ public class CartClubServiceImpl implements CartClubService {
             cartClubMapper.insertCart(cart);
         }
         // 结算商品
-        return settlementShoppingCart(cartDto.getUserId(), cartDto.getProductId().toString());
+        return settlementShoppingCart(cartDto.getUserId(), cartDto.getProductId().toString(), cartDto.getSource());
     }
 
     /**