Mr.qian пре 3 недеља
родитељ
комит
5358e80aaa

+ 30 - 25
cif-api/src/main/java/com/txz/cif/dto/AccountDTO.java

@@ -5,6 +5,7 @@ import lombok.*;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.Date;
+
 @Getter
 @Setter
 @NoArgsConstructor
@@ -12,85 +13,89 @@ import java.util.Date;
 @Builder
 public class AccountDTO implements Serializable {
     private Long id;
-
+    
     private Long userId;
-
+    
     /**
      * 备注
      */
     private String remark;
-
+    
     /**
      * 名称
      */
     private String name;
-
+    
     private String direction;
-
-
+    
+    
     /**
      * 类型 1外部账户 2内部账户 3手续费账户 4营销账户
      */
     private Integer type;
-
+    
     private String aliases;
-
+    
     private Integer subjectType;
-
+    
     private Integer bizType;
-
+    
     /**
      * 余额
      */
     private BigDecimal balance;
-
+    
     /**
      * 冻结金额
      */
     private BigDecimal freezeAmount;
-
+    
     /**
      * 余额
      */
     private BigDecimal totalInamount;
-
+    
     /**
      * 冻结金额
      */
     private BigDecimal totalOutAmount;
-
+    
     /**
      * 上日余额
      */
     private BigDecimal beforeDayBalance;
-
+    
     private BigDecimal beforeDayInitBalance;
-
-
+    
+    
     /**
      * 上日余额更新时间
      */
     private Date beforeDayTime;
-
+    
     /**
      * 创建时间
      */
     private Date createTime;
-
+    
     /**
      * 更新时间
      */
     private Date updateTime;
-
-
+    
+    
     private String version;
-
+    
     /**
-     * 获取有效余
+     * 可提现金
      */
     public BigDecimal getEffectiveBalance() {
         return balance.subtract(freezeAmount);
     }
-
-
+    
+    /**
+     * 可支付金额
+     */
+    private BigDecimal payPrice;
+    
 }

+ 4 - 0
cif-service/src/main/java/com/txz/cif/dao/AccountFreezdMapper.java

@@ -12,4 +12,8 @@ public interface AccountFreezdMapper extends Mapper<AccountFreezd> {
     @Select("SELECT IFNULL(SUM(amount), 0) - IFNULL(SUM(unfreeze_amount), 0) FROM c_account_freezd WHERE type = 2 AND status IN (1,2) AND user_id = #{userId} ")
     BigDecimal sumFreezdForRefundByUserId(@Param("userId") Long userId);
     
+    
+    @Select("SELECT IFNULL(SUM(amount), 0) FROM c_account_freezd WHERE type = 1 AND status IN (1,2) AND user_id = #{userId} ")
+    BigDecimal sumFreezdForWithdraw(@Param("userId") Long userId);
+    
 }

+ 26 - 22
cif-service/src/main/java/com/txz/cif/dubbo/impl/AccountDubboServiceImpl.java

@@ -45,6 +45,8 @@ public class AccountDubboServiceImpl implements AccountDubboService {
     @Resource
     private OperatingConfigDubboServiceClient operatingConfigDubboServiceClient;
     
+    @Resource
+    private AccountFreezdService accountFreezdService;
     
     //    @Override
     //    public Result freeze(FreezdParam param) {
@@ -87,19 +89,21 @@ public class AccountDubboServiceImpl implements AccountDubboService {
         if (account == null) {
             return Result.genFailResult(LocalUtil.get("not.found"));
         }
+        BigDecimal forWithdraw = accountFreezdService.sumFreezdForWithdraw(userId);
         AccountDTO dto = BeanUtil.toBean(account, AccountDTO.class);
+        dto.setPayPrice(account.getBalance().subtract(forWithdraw));
         return Result.genSuccessResult(dto);
     }
     
     @Override
     public Result openGroup(OpenParam param) {
-        if (param == null){
+        if (param == null) {
             return Result.genFailResult(LocalUtil.get("object.is.empty"));
         }
-        if (param.getUserId() == null){
+        if (param.getUserId() == null) {
             return Result.genFailResult(LocalUtil.get("userid.is.empty"));
         }
-        if (param.getAmount() == null){
+        if (param.getAmount() == null) {
             return Result.genFailResult(LocalUtil.get("amount.is.empty"));
         }
         // 支付
@@ -111,19 +115,19 @@ public class AccountDubboServiceImpl implements AccountDubboService {
                 .transTime(param.getTransTime())
                 .bizType(BizTypeEnum.OPEN_GROUP_PAY.getKey())
                 .build());
-
+        
         return result;
     }
     
     @Override
     public Result joinGroup(JoinParam param) {
-        if (param == null){
+        if (param == null) {
             return Result.genFailResult(LocalUtil.get("object.is.empty"));
         }
-        if (param.getUserId() == null){
+        if (param.getUserId() == null) {
             return Result.genFailResult(LocalUtil.get("userid.is.empty"));
         }
-        if (param.getAmount() == null){
+        if (param.getAmount() == null) {
             return Result.genFailResult(LocalUtil.get("amount.is.empty"));
         }
         // 支付
@@ -158,7 +162,7 @@ public class AccountDubboServiceImpl implements AccountDubboService {
     
     @Override
     public Result accomplishGroup(AccomplishParam param) {
-        log.info("accomplishGroup param :"+ JSONObject.toJSONString(param));
+        log.info("accomplishGroup param :" + JSONObject.toJSONString(param));
         // 类型 1001充值 2001提现  3001开团支付 3002参团支付  4001未成团退款 4002成团退款 5001开团红包收益 5002参团红包收益 5003签到红包收益 5004下级红包佣金 5005下下级红包佣金
         for (OrderParam orderParam : param.getUserIds()) {
             Result result = flowService.refund(RefundParam.builder()
@@ -172,15 +176,15 @@ public class AccountDubboServiceImpl implements AccountDubboService {
                 throw new ServiceException();
             }
         }
-
+        
         if (param.getOpenGroupUserId() != null) {
-            log.info("param.getOpenGroupUserId() :"+ param.getOpenGroupUserId());
+            log.info("param.getOpenGroupUserId() :" + param.getOpenGroupUserId());
             // 计算开团红包金额
             com.txz.operating.result.Result<ConfigDTO> openRedEnvelopeRate = operatingConfigDubboServiceClient.getConfigByCode("open_red_envelope_rate");
-            log.info("operatingConfigDubboServiceClient.getConfigByCode openRedEnvelopeRate:"+ JSONObject.toJSONString(openRedEnvelopeRate));
+            log.info("operatingConfigDubboServiceClient.getConfigByCode openRedEnvelopeRate:" + JSONObject.toJSONString(openRedEnvelopeRate));
             String rate = openRedEnvelopeRate.getData().getValueInfo();
             BigDecimal amount = param.getAmount().multiply(new BigDecimal(rate)).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
-
+            
             // 开团红包
             Result result1 = redEnvelopeService.addRedEnvelope(RedEnvelopeParam.builder()
                     .amount(amount).bizType(BizTypeEnum.OPEN_GROUP_RED_ENVELOPE.getKey()).orderNo(param.getBizNo())
@@ -188,33 +192,33 @@ public class AccountDubboServiceImpl implements AccountDubboService {
                     .transTime(param.getTransTime())
                     .build());
         }
-
+        
         //  计算参团红包金额
-        for (int i = param.getUserIds().size() -1; i >=0 ; i--) {
+        for (int i = param.getUserIds().size() - 1; i >= 0; i--) {
             OrderParam p = param.getUserIds().get(i);
-            if (p.getUserId().compareTo(param.getOpenGroupUserId()) == 0){
+            if (p.getUserId().compareTo(param.getOpenGroupUserId()) == 0) {
                 param.getUserIds().remove(i);
             }
         }
-        if (param.getWinnerUserId().compareTo(param.getOpenGroupUserId()) != 0){
+        if (param.getWinnerUserId().compareTo(param.getOpenGroupUserId()) != 0) {
             param.getUserIds().add(OrderParam.builder().orderNo(param.getWinnerOrderNo()).userId(param.getWinnerUserId()).build());
         }
-
-
+        
+        
         com.txz.operating.result.Result<ConfigDTO> openRedEnvelopeRate = operatingConfigDubboServiceClient.getConfigByCode("join_red_envelope_rate");
-        log.info("operatingConfigDubboServiceClient.getConfigByCode2 openRedEnvelopeRate:"+ JSONObject.toJSONString(openRedEnvelopeRate));
+        log.info("operatingConfigDubboServiceClient.getConfigByCode2 openRedEnvelopeRate:" + JSONObject.toJSONString(openRedEnvelopeRate));
         String rate = openRedEnvelopeRate.getData().getValueInfo();
         BigDecimal amount = param.getAmount().multiply(new BigDecimal(rate)).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN);
         // 参团红包
-        if (CollUtil.isNotEmpty(param.getUserIds())){
+        if (CollUtil.isNotEmpty(param.getUserIds())) {
             Result result1 = redEnvelopeService.addRedEnvelope(RedEnvelopeParam.builder()
                     .amount(amount).bizType(BizTypeEnum.JOIN_GROUP_RED_ENVELOPE.getKey()).orderNo(param.getBizNo())
                     .userIds(param.getUserIds())
                     .transTime(param.getTransTime())
                     .build());
         }
-
-        log.info("accomplishGroup end param :"+ JSONObject.toJSONString(param));
+        
+        log.info("accomplishGroup end param :" + JSONObject.toJSONString(param));
         return Result.genSuccessResult();
     }
     

+ 1 - 2
cif-service/src/main/java/com/txz/cif/model/AccountFreezd.java

@@ -1,6 +1,5 @@
 package com.txz.cif.model;
 
-import com.txz.cif.enums.AccountFreezdTypeEnum;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.*;
@@ -81,7 +80,7 @@ public class AccountFreezd {
      * 类型 1提现冻结 2退款冻结
      */
     @Column(name = "type")
-    private AccountFreezdTypeEnum type;
+    private Integer type;
     
     /**
      * 解冻时间

+ 10 - 1
cif-service/src/main/java/com/txz/cif/service/AccountFreezdService.java

@@ -1,4 +1,5 @@
 package com.txz.cif.service;
+
 import com.txz.cif.model.AccountFreezd;
 import com.txz.cif.core.Service;
 
@@ -9,7 +10,15 @@ import java.math.BigDecimal;
  * Created by CodeGenerator on 2022/11/19.
  */
 public interface AccountFreezdService extends Service<AccountFreezd> {
-
+    
+    /**
+     * 冻结可用金额
+     */
     BigDecimal sumFreezdForRefundByUserId(Long userId);
     
+    /**
+     * 冻结提现金额
+     */
+    BigDecimal sumFreezdForWithdraw(Long userId);
+    
 }

+ 5 - 0
cif-service/src/main/java/com/txz/cif/service/impl/AccountFreezdServiceImpl.java

@@ -25,4 +25,9 @@ public class AccountFreezdServiceImpl extends AbstractService<AccountFreezd> imp
     public BigDecimal sumFreezdForRefundByUserId(Long userId) {
         return cAccountFreezdMapper.sumFreezdForRefundByUserId(userId);
     }
+    
+    @Override
+    public BigDecimal sumFreezdForWithdraw(Long userId) {
+        return cAccountFreezdMapper.sumFreezdForWithdraw(userId);
+    }
 }

+ 5 - 1
cif-service/src/main/java/com/txz/cif/service/impl/FlowServiceImpl.java

@@ -87,7 +87,7 @@ public class FlowServiceImpl extends AbstractService<Flow> implements FlowServic
                     .amount(param.getAmount())
                     .createTime(today)
                     .unfreezeAmount(BigDecimal.ZERO)
-                    .type(param.getType())
+                    .type(param.getType().getCode())
                     .updateTime(today)
                     .status(1)
                     .unfreezeTime(param.getUnfreezeTime())
@@ -266,6 +266,10 @@ public class FlowServiceImpl extends AbstractService<Flow> implements FlowServic
                     }
                 }
             }
+        }else{
+            if (account.getBalance().subtract(account.getFreezeAmount()).compareTo(param.getAmount()) == -1) {
+                return Result.genFailResult(LocalUtil.get("account.not.found"));
+            }
         }
         
         // 借:个人账户钱包(贷)     -500元

+ 7 - 2
cif-service/src/main/java/com/txz/cif/web/AccountApiController.java

@@ -31,6 +31,7 @@ import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 
@@ -200,8 +201,12 @@ public class AccountApiController extends AbstractApiController {
         }
         c.setOrderByClause("create_time desc");
         List<AccountFlow> flows = accountFlowService.findByCondition(c);
-        PageInfo pageInfo = new PageInfo(flows);
-        List<AccountFlowBO> bos = flows.stream().map(temp -> {
+        List<AccountFlow> distinctFlows = flows.stream()
+                .collect(Collectors.toMap(AccountFlow::getId, Function.identity(), (existing, replacement) -> existing))
+                .values().stream()
+                .collect(Collectors.toList());
+        PageInfo pageInfo = new PageInfo(distinctFlows);
+        List<AccountFlowBO> bos = distinctFlows.stream().map(temp -> {
             AccountFlowBO bo = temp.generator();
             if (account != null) {
                 bo.setAccountName(account.getName());