|
@@ -8,10 +8,8 @@ import com.gree.mall.miniapp.constant.Constant;
|
|
|
import com.gree.mall.miniapp.enums.TransactionTypeEnum;
|
|
import com.gree.mall.miniapp.enums.TransactionTypeEnum;
|
|
|
import com.gree.mall.miniapp.exception.RemoteServiceException;
|
|
import com.gree.mall.miniapp.exception.RemoteServiceException;
|
|
|
import com.gree.mall.miniapp.helper.ResponseHelper;
|
|
import com.gree.mall.miniapp.helper.ResponseHelper;
|
|
|
-import com.gree.mall.miniapp.plus.entity.OrderInfo;
|
|
|
|
|
-import com.gree.mall.miniapp.plus.entity.User;
|
|
|
|
|
-import com.gree.mall.miniapp.plus.entity.UserCompanyCredit;
|
|
|
|
|
-import com.gree.mall.miniapp.plus.entity.UserCompanyCreditBillItem;
|
|
|
|
|
|
|
+import com.gree.mall.miniapp.plus.entity.*;
|
|
|
|
|
+import com.gree.mall.miniapp.plus.service.UserCompanyCreditBillService;
|
|
|
import com.gree.mall.miniapp.plus.service.UserCompanyCreditService;
|
|
import com.gree.mall.miniapp.plus.service.UserCompanyCreditService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -33,13 +31,14 @@ public class UserCompanyCreditLogic {
|
|
|
|
|
|
|
|
private final RedisLockRegistry redisLockRegistry;
|
|
private final RedisLockRegistry redisLockRegistry;
|
|
|
private final UserCompanyCreditService userCompanyCreditService;
|
|
private final UserCompanyCreditService userCompanyCreditService;
|
|
|
|
|
+ private final UserCompanyCreditBillService userCompanyCreditBillService;
|
|
|
private final LockQueryMapper lockQueryMapper;
|
|
private final LockQueryMapper lockQueryMapper;
|
|
|
|
|
|
|
|
public void createCreditRecord(OrderInfo orderInfo, User user) throws Exception {
|
|
public void createCreditRecord(OrderInfo orderInfo, User user) throws Exception {
|
|
|
if(!TransactionSynchronizationManager.isSynchronizationActive()) {
|
|
if(!TransactionSynchronizationManager.isSynchronizationActive()) {
|
|
|
throw new RemoteServiceException("请先开启事务");
|
|
throw new RemoteServiceException("请先开启事务");
|
|
|
}
|
|
}
|
|
|
- Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_CREDIT_ORDER + user.getUserId());
|
|
|
|
|
|
|
+ Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_USER_COMPANY_CREDIT + user.getUserId() + ":" + orderInfo.getCompanyWechatId());
|
|
|
if(!obtain.tryLock(10, TimeUnit.SECONDS)){
|
|
if(!obtain.tryLock(10, TimeUnit.SECONDS)){
|
|
|
throw new RemoteServiceException("订单创建过于频繁, 请稍后再试");
|
|
throw new RemoteServiceException("订单创建过于频繁, 请稍后再试");
|
|
|
}
|
|
}
|
|
@@ -58,8 +57,19 @@ public class UserCompanyCreditLogic {
|
|
|
if (userCompanyCredit.getAvailableCredit().compareTo(payAmount) < 0) {
|
|
if (userCompanyCredit.getAvailableCredit().compareTo(payAmount) < 0) {
|
|
|
throw new RemoteServiceException("商户授信额度不足");
|
|
throw new RemoteServiceException("商户授信额度不足");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
final DateTime curDate = DateUtil.date();
|
|
final DateTime curDate = DateUtil.date();
|
|
|
|
|
+
|
|
|
|
|
+ final Integer count = userCompanyCreditBillService.lambdaQuery()
|
|
|
|
|
+ .eq(UserCompanyCreditBill::getCompanyWechatId, orderInfo.getCompanyWechatId())
|
|
|
|
|
+ .eq(UserCompanyCreditBill::getUserId, orderInfo.getUserId())
|
|
|
|
|
+ .eq(UserCompanyCreditBill::getIsPaid, false)
|
|
|
|
|
+ .eq(UserCompanyCreditBill::getDueDate, curDate)
|
|
|
|
|
+ .count();
|
|
|
|
|
+
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ throw new RemoteServiceException("用户有逾期未还的账单, 暂时无法使用授信额度");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 更新用户商户授信记录
|
|
// 更新用户商户授信记录
|
|
|
userCompanyCreditService.lambdaUpdate()
|
|
userCompanyCreditService.lambdaUpdate()
|
|
|
.set(UserCompanyCredit::getAvailableCredit, userCompanyCredit.getAvailableCredit().subtract(payAmount))
|
|
.set(UserCompanyCredit::getAvailableCredit, userCompanyCredit.getAvailableCredit().subtract(payAmount))
|