Просмотр исходного кода

红德堂-多端红包配置、发放调整

Long 2 недель назад
Родитель
Сommit
5bfa7f3483

+ 2 - 2
fs-admin/src/main/java/com/fs/course/controller/FsUserCoursePeriodController.java

@@ -196,7 +196,7 @@ public class FsUserCoursePeriodController extends BaseController {
     @PreAuthorize("@ss.hasPermi('course:period:setCourseRedPacket')")
     @ApiOperation("按课程批量保存设置红包金额")
     @PostMapping("/batchRedPacket")
-    public R batchRedPacketMoney(@RequestBody List<FsUserCourseVideoRedPackage> videoRedPackageList) {
+    public R batchRedPacketMoney(@Validated @RequestBody List<FsUserCourseVideoRedPackage> videoRedPackageList) {
         try {
             fsUserCourseVideoRedPackageService.batchSaveCompanyRedPackage(videoRedPackageList);
         } catch (Exception e) {
@@ -210,7 +210,7 @@ public class FsUserCoursePeriodController extends BaseController {
     @PreAuthorize("@ss.hasPermi('course:period:setRedPacket')")
     @ApiOperation("按营期批量保存设置红包金额")
     @PostMapping("/batchRedPacket/byPeriod")
-    public R batchRedPacketByPeriod(@RequestBody List<FsBatchPeriodRedPackageParam> periodRedPackageList) {
+    public R batchRedPacketByPeriod(@Validated @RequestBody List<FsBatchPeriodRedPackageParam> periodRedPackageList) {
         try {
             fsUserCourseVideoRedPackageService.batchRedPacketByPeriod(periodRedPackageList);
         } catch (Exception e) {

+ 17 - 0
fs-service/src/main/java/com/fs/course/annotation/RedPacketMoney.java

@@ -0,0 +1,17 @@
+package com.fs.course.annotation;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import java.lang.annotation.*;
+
+@Documented
+@Constraint(validatedBy = RedPacketMoneyValidator.class)
+@Target({ElementType.FIELD, ElementType.PARAMETER})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface RedPacketMoney {
+    String message() default "金额不能小于0,且不能在0到0.1之间";
+    
+    Class<?>[] groups() default {};
+    
+    Class<? extends Payload>[] payload() default {};
+}

+ 22 - 0
fs-service/src/main/java/com/fs/course/annotation/RedPacketMoneyValidator.java

@@ -0,0 +1,22 @@
+package com.fs.course.annotation;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import java.math.BigDecimal;
+
+public class RedPacketMoneyValidator implements ConstraintValidator<RedPacketMoney, BigDecimal> {
+
+    @Override
+    public void initialize(RedPacketMoney constraintAnnotation) {
+    }
+
+    @Override
+    public boolean isValid(BigDecimal value, ConstraintValidatorContext context) {
+        if (value == null) {
+            return true; // 让@NotNull注解处理空值校验
+        }
+        
+        // 允许0,或者大于等于0.1的值
+        return value.compareTo(BigDecimal.ZERO) == 0 || value.compareTo(new BigDecimal("0.1")) >= 0;
+    }
+}

+ 16 - 0
fs-service/src/main/java/com/fs/course/domain/FsUserCourseVideoRedPackage.java

@@ -2,8 +2,10 @@ package com.fs.course.domain;
 
 import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
+import com.fs.course.annotation.RedPacketMoney;
 import lombok.Data;
 
+import javax.validation.constraints.NotNull;
 import java.math.BigDecimal;
 
 /**
@@ -30,8 +32,22 @@ public class FsUserCourseVideoRedPackage extends BaseEntity
 
     /** 红包价格 */
     @Excel(name = "红包价格")
+    @NotNull(message = "小程序红包金额不能为空")
+    @RedPacketMoney
     private BigDecimal redPacketMoney;
 
+    /** APP红包价格 */
+    @Excel(name = "APP红包价格")
+    @NotNull(message = "APP红包金额不能为空")
+    @RedPacketMoney
+    private BigDecimal redPacketMoneyApp;
+
+    /** H5红包价格 */
+    @Excel(name = "H5红包价格")
+    @NotNull(message = "H5红包金额不能为空")
+    @RedPacketMoney
+    private BigDecimal redPacketMoneyH5;
+
     @Excel(name = "营期id")
     private Long periodId;
 

+ 11 - 3
fs-service/src/main/java/com/fs/course/param/BatchCompanyRedPackageParam.java

@@ -1,8 +1,8 @@
 package com.fs.course.param;
 
+import com.fs.course.annotation.RedPacketMoney;
 import lombok.Data;
 
-import javax.validation.constraints.DecimalMin;
 import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 import java.math.BigDecimal;
@@ -17,7 +17,15 @@ public class BatchCompanyRedPackageParam {
     @NotEmpty(message = "公司ID不能为空")
     private List<Long> companyIds;
 
-    @NotNull(message = "红包金额不能为空")
-    @DecimalMin(value = "0.1", message = "红包金额必须大于0.1")
+    @NotNull(message = "小程序红包金额不能为空")
+    @RedPacketMoney
     private BigDecimal redPacketMoney;
+
+    @NotNull(message = "APP红包金额不能为空")
+    @RedPacketMoney
+    private BigDecimal redPacketMoneyApp;
+
+    @NotNull(message = "H5红包金额不能为空")
+    @RedPacketMoney
+    private BigDecimal redPacketMoneyH5;
 }

+ 14 - 0
fs-service/src/main/java/com/fs/course/param/FsBatchPeriodRedPackageParam.java

@@ -1,8 +1,10 @@
 package com.fs.course.param;
 
+import com.fs.course.annotation.RedPacketMoney;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 import java.math.BigDecimal;
 
@@ -13,8 +15,20 @@ import java.math.BigDecimal;
 public class FsBatchPeriodRedPackageParam implements Serializable {
 
     @ApiModelProperty(value = "红包金额")
+    @NotNull(message = "小程序红包金额不能为空")
+    @RedPacketMoney
     private BigDecimal redPacketMoney;
 
+    @ApiModelProperty(value = "APP红包金额")
+    @NotNull(message = "APP红包金额不能为空")
+    @RedPacketMoney
+    private BigDecimal redPacketMoneyApp;
+
+    @ApiModelProperty(value = "H5红包金额")
+    @NotNull(message = "H5红包金额不能为空")
+    @RedPacketMoney
+    private BigDecimal redPacketMoneyH5;
+
     @ApiModelProperty(value = "营期id")
     private Long periodId;
 

+ 4 - 0
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoRedPackageServiceImpl.java

@@ -222,6 +222,8 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
                     fsUserCourseVideoRedPackage.setCompanyId(Long.parseLong(companyId));
                     fsUserCourseVideoRedPackage.setVideoId(c.getVideoId());
                     fsUserCourseVideoRedPackage.setRedPacketMoney(v.getRedPacketMoney());
+                    fsUserCourseVideoRedPackage.setRedPacketMoneyApp(v.getRedPacketMoneyApp());
+                    fsUserCourseVideoRedPackage.setRedPacketMoneyH5(v.getRedPacketMoneyH5());
                     fsUserCourseVideoRedPackage.setPeriodId(periodId);
                     fsUserCourseVideoRedPackage.setDataType(2);
                     fsRedPackageList.add(fsUserCourseVideoRedPackage);
@@ -273,6 +275,8 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
                     redPkg.setCompanyId(companyId);
                     redPkg.setVideoId(video.getVideoId());
                     redPkg.setRedPacketMoney(param.getRedPacketMoney());
+                    redPkg.setRedPacketMoneyApp(param.getRedPacketMoneyApp());
+                    redPkg.setRedPacketMoneyH5(param.getRedPacketMoneyH5());
                     redPkg.setPeriodId(period.getPeriodId());
                     redPkg.setDataType(2);
                     return redPkg;

+ 30 - 5
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -1647,12 +1647,8 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService {
         }
 
         // 确定红包金额
-        BigDecimal amount = BigDecimal.ZERO;
-        FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByCompanyId(param.getVideoId(), log.getCompanyId(), param.getPeriodId());
+        BigDecimal amount = getRedPacketAmount(param, log);
 
-        if (redPackage != null && redPackage.getRedPacketMoney() != null) {
-            amount = redPackage.getRedPacketMoney();
-        }
         // 准备发送红包参数
         WxSendRedPacketParam packetParam = new WxSendRedPacketParam();
         packetParam.setOpenId(user.getMpOpenId());
@@ -1810,6 +1806,35 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService {
 
     }
 
+    /**
+     * 获取红包金额
+     */
+    private BigDecimal getRedPacketAmount(FsCourseSendRewardUParam param, FsCourseWatchLog log) {
+        BigDecimal amount = BigDecimal.ZERO;
+        FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByCompanyId(param.getVideoId(), log.getCompanyId(), param.getPeriodId());
+
+        if (redPackage != null) {
+            // 根据不同端设置不同的金额
+            if (param.getSource() == 2) {
+                // 小程序
+                if (redPackage.getRedPacketMoney() != null) {
+                    amount = redPackage.getRedPacketMoney();
+                }
+            } else if (param.getSource() == 3) {
+                // APP
+                if (redPackage.getRedPacketMoneyApp() != null) {
+                    amount = redPackage.getRedPacketMoneyApp();
+                }
+            } else {
+                // H5 (source=1) 或其他默认情况
+                if (redPackage.getRedPacketMoneyH5() != null) {
+                    amount = redPackage.getRedPacketMoneyH5();
+                }
+            }
+        }
+        return amount;
+    }
+
     /**
      * 获取红包开关
      */

+ 6 - 0
fs-service/src/main/java/com/fs/course/vo/PeriodRedPacketVO.java

@@ -31,4 +31,10 @@ public class PeriodRedPacketVO implements Serializable {
     @ApiModelProperty(value = "金额")
     private BigDecimal amount;
 
+    @ApiModelProperty(value = "App金额")
+    private BigDecimal appAmount;
+
+    @ApiModelProperty(value = "H5金额")
+    private BigDecimal h5Amount;
+
 }

+ 3 - 1
fs-service/src/main/resources/mapper/course/FsUserCoursePeriodMapper.xml

@@ -230,7 +230,9 @@
             DISTINCT a.*,
                      c.course_name,
                      cv.title videoName,
-                     ifnull ( fvrp.red_packet_money, 0 ) AS amount
+                     ifnull ( fvrp.red_packet_money, 0 ) AS amount,
+                     ifnull ( fvrp.red_packet_money_app, 0 ) AS appAmount,
+                     ifnull ( fvrp.red_packet_money_h5, 0 ) AS h5Amount
         FROM
             fs_user_course_period_days a
                 LEFT JOIN fs_user_course_video cv ON a.video_id = cv.video_id

+ 7 - 1
fs-service/src/main/resources/mapper/course/FsUserCourseVideoRedPackageMapper.xml

@@ -94,7 +94,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <!-- 按条件更新红包金额 -->
     <update id="updateRedPackageByParams" parameterType="FsUserCourseVideoRedPackage">
         update fs_user_course_video_red_package
-        set red_packet_money = #{redPacketMoney}
+        set red_packet_money = #{redPacketMoney},
+            red_packet_money_app = #{redPacketMoneyApp},
+            red_packet_money_h5 = #{redPacketMoneyH5}
         where period_id = #{periodId}
           and video_id = #{videoId}
           and company_id = #{companyId}
@@ -110,6 +112,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="list[0].companyId != null">company_id,</if>
             <if test="list[0].videoId != null">video_id,</if>
             <if test="list[0].redPacketMoney != null">red_packet_money,</if>
+            <if test="list[0].redPacketMoneyApp != null">red_packet_money_app,</if>
+            <if test="list[0].redPacketMoneyH5 != null">red_packet_money_h5,</if>
             <if test="list[0].periodId !=null">period_id,</if>
             <if test="list[0].dataType !=null">data_type,</if>
             <if test="list[0].ruleId !=null">rule_id,</if>
@@ -120,6 +124,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 <if test="item.companyId != null">#{item.companyId},</if>
                 <if test="item.videoId != null">#{item.videoId},</if>
                 <if test="item.redPacketMoney != null">#{item.redPacketMoney},</if>
+                <if test="item.redPacketMoneyApp != null">#{item.redPacketMoneyApp},</if>
+                <if test="item.redPacketMoneyH5 != null">#{item.redPacketMoneyH5},</if>
                 <if test="item.periodId !=null">#{item.periodId},</if>
                 <if test="item.dataType !=null">#{item.dataType},</if>
                 <if test="item.ruleId !=null">#{item.ruleId},</if>