Prechádzať zdrojové kódy

优化提现流水判断

dos 2 mesiacov pred
rodič
commit
1cbd0c03d4

+ 1 - 1
game-business/src/main/java/com/game/business/domain/FinTranRecord.java

@@ -232,7 +232,7 @@ private static final long serialVersionUID=1L;
     private Long uid;
 
     /**  是否已满足提现 */
-    @ApiModelProperty(value = " 是否已满足提现 0:未满足  1:已满足")
+    @ApiModelProperty(value = " 是否已满足提现 0:未满足  1:已满足  2:已作废")
     @Excel(name = " 是否已满足提现")
     @TableField(value = "withdraw_flag")
     private Integer withdrawFlag;

+ 1 - 0
game-business/src/main/java/com/game/business/mapper/FinTranRecordMapper.java

@@ -84,6 +84,7 @@ public interface FinTranRecordMapper extends BaseMapper<FinTranRecord> {
     List<FinTranVo> selectTranList(FinTranDto finTranDto);
 
     Double sumUserTran(@Param("type1") Integer type1, @Param("type3s") String type3s, @Param("userId") Long userId, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate, @Param("withdrawFlag") Integer withDrawFlag);
+    Double sumUserRechareTran(@Param("userId") Long userId, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
 
     Map<String,Double> selectExChangeSum(FinTranRecordDTO recordDTO);
 }

+ 5 - 0
game-business/src/main/java/com/game/business/service/IAppUserService.java

@@ -101,4 +101,9 @@ public interface IAppUserService extends IService<AppUser> {
     Map<String, BigDecimal> getUserCount(Long userId);
 
     List<OffLineUserVo> selectOffLineUser();
+
+    /**
+     * 获取用户资产
+     * */
+    AppUser getUserAsset(Long userId);
 }

+ 3 - 0
game-business/src/main/java/com/game/business/service/IFinTranRecordService.java

@@ -15,6 +15,7 @@ import com.game.business.dto.FinTranRecordDTO;
 import com.game.business.vo.FinTranVo;
 import com.game.common.core.domain.HttpRet;
 import com.game.common.core.domain.R;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 消费记录Service接口
@@ -110,5 +111,7 @@ public interface IFinTranRecordService extends IService<FinTranRecord> {
 
     Double sumUserTran(Integer type1, String type3s, Long userId, Date beginDate,Date endDate,Integer withDrawFlag);
 
+    Double sumUserRechareTran(Long userId,Date beginDate,Date endDate);
+
     Map<String,Double> selectExChangeSum(FinTranRecordDTO recordDTO);
 }

+ 6 - 4
game-business/src/main/java/com/game/business/service/impl/AppUserCountDividendServiceImpl.java

@@ -186,11 +186,13 @@ public class AppUserCountDividendServiceImpl extends ServiceImpl<AppUserCountDiv
             return HttpRet.fail("发放失败,不存在或已发放");
         }*/
         AppUser user = appUserService.selectAppUserByUserid(sendUserId);
-        if(user.getDiamondCoin() < dividendList.stream().mapToDouble(e->e.getDiamondCoin()).sum()){
-            return HttpRet.fail("发放失败,余额不足");
+        double totalAmount = dividendList.stream().mapToDouble(e->e.getDiamondCoin()).sum();
+        if(user.getDiamondCoin() < totalAmount){
+            return HttpRet.fail("发放失败,余额不足,还差" + (totalAmount - user.getDiamondCoin()));
         }
-        if(user.getCoin() < dividendList.stream().mapToDouble(e->e.getCoin()).sum()){
-            return HttpRet.fail("发放失败,金币不足");
+        double coinTotal = dividendList.stream().mapToDouble(e->e.getCoin()).sum();
+        if(user.getCoin() < coinTotal){
+            return HttpRet.fail("发放失败,金币不足, 还差" + (coinTotal - user.getCoin()));
         }
         List<Long> userIds = new ArrayList<>();
         userIds.add(sendUserId);

+ 22 - 0
game-business/src/main/java/com/game/business/service/impl/AppUserServiceImpl.java

@@ -259,6 +259,28 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
         return appUserMapper.selectOffLineUser();
     }
 
+    @Override
+    @DataSource(DataSourceType.SLAVE)
+    public AppUser getUserAsset(Long userId) {
+        RLock rLock = redisson.getLock("app_user_amount_".concat(String.valueOf(userId)));
+        boolean tryLock = false;
+        try {
+            tryLock = rLock.tryLock(10L, 10L, TimeUnit.SECONDS); //等待10秒 最多持有锁10秒
+            if(tryLock){
+                AppUser appUser = selectAppUserByUserid(userId);
+                return appUser;
+            }
+            rLock.unlock();
+        }catch (Exception e){
+            log.info("获取用户资产出错:{}",e);
+            return null;
+        }
+        if(null != rLock){
+            rLock.unlock();
+        }
+        return null;
+    }
+
     @Override
     @DataSource(DataSourceType.SLAVE)
     public ApiUserInfoVo getUserInfo(Long userId) {

+ 6 - 0
game-business/src/main/java/com/game/business/service/impl/FinTranRecordServiceImpl.java

@@ -439,6 +439,12 @@ public class FinTranRecordServiceImpl extends ServiceImpl<FinTranRecordMapper, F
         return finTranRecordMapper.sumUserTran(type1,type3s,userId,beginDate,endDate,withDrawFlag);
     }
 
+    @Override
+    @DataSource(DataSourceType.SLAVE)
+    public Double sumUserRechareTran(Long userId, Date beginDate, Date endDate) {
+        return finTranRecordMapper.sumUserRechareTran(userId,beginDate,endDate);
+    }
+
     @Override
     @DataSource(DataSourceType.SLAVE)
     public Map<String, Double> selectExChangeSum(FinTranRecordDTO recordDTO) {

+ 32 - 5
game-business/src/main/java/com/game/business/task/AppUserCountTask.java

@@ -604,7 +604,7 @@ public class AppUserCountTask {
                 int i = 1;
                 List<FinTranRecord> dealTranList = new ArrayList<>();
                 for (FinTranRecord tranRecord : userChargeList) {
-                    dealTranList.add(tranRecord);
+//                    dealTranList.add(tranRecord);
                     if (null == beginDate){
                         beginDate = tranRecord.getCreateTime();
                     }
@@ -613,13 +613,13 @@ public class AppUserCountTask {
                     }else{
                         endDate = new Date();
                     }
-                    money += tranRecord.getDiamondCoinChange();
+                    double curMoney = tranRecord.getDiamondCoinChange();
                     //查询赠送金额
                     AppUsersCharge appUsersCharge = appUsersChargeService.selectByOrderNo(String.valueOf(tranRecord.getTranGroupId()));
                     if(null != appUsersCharge && null != appUsersCharge.getCoinGive()){
-                        money += appUsersCharge.getCoinGive().doubleValue();
+                        curMoney += appUsersCharge.getCoinGive().doubleValue();
                     }
-                    dealTran(dealTranList,beginDate,endDate,uid,money);
+                    dealTran(dealTranList,beginDate,endDate,uid,money,curMoney,tranRecord);
                     i++;
                 }
 
@@ -628,10 +628,37 @@ public class AppUserCountTask {
         }
     }
 
-    private void dealTran(List<FinTranRecord> userChargeList,Date beginDate,Date endDate,Long userId,Double money){
+    private void dealTran(List<FinTranRecord> userChargeList,Date beginDate,Date endDate,Long userId,Double money,Double curMoney,FinTranRecord tranRecord){
         //查询用户这段时间流水记录
         String type3s = FinTranType3.CONSUM_GAME_ANCHOR_ZHUANPAN.getType() + "," + FinTranType3.CONSUM_GAME_ANCHOR_WITHDRAW.getType();
         List<FinTranRecord> curTranList = finTranRecordService.selectUserTran(null,type3s,userId,beginDate,endDate,0);
+        //获取用户资产
+        AppUser appUser = appUserService.getUserAsset(userId);
+        //资产为0 则充值两倍流水条件设为已作废
+        if(null != appUser && appUser.getDiamondCoin().doubleValue() < 1){
+            //更新为已满足提现
+//            userChargeList.forEach(e->{
+                FinTranRecord updateTran = new FinTranRecord();
+                updateTran.setId(tranRecord.getId());
+                updateTran.setWithdrawFlag(2);
+                finTranRecordService.updateFinTranRecord(updateTran);
+                log.info("用户{},流水单号:{} 因金额已使用完,该笔订单流水条件已作废",userId,tranRecord.getId());
+//            });
+        }else{
+            //查询本次充值到下次充值期间资产除去返佣后是否已归零
+            double amount  = finTranRecordService.sumUserRechareTran(userId,beginDate,endDate);
+            if(amount < 1){
+                FinTranRecord updateTran = new FinTranRecord();
+                updateTran.setId(tranRecord.getId());
+                updateTran.setWithdrawFlag(2);
+                finTranRecordService.updateFinTranRecord(updateTran);
+                log.info("用户{},流水单号:{} 因充值金额已使用完,该笔订单流水条件已作废",userId,tranRecord.getId());
+            }else{
+                //未归零,则叠加
+                userChargeList.add(tranRecord);
+                money += curMoney;
+            }
+        }
         if(null != curTranList && curTranList.size() > 0){
             //筛选投注流水
             double bettingAmount = curTranList.stream().filter(e->

+ 16 - 0
game-business/src/main/resources/mapper/business/FinTranRecordMapper.xml

@@ -370,6 +370,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="sumUserTran" resultType="java.lang.Double">
         select sum(diamond_coin_change) from fin_tran_record
         <where>
+            currency_type = 4
             <if test="type1 != null">
                 and tran_type1 = #{type1}
             </if>
@@ -397,6 +398,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
 
+    <select id="sumUserRechareTran" resultType="java.lang.Double">
+        select sum(diamond_coin_change) from fin_tran_record
+        <where>
+            currency_type = 4
+            and tran_type3 not in ('20002','5005')
+            and uid = #{userId}
+            <if test="beginDate != null">
+                and create_time &gt;= #{beginDate}
+            </if>
+            <if test="endDate != null">
+                and create_time &lt;= #{endDate}
+            </if>
+        </where>
+    </select>
+
     <select id="selectExChangeSum" parameterType="com.game.business.dto.FinTranRecordDTO" resultType="java.util.Map">
         SELECT
             ifnull( sum( CASE WHEN tran_type1 = '12' THEN coin_change ELSE 0 END ), 0 ) AS coin,