소스 검색

提现修改

liweifan 3 년 전
부모
커밋
c0aa93fc5e

+ 4 - 4
cooleshow-common/src/main/java/com/yonge/cooleshow/common/constant/SysConfigConstant.java

@@ -184,25 +184,25 @@ public interface SysConfigConstant {
      */
     String PIANO_ROOM_MIN_TIME = "piano_room_min_time";
     /***
-     * 提现开关 0 关闭 1开启
+     * 结算开关 0 关闭 1开启
      * @author liweifan
      * @updateTime 2022/3/24 17:15
      */
     String WITHDRAWAL_SWITCH = "withdrawal_switch";
     /***
-     * 提现审核开关 0 关闭 1开启
+     * 结算审核开关 0 关闭 1开启
      * @author liweifan
      * @updateTime 2022/3/24 17:15
      */
     String WITHDRAWAL_AUTH_SWITCH = "withdrawal_auth_switch";
     /***
-     * 提现审核额度(小于该额度免审核提现)
+     * 结算审核额度(小于该额度免审核结算)
      * @author liweifan
      * @updateTime 2022/3/24 17:15
      */
     String WITHDRAWAL_AUTH_FEE = "withdrawal_auth_fee";
     /***
-     * 一天最多提现次数
+     * 一天最多结算次数
      * @author liweifan
      * @updateTime 2022/3/24 17:15
      */

+ 1 - 1
cooleshow-common/src/main/java/com/yonge/cooleshow/common/enums/CacheNameEnum.java

@@ -22,7 +22,7 @@ public enum CacheNameEnum implements BaseEnum<String, CacheNameEnum> {
 
     LOCK_EXECUTE_ORDER("用户下单/付款/取消订单锁"),
     LOCK_CHANGE_ACCOUNT("账户变更锁"),
-    LOCK_WITHDRAWAL("锁用户提现"),
+    LOCK_WITHDRAWAL("锁用户结算"),
 
 
     ;

+ 22 - 31
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/UserWithdrawalController.java

@@ -6,6 +6,9 @@ import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dto.excel.UserWithdrawalExport;
 import com.yonge.cooleshow.biz.dal.dto.req.AuthOperaReq;
+import com.yonge.cooleshow.biz.dal.support.DistributedLock;
+import com.yonge.cooleshow.common.enums.CacheNameEnum;
+import com.yonge.toolset.base.exception.BizException;
 import com.yonge.toolset.mybatis.support.PageUtil;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
@@ -13,6 +16,7 @@ import com.yonge.toolset.base.page.PageInfo;
 import com.yonge.toolset.utils.easyexcel.*;
 import io.swagger.annotations.*;
 import org.apache.commons.beanutils.BeanUtils;
+import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -26,6 +30,7 @@ import springfox.documentation.annotations.ApiIgnore;
 import javax.validation.Valid;
 import java.lang.reflect.InvocationTargetException;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 @RestController
 @RequestMapping("/userWithdrawal")
@@ -35,7 +40,8 @@ public class UserWithdrawalController extends BaseController {
     private SysUserFeignService sysUserFeignService;
     @Autowired
     private UserWithdrawalService userWithdrawalService;
-
+    @Autowired
+    private RedissonClient redissonClient;
     /**
      * 查询单条
      */
@@ -70,13 +76,6 @@ public class UserWithdrawalController extends BaseController {
             UserWithdrawalExport export = new UserWithdrawalExport();
             try {
                 BeanUtils.copyProperties(export, o);
-                /*StringBuffer buffer = new StringBuffer(export.getId().toString());
-                buffer.append(export.getUserId());
-                buffer.append(export.getAmount().setScale(2, RoundingMode.HALF_UP));
-                buffer.append(export.getPlantformFee().setScale(2, RoundingMode.HALF_UP));
-                buffer.append(export.getActualAmount().setScale(2, RoundingMode.HALF_UP));
-                String s = DigestUtils.md5DigestAsHex(buffer.toString().getBytes());
-                export.setSign(s);*/
                 list.add(export);
             } catch (IllegalAccessException e) {
                 e.printStackTrace();
@@ -97,7 +96,7 @@ public class UserWithdrawalController extends BaseController {
         if (user == null || null == user.getId()) {
             return failed(HttpStatus.FORBIDDEN, "请登录");
         }
-        return userWithdrawalService.doAuth(authOperaReq, user);
+        return userWithdrawalService.batchAuth(authOperaReq, user);
     }
 
     @ApiImplicitParams({
@@ -115,29 +114,21 @@ public class UserWithdrawalController extends BaseController {
         if (user == null || null == user.getId()) {
             return failed(HttpStatus.FORBIDDEN, "请登录");
         }
-        return userWithdrawalService.transferAccount(authOperaReq, user);
-    }
 
-    /**
-     * 导入
-     */
-    /*@PostMapping("/importExcel")
-    @ApiOperation(value = "导入", notes = "传入file")
-    @PreAuthorize("@pcs.hasPermissions('userWithdrawal/importExcel')")
-    public HttpResponseResult<List<ErrMsg>> importExcel(@RequestParam("file") MultipartFile file) {
-        if (null == file) {
-            return HttpResponseResult.failed("请上传文件");
-        }
-        SysUser user = sysUserFeignService.queryUserInfo();
-        if (user == null || null == user.getId()) {
-            return failed(HttpStatus.FORBIDDEN, "请登录");
-        }
         try {
-            ExcelDataReader<UserWithdrawalExport> reader = ExcelUtils.getReader(UserWithdrawalExport.class, file);
-            userWithdrawalService.importExcel(reader.getDataList(), user.getId());
-            return HttpResponseResult.succeed();
-        } catch (ExcelException e) {
-            return HttpResponseResult.failed(BizHttpStatus.IMPORT.getCode(), e.getErrMsgList(), BizHttpStatus.IMPORT.getMsg());
+            HttpResponseResult<Boolean> res = DistributedLock.of(redissonClient)
+                    .runIfLockCanGet(CacheNameEnum.LOCK_WITHDRAWAL.getRedisKey(authOperaReq.getId())
+                            , () -> userWithdrawalService.transferAccount(authOperaReq, user), 60L, TimeUnit.SECONDS);
+            if(null != res){
+                return res;
+            }else{
+                return HttpResponseResult.failed("转账失败");
+            }
+        } catch (BizException e) {
+            return HttpResponseResult.failed(e.getMessage());
+        }  catch (Exception e) {
+            e.printStackTrace();
+            return HttpResponseResult.failed("转账失败");
         }
-    }*/
+    }
 }

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/UserWithdrawalDao.java

@@ -42,7 +42,7 @@ public interface UserWithdrawalDao extends BaseMapper<UserWithdrawal> {
     List<UserWithdrawalVo> selectList(@Param("param") TeacherWithdrawalSearch teacherWithdrawal);
 
     /**
-     * 查询用户今天发起的提现次数
+     * 查询用户今天发起的结算次数
      *
      * @param userId
      * @return

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/sdk/WithdrawSdk.java

@@ -204,7 +204,7 @@ public class WithdrawSdk {
         } catch (IOException e) {
             logger.info("发送失败:{}", e);
         }
-        return HttpResponseResult.failed("提现失败");
+        return HttpResponseResult.failed("结算失败");
     }
 
     /**

+ 4 - 9
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/UserWithdrawalService.java

@@ -13,6 +13,7 @@ import com.yonge.cooleshow.biz.dal.entity.UserWithdrawal;
 import com.yonge.cooleshow.biz.dal.vo.res.WithdrawalInfoRes;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.toolset.utils.easyexcel.ExcelDataReaderProperty;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
@@ -86,15 +87,9 @@ public interface UserWithdrawalService extends IService<UserWithdrawal> {
      * @param errMsg
      */
     void contractCallback(String status, String serialNo, String url, String errMsg);
-    /***
-     * 审核
-     * @author liweifan
-     * @param: authOperaReq
-     * @param: sysUser
-     * @updateTime 2022/3/21 14:21
-     * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<java.lang.Boolean>
-     */
-    HttpResponseResult<Boolean> doAuth(AuthOperaReq authOperaReq, SysUser user);
+
+    @Transactional(rollbackFor = Exception.class)
+    HttpResponseResult<Boolean> batchAuth(AuthOperaReq authOperaReq, SysUser sysUser);
 
     /**
      * 继续转账

+ 78 - 54
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserWithdrawalServiceImpl.java

@@ -10,6 +10,7 @@ import com.yonge.cooleshow.biz.dal.entity.UserWithdrawalCallback;
 import com.yonge.cooleshow.biz.dal.enums.*;
 import com.yonge.cooleshow.biz.dal.sdk.WithdrawSdk;
 import com.yonge.cooleshow.biz.dal.service.*;
+import com.yonge.cooleshow.biz.dal.support.DistributedLock;
 import com.yonge.cooleshow.common.constant.SysConfigConstant;
 import com.yonge.cooleshow.biz.dal.dao.UserBankCardDao;
 import com.yonge.cooleshow.biz.dal.dto.UserAccountRecordDto;
@@ -19,6 +20,7 @@ import com.yonge.cooleshow.biz.dal.vo.UserAccountVo;
 import com.yonge.cooleshow.biz.dal.vo.UserBankCardVo;
 import com.yonge.cooleshow.biz.dal.vo.res.WithdrawalInfoRes;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import com.yonge.cooleshow.common.enums.CacheNameEnum;
 import com.yonge.cooleshow.common.service.IdGeneratorService;
 import com.yonge.toolset.base.exception.BizException;
 import com.yonge.toolset.base.string.StringPool;
@@ -26,6 +28,7 @@ import com.yonge.toolset.base.util.StringUtil;
 import com.yonge.toolset.payment.base.enums.TradeStatusEnum;
 import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 import com.yonge.toolset.utils.string.ValueUtil;
+import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +41,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 
 @Service
@@ -60,6 +64,8 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
     private SysUserContractRecordDao userContractRecordDao;
     @Autowired
     private IdGeneratorService idGeneratorService;
+    @Autowired
+    private RedissonClient redissonClient;
 
     @Override
     public UserWithdrawalVo detail(Long id) {
@@ -108,18 +114,18 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
         if (StringUtil.isEmpty(user.getIdCardNo())) {
             return HttpResponseResult.failed("用户未实名认证");
         }
-        //校验--提现开关
+        //校验--结算开关
         String withdrawalSwitch = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_SWITCH);
         if (!YesOrNoEnum.YES.getCode().toString().equals(withdrawalSwitch)) {
-            return HttpResponseResult.failed("当前不允许提现");
+            return HttpResponseResult.failed("当前不允许结算");
         }
-        //校验--判断今天提现次数
+        //校验--判断今天结算次数
         String withdrawalMaxCount = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_MAX_COUNT);
         Integer count = getNowDayWithdrawalCount(user.getId());
         if (count >= Integer.parseInt(withdrawalMaxCount)) {
-            return HttpResponseResult.failed("达到当天提现最大次数");
+            return HttpResponseResult.failed("达到当天结算最大次数");
         }
-        //校验--校验金额(金额不能小于手续费,手续费从提现金额里面扣除)
+        //校验--校验金额(金额不能小于手续费,手续费从结算金额里面扣除)
         BigDecimal withdrawalServiceFee = getWithdrawalServiceFee();
         BigDecimal actualAmount = withdrawalReq.getAmountWithdrawal().subtract(withdrawalServiceFee);
         if (actualAmount.compareTo(BigDecimal.ZERO) <= 0) {
@@ -135,9 +141,9 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
         if (null == bankCardVo) {
             return HttpResponseResult.failed("未找到用户绑卡信息");
         }
-        //提现审核开关
+        //结算审核开关
         String withdrawalAuthSwitch = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_AUTH_SWITCH);
-        //提现审核额度(小于该额度免审核提现)
+        //结算审核额度(小于该额度免审核结算)
         String withdrawalAuthFee = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_AUTH_FEE);
 
         //插入用户结算表
@@ -179,68 +185,86 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public HttpResponseResult<Boolean> doAuth(AuthOperaReq authOperaReq, SysUser sysUser) {
+    public HttpResponseResult<Boolean> batchAuth(AuthOperaReq authOperaReq, SysUser sysUser) {
         Long[] ids = StringUtil.toLongArray(StringPool.COMMA, authOperaReq.getId());
         for (Long id : ids) {
-            UserWithdrawalVo build = detail(id);
-            if (null == build || !AuthStatusEnum.DOING.equals(build.getAuthStatus())) {
-                continue;
+            AuthOperaReq param = new AuthOperaReq();
+            param.setId(id.toString());
+            param.setReason(authOperaReq.getReason());
+            param.setPass(authOperaReq.getPass());
+
+            try {
+                DistributedLock.of(redissonClient)
+                        .runIfLockCanGet(CacheNameEnum.LOCK_WITHDRAWAL.getRedisKey(id.toString())
+                                , () -> doAuth(param, sysUser), 60L, TimeUnit.SECONDS);
+            } catch (BizException e) {
+                return HttpResponseResult.failed(e.getMessage());
+            } catch (Exception e) {
+                e.printStackTrace();
+                return HttpResponseResult.failed("结算失败");
             }
-            build.setAuthStatus(authOperaReq.getPass() ? AuthStatusEnum.PASS : AuthStatusEnum.UNPASS);
-            build.setReason(authOperaReq.getReason());
-            build.setAuthUserId(sysUser.getId());
-            build.setUpdateTime(new Date());
-            build.setAuthTime(new Date());
-
-            //请求三方
-            SysUser withdrawalUser = sysUserService.findUserById(build.getUserId());
-            Boolean flag = false;
-            if (authOperaReq.getPass()) {
-                //请求三方接口
-
-                //交易流水号生成
-                Long transNo = idGeneratorService.generatorId("withdrawNo");
+        }
+        return HttpResponseResult.succeed();
+    }
 
-                HttpResponseResult<Boolean> withdraw = withdrawSdk.withdraw(
-                        transNo.toString(), build.getRealName(), build.getPhone(), withdrawalUser.getIdCardNo(),
-                        build.getActualAmount().multiply(new BigDecimal("100")).intValue(), build.getBankCard(), null
-                );
-                if (withdraw.getStatus() && withdraw.getData()) {
-                    build.setTradeStatus(TradeStatusEnum.pending);
-                    build.setTransNo(transNo.toString());
-                    flag = true;
-                } else {
-                    build.setTradeStatus(TradeStatusEnum.failed);
-                    build.setErrorMsg("请求三方接口返回失败");
-                }
-            }
-            //修改系统中账户
-            if (!authOperaReq.getPass() || !flag) {
-                //审核不通过,账户解冻
-                UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
-                        build.getUserId(), build.getAmount(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
-                        build.getId(), "老师结算", null
-                );
-                accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN_BACK);
-                accountRecordDto.setSaveRecord(false);
-                userAccountService.accountChange(accountRecordDto);
+    @Transactional(rollbackFor = Exception.class)
+    public void doAuth(AuthOperaReq authOperaReq, SysUser sysUser) {
+        UserWithdrawalVo build = detail(Long.parseLong(authOperaReq.getId()));
+        if (null == build || !AuthStatusEnum.DOING.equals(build.getAuthStatus())) {
+            return;
+        }
+        build.setAuthStatus(authOperaReq.getPass() ? AuthStatusEnum.PASS : AuthStatusEnum.UNPASS);
+        build.setReason(authOperaReq.getReason());
+        build.setAuthUserId(sysUser.getId());
+        build.setUpdateTime(new Date());
+        build.setAuthTime(new Date());
+
+        //请求三方
+        SysUser withdrawalUser = sysUserService.findUserById(build.getUserId());
+        Boolean flag = false;
+        if (authOperaReq.getPass()) {
+            //请求三方接口
+            //交易流水号生成
+            Long transNo = idGeneratorService.generatorId("withdrawNo");
+
+            HttpResponseResult<Boolean> withdraw = withdrawSdk.withdraw(
+                    transNo.toString(), build.getRealName(), build.getPhone(), withdrawalUser.getIdCardNo(),
+                    build.getActualAmount().multiply(new BigDecimal("100")).intValue(), build.getBankCard(), null
+            );
+            if (withdraw.getStatus() && withdraw.getData()) {
+                build.setTradeStatus(TradeStatusEnum.pending);
+                build.setTransNo(transNo.toString());
+                flag = true;
+            } else {
+                build.setTradeStatus(TradeStatusEnum.failed);
+                build.setErrorMsg("请求三方接口返回失败");
             }
-            updateById(build);
         }
-        return HttpResponseResult.succeed();
+        //修改系统中账户
+        if (!authOperaReq.getPass() || !flag) {
+            //审核不通过,账户解冻
+            UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
+                    build.getUserId(), build.getAmount(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
+                    build.getId(), "老师结算", null
+            );
+            accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN_BACK);
+            accountRecordDto.setSaveRecord(false);
+            userAccountService.accountChange(accountRecordDto);
+        }
+        updateById(build);
     }
 
     @Override
     public HttpResponseResult<Boolean> transferAccount(AuthOperaReq authOperaReq, SysUser user) {
         UserWithdrawalVo detail = detail(Long.parseLong(authOperaReq.getId()));
         if (detail == null) {
-            return HttpResponseResult.failed("提现记录不存在");
+            return HttpResponseResult.failed("结算记录不存在");
         }
         if (!AuthStatusEnum.PASS.equals(detail.getAuthStatus())) {
-            return HttpResponseResult.failed("提现记录未审核");
+            return HttpResponseResult.failed("结算记录未审核");
         }
         if (TradeStatusEnum.succeeded.equals(detail.getTradeStatus())) {
-            return HttpResponseResult.failed("提现已经交易成功");
+            return HttpResponseResult.failed("结算已经交易成功");
         }
 
         //交易流水号生成
@@ -316,7 +340,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
     }
 
     /**
-     * 查询用户今天发起的提现次数
+     * 查询用户今天发起的结算次数
      *
      * @param userId
      * @return

+ 2 - 2
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/UserWithdrawalController.java

@@ -74,13 +74,13 @@ public class UserWithdrawalController extends BaseController {
             if(null != res){
                 return res;
             }else{
-                return HttpResponseResult.failed("提现失败");
+                return HttpResponseResult.failed("结算失败");
             }
         } catch (BizException e) {
             return HttpResponseResult.failed(e.getMessage());
         }  catch (Exception e) {
             e.printStackTrace();
-            return HttpResponseResult.failed("提现失败");
+            return HttpResponseResult.failed("结算失败");
         }
     }