Parcourir la source

1、储值记录需求充值限制,导出开发

yys il y a 1 mois
Parent
commit
9b05c6b67a

+ 3 - 2
fs-company/src/main/java/com/fs/company/controller/company/RechargeRecordController.java

@@ -19,6 +19,7 @@ import com.fs.company.service.ICompanyService;
 import com.fs.company.service.IRechargeRecordService;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
+import com.fs.sop.domain.QwSop;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -66,10 +67,10 @@ public class RechargeRecordController extends BaseController
     @PreAuthorize("@ss.hasPermi('company:rechargeRecord:export')")
     @Log(title = "储值支付记录", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, RechargeRecord rechargeRecord) throws IOException {
+    public AjaxResult export(@RequestBody RechargeRecord rechargeRecord) throws IOException {
         List<RechargeRecord> list = rechargeRecordService.selectRechargeRecordList(rechargeRecord);
         ExcelUtil<RechargeRecord> util = new ExcelUtil<RechargeRecord>(RechargeRecord.class);
-        util.exportExcel(response, list, "储值支付记录数据");
+        return util.exportExcel(list, "储值支付记录数据");
     }
 
     /**

+ 24 - 0
fs-service/src/main/java/com/fs/company/mapper/RechargeRecordMapper.java

@@ -1,7 +1,10 @@
 package com.fs.company.mapper;
 
 import com.fs.company.domain.RechargeRecord;
+import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.List;
 
 /**
@@ -59,4 +62,25 @@ public interface RechargeRecordMapper
      * @return 结果
      */
     public int deleteRechargeRecordByIds(Long[] ids);
+
+
+    /**
+     * 根据用户查询充值金额
+     *
+     * @param userId
+     * @param date
+     * @return
+     */
+    BigDecimal selectTodayRechargeAmount(@Param("userId") Long userId, @Param("date") LocalDate date);
+
+    /**
+     * 根据用户查询充值次数
+     *
+     * @param userId
+     * @param date
+     * @return
+     */
+    Integer selectTodayRechargeCount(@Param("userId") Long userId, @Param("date") LocalDate date);
+
+
 }

+ 61 - 3
fs-service/src/main/java/com/fs/company/service/impl/RechargeRecordServiceImpl.java

@@ -1,10 +1,22 @@
 package com.fs.company.service.impl;
 
+import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.List;
 
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONUtil;
+import com.fs.chat.config.QwConfig;
+import com.fs.company.domain.CompanyConfig;
 import com.fs.company.domain.RechargeRecord;
+import com.fs.company.mapper.CompanyConfigMapper;
 import com.fs.company.mapper.RechargeRecordMapper;
+import com.fs.company.service.ICompanyConfigService;
 import com.fs.company.service.IRechargeRecordService;
+import com.fs.his.domain.FsUser;
+import com.fs.his.mapper.FsUserMapper;
+import com.fs.his.service.IFsUserService;
+import com.fs.hisStore.config.RechargeRecordConfig;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -19,7 +31,10 @@ public class RechargeRecordServiceImpl implements IRechargeRecordService
 {
     @Autowired
     private RechargeRecordMapper rechargeRecordMapper;
-
+    @Autowired
+    private FsUserMapper userMapper;
+    @Autowired
+    private CompanyConfigMapper companyConfigMapper;
     /**
      * 查询储值支付记录
      *
@@ -51,12 +66,55 @@ public class RechargeRecordServiceImpl implements IRechargeRecordService
      * @return 结果
      */
     @Override
-    public int insertRechargeRecord(RechargeRecord rechargeRecord)
-    {
+    public int insertRechargeRecord(RechargeRecord rechargeRecord) {
+        // 1. 校验用户
+        FsUser fsUser = userMapper.selectFsUserById(rechargeRecord.getUserId());
+        if (fsUser == null) {
+            throw new RuntimeException("用户不存在!");
+        }
+
+        // 2. 获取配置
+        CompanyConfig config = companyConfigMapper.selectCompanyConfigByKey(
+                rechargeRecord.getCompanyId(), "recharge:record:config");
+        RechargeRecordConfig rechargeRecordConfig = JSONUtil.toBean(
+                config.getConfigValue(), RechargeRecordConfig.class);
+        if (ObjectUtil.isEmpty(rechargeRecordConfig)){
+            throw new RuntimeException("请先联系管理员进行配置限额金额!");
+        }
 
+        // 3. 统计当天充值金额和次数
+        BigDecimal todayRechargedAmount = rechargeRecordMapper.selectTodayRechargeAmount(
+                fsUser.getUserId(), LocalDate.now());
+
+        Integer todayRechargeCount = rechargeRecordMapper.selectTodayRechargeCount(
+                fsUser.getUserId(), LocalDate.now());
+
+        // 4. 每日额度校验
+        if (rechargeRecordConfig.getDailyLimit() != null
+                && rechargeRecordConfig.getDailyLimit().compareTo(BigDecimal.ZERO) > 0) {
+            BigDecimal totalAmount = todayRechargedAmount.add(rechargeRecord.getTotalAmount());
+            if (totalAmount.compareTo(rechargeRecordConfig.getDailyLimit()) > 0) {
+                throw new RuntimeException(
+                        "每日充值限额" + rechargeRecordConfig.getDailyLimit() +
+                                "元,今日已充值" + todayRechargedAmount + "元");
+            }
+        }
+
+        // 5. 每日次数校验
+        if (rechargeRecordConfig.getDailyCount() != null
+                    && rechargeRecordConfig.getDailyCount() > 0) {
+            if (todayRechargeCount >= rechargeRecordConfig.getDailyCount()) {
+                throw new RuntimeException(
+                        "每日充值次数限制" + rechargeRecordConfig.getDailyCount() +
+                                "次,今日已充值" + todayRechargeCount + "次");
+            }
+        }
+        fsUser.setRechargeBalance(fsUser.getRechargeBalance().add(rechargeRecord.getTotalAmount()));
+        userMapper.updateFsUser(fsUser);
         return rechargeRecordMapper.insertRechargeRecord(rechargeRecord);
     }
 
+
     /**
      * 修改储值支付记录
      *

+ 5 - 0
fs-service/src/main/java/com/fs/his/domain/FsUser.java

@@ -246,6 +246,11 @@ public class FsUser extends BaseEntity
     @TableField(exist = false)
     private String nicknameExact;
 
+    /**
+     * 储值金额
+     */
+    private BigDecimal rechargeBalance;
+
 //    /**
 //     * 搜索关键词-电话号码/会员id/会员昵称
 //     * **/

+ 0 - 1
fs-service/src/main/java/com/fs/his/mapper/MerchantAppConfigMapper.java

@@ -33,7 +33,6 @@ public interface MerchantAppConfigMapper extends BaseMapper<MerchantAppConfig>{
      * @param id 商户应用配置主键
      * @return 商户应用配置
      */
-    @DataSource(DataSourceType.SLAVE)
     MerchantAppConfig selectMerchantAppConfigById(Long id);
 
     /**

+ 20 - 0
fs-service/src/main/java/com/fs/hisStore/config/RechargeRecordConfig.java

@@ -0,0 +1,20 @@
+package com.fs.hisStore.config;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+public class RechargeRecordConfig implements Serializable {
+
+    /**
+     * 每日充值额度限制
+     */
+    private BigDecimal dailyLimit;
+
+    /**
+     * 每月充值限制次数
+     */
+    private Integer dailyCount;
+}

+ 19 - 0
fs-service/src/main/resources/mapper/company/RechargeRecordMapper.xml

@@ -99,4 +99,23 @@
             #{id}
         </foreach>
     </delete>
+
+
+    <select id="selectTodayRechargeAmount" resultType="java.math.BigDecimal">
+        SELECT IFNULL(SUM(total_amount), 0)
+        FROM recharge_record
+        WHERE user_id = #{userId}
+          AND DATE(create_time) = #{date}
+          AND business_type = 0 and del_flag =0
+    </select>
+
+
+    <select id="selectTodayRechargeCount" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM recharge_record
+        WHERE user_id = #{userId}
+          AND DATE(create_time) = #{date}
+          AND business_type = 0 and del_flag =0
+    </select>
+
 </mapper>

+ 4 - 1
fs-service/src/main/resources/mapper/his/FsUserMapper.xml

@@ -53,10 +53,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="isShow" column="is_show"/>
         <result property="appOpenId"    column="app_open_id"    />
         <result property="appleKey"    column="apple_key"    />
+        <result property="rechargeBalance"    column="recharge_balance"    />
     </resultMap>
 
     <sql id="selectFsUserVo">
-        select user_id,qw_ext_id,sex,is_buy,`level`,course_ma_open_id,is_push,is_add_qw,source,login_device,is_individuation_push,store_open_id,password,jpush_id, is_vip,vip_start_date,vip_end_date,vip_level,vip_status,nick_name,integral_status, avatar, phone, integral,sign_num, status, tui_user_id, tui_time, tui_user_count, ma_open_id, mp_open_id, union_id, is_del, user_code, remark, create_time, update_time, last_ip, balance,is_weixin_auth,parent_id,qw_user_id,app_id,company_id,company_user_id,is_promoter,now_money,brokerage_price,spread_user_id, spread_time,pay_count, spread_count,user_type,invited_by_sales_id,app_open_id,apple_key from fs_user
+        select user_id,qw_ext_id,recharge_balance,sex,is_buy,`level`,course_ma_open_id,is_push,is_add_qw,source,login_device,is_individuation_push,store_open_id,password,jpush_id, is_vip,vip_start_date,vip_end_date,vip_level,vip_status,nick_name,integral_status, avatar, phone, integral,sign_num, status, tui_user_id, tui_time, tui_user_count, ma_open_id, mp_open_id, union_id, is_del, user_code, remark, create_time, update_time, last_ip, balance,is_weixin_auth,parent_id,qw_user_id,app_id,company_id,company_user_id,is_promoter,now_money,brokerage_price,spread_user_id, spread_time,pay_count, spread_count,user_type,invited_by_sales_id,app_open_id,apple_key from fs_user
     </sql>
 
     <select id="selectFsUserList" parameterType="FsUser" resultMap="FsUserResult">
@@ -95,6 +96,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="registerCode != null   and registerCode != '' ">and register_code = #{registerCode}</if>
             <if test="source != null  and source != '' ">and source = #{source}</if>
             <if test="isShow != null  ">and is_show = #{isShow}</if>
+            <if test="rechargeBalance != null  ">and recharge_balance = #{rechargeBalance}</if>
             <!--<if test="qwRepeat != null  ">and qw_repeat = #{qwRepeat}</if>
             <if test="userRepeat != null  ">and user_repeat = #{userRepeat}</if>-->
 <!--            <if test="payOrder != null  ">and pay_order = #{payOrder}</if>-->
@@ -713,6 +715,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="invitedBySalesId != null">invited_by_sales_id = #{invitedBySalesId},</if>
             <if test="appOpenId != null">app_open_id = #{appOpenId},</if>
             <if test="appleKey != null">apple_key = #{appleKey},</if>
+            <if test="rechargeBalance != null">recharge_balance = #{rechargeBalance},</if>
         </trim>
         where user_id = #{userId}
     </update>