Преглед изворни кода

添加同一个手机号报名问题

zhangchen пре 2 месеци
родитељ
комит
8916cabe21

+ 10 - 0
alien-entity/src/main/java/shop/alien/mapper/storePlantform/StoreOperationalActivitySignupMapper.java

@@ -52,6 +52,16 @@ public interface StoreOperationalActivitySignupMapper extends BaseMapper<StoreOp
                                            @Param("userId") Integer userId);
 
     /**
+     * 统计同一活动同一手机号已报名数量(未删除,待审核或通过)。
+     *
+     * @param activityId 活动ID
+     * @param phone      手机号
+     * @return 报名数量
+     */
+    Integer countByActivityIdAndPhone(@Param("activityId") Integer activityId,
+                                      @Param("phone") String phone);
+
+    /**
      * 统计用户是否已报名(待审核/通过)。
      *
      * @param activityId 活动ID

+ 9 - 0
alien-entity/src/main/resources/mapper/storePlatform/StoreOperationalActivitySignupMapper.xml

@@ -60,6 +60,15 @@
         LIMIT 1
     </select>
 
+    <select id="countByActivityIdAndPhone" resultType="java.lang.Integer">
+        SELECT COUNT(1)
+        FROM store_operational_activity_signup
+        WHERE activity_id = #{activityId}
+          AND phone = #{phone}
+          AND delete_flag = 0
+          AND status IN (0, 2)
+    </select>
+
     <select id="countSignedUpByActivityAndUser" resultType="java.lang.Integer">
         SELECT COUNT(1)
         FROM store_operational_activity_signup

+ 8 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreOperationalActivityServiceImpl.java

@@ -237,6 +237,9 @@ public class StoreOperationalActivityServiceImpl implements StoreOperationalActi
         if (dto.getUserId() == null) {
             throw new IllegalArgumentException("用户ID不能为空");
         }
+        if (dto.getPhone() == null || dto.getPhone().trim().isEmpty()) {
+            throw new IllegalArgumentException("手机号不能为空");
+        }
 
         StoreOperationalActivity activity = activityMapper.selectById(dto.getActivityId());
         if (activity == null) {
@@ -256,6 +259,11 @@ public class StoreOperationalActivityServiceImpl implements StoreOperationalActi
                 throw new IllegalArgumentException("已成功报名,请勿重复报名");
             }
 
+            Integer samePhoneCount = signupMapper.countByActivityIdAndPhone(dto.getActivityId(), dto.getPhone().trim());
+            if (samePhoneCount != null && samePhoneCount > 0) {
+                throw new IllegalArgumentException("同一活动同一手机号已报名,不允许重复报名");
+            }
+
             Integer approvedCount = signupMapper.countSignupByActivityId(dto.getActivityId());
             Integer limitPeople = activity.getActivityLimitPeople();
             if (limitPeople != null && limitPeople > 0 && approvedCount != null && approvedCount >= limitPeople) {