|
|
|
|
@@ -1,7 +1,9 @@
|
|
|
|
|
package com.cool.store.service.store.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollStreamUtil;
|
|
|
|
|
import com.alibaba.excel.converters.bigdecimal.BigDecimalNumberConverter;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.cool.store.constants.RedisConstant;
|
|
|
|
|
import com.cool.store.dao.FranchiseFeeDAO;
|
|
|
|
|
import com.cool.store.dao.LineInfoDAO;
|
|
|
|
|
import com.cool.store.dao.ShopInfoDAO;
|
|
|
|
|
@@ -15,7 +17,9 @@ import com.cool.store.dao.wallet.WalletTradeDAO;
|
|
|
|
|
import com.cool.store.dto.fees.ExpenseTypeAmountDTO;
|
|
|
|
|
import com.cool.store.dto.fees.WalletAllocationDTO;
|
|
|
|
|
import com.cool.store.dto.wallet.AccountInfoDTO;
|
|
|
|
|
import com.cool.store.dto.wallet.AccountTransferDTO;
|
|
|
|
|
import com.cool.store.dto.wallet.BatchTransferDTO;
|
|
|
|
|
import com.cool.store.dto.wallet.TradeRecordDTO;
|
|
|
|
|
import com.cool.store.entity.FranchiseFeeDO;
|
|
|
|
|
import com.cool.store.entity.LineInfoDO;
|
|
|
|
|
import com.cool.store.entity.ShopInfoDO;
|
|
|
|
|
@@ -36,12 +40,14 @@ import com.cool.store.enums.fees.WalletFeeItemEnum;
|
|
|
|
|
import com.cool.store.enums.order.StoreOrderStatusEnum;
|
|
|
|
|
import com.cool.store.enums.point.ShopSubStageEnum;
|
|
|
|
|
import com.cool.store.enums.point.ShopSubStageStatusEnum;
|
|
|
|
|
import com.cool.store.enums.wallet.TradeTypeEnum;
|
|
|
|
|
import com.cool.store.exception.ServiceException;
|
|
|
|
|
import com.cool.store.mapper.FranchiseFeeMapper;
|
|
|
|
|
import com.cool.store.request.store.PreAllocationAddRequest;
|
|
|
|
|
import com.cool.store.request.store.PreAllocationEditRequest;
|
|
|
|
|
import com.cool.store.request.store.PreAllocationSaveRequest;
|
|
|
|
|
import com.cool.store.request.wallet.BatchTransferQueryRequest;
|
|
|
|
|
import com.cool.store.request.wallet.BatchTransferRequest;
|
|
|
|
|
import com.cool.store.request.wallet.OutStoreIdRequest;
|
|
|
|
|
import com.cool.store.request.store.TransRequest;
|
|
|
|
|
import com.cool.store.request.wallet.*;
|
|
|
|
|
import com.cool.store.request.xgj.PushFranchiseFeeRequest;
|
|
|
|
|
import com.cool.store.request.xgj.ReceiptRequest;
|
|
|
|
|
import com.cool.store.service.PushService;
|
|
|
|
|
@@ -50,12 +56,10 @@ import com.cool.store.service.fees.WalletPayInfoService;
|
|
|
|
|
import com.cool.store.service.order.MiniStoreOrderService;
|
|
|
|
|
import com.cool.store.service.store.PreAllocationRecordService;
|
|
|
|
|
import com.cool.store.service.wallet.WalletApiService;
|
|
|
|
|
import com.cool.store.utils.BeanUtil;
|
|
|
|
|
import com.cool.store.utils.GenerateNoUtil;
|
|
|
|
|
import com.cool.store.utils.RedisUtil;
|
|
|
|
|
import com.cool.store.utils.StringUtil;
|
|
|
|
|
import com.cool.store.utils.*;
|
|
|
|
|
import com.cool.store.vo.order.MiniStoreOrderDetailVO;
|
|
|
|
|
import com.cool.store.vo.order.PreAllocationRecordVO;
|
|
|
|
|
import com.sun.xml.bind.v2.TODO;
|
|
|
|
|
import groovy.util.logging.Slf4j;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
@@ -64,6 +68,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.MessageFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
@@ -71,7 +76,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import static com.cool.store.enums.order.StoreOrderStatusEnum.PAY_FAIL;
|
|
|
|
|
import static com.cool.store.enums.wallet.WalletTradeModuleEnum.STANDARD_STORE;
|
|
|
|
|
import static com.cool.store.enums.point.ShopSubStageStatusEnum.*;
|
|
|
|
|
import static com.cool.store.enums.wallet.WalletTradeModuleEnum.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Auther zx_szh
|
|
|
|
|
@@ -715,4 +721,157 @@ public class PreAllocationRecordServiceImpl implements PreAllocationRecordServic
|
|
|
|
|
pushService.pushFranchiseFeeToXGJ(feeRequest);
|
|
|
|
|
return franchiseFeeDO.getId().intValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean trans(TransRequest transRequest) {
|
|
|
|
|
String lockKey = MessageFormat.format(RedisConstant.PRE_ALLOCATION,transRequest.getId());
|
|
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
|
|
if(!Boolean.TRUE.equals(redisUtil.tryLock(lockKey, uuid,10, TimeUnit.MINUTES))){
|
|
|
|
|
throw new ServiceException(ErrorCodeEnum.TRANSFER_ING);
|
|
|
|
|
}
|
|
|
|
|
PreAllocationRecordDO record = preAllocationRecordDAO.getById(transRequest.getId());
|
|
|
|
|
if (record==null){
|
|
|
|
|
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(record.getShopId());
|
|
|
|
|
OutStoreIdRequest outStoreIdRequest = new OutStoreIdRequest();
|
|
|
|
|
outStoreIdRequest.setOutStoreId(shopInfo.getStoreId());
|
|
|
|
|
List<AccountInfoDTO> accountInfoList = walletApiService.getAccountInfo(outStoreIdRequest);
|
|
|
|
|
if (CollectionUtils.isEmpty(accountInfoList)){
|
|
|
|
|
throw new ServiceException(ErrorCodeEnum.NOT_EXIST_WANG_SHANG_ACCOUNT);
|
|
|
|
|
}
|
|
|
|
|
//校验金额
|
|
|
|
|
AccountInfoDTO accountInfoDTO = accountInfoList.get(0);
|
|
|
|
|
String totalAmount = accountInfoDTO.getTotalAmount();
|
|
|
|
|
Boolean amountSupport = BigDecimalUtils.greaterThanOrEqual(new BigDecimal(totalAmount), record.getPayAmount());
|
|
|
|
|
if (!amountSupport){
|
|
|
|
|
throw new ServiceException(ErrorCodeEnum.WALLET_BALANCE_INSUFFICIENT);
|
|
|
|
|
}
|
|
|
|
|
AccountTransferDTO accountTransferDTO ;
|
|
|
|
|
try {
|
|
|
|
|
accountTransferDTO = walletPayInfoService.accountPay(record.getExpenseType(), record.getPayAmount(),
|
|
|
|
|
record.getPayeeCode(), accountInfoDTO.getAccountNo(), record.getPayNo(), transRequest.getRemark());
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
//分账失败 释放锁
|
|
|
|
|
redisUtil.unlock(lockKey);
|
|
|
|
|
log.error("confirmSplitOrder:{}",e.getMessage());
|
|
|
|
|
throw new ServiceException(ErrorCodeEnum.ERROR_MESSAGE,e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
record.setAllocationStatus(AllocationPayStatusEnum.PAYING.getStatus());
|
|
|
|
|
record.setRemark(transRequest.getRemark());
|
|
|
|
|
//先改为分账中
|
|
|
|
|
preAllocationRecordDAO.updateByPrimaryKeySelective(record);
|
|
|
|
|
WalletTradeDO walletTradeDO = new WalletTradeDO();
|
|
|
|
|
walletTradeDO.setPayStatus(accountTransferDTO.getTradeStatus());
|
|
|
|
|
walletTradeDO.setModule(TRANSFER.getModule());
|
|
|
|
|
walletTradeDO.setRemark(transRequest.getRemark());
|
|
|
|
|
walletTradeDO.setPayAmount(new BigDecimal(accountTransferDTO.getAmount()));
|
|
|
|
|
walletTradeDO.setPayTime(new Date());
|
|
|
|
|
walletTradeDO.setPayNo(record.getPayNo());
|
|
|
|
|
walletTradeDO.setTradeId(String.valueOf(accountTransferDTO.getTradeId()));
|
|
|
|
|
walletTradeDO.setType(TradeTypeEnum.ADD_BY_HAND.getStatus());
|
|
|
|
|
walletTradeDAO.insertSelective(walletTradeDO);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean transStatusRefresh(WalletTradeDO walletTradeDO) {
|
|
|
|
|
BillDetailRequest request = new BillDetailRequest();
|
|
|
|
|
request.setTradeId(Long.valueOf(walletTradeDO.getTradeId()));
|
|
|
|
|
TradeRecordDTO billDetail = walletApiService.getBillDetail(request);
|
|
|
|
|
walletTradeDO.setPayStatus(billDetail.getTradeStatus());
|
|
|
|
|
walletTradeDAO.updateByPrimaryKeySelective(walletTradeDO);
|
|
|
|
|
PreAllocationRecordDO preAllocationRecordDO = preAllocationRecordDAO.queryPageByPayNo(walletTradeDO.getPayNo());
|
|
|
|
|
preAllocationRecordDO.setAllocationStatus(billDetail.getTradeStatus());
|
|
|
|
|
preAllocationRecordDO.setUpdateTime(new Date());
|
|
|
|
|
preAllocationRecordDAO.updateByPrimaryKeySelective(preAllocationRecordDO);
|
|
|
|
|
if (AllocationPayStatusEnum.PAID.getStatus().equals(walletTradeDO.getPayStatus())) {
|
|
|
|
|
ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(preAllocationRecordDO.getShopId());
|
|
|
|
|
//订单状态更新
|
|
|
|
|
StoreOrderDO storeOrder = storeOrderDAO.getById(preAllocationRecordDO.getOrderId());
|
|
|
|
|
//部分支付
|
|
|
|
|
StoreOrderDO updateOrder = StoreOrderDO.builder()
|
|
|
|
|
.id(storeOrder.getId())
|
|
|
|
|
.status(StoreOrderStatusEnum.PART_OF_WAIT_PAY.getCode())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.build();
|
|
|
|
|
//当前缴纳金额 = 本次缴纳前已缴纳金额+本次缴纳金额
|
|
|
|
|
BigDecimal currentAmount = new BigDecimal(billDetail.getAmount());
|
|
|
|
|
BigDecimal paidAmount = storeOrder.getPaidAmount().add(currentAmount);
|
|
|
|
|
BigDecimal unpaidAmount = storeOrder.getTotalAmount().subtract(paidAmount);
|
|
|
|
|
//支付成功 修改金额,支付中 回调的时候习惯
|
|
|
|
|
updateOrder.setPaidAmount(paidAmount);
|
|
|
|
|
updateOrder.setUnpaidAmount(unpaidAmount);
|
|
|
|
|
updateOrder.setPayTime(new Date());
|
|
|
|
|
if (BigDecimalUtils.equals(unpaidAmount,new BigDecimal(0))){
|
|
|
|
|
//剩余缴纳金额是0 缴费完成
|
|
|
|
|
updateOrder.setStatus( StoreOrderStatusEnum.PAID.getCode());
|
|
|
|
|
//阶段状态变为完成
|
|
|
|
|
shopStageInfoDAO.updateShopStageInfo(storeOrder.getShopId(), SHOP_SUB_STAGE_STATUS_285);
|
|
|
|
|
}
|
|
|
|
|
storeOrderDAO.updateSelective(updateOrder);
|
|
|
|
|
//清除缓存
|
|
|
|
|
String lockKey = MessageFormat.format(RedisConstant.PRE_ALLOCATION,preAllocationRecordDO.getId());
|
|
|
|
|
redisUtil.unlock(lockKey);
|
|
|
|
|
}
|
|
|
|
|
return Boolean.TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean add(PreAllocationAddRequest request) {
|
|
|
|
|
if (request == null) {
|
|
|
|
|
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PreAllocationRecordDO record = PreAllocationRecordDO.builder()
|
|
|
|
|
.orderId(request.getOrderId())
|
|
|
|
|
.shopId(request.getShopId())
|
|
|
|
|
.expenseType(request.getExpenseType())
|
|
|
|
|
.payeeName(request.getPayeeName())
|
|
|
|
|
.payeeCode(request.getPayeeCode())
|
|
|
|
|
.payAmount(request.getPayAmount())
|
|
|
|
|
.payNo(GenerateNoUtil.generateMillsNoWithRandom())
|
|
|
|
|
.remark(request.getRemark())
|
|
|
|
|
.deleted(0)
|
|
|
|
|
.allocationStatus(AllocationPayStatusEnum.UNPAID.getStatus())
|
|
|
|
|
.createTime(new Date())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
return dao.insertSelective(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean edit(PreAllocationEditRequest request) {
|
|
|
|
|
if (request == null || request.getId() == null) {
|
|
|
|
|
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PreAllocationRecordDO exist = dao.getById(request.getId());
|
|
|
|
|
if (exist == null) {
|
|
|
|
|
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PreAllocationRecordDO record = PreAllocationRecordDO.builder()
|
|
|
|
|
.id(request.getId())
|
|
|
|
|
.expenseType(request.getExpenseType())
|
|
|
|
|
.payeeName(request.getPayeeName())
|
|
|
|
|
.payeeCode(request.getPayeeCode())
|
|
|
|
|
.payAmount(request.getPayAmount())
|
|
|
|
|
.remark(request.getRemark())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
return dao.updateByPrimaryKeySelective(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean delete(Long id) {
|
|
|
|
|
if (id == null) {
|
|
|
|
|
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
return dao.softDeleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|