| 
					
				 | 
			
			
				@@ -16,7 +16,9 @@ import com.gree.mall.manager.exception.RemoteServiceException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.logic.common.CommonLogic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.plus.entity.OrderInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.plus.entity.UserCompanyCredit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.manager.plus.entity.UserCompanyCreditBill; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.plus.entity.UserCompanyCreditBillItem; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.gree.mall.manager.plus.service.UserCompanyCreditBillService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.plus.service.UserCompanyCreditService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.zfire.bean.ZfireParamBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.gree.mall.manager.zfire.util.FieldUtils; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -25,6 +27,7 @@ import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.integration.redis.util.RedisLockRegistry; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.support.TransactionSynchronization; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.support.TransactionSynchronizationManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -43,6 +46,7 @@ public class UserCompanyCreditLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final RedisLockRegistry redisLockRegistry; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final LockQueryMapper lockQueryMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final UserCompanyCreditService userCompanyCreditService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final UserCompanyCreditBillService userCompanyCreditBillService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public IPage<UserCompanyCreditBillVO> list(ZfireParamBean zfireParamBean) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         AdminUserCom adminUser = commonLogic.getAdminUser(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -63,6 +67,40 @@ public class UserCompanyCreditLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 账单还款 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param billId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param amount 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void billRepay(String billId, BigDecimal amount) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserCom adminUser = commonLogic.getAdminUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        UserCompanyCreditBill creditBill = userCompanyCreditBillService.getById(billId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!creditBill.getCompanyWechatId().equals(adminUser.getCompanyWechatId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("请使用商户账号"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (creditBill.getIsPaid()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException(billId + "账单已还款"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 判断还款金额是否大于剩余未还 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (amount.compareTo(creditBill.getRemainingAmount()) > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("还款金额不能大于剩余未还金额"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 剩余未还金额 - 还款金额 = (新)剩余未还金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final BigDecimal newRemainingAmount = creditBill.getRemainingAmount().subtract(amount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 恢复使用额度 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.repay(null, creditBill.getUserId(), creditBill.getCompanyWechatId(), amount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 更新账单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        creditBill.setIsPaid(newRemainingAmount.compareTo(BigDecimal.ZERO) == 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .setRemainingAmount(newRemainingAmount) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .updateById(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 授信订单退款 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param orderInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -80,13 +118,13 @@ public class UserCompanyCreditLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_USER_COMPANY_CREDIT + userId + ":" + companyWechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if(!obtain.tryLock(10, TimeUnit.SECONDS)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            throw new RemoteServiceException("订单操作过于频繁, 请稍后再试"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new RemoteServiceException("操作过于频繁, 请稍后再试"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 处理授信 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 验证金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (Objects.isNull(amount) || amount.compareTo(BigDecimal.ZERO) <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                throw new RemoteServiceException("还示金额必须大于0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new RemoteServiceException(StringUtils.isBlank(orderId) ? "还款" : "退款" + "金额必须大于0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             final UserCompanyCredit userCompanyCredit = lockQueryMapper.queryExistUserCompanyCredit(companyWechatId, userId); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -149,5 +187,4 @@ public class UserCompanyCreditLogic { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |