1
0
Эх сурвалжийг харах

fixed 卡券发放数量检查

fushengqian 11 сар өмнө
parent
commit
98e91e1f68

+ 16 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/CouponServiceImpl.java

@@ -595,6 +595,22 @@ public class CouponServiceImpl extends ServiceImpl<MtCouponMapper, MtCoupon> imp
             throw new BusinessCheckException("卡券“"+couponInfo.getName()+"”已停用,不能发放");
         }
 
+        // 是否超过拥有数量
+        if (couponInfo.getLimitNum() != null && couponInfo.getLimitNum() > 0) {
+            if (num > couponInfo.getLimitNum()) {
+                throw new BusinessCheckException("该卡券每个会员最多拥有数量是" + couponInfo.getLimitNum());
+            }
+        }
+
+        // 发放总数量是否已经超额
+        if (couponInfo.getTotal() != null && couponInfo.getTotal() > 0) {
+            Long sendNum = mtUserCouponMapper.getSendNum(couponId);
+            Long total = Long.parseLong(couponInfo.getTotal().toString());
+            if (sendNum.compareTo(total) >= 0) {
+                throw new BusinessCheckException("该卡券发行总数量是" + couponInfo.getTotal() + ",现已超额!");
+            }
+        }
+
         // 发放的是储值卡
         if (couponInfo.getType().equals(CouponTypeEnum.PRESTORE.getKey())) {
             if (StringUtil.isNotEmpty(couponInfo.getInRule())) {

+ 1 - 1
fuint-repository/src/main/resources/mapper/MtUserCouponMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fuint.repository.mapper.MtUserCouponMapper">
     <select id="getSendNum" resultType="java.lang.Long">
-        select count(*) from mt_user_coupon t where t.GROUP_ID = #{couponId}
+        select count(*) from mt_user_coupon t where t.COUPON_ID = #{couponId}
     </select>
 
     <select id="getPeopleNumByCouponId" resultType="com.fuint.repository.bean.CouponNumBean">