瀏覽代碼

供应商优惠券

chao 3 年之前
父節點
當前提交
15aa8b2ff1

+ 30 - 4
src/main/java/com/caimei365/order/controller/CartClubApi.java

@@ -11,10 +11,7 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.Map;
 
@@ -232,4 +229,33 @@ public class CartClubApi {
         return cartClubService.updateUserInvoice(invoiceDto);
     }
 
+    /**
+     * 供应商优惠券
+     *
+     * @param userId 用户id
+     * @param shopId 供应商id
+     * @param source 来源 : 1 网站 ; 2 小程序
+     * @param status 状态: 1未领取 2已领取
+     */
+    @ApiOperation("领取供应商优惠券(旧:/shoppingCart/get/coupon)")
+    @ApiImplicitParams({
+            @ApiImplicitParam(required = false, name = "userId", value = "用户Id"),
+            @ApiImplicitParam(required = false, name = "shopId", value = "供应商Id"),
+            @ApiImplicitParam(required = false, name = "status", value = "状态: 1未领取, 2已领取"),
+            @ApiImplicitParam(required = false, name = "source", value = "来源: 1网站, 2小程序")
+    })
+    @GetMapping("/coupon")
+    public ResponseJson<Map<String, Object>>  getShopCoupons(Integer userId, Integer shopId, Integer source,
+                                   @RequestParam(name = "status", defaultValue = "1") Integer status) {
+        if (null == userId) {
+            return ResponseJson.error("用户Id不能为空!", null);
+        }
+        if (null == shopId) {
+            return ResponseJson.error("供应商Id不能为空!", null);
+        }
+        if (null == source) {
+            return ResponseJson.error("来源source不能为空!", null);
+        }
+        return cartClubService.getShopCoupons(userId, shopId, source, status);
+    }
 }

+ 5 - 0
src/main/java/com/caimei365/order/mapper/OrderCommonMapper.java

@@ -126,6 +126,11 @@ public interface OrderCommonMapper {
      * @param userId 用户Id
      */
     List<CouponVo> getClubCouponList(Integer userId);
+    /**
+     * 未领取的优惠券
+     * @param userId 用户Id
+     */
+    List<CouponVo> getPrevCouponList(Integer userId);
     /**
      * 活动券商品Ids
      */

+ 9 - 0
src/main/java/com/caimei365/order/service/CartClubService.java

@@ -111,4 +111,13 @@ public interface CartClubService {
      */
     ResponseJson<Integer> updateUserInvoice(InvoiceDto invoiceDto);
 
+    /**
+     * 供应商优惠券
+     *
+     * @param userId 用户id
+     * @param shopId 供应商id
+     * @param source 来源 : 1 网站 ; 2 小程序
+     * @param status 状态: 1未领取 2已领取
+     */
+    ResponseJson<Map<String, Object>> getShopCoupons(Integer userId, Integer shopId, Integer source, Integer status);
 }

+ 33 - 0
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -988,5 +988,38 @@ public class CartClubServiceImpl implements CartClubService {
         return ResponseJson.success(1);
     }
 
+    /**
+     * 供应商优惠券
+     *
+     * @param userId 用户id
+     * @param shopId 供应商id
+     * @param source 来源 : 1 网站 ; 2 小程序
+     * @param status 状态: 1未领取 2已领取
+     */
+    @Override
+    public ResponseJson<Map<String, Object>> getShopCoupons(Integer userId, Integer shopId, Integer source, Integer status) {
+        // 供应商下购物车商品列表
+        List<CartItemVo> productList = cartClubMapper.getCartProductsByShopId(shopId, userId);
+        // 未领取的优惠券
+        List<CouponVo> preCouponList = orderCommonMapper.getPrevCouponList(userId);
+        // 过滤与当前购物车商品无关的优惠券
+        filterCoupon(source, productList, preCouponList);
+        // 用户可用优惠券(已领取)
+        List<CouponVo> couponList = orderCommonMapper.getClubCouponList(userId);
+        // 过滤与当前购物车商品无关的优惠券
+        filterCoupon(source, productList, couponList);
+        Map<String, Object> map = new HashMap<>(3);
+        map.put("notCouponNum", preCouponList == null ? 0 : preCouponList.size());
+        map.put("couponNum", couponList == null ? 0 : couponList.size());
+        if (status == 1) {
+            //未领取
+            map.put("couponList", preCouponList);
+        } else {
+            //已领取
+            map.put("couponList", couponList);
+        }
+        return ResponseJson.success(map);
+    }
+
 
 }

+ 2 - 2
src/main/resources/mapper/CartClubMapper.xml

@@ -3,7 +3,7 @@
 <mapper namespace="com.caimei365.order.mapper.CartClubMapper">
     <!-- 购物车供应商列表 -->
     <select id="getCartShops" resultType="com.caimei365.order.model.vo.CartShopVo">
-        SELECT
+        SELECT DISTINCT
             c.shopID AS shopId,
             s.name AS shopName,
             s.logo AS shopLogo
@@ -14,7 +14,7 @@
         ORDER BY c.cm_cartID DESC
     </select>
     <select id="getCartShopsByProductIds" resultType="com.caimei365.order.model.vo.CartShopVo">
-        SELECT
+        SELECT DISTINCT
             c.shopID AS shopId,
             s.name AS shopName,
             s.logo AS shopLogo

+ 39 - 14
src/main/resources/mapper/OrderCommonMapper.xml

@@ -10,7 +10,6 @@
         cso.orderID AS orderId,
         cso.orderNo,
         cso.shopID AS shopId,
-        cso.shopName,
         cso.note,
         cso.userID AS userId,
         cso.clubID AS clubId,
@@ -294,7 +293,6 @@
         orderID AS orderId,
         orderNo,
         shopID AS shopId,
-        shopName,
         note,
         userID AS userId,
         clubID AS clubId,
@@ -316,7 +314,7 @@
         payStatus,
         splitFlag
         FROM cm_shop_order
-        WHERE cso.delFlag = 0
+        WHERE delFlag = 0
         AND orderID = #{orderId}
     </select>
     <select id="getLogisticsBatchList" resultType="com.caimei365.order.model.vo.LogisticsBatchVo">
@@ -369,19 +367,46 @@
         FROM logistics_information li
         WHERE li.logisticsBatchID = #{logisticsBatchId}
     </select>
+    <select id="getPrevCouponList" resultType="com.caimei365.order.model.vo.CouponVo">
+        SELECT
+            id AS couponId,
+            couponAmount,
+            touchPrice,
+            startDate,
+            endDate,
+            couponType,
+            userId,
+            shopId,
+            productType,
+            categoryType
+        FROM cm_coupon
+        WHERE delFlag = 0 AND couponsMode = 0 AND status != 2
+        AND (NOW() BETWEEN startDate AND endDate)
+        <if test="userId == null or userId == 0">
+            AND couponType != 2
+        </if>
+        <if test="userId > 0">
+            AND id NOT IN(SELECT couponId FROM cm_coupon_club WHERE userId = #{userId})
+            AND (couponType IN (0,1,3)
+            OR couponType = 2 AND userId = #{userId}
+            OR ((SELECT registerTime FROM USER WHERE userID = #{userId}) <![CDATA[ >= ]]> startDate
+            AND couponType = 4))
+        </if>
+        ORDER BY createDate DESC
+    </select>
     <select id="getClubCouponList" resultType="com.caimei365.order.model.vo.CouponVo">
         SELECT
-        a.id AS clubCouponId,
-        cc.`id` AS couponId,
-        cc.`couponAmount`,
-        cc.`touchPrice`,
-        cc.`startDate`,
-        cc.`endDate`,
-        cc.`couponType`,
-        cc.`userId`,
-        cc.`shopId`,
-        cc.`productType`,
-        cc.`categoryType`
+            a.id AS clubCouponId,
+            cc.id AS couponId,
+            cc.couponAmount,
+            cc.touchPrice,
+            cc.startDate,
+            cc.endDate,
+            cc.couponType,
+            cc.userId,
+            cc.shopId,
+            cc.productType,
+            cc.categoryType
         FROM cm_coupon_club a
         LEFT JOIN cm_coupon cc ON a.couponId = cc.id
         WHERE cc.delFlag = 0