Bladeren bron

添加积分明细

yuhongqi 1 dag geleden
bovenliggende
commit
c5772ecd61

+ 1 - 0
fs-service/src/main/java/com/fs/his/enums/FsUserIntegralLogTypeEnum.java

@@ -33,6 +33,7 @@ public enum FsUserIntegralLogTypeEnum {
     TYPE_23(23,"管理员添加"),
     TYPE_24(24, "付费课程订阅"),
     TYPE_25(25, "直播完课积分"),
+    TYPE_26(26, "直播红包积分"),
     ;
 
 

+ 6 - 0
fs-service/src/main/java/com/fs/hisStore/domain/FsStoreAfterSalesScrm.java

@@ -150,4 +150,10 @@ public class FsStoreAfterSalesScrm extends BaseEntity
     @TableField(exist = false)
     private String hfOrderCode;
 
+    /**
+     * 用于查询银行交易流水
+     */
+    @TableField(exist = false)
+    private String bankTransactionId;
+
 }

+ 3 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreAfterSalesScrmMapper.java

@@ -102,6 +102,9 @@ public interface FsStoreAfterSalesScrmMapper
             "<if test =\"maps.hfOrderCode != null and  maps.hfOrderCode!='' \"> " +
               "and fsps.pay_code = #{maps.hfOrderCode} " +
             "</if>" +
+            "<if test =\"maps.bankTransactionId != null and  maps.bankTransactionId!='' \"> " +
+              "and fsps.bank_transaction_id = #{maps.bankTransactionId} " +
+            "</if>" +
             "<if test = 'maps.status != null    '> " +
             "and s.status = #{maps.status} " +
             "</if>" +

+ 9 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsUserScrmMapper.java

@@ -124,6 +124,15 @@ public interface FsUserScrmMapper
     @Update("update fs_user set pay_count=pay_count+1" +
             " where user_id=#{userId}")
     int incPayCount(Long userId);
+    
+    /**
+     * 增加用户余额
+     * @param userId 用户ID
+     * @param integral 增加的积分
+     * @return 结果
+     */
+    @Update("update fs_user set integral = IFNULL(integral, 0) + #{integral} where user_id = #{userId}")
+    int incrIntegral(@Param("userId") Long userId, @Param("integral") BigDecimal integral);
     @Select("select * from fs_user where phone=#{phone}")
     FsUserScrm selectFsUserByPhone(String phone);
 

+ 36 - 1
fs-service/src/main/java/com/fs/live/service/impl/LiveRedConfServiceImpl.java

@@ -8,8 +8,13 @@ import com.fs.common.constant.LiveKeysConstant;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
 import com.fs.common.utils.DateUtils;
+import com.fs.his.domain.FsUserIntegralLogs;
+import com.fs.his.enums.FsUserIntegralLogTypeEnum;
+import com.fs.his.mapper.FsUserIntegralLogsMapper;
 import com.fs.his.mapper.FsUserMapper;
 import com.fs.his.service.IFsUserService;
+import com.fs.hisStore.mapper.FsUserIntegralLogsScrmMapper;
+import com.fs.hisStore.mapper.FsUserScrmMapper;
 import com.fs.live.domain.*;
 import com.fs.live.mapper.LiveMapper;
 import com.fs.live.mapper.LiveRedConfMapper;
@@ -57,6 +62,11 @@ public class LiveRedConfServiceImpl implements ILiveRedConfService {
     private LiveRewardRecordMapper liveRewardRecordMapper;
     @Autowired
     private ILiveAutoTaskService liveAutoTaskService;
+    @Autowired
+    private FsUserScrmMapper fsUserScrmMapper;
+    @Autowired
+    private FsUserIntegralLogsMapper fsUserIntegralLogsMapper;
+
 
     private static final String REDPACKET_REMAININGLOTS_KEY = "live:red:remainingLots:";
     private static final String REDPACKET_REMAININGNUM_KEY = "live:red:remainingNum:";
@@ -223,7 +233,7 @@ public class LiveRedConfServiceImpl implements ILiveRedConfService {
     @Transactional
     public R claimRedPacket(RedPO red) {
         // String claimKey = REDPACKET_CLAIM_KEY + red.getRedId();
-        Object o = redisCache.hashGet(String.format(LiveKeysConstant.LIVE_HOME_PAGE_CONFIG_RED, red.getLiveId(), red.getRedId()), String.valueOf(red.getUserId()));
+        Object o = redisCache.hashGet(String.format(LiveKeysConstant. LIVE_HOME_PAGE_CONFIG_RED, red.getLiveId(), red.getRedId()), String.valueOf(red.getUserId()));
         if (ObjectUtil.isNotEmpty(o)) {
             return R.error("您已经领取过红包了!");
         }
@@ -270,6 +280,31 @@ public class LiveRedConfServiceImpl implements ILiveRedConfService {
         record.setUserId(red.getUserId());
         record.setIntegral(integral);
         record.setCreateTime(new Date());
+        // 更新用户余额
+        BigDecimal balanceAmount = BigDecimal.valueOf(integral);
+        int updateResult = fsUserScrmMapper.incrIntegral(red.getUserId(), balanceAmount);
+        if (updateResult <= 0) {
+            log.error("更新用户余额失败,userId: {}, balance: {}", red.getUserId(), balanceAmount);
+            return R.error("更新用户余额失败");
+        }
+
+        // 查询用户当前余额
+        com.fs.hisStore.domain.FsUserScrm user = fsUserScrmMapper.selectFsUserById(red.getUserId());
+        Long currentIntegral = user.getIntegral() != null ? user.getIntegral() : 0L;
+        Long newIntegral = currentIntegral + integral;
+
+        // 添加余额变动记录
+        FsUserIntegralLogs integralLogs = new FsUserIntegralLogs();
+        integralLogs.setUserId(red.getUserId());
+        integralLogs.setIntegral(integral);
+        integralLogs.setBalance(newIntegral);
+        integralLogs.setLogType(FsUserIntegralLogTypeEnum.TYPE_26.getValue()); // 3表示分享获得积分,可根据实际情况调整
+        integralLogs.setBusinessId(String.valueOf(red.getRedId()));
+        integralLogs.setBusinessType(Math.toIntExact(conf.getRedId())); // 1表示直播红包
+        integralLogs.setStatus(0);
+        integralLogs.setCreateTime(new Date());
+        fsUserIntegralLogsMapper.insertFsUserIntegralLogs(integralLogs);
+
         // WebSocket 通知
         //String msg = String.format("用户 %d 抢到了红包 %d,获得 %d 芳华币", userId, redId, integral);
         //WebSocketServer.notifyUsers(msg);

+ 6 - 0
fs-service/src/main/resources/mapper/live/LiveAfterSalesMapper.xml

@@ -80,6 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
         <where>
             <if test="hfOrderCode != null and hfOrderCode != ''"> and lop.pay_code = #{hfOrderCode}</if>
+            <if test="bankTransactionId != null and bankTransactionId != ''"> and lop.bank_transaction_id = #{bankTransactionId}</if>
             <if test="liveId != null and liveId != ''"> and las.live_id = #{liveId}</if>
             <if test="companyUserNickName != null and companyUserNickName != ''"> and cu.nick_name like concat(#{companyUserNickName},'%')</if>
             <if test="storeId != null and storeId != ''"> and las.store_id = #{storeId}</if>
@@ -109,6 +110,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="companyUserId != null "> and las.company_user_id = #{companyUserId}</if>
             <if test="deptId != null "> and cu.dept_id = #{deptId}</if>
             <if test="userPhone != null "> and lo.user_phone like concat(#{userPhone},'%')</if>
+            <if test="createTimeBegin != null and createTimeBegin != ''"> and date_format(las.create_time,'%y%m%d') &gt;= date_format(#{createTimeBegin},'%y%m%d')</if>
+            <if test="createTimeEnd != null and createTimeEnd != ''"> and date_format(las.create_time,'%y%m%d') &lt;= date_format(#{createTimeEnd},'%y%m%d')</if>
         </where>
         <if test="productName != null and productName != ''">
         group by las.id
@@ -133,6 +136,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
         where 1=1 and las.is_del = 0 and lo.status = -2 and lop.bank_transaction_id is not null
             <if test="hfOrderCode != null and hfOrderCode != ''"> and lop.pay_code = #{hfOrderCode}</if>
+            <if test="bankTransactionId != null and bankTransactionId != ''"> and lop.bank_transaction_id = #{bankTransactionId}</if>
             <if test="liveId != null and liveId != ''"> and las.live_id = #{liveId}</if>
             <if test="companyUserNickName != null and companyUserNickName != ''"> and cu.nick_name like concat(#{companyUserNickName},'%')</if>
             <if test="storeId != null and storeId != ''"> and las.store_id = #{storeId}</if>
@@ -162,6 +166,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="companyUserId != null "> and las.company_user_id = #{companyUserId}</if>
             <if test="deptId != null "> and cu.dept_id = #{deptId}</if>
             <if test="userPhone != null "> and lo.user_phone like concat(#{userPhone},'%')</if>
+            <if test="createTimeBegin != null and createTimeBegin != ''"> and date_format(las.create_time,'%y%m%d') &gt;= date_format(#{createTimeBegin},'%y%m%d')</if>
+            <if test="createTimeEnd != null and createTimeEnd != ''"> and date_format(las.create_time,'%y%m%d') &lt;= date_format(#{createTimeEnd},'%y%m%d')</if>
 
         <if test="productName != null and productName != ''">
         group by las.id