Browse Source

优惠券领取开发

qizai 1 năm trước cách đây
mục cha
commit
13d0eafb70

+ 6 - 2
vehicle-api/src/main/java/com/chelvc/cloud/vehicle/api/param/CouponPagingParam.java

@@ -1,5 +1,6 @@
 package com.chelvc.cloud.vehicle.api.param;
 
+import com.chelvc.cloud.vehicle.api.constant.CouponClaimType;
 import com.chelvc.cloud.vehicle.api.constant.CouponStatus;
 import com.chelvc.cloud.vehicle.api.constant.CouponType;
 import com.chelvc.framework.common.model.Paging;
@@ -38,15 +39,18 @@ public class CouponPagingParam implements Serializable {
     /**
      * 优惠券类型
      */
-    @NotNull(message = "优惠券类型不能为空")
     private CouponType couponType;
 
     /**
      * 优惠券状态
      */
-    @NotNull(message = "优惠券状态不能为空")
     private CouponStatus couponStatus;
 
+    /**
+     * 优惠券领取方式
+     */
+    private CouponClaimType couponClaimType;
+
     /**
      * 商家ID
      */

+ 3 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/dao/CouponMapper.java

@@ -32,6 +32,8 @@ public interface CouponMapper extends BaseMapper<Coupon> {
      *
      * @param id   优惠券ID
      * @param receiveNum 领取数量
+     * @param publishNum 发行数量
      */
-    void updateCouponReceivedNum(@Param("id") Long id, @Param("receiveNum") Integer receiveNum);
+    int updateCouponReceivedNum(@Param("id") Long id, @Param("receiveNum") Integer receiveNum,
+                                 @Param("publishNum") Integer publishNum);
 }

+ 2 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/entity/Coupon.java

@@ -3,6 +3,7 @@ package com.chelvc.cloud.vehicle.server.entity;
 import java.util.Date;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.chelvc.cloud.vehicle.api.constant.CouponClaimType;
 import com.chelvc.cloud.vehicle.api.constant.CouponStatus;
@@ -108,5 +109,6 @@ public class Coupon extends ModifyEntity<Long> {
     /**
      * 促销状态
      */
+    @TableField(exist = false)
     private PromotionStatus promotionStatus;
 }

+ 9 - 4
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/CouponServiceImpl.java

@@ -22,6 +22,7 @@ import com.chelvc.framework.common.model.Pagination;
 import com.chelvc.framework.database.context.DatabaseContextHolder;
 import com.chelvc.framework.database.util.PagingUtils;
 import lombok.NonNull;
+import org.apache.dubbo.config.annotation.DubboService;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
@@ -32,7 +33,7 @@ import org.springframework.util.StringUtils;
  * @author Woody
  * @date 2023/7/17
  */
-@Service
+@DubboService(interfaceClass = com.chelvc.cloud.vehicle.api.service.CouponService.class)
 public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements CouponService,
         com.chelvc.cloud.vehicle.api.service.CouponService {
     @Override
@@ -65,8 +66,9 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
         // 查询优惠券列表
         Page<Coupon> page = this.lambdaQuery()
                 .eq(Objects.nonNull(param.getMerchantId()), Coupon::getMerchantId, param.getMerchantId())
-                .eq(Objects.nonNull(param.getCouponType()), Coupon::getType, param.getCouponType().name())
-                .eq(Objects.nonNull(param.getCouponStatus()), Coupon::getStatus, param.getCouponStatus().name())
+                .eq(Objects.nonNull(param.getCouponType()), Coupon::getType, param.getCouponType())
+                .eq(Objects.nonNull(param.getCouponStatus()), Coupon::getStatus, param.getCouponStatus())
+                .eq(Objects.nonNull(param.getCouponClaimType()), Coupon::getClaimType, param.getCouponClaimType())
                 .or().like(!StringUtils.isEmpty(param.getKeyword()), Coupon::getName, param.getKeyword())
                 .orderByDesc(Coupon::getCreateTime).page(PagingUtils.convert(param.getPaging()));
         List<Coupon> records = page.getRecords();
@@ -101,7 +103,10 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
         if (Objects.isNull(coupon)) {
             throw new ResourceUnavailableException("当前优惠券不存在");
         }
-        this.baseMapper.updateCouponReceivedNum(couponId, receiveNum);
+        int row = this.baseMapper.updateCouponReceivedNum(couponId, receiveNum, coupon.getPublishNum());
+        if (row < 1) {
+            throw new ResourceUnavailableException("修改优惠券已被领取数量失败!");
+        }
     }
 
     /**

+ 3 - 0
vehicle-server/src/main/resources/mapper/CouponMapper.xml

@@ -23,5 +23,8 @@
     <update id="updateCouponReceivedNum">
         update coupon cn set cn.received_num = cn.received_num + #{receiveNum}
         where cn.id = #{id}
+        <if test="publishNum != null and publishNum != 0">
+            and cn.publish_num >= cn.received_num + #{receiveNum}
+        </if>
     </update>
 </mapper>