浏览代码

完善老师提现逻辑

weifanli 3 年之前
父节点
当前提交
d69379e990
共有 13 个文件被更改,包括 189 次插入56 次删除
  1. 1 0
      cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/UserWithdrawalController.java
  2. 11 2
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/UserAccountDao.java
  3. 10 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/UserAccountRecordDto.java
  4. 37 35
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/excel/UserWithdrawalExport.java
  5. 1 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/req/WithdrawalReq.java
  6. 2 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/enums/FrozenTypeEnum.java
  7. 8 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/UserBankCardService.java
  8. 12 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentStarServiceImpl.java
  9. 11 7
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserAccountServiceImpl.java
  10. 21 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserBankCardServiceImpl.java
  11. 38 9
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserWithdrawalServiceImpl.java
  12. 14 1
      cooleshow-user/user-biz/src/main/resources/config/mybatis/UserAccountMapper.xml
  13. 23 0
      cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/UserBankCardController.java

+ 1 - 0
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/UserWithdrawalController.java

@@ -82,6 +82,7 @@ public class UserWithdrawalController extends BaseController {
                 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);

+ 11 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/UserAccountDao.java

@@ -40,14 +40,23 @@ public interface UserAccountDao extends BaseMapper<UserAccount>{
 	 */
     Integer frozenChangeAccount(@Param("userId") Long userId, @Param("transAmount") BigDecimal transAmount,@Param("inOrOut") String inOrOut);
 	/***
-	 * 账户变更(冻)
+	 * 账户变更(冻结后交易成功)
 	 * @author liweifan
 	 * @param: userId
 	 * @param: transAmount
 	 * @updateTime 2022/4/7 17:54
 	 * @return: java.lang.Integer
 	 */
-	Integer unfrozenChangeAccount(@Param("userId") Long userId, @Param("transAmount") BigDecimal transAmount,@Param("inOrOut") String inOrOut);
+	Integer frozenDeductChangeAccount(@Param("userId") Long userId, @Param("transAmount") BigDecimal transAmount,@Param("inOrOut") String inOrOut);
+	/***
+	 * 账户变更(冻结后交易退回)
+	 * @author liweifan
+	 * @param: userId
+	 * @param: transAmount
+	 * @updateTime 2022/4/7 17:54
+	 * @return: java.lang.Integer
+	 */
+	Integer frozenBackChangeAccount(@Param("userId") Long userId, @Param("transAmount") BigDecimal transAmount,@Param("inOrOut") String inOrOut);
 	/***
 	 * 账户变更(余额)
 	 * @author liweifan

+ 10 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/UserAccountRecordDto.java

@@ -23,6 +23,8 @@ public class UserAccountRecordDto extends UserAccountRecord {
     @ApiModelProperty(value = "变更冻结类型 NONE 无 FROZEN 冻结 UNFROZEN 解冻")
     private FrozenTypeEnum frozenType;
 
+    private Boolean saveRecord = true;
+
     public UserAccountRecordDto() {
     }
 
@@ -44,6 +46,14 @@ public class UserAccountRecordDto extends UserAccountRecord {
         this.setOrderNo(orderNo);
     }
 
+    public Boolean getSaveRecord() {
+        return saveRecord;
+    }
+
+    public void setSaveRecord(Boolean saveRecord) {
+        this.saveRecord = saveRecord;
+    }
+
     public Long getUserId() {
         return userId;
     }

+ 37 - 35
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/excel/UserWithdrawalExport.java

@@ -24,24 +24,26 @@ public class UserWithdrawalExport {
     @ExcelProperty(value = "提现人编号", index = 2)
     @NotNull(message = "提现人编号不能为空")
     private Long userId;
-    @NotNull(message = "提现金额不能为空")
-    @ExcelProperty(value = "提现金额", index = 3)
-    private BigDecimal amount;
-    @ExcelProperty(value = "发起时间", index = 4)
-    private Date createTime;
-    @ExcelProperty(value = "开户行", index = 5)
+    @ExcelProperty(value = "开户行", index = 3)
     private String bankName;
-    @ExcelProperty(value = "银行卡号", index = 6)
+    @ExcelProperty(value = "银行卡号", index = 4)
     private String bankCard;
+    @NotNull(message = "提现金额不能为空")
+    @ExcelProperty(value = "提现金额", index = 5)
+    private BigDecimal amount;
+    @NotNull(message = "平台服务费不能为空")
+    @ExcelProperty(value = "平台服务费", index = 6)
+    private BigDecimal plantformFee;
     @ExcelProperty(value = "转账金额", index = 7)
     private BigDecimal actualAmount;
-    @ExcelProperty(value = "银行流水号", index = 8)
-    private String bankFlowNo;
+
     @NotNull(message = "提现状态不能为空")
-    @ExcelProperty(value = "提现状态 审核中/通过/不通过", index = 9,converter = WithdrawalStatusConvert.class)
+    @ExcelProperty(value = "提现状态 审核中/通过/不通过", index = 8,converter = WithdrawalStatusConvert.class)
     private AuthStatusEnum status;
-    @ExcelProperty(value = "审核原因", index = 10)
+    @ExcelProperty(value = "审核原因", index = 9)
     private String verifyReason;
+    @ExcelProperty(value = "银行流水号", index = 10)
+    private String bankFlowNo;
     @NotBlank(message = "签名不能为空")
     @ExcelProperty(value = "签名", index = 11)
     private String sign;
@@ -70,22 +72,6 @@ public class UserWithdrawalExport {
         this.userId = userId;
     }
 
-    public BigDecimal getAmount() {
-        return amount;
-    }
-
-    public void setAmount(BigDecimal amount) {
-        this.amount = amount;
-    }
-
-    public Date getCreateTime() {
-        return createTime;
-    }
-
-    public void setCreateTime(Date createTime) {
-        this.createTime = createTime;
-    }
-
     public String getBankName() {
         return bankName;
     }
@@ -102,6 +88,22 @@ public class UserWithdrawalExport {
         this.bankCard = bankCard;
     }
 
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public void setAmount(BigDecimal amount) {
+        this.amount = amount;
+    }
+
+    public BigDecimal getPlantformFee() {
+        return plantformFee;
+    }
+
+    public void setPlantformFee(BigDecimal plantformFee) {
+        this.plantformFee = plantformFee;
+    }
+
     public BigDecimal getActualAmount() {
         return actualAmount;
     }
@@ -126,14 +128,6 @@ public class UserWithdrawalExport {
         this.status = status;
     }
 
-    public String getSign() {
-        return sign;
-    }
-
-    public void setSign(String sign) {
-        this.sign = sign;
-    }
-
     public String getVerifyReason() {
         return verifyReason;
     }
@@ -141,4 +135,12 @@ public class UserWithdrawalExport {
     public void setVerifyReason(String verifyReason) {
         this.verifyReason = verifyReason;
     }
+
+    public String getSign() {
+        return sign;
+    }
+
+    public void setSign(String sign) {
+        this.sign = sign;
+    }
 }

+ 1 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/req/WithdrawalReq.java

@@ -15,6 +15,7 @@ public class WithdrawalReq {
     @NotNull(message = "缺少用户银行卡id")
     @ApiModelProperty("用户银行卡id")
     private Long bankCardId;
+
     @NotNull(message = "缺少提现金额")
     @ApiModelProperty("提现金额")
     private BigDecimal amountWithdrawal;

+ 2 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/enums/FrozenTypeEnum.java

@@ -11,7 +11,8 @@ import com.yonge.cooleshow.common.enums.BaseEnum;
 public enum  FrozenTypeEnum implements BaseEnum<String, FrozenTypeEnum> {
     NONE("无"),
     FROZEN("冻结"),
-    UNFROZEN("解冻");
+    FROZEN_DEDUCT("冻结后交易成功"),
+    FROZEN_BACK("冻结后退回");
     @EnumValue
     private String code;
     private String msg;

+ 8 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/UserBankCardService.java

@@ -36,4 +36,12 @@ public interface UserBankCardService extends IService<UserBankCard>  {
 	 * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<com.yonge.cooleshow.biz.dal.entity.UserBankCard>
 	 */
     HttpResponseResult<UserBankCard> bankCard(UserBankCardDto bankCard);
+	/***
+	 * 解绑银行卡
+	 * @author liweifan
+	 * @param: bankCard
+	 * @updateTime 2022/4/26 20:47
+	 * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<com.yonge.cooleshow.biz.dal.entity.UserBankCard>
+	 */
+    HttpResponseResult<UserBankCard> unBind(UserBankCardDto bankCard);
 }

+ 12 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentStarServiceImpl.java

@@ -3,8 +3,12 @@ package com.yonge.cooleshow.biz.dal.service.impl;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.yonge.cooleshow.biz.dal.entity.TeacherTotal;
+import com.yonge.cooleshow.biz.dal.enums.CacheNameEnum;
 import com.yonge.cooleshow.biz.dal.enums.YesOrNoEnum;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import org.redisson.api.RedissonClient;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.yonge.cooleshow.biz.dal.entity.StudentStar;
 import com.yonge.cooleshow.biz.dal.dao.StudentStarDao;
@@ -13,7 +17,8 @@ import com.yonge.cooleshow.biz.dal.service.StudentStarService;
 
 @Service
 public class StudentStarServiceImpl extends ServiceImpl<StudentStarDao, StudentStar> implements StudentStarService {
-
+    @Autowired
+    private RedissonClient redissonClient;
     @Override
     public StudentStar getByStudentIdAndTeacherId(Long studentId, Long teacherId) {
         return baseMapper.getByStudentIdAndTeacherId(studentId, teacherId);
@@ -22,17 +27,23 @@ public class StudentStarServiceImpl extends ServiceImpl<StudentStarDao, StudentS
     @Override
     public HttpResponseResult<Boolean> starOrUnStar(Long studentId, Long teacherId, YesOrNoEnum starStatus) {
         StudentStar studentStar = getByStudentIdAndTeacherId(studentId, teacherId);
+        TeacherTotal total = (TeacherTotal) redissonClient.getBucket(CacheNameEnum.TEACHER_TOTAL.getRedisKey(teacherId)).get();
+
         if (YesOrNoEnum.YES.equals(starStatus) && null == studentStar) {
             studentStar = new StudentStar();
             studentStar.setStudentId(studentId);
             studentStar.setTeacherId(teacherId);
             save(studentStar);
+            total.setFansNum(total.getFansNum() + 1);
         } else if (YesOrNoEnum.NO.equals(starStatus) && null != studentStar) {
             remove(Wrappers.<StudentStar>lambdaQuery()
                     .eq(StudentStar::getStudentId, studentId)
                     .eq(StudentStar::getTeacherId, teacherId)
             );
+            total.setFansNum(total.getFansNum() - 1);
         }
+        redissonClient.getBucket(CacheNameEnum.TEACHER_TOTAL.getRedisKey(teacherId))
+                .set(total);
         return HttpResponseResult.succeed(true);
     }
 }

+ 11 - 7
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserAccountServiceImpl.java

@@ -113,9 +113,11 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
     private HttpResponseResult<UserAccountRecord> doAccountChange(UserAccountRecordDto accountRecordDto) {
         if (FrozenTypeEnum.FROZEN.equals(accountRecordDto.getFrozenType())) {
             baseMapper.frozenChangeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode());
-        } else if (FrozenTypeEnum.UNFROZEN.equals(accountRecordDto.getFrozenType())) {
-            baseMapper.unfrozenChangeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode());
-        } else {
+        } else if (FrozenTypeEnum.FROZEN_DEDUCT.equals(accountRecordDto.getFrozenType())) {
+            baseMapper.frozenDeductChangeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode());
+        } else if (FrozenTypeEnum.FROZEN_BACK.equals(accountRecordDto.getFrozenType())) {
+            baseMapper.frozenBackChangeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode());
+        }  else {
             baseMapper.changeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode());
         }
 
@@ -124,10 +126,12 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
                 || detail.getAmountUsable().doubleValue() < 0 || detail.getAmountFrozen().doubleValue() < 0) {
             throw new BizException("账户变更失败");
         }
-        //插入账户变更记录
-        accountRecordDto.setAccountId(accountRecordDto.getUserId());
-        accountRecordDto.setAccountBalance(detail.getAmountUsable());
-        userAccountRecordService.save(accountRecordDto);
+        if(accountRecordDto.getSaveRecord()){
+            //插入账户变更记录
+            accountRecordDto.setAccountId(accountRecordDto.getUserId());
+            accountRecordDto.setAccountBalance(detail.getAmountUsable());
+            userAccountRecordService.save(accountRecordDto);
+        }
         return HttpResponseResult.succeed(accountRecordDto);
     }
 }

+ 21 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserBankCardServiceImpl.java

@@ -71,4 +71,25 @@ public class UserBankCardServiceImpl extends ServiceImpl<UserBankCardDao, UserBa
         return HttpResponseResult.succeed(bankCard);
     }
 
+    @Override
+    public HttpResponseResult<UserBankCard> unBind(UserBankCardDto bankCard) {
+        UserBankCardVo detail = baseMapper.detail(bankCard.getId());
+        if(null == detail){
+            return HttpResponseResult.failed("未找到银行卡信息");
+        }
+        //验证身份证合法性
+        IdcardValidator idcardValidator = new IdcardValidator();
+        //验证身份证号合法性
+        boolean validatedAllIdcard = idcardValidator.isValidatedAllIdcard(bankCard.getIdCardNo());
+        if (!validatedAllIdcard) {
+            return HttpResponseResult.failed("身份证号不合法");
+        }
+        boolean verify = realnameAuthenticationPlugin.verify(bankCard.getName(), bankCard.getIdCardNo());
+        if (!verify) {
+            return HttpResponseResult.failed("未通过验证");
+        }
+        int i = baseMapper.deleteById(bankCard.getId());
+        return HttpResponseResult.succeed(detail);
+    }
+
 }

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

@@ -89,7 +89,8 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
         BigDecimal withdrawalServiceFee = getWithdrawalServiceFee();
         withdrawalInfoRes.setWithdrawalServiceFee(withdrawalServiceFee);
         //获取用户可用于提现余额
-        withdrawalInfoRes.setAmountWithdrawal(getAmountWithdrawal(userId));
+        withdrawalInfoRes.setAmountWithdrawal(getAmountUsable(userId).subtract(withdrawalServiceFee)
+                .setScale(2, RoundingMode.HALF_UP));
         return HttpResponseResult.succeed(withdrawalInfoRes);
     }
 
@@ -102,7 +103,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
             return HttpResponseResult.failed("提现金额过小");
         }
         //获取用户提现金额
-        BigDecimal amountWithdrawal = getAmountWithdrawal(userId);
+        BigDecimal amountWithdrawal = getAmountUsable(userId);
         //比较大小
         if (amountWithdrawal.compareTo(withdrawalReq.getAmountWithdrawal()) < 0) {
             return HttpResponseResult.failed("账户余额不足");
@@ -120,6 +121,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
                 userWithdrawal.getId(), "老师提现", null
         );
         accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN);
+        accountRecordDto.setSaveRecord(false);
         HttpResponseResult<UserAccountRecord> accountChange = userAccountService.accountChange(accountRecordDto);
         if (accountChange.getStatus()) {
             return HttpResponseResult.succeed(true);
@@ -144,18 +146,20 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
             StringBuffer buffer = new StringBuffer(data.getId().toString());
             buffer.append(data.getUserId());
             buffer.append(data.getAmount().setScale(2, RoundingMode.HALF_UP));
+            buffer.append(data.getPlantformFee().setScale(2, RoundingMode.HALF_UP));
             buffer.append(data.getActualAmount().setScale(2, RoundingMode.HALF_UP));
+
             String sign = DigestUtils.md5DigestAsHex(buffer.toString().getBytes());
             if (!data.getSign().equals(sign)) {
                 errMsgList.add(new ErrMsg(dataReaderProperty.getRowIndex(), "验签失败"));
                 continue;
             }
-            if(AuthStatusEnum.PASS.equals(data.getStatus()) && StringUtil.isEmpty(data.getBankFlowNo())){
+            if (AuthStatusEnum.PASS.equals(data.getStatus()) && StringUtil.isEmpty(data.getBankFlowNo())) {
                 errMsgList.add(new ErrMsg(dataReaderProperty.getRowIndex(), "审核通过时,转账流水号不能为空"));
                 continue;
             }
-            if(!AuthStatusEnum.DOING.equals(data.getStatus())
-                    && StringUtil.isEmpty(data.getVerifyReason())){
+            if (!AuthStatusEnum.DOING.equals(data.getStatus())
+                    && StringUtil.isEmpty(data.getVerifyReason())) {
                 errMsgList.add(new ErrMsg(dataReaderProperty.getRowIndex(), "审核理由不能为空"));
                 continue;
             }
@@ -184,10 +188,34 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
     private void authWithdrawalBancth(List<UserWithdrawal> userWithdrawalList) {
         for (UserWithdrawal userWithdrawal : userWithdrawalList) {
             UserWithdrawal old = baseMapper.selectById(userWithdrawal.getId());
-            if(null != old && !AuthStatusEnum.PASS.equals(old.getStatus())
-                && !old.getStatus().equals(userWithdrawal.getStatus())){
+            if (null == old) {
+                continue;
+            }
+            if (!AuthStatusEnum.PASS.equals(old.getStatus())
+                    && !old.getStatus().equals(userWithdrawal.getStatus())) {
                 baseMapper.updateById(userWithdrawal);
+
+                if (AuthStatusEnum.PASS.equals(userWithdrawal.getStatus())) {
+                    //审核通过,账户解冻,入账户明细
+                    UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
+                            old.getUserId(), old.getAmount(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
+                            userWithdrawal.getId(), "老师提现", null
+                    );
+                    accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN_DEDUCT);
+                    accountRecordDto.setSaveRecord(true);
+                    userAccountService.accountChange(accountRecordDto);
+                } else if (AuthStatusEnum.UNPASS.equals(userWithdrawal.getStatus())) {
+                    //审核不通过,账户解冻
+                    UserAccountRecordDto accountRecordDto = new UserAccountRecordDto(
+                            old.getUserId(), old.getAmount(), InOrOutEnum.OUT, AccountBizTypeEnum.WITHDRAWAL,
+                            userWithdrawal.getId(), "老师提现", null
+                    );
+                    accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN_BACK);
+                    accountRecordDto.setSaveRecord(false);
+                    userAccountService.accountChange(accountRecordDto);
+                }
             }
+
         }
     }
 
@@ -225,13 +253,14 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
      * @return: java.math.BigDecimal
      */
     private BigDecimal getWithdrawalServiceFee() {
-        BigDecimal withdrawalServiceFee = new BigDecimal(0);
+        BigDecimal withdrawalServiceFee;
         try {
             String configValue = sysConfigService.findConfigValue(SysConfigConstant.WITHDRAWAL_SERVICE_FEE);
             withdrawalServiceFee = new BigDecimal(configValue);
         } catch (Exception e) {
             e.printStackTrace();
             log.info("获取平台配置失败 key={}", SysConfigConstant.WITHDRAWAL_SERVICE_FEE);
+            withdrawalServiceFee = new BigDecimal(0);
         }
         return withdrawalServiceFee;
     }
@@ -244,7 +273,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
      * @updateTime 2022/4/7 15:02
      * @return: java.math.BigDecimal
      */
-    private BigDecimal getAmountWithdrawal(Long userId) {
+    private BigDecimal getAmountUsable(Long userId) {
         //查询用户账户余额
         UserAccountVo detail = userAccountService.detail(userId);
         BigDecimal subtract = detail.getAmountUsable();

+ 14 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/UserAccountMapper.xml

@@ -35,7 +35,7 @@
         update_time_ = now()
         where user_id_ = #{userId}
     </update>
-    <update id="unfrozenChangeAccount">
+    <update id="frozenDeductChangeAccount">
         update user_cash_account
         <choose>
             <when test="null != inOrOut and inOrOut == 'IN'">
@@ -48,6 +48,19 @@
         update_time_ = now()
         where user_id_ = #{userId}
     </update>
+    <update id="frozenBackChangeAccount">
+        update user_cash_account
+        <choose>
+            <when test="null != inOrOut and inOrOut == 'IN'">
+                set amount_total_ = (amount_total_ - #{transAmount}),amount_frozen_ = (amount_frozen_ - #{transAmount}),
+            </when>
+            <otherwise>
+                set amount_usable_ = (amount_usable_ + #{transAmount}),amount_frozen_ = (amount_frozen_ - #{transAmount}),
+            </otherwise>
+        </choose>
+        update_time_ = now()
+        where user_id_ = #{userId}
+    </update>
     <update id="changeAccount">
         update user_cash_account
         <choose>

+ 23 - 0
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/UserBankCardController.java

@@ -14,11 +14,15 @@ import com.yonge.cooleshow.biz.dal.vo.UserBankCardVo;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.cooleshow.common.page.PageInfo;
+import com.yonge.toolset.utils.string.StringUtil;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.bind.annotation.*;
+import springfox.documentation.annotations.ApiIgnore;
 
 import javax.validation.Valid;
 import java.util.HashMap;
@@ -72,4 +76,23 @@ public class UserBankCardController extends BaseController {
 		return userBankCardService.bankCard(bankCard);
 	}
 
+	@PostMapping("/unBind")
+	@ApiOperation(value = "用户解绑银行卡")
+	@ApiImplicitParams({
+			@ApiImplicitParam(name = "id", value = "银行卡id", paramType = "query", dataType = "long"),
+			@ApiImplicitParam(name = "name", value = "真实姓名", paramType = "query", dataType = "String"),
+			@ApiImplicitParam(name = "idCardNo", value = "身份证号码", paramType = "query", dataType = "String"),
+	})
+	public HttpResponseResult<UserBankCard> unBind(@ApiIgnore @RequestBody UserBankCardDto bankCard) {
+		if(null == bankCard.getId() || StringUtil.isEmpty(bankCard.getIdCardNo()) || StringUtil.isEmpty(bankCard.getName())){
+			return HttpResponseResult.failed("缺少参数");
+		}
+		SysUser user = sysUserFeignService.queryUserInfo();
+		if (user == null || null == user.getId()) {
+			return failed(HttpStatus.FORBIDDEN, "请登录");
+		}
+		bankCard.setUserId(user.getId());
+		return userBankCardService.unBind(bankCard);
+	}
+
 }