加盟费改造

This commit is contained in:
shuo.wang
2025-05-30 18:17:57 +08:00
parent 20fcd02ac2
commit c014841e8c
15 changed files with 464 additions and 43 deletions

View File

@@ -4,9 +4,12 @@ import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.dto.AmountDTO;
import com.cool.store.request.LinePaySubmitRequest;
import com.cool.store.response.FranchiseFeePayInfoResponse;
import com.cool.store.vo.LinePayVO;
import com.cool.store.vo.PartnerUserInfoVO;
import java.util.List;
/**
* @Author wxp
* @Date 2024/3/25 13:45
@@ -27,5 +30,9 @@ public interface LinePayService {
Long submitPayInfo(LinePaySubmitRequest followLog, PartnerUserInfoVO partnerUser);
Long submitFranchiseFeePayInfo(LinePaySubmitRequest request, String userId);
List<FranchiseFeePayInfoResponse> getFranchiseFeePayInfoList(Long shopId);
Boolean deleteFranchiseFeePayInfo(Long id,String userId);
}

View File

@@ -103,22 +103,6 @@ public class FranchiseFeeServiceImpl implements FranchiseFeeService {
return new FranchiseFeeResponse();
}
FranchiseFeeResponse resp = FranchiseFeeResponse.from(result);
LinePayDO linePayDO = linePayMapper.selectByPrimaryKey(result.getPayId());
if (Objects.nonNull(linePayDO)) {
FranchiseFeeResponse.LinePay linePayResult = FranchiseFeeResponse.LinePay.from(linePayDO);
if (Objects.nonNull(linePayDO.getLineId())){
LineInfoDO lineInfoDO = lineInfoMapper.getByLineId(linePayDO.getLineId());
linePayResult.setPartnerName(lineInfoDO.getUsername());
}
linePayResult.setAmount(new BigDecimal(result.getPerformanceBond()).add(new BigDecimal(result.getFirstYearFee())).add(new BigDecimal(result.getFirstYearManageFee()))
.add(new BigDecimal(result.getYearFranchiseFee())).add(new BigDecimal(result.getLoanMargin())).toString());
if (Objects.nonNull(result.getAuditId())) {
ShopAuditInfoDO shopAuditInfoDO = shopAuditInfoMapper.selectByPrimaryKey(result.getAuditId());
linePayResult.setStatus(shopAuditInfoDO.getResultType());
linePayResult.setResult(shopAuditInfoDO.getResultType() == 0 ? shopAuditInfoDO.getPassReason() : shopAuditInfoDO.getRejectReason());
}
resp.setLinePayDO(linePayResult);
}
ShopInfoDO shopInfoDO = shopInfoMapper.selectByPrimaryKey(shopId);
if (shopInfoDO.getPointId() != null ){
PointInfoDO pointInfoDO = pointInfoDAO.getPointInfoById(shopInfoDO.getPointId());

View File

@@ -14,21 +14,25 @@ import com.cool.store.entity.*;
import com.cool.store.enums.*;
import com.cool.store.enums.point.PayBusinessTypeEnum;
import com.cool.store.enums.point.PayTypeEnum;
import com.cool.store.enums.point.ShopSubStageEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.exception.ServiceException;
import com.cool.store.mapper.FranchiseFeeMapper;
import com.cool.store.mapper.LineInfoMapper;
import com.cool.store.mapper.ShopInfoMapper;
import com.cool.store.request.LinePaySubmitRequest;
import com.cool.store.response.FranchiseFeePayInfoResponse;
import com.cool.store.service.LinePayService;
import com.cool.store.service.UserAuthMappingService;
import com.cool.store.utils.RedisUtilPool;
import com.cool.store.utils.UUIDUtils;
import com.cool.store.utils.poi.DateUtils;
import com.cool.store.utils.poi.StringUtils;
import com.cool.store.utils.poi.constant.Constants;
import com.cool.store.vo.LinePayVO;
import com.cool.store.vo.PartnerUserInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -132,6 +136,122 @@ public class LinePayServiceImpl implements LinePayService {
return Boolean.TRUE;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Long submitFranchiseFeePayInfo(LinePaySubmitRequest request, String userId) {
log.info("submitPayInfo request{}userId{}", JSONObject.toJSONString(request), JSONObject.toJSONString(userId));
if (!checkSubmitFranchiseFeePayRequest(request)) {
throw new ServiceException(ErrorCodeEnum.PARAMS_VALIDATE_ERROR);
}
if (StringUtils.isBlank(userId)){
throw new ServiceException(ErrorCodeEnum.ACCESS_TOKEN_INVALID);
}
//判断付款人最多2人可重复
List<LinePayDO> list = linePayDAO.getFranchiseFeePayInfoByShopId(request.getShopId());
Set<String> payUserList = list.stream().map(LinePayDO::getPayUserName).collect(Collectors.toSet());
if (!payUserList.contains(request.getPayUserName())&&payUserList.size()>=2){
throw new ServiceException(ErrorCodeEnum.PAY_USER_NAME_ERROR);
}
if (request.getId() != null) {
LinePayDO linePayById = linePayDAO.getById(request.getId());
if (linePayById == null) {
throw new ServiceException(ErrorCodeEnum.UPDATE_ERROR);
}
if (linePayById.getXgjClaimStatus().equals(ClaimStatusEnum.Claimed.getCode())) {
throw new ServiceException(ErrorCodeEnum.CLAIM_STATUS_ERROR);
}
}
ShopStageInfoDO shopSubStageInfo = shopStageInfoDAO.getShopSubStageInfo(request.getShopId(), ShopSubStageEnum.SHOP_STAGE_7);
if (!shopSubStageInfo.getShopSubStageStatus().equals(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_72.getShopSubStageStatus())
&& !shopSubStageInfo.getShopSubStageStatus().equals(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_71.getShopSubStageStatus())) {
throw new ServiceException(ErrorCodeEnum.NOT_ALLOW_OPERATE);
}
String lockKey = "submitFranchiseFeePayInfo:lineId" + request.getLineId() + "shopId" + request.getShopId();
//流水
String lockValue = UUID.randomUUID().toString();
boolean acquired = false;
try {
//10s过期
acquired = redisUtilPool.setNxExpire(lockKey, lockValue, CommonConstants.TEN_SECONDS);
if (Boolean.TRUE.equals(acquired)) {
LineInfoDO lineInfo = lineInfoDAO.getLineInfo(request.getLineId());
LinePayDO linePayDO = LinePaySubmitRequest.convertFranchiseFee(request);
linePayDO.setPartnerId(lineInfo.getPartnerId());
linePayDO.setCreateUserId(userId);
linePayDO.setCreateTime(new Date());
if (linePayDO.getId() != null) {
linePayDAO.updateLinePay(linePayDO);
} else {
linePayDO.setPaymentReceiptCode(UUIDUtils.generateCustomUUID());
linePayDAO.addLinePay(linePayDO);
}
if (shopSubStageInfo.getShopSubStageStatus().equals(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_71.getShopSubStageStatus()))
{
shopStageInfoDAO.updateShopStageInfo(request.getShopId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_72);
}
//todo 苏竹红推送数据
return linePayDO.getId();
} else {
throw new ServiceException(ErrorCodeEnum.DUPLICATE_SUBMISSION);
}
} finally {
if (Boolean.TRUE.equals(acquired)) {
String currentValue = redisUtilPool.getString(lockKey);
if (lockValue.equals(currentValue)) {
redisUtilPool.delKey(lockKey);
}
}
}
}
@Override
public List<FranchiseFeePayInfoResponse> getFranchiseFeePayInfoList(Long shopId) {
List<LinePayDO> list = linePayDAO.getFranchiseFeePayInfoByShopId(shopId);
List<FranchiseFeePayInfoResponse> result = new ArrayList<>();
if (CollectionUtils.isEmpty(list)){
return result;
}
ShopInfoDO shopInfoDO = shopInfoMapper.selectByPrimaryKey(shopId);
LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId());
String username = lineInfoDO.getUsername();
for (LinePayDO linePayDO : list){
FranchiseFeePayInfoResponse response = new FranchiseFeePayInfoResponse();
BeanUtil.copyProperties(linePayDO, response);
response.setPartnerName(username);
result.add(response);
}
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean deleteFranchiseFeePayInfo(Long id,String userId) {
LinePayDO linePay = linePayDAO.getById(id);
if (linePay == null){
throw new ServiceException(ErrorCodeEnum.DELETE_ERROR);
}
if (linePay.getXgjClaimStatus().equals(ClaimStatusEnum.Claimed.getCode())) {
throw new ServiceException(ErrorCodeEnum.CLAIM_STATUS_ERROR);
}
linePayDAO.deleteById(id,userId);
//todo 苏竹红推送数据
return Boolean.TRUE;
}
private Boolean checkSubmitFranchiseFeePayRequest(LinePaySubmitRequest request) {
if (StringUtils.isAnyBlank(request.getPayUserName(), request.getPayAccount(), request.getBankName(), request.getBranchBankName(),
request.getPayTime(), request.getPayPic())) {
return Boolean.FALSE;
}
if (Objects.isNull(request.getPayType()) || request.getLineId() == null || request.getShopId() == null) {
return Boolean.FALSE;
}
if (!request.getPayBusinessType().equals(PayBusinessTypeEnum.FRANCHISE_FEE.getCode())) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Long submitPayInfo(LinePaySubmitRequest request, PartnerUserInfoVO partnerUser) {
@@ -139,26 +259,54 @@ public class LinePayServiceImpl implements LinePayService {
if (Objects.isNull(request.getPayBusinessType())) {
request.setPayBusinessType(Constants.ZERO_INTEGER);
}
if (request.getPayBusinessType().equals(PayBusinessTypeEnum.FRANCHISE_FEE.getCode())) {
throw new ServiceException(ErrorCodeEnum.API_CALL_ERROR);
}
LineInfoDO lineInfo = new LineInfoDO();
if (request.getLineId() != null) {
lineInfo = lineInfoDAO.getLineInfo(request.getLineId());
}
// //缴纳加盟费检验缴费人必须是加盟商
// if(PayBusinessTypeEnum.FRANCHISE_FEE.getCode().equals(request.getPayBusinessType()) && !lineInfo.getUsername().trim().equals(request.getPayUserName().trim())){
// throw new ServiceException(ErrorCodeEnum.CHECK_PAYER_ERROR);
// }
LinePayDO linePayDO = linePayDAO.getByLineIdAndPayTypeAndShopId(request.getLineId(), request.getPayBusinessType(), request.getShopId());
linePayDO = checkAndFill(linePayDO, request, partnerUser);
Long payId = linePayDO.getId();
if (PayBusinessTypeEnum.FRANCHISE_FEE.getCode().equals(request.getPayBusinessType()) && payId != null) {
FranchiseFeeDO franchiseFeeDO = franchiseFeeMapper.selectByShopId(request.getShopId());
if (Objects.isNull(franchiseFeeDO)) {
throw new ServiceException(ErrorCodeEnum.UNISSUED_STATEMENT);
}
franchiseFeeDO.setPayId(payId);
franchiseFeeMapper.updateByPrimaryKeySelective(franchiseFeeDO);
shopStageInfoDAO.updateShopStageInfo(request.getShopId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_72);
//todo 苏竹红推送数据
// if (PayBusinessTypeEnum.FRANCHISE_FEE.getCode().equals(request.getPayBusinessType()) && payId != null) {
// FranchiseFeeDO franchiseFeeDO = franchiseFeeMapper.selectByShopId(request.getShopId());
// if (Objects.isNull(franchiseFeeDO)) {
// throw new ServiceException(ErrorCodeEnum.UNISSUED_STATEMENT);
// }
// franchiseFeeDO.setPayId(payId);
// franchiseFeeMapper.updateByPrimaryKeySelective(franchiseFeeDO);
// shopStageInfoDAO.updateShopStageInfo(request.getShopId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_72);
// ShopInfoDO shopInfoDO = shopInfoMapper.selectByPrimaryKey(franchiseFeeDO.getShopId());
// Set<String> auditFranchiseFeeUsers = new HashSet<>();
// List<EnterpriseUserDO> branchUser = userAuthMappingService.getAllUserByRoleEnumAndRegionId(UserRoleEnum.BRANCH_OFFICE, shopInfoDO.getRegionId());
// if (Objects.nonNull(branchUser)) {
// Set<String> branchUserIds = branchUser.stream().map(EnterpriseUserDO::getUserId).collect(Collectors.toSet());
// auditFranchiseFeeUsers.addAll(branchUserIds);
// }
// List<EnterpriseUserDO> regionUser = userAuthMappingService.getAllUserByRoleEnumAndRegionId(UserRoleEnum.REGION_OFFICE, shopInfoDO.getRegionId());
// if (Objects.nonNull(regionUser)) {
// Set<String> regionUserIds = regionUser.stream().map(EnterpriseUserDO::getUserId).collect(Collectors.toSet());
// auditFranchiseFeeUsers.addAll(regionUserIds);
// }
// HashMap<String, String> map = new HashMap<>();
// map.put("partnerUsername", lineInfo.getUsername());
// map.put("partnerMobile", lineInfo.getMobile());
// map.put("storeName", shopInfoDO.getShopName());
// commonService.sendQWMessage(new ArrayList<>(auditFranchiseFeeUsers),
// MessageEnum.MESSAGE_18,
// map);
// }
if (PayBusinessTypeEnum.INTENT_MONEY.getCode().equals(request.getPayBusinessType())) {
lineInfo.setWorkflowSubStage(WorkflowSubStageEnum.PAY_DEPOSIT.getCode());
lineInfo.setWorkflowSubStageStatus(WorkflowSubStageStatusEnum.PAY_DEPOSIT_50.getCode());
lineInfoDAO.insertOrUpdate(lineInfo);
HashMap<String, String> map = new HashMap<>();
map.put("partnerUsername", lineInfo.getUsername());
map.put("partnerMobile", lineInfo.getMobile());
commonService.sendQWMessage(Collections.singletonList(lineInfo.getInvestmentManager()),
MessageEnum.MESSAGE_5,
map);
}
return payId == null ? null : payId;
}
@@ -179,7 +327,6 @@ public class LinePayServiceImpl implements LinePayService {
}
private void fillLinePay(Boolean isAdd, LinePayDO linePayDO, LinePaySubmitRequest request, PartnerUserInfoVO partnerUser) {
linePayDO.setPaySerialNumber(request.getPaySerialNumber());
linePayDO.setCombinedField(request.getCombinedField());
linePayDO.setPayType(request.getPayType());
linePayDO.setPayUserName(request.getPayUserName());
@@ -190,7 +337,7 @@ public class LinePayServiceImpl implements LinePayService {
linePayDO.setBranchBankName(request.getBranchBankName());
if (Objects.nonNull(request.getPayTime())) {
linePayDO.setPayTime(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", request.getPayTime()));
}else {
} else {
linePayDO.setPayTime(null);
}
linePayDO.setPayPic(request.getPayPic());