入驻分账比例,如果有值,去掉自动计算。

This commit is contained in:
Jack 2025-09-23 01:31:46 +08:00
parent e21eb8f518
commit 3f716c3036
5 changed files with 107 additions and 21 deletions

View File

@ -11,7 +11,6 @@ package com.suisung.mall.shop.lakala.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
@ -502,7 +501,7 @@ public class LakalaApiServiceImpl implements LakalaApiService {
}
ecParams.put("E3", "1");
ecParams.put("E4", NumberUtil.toStr(shopMchEntry.getSplit_ratio(), splitLowestRatio));
ecParams.put("E4", splitLowestRatio); // 商家签合同最低比例直接分账根据入驻时平台给的比例来计算
ecParams.put("E7", signDate);
ecParams.put("E8", shopMchEntry.getAccount_holder_name());

View File

@ -118,7 +118,7 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
ShopMchEntry shopMchEntry;
if (ObjectUtil.isEmpty(mchId)) {
shopMchEntry = shopMchEntryService.shopMerchEntryByStoreId(storeId);
shopMchEntry = shopMchEntryService.getShopMerchEntryByStoreId(storeId);
} else {
shopMchEntry = shopMchEntryService.shopMerchEntryById(mchId);
}

View File

@ -114,7 +114,7 @@ public interface ShopMchEntryService {
* @param storeId
* @return
*/
ShopMchEntry shopMerchEntryByStoreId(Integer storeId);
ShopMchEntry getShopMerchEntryByStoreId(Integer storeId);
/**

View File

@ -912,12 +912,15 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
return CommonResult.failed("商家入驻记录不存在!");
}
// 分账比例
BigDecimal splitRatio = record.getSplit_ratio();
if (splitRatio == null || BigDecimal.ZERO.compareTo(splitRatio) >= 0
|| record.getSplit_ratio().compareTo(new BigDecimal(100)) >= 0) {
// 自动计算商家分成比例
splitRatio = shopBaseStoreCategoryService.getStoreCategoryRatio(record.getBiz_category());
if (splitRatio == null || splitRatio.compareTo(BigDecimal.ZERO) <= 0) {
if (splitRatio == null
|| splitRatio.compareTo(BigDecimal.ZERO) <= 0
|| splitRatio.compareTo(new BigDecimal(100)) >= 0) {
splitRatio = new BigDecimal(94);
}
}
@ -1173,7 +1176,7 @@ public class ShopMchEntryServiceImpl extends BaseServiceImpl<ShopMchEntryMapper,
* @return
*/
@Override
public ShopMchEntry shopMerchEntryByStoreId(Integer storeId) {
public ShopMchEntry getShopMerchEntryByStoreId(Integer storeId) {
// 1. 参数校验商户ID不能为空
if (ObjectUtil.isEmpty(storeId)) {
return null;

View File

@ -3700,50 +3700,92 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
* 获取店铺的分账比例
* 根据店铺的大分小分类来计算分账比例
*
* @param storeId
* @param storeId 店铺ID
* @param reCalculate 是否根据店铺的分类来重新计算
* @return 平台分账比例的数值
*/
@Override
public BigDecimal getStoreSplitRatio(Integer storeId, boolean reCalculate) {
BigDecimal defaultSplitRatio = new BigDecimal(100);
log.debug("开始获取店铺分账比例storeId={}, reCalculate={}", storeId, reCalculate);
BigDecimal defaultSplitRatio = new BigDecimal(94);
if (storeId == null || storeId <= 0) {
log.warn("店铺ID无效使用默认分账比例: {}", defaultSplitRatio);
return defaultSplitRatio;
}
// 获取店铺基础信息
BigDecimal splitRatio = null;
ShopStoreBase shopStoreBase = get(storeId);
if (shopStoreBase == null) {
return defaultSplitRatio;
ShopMchEntry shopMchEntry = shopMchEntryService.getShopMerchEntryByStoreId(storeId);
log.debug("获取店铺和商户入驻信息完成shopStoreBase={}, shopMchEntry={}",
shopStoreBase != null ? shopStoreBase.getStore_id() : null,
shopMchEntry != null ? shopMchEntry.getId() : null);
if (shopStoreBase != null && CheckUtil.isNotEmpty(shopStoreBase.getSplit_ratio())
&& shopMchEntry != null && CheckUtil.isNotEmpty(shopMchEntry.getSplit_ratio()) &&
shopMchEntry.getSplit_ratio().compareTo(shopStoreBase.getSplit_ratio()) != 0) {
// 如果入驻申请的分账比例和店铺的分账比例不一致则使用入驻申请比例并同步给店铺记录
splitRatio = shopMchEntry.getSplit_ratio();
log.debug("入驻申请分账比例与店铺分账比例不一致,使用入驻申请比例: {}", splitRatio);
// RMK 同步给店铺记录
updateStoreBaseSplitRatio(storeId, splitRatio);
} else if (shopMchEntry != null) {
// 优先获取商家入驻申请已配置的分账比例
splitRatio = CheckUtil.isEmpty(shopMchEntry.getSplit_ratio()) ? null : shopMchEntry.getSplit_ratio();
log.debug("从商户入驻信息获取分账比例: {}", splitRatio);
} else {
// 获取店铺基础信息
if (shopStoreBase == null) {
log.warn("店铺基础信息不存在,使用默认分账比例: {}", defaultSplitRatio);
return defaultSplitRatio;
}
// 获取店铺已配置的分账比例
splitRatio = CheckUtil.isEmpty(shopStoreBase.getSplit_ratio()) ? null : shopStoreBase.getSplit_ratio();
log.debug("从店铺基础信息获取分账比例: {}", splitRatio);
}
// 获取店铺已配置的分账比例
BigDecimal splitRatio = shopStoreBase.getSplit_ratio();
// 如果没有配置或需要重新计算则基于店铺分类获取比例
if (reCalculate || splitRatio == null) {
Integer storeCategoryId = shopStoreBase.getStore_category_id();
log.debug("需要重新计算分账比例或当前比例为空,基于店铺分类计算");
if (shopStoreBase == null) {
shopStoreBase = get(storeId);
}
Integer storeCategoryId = shopStoreBase != null ? shopStoreBase.getStore_category_id() : null;
if (storeCategoryId == null) {
return defaultSplitRatio; // 默认 100%
log.warn("店铺分类ID为空使用默认分账比例: {}", defaultSplitRatio);
return defaultSplitRatio; // 默认 94%
}
// 获取店铺分类信息
ShopBaseStoreCategory category = shopBaseStoreCategoryService.get(storeCategoryId);
if (category != null && category.getSplit_ratio() != null) {
splitRatio = category.getSplit_ratio();
log.debug("从店铺分类获取分账比例: {}", splitRatio);
} else {
splitRatio = defaultSplitRatio; // 默认值
}
// 确保比例不超过 100%
if (splitRatio.compareTo(BigDecimal.ZERO) < 0 || splitRatio.compareTo(defaultSplitRatio) > 0) {
splitRatio = defaultSplitRatio;
log.warn("店铺分类分账比例为空,使用默认分账比例: {}", defaultSplitRatio);
splitRatio = defaultSplitRatio; // 默认 94%
}
}
// 确保比例在有效范围内 (0%, 100%)
if (splitRatio != null && (splitRatio.compareTo(BigDecimal.ZERO) <= 0 || splitRatio.compareTo(BigDecimal.valueOf(100)) >= 0)) {
log.warn("分账比例超出有效范围 (0, 100),使用默认分账比例: {},当前比例: {}", defaultSplitRatio, splitRatio);
splitRatio = defaultSplitRatio;
}
log.info("获取店铺分账比例完成storeId={}, splitRatio={}", storeId, splitRatio);
return splitRatio;
}
/**
* 修改店铺的营业状态
*
@ -4090,6 +4132,48 @@ public class ShopStoreBaseServiceImpl extends BaseServiceImpl<ShopStoreBaseMappe
}
}
/**
* 更新店铺分账比例
*
* @param storeId 店铺ID
* @param splitRatio 分账比例
* @return 更新结果成功返回true失败返回false
*/
protected Boolean updateStoreBaseSplitRatio(Integer storeId, BigDecimal splitRatio) {
log.debug("开始更新店铺分账比例storeId={}, splitRatio={}", storeId, splitRatio);
// 参数校验
if (storeId == null || storeId <= 0) {
log.warn("更新店铺分账比例参数校验失败storeId不能为空或小于等于0");
return false;
}
if (splitRatio == null || splitRatio.compareTo(BigDecimal.ZERO) <= 0
|| splitRatio.compareTo(BigDecimal.valueOf(100)) >= 0) {
log.warn("更新店铺分账比例参数校验失败splitRatio 值无效");
return false;
}
try {
UpdateWrapper<ShopStoreBase> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("store_id", storeId);
updateWrapper.set("split_ratio", splitRatio);
boolean result = update(updateWrapper);
if (result) {
log.info("店铺分账比例更新成功storeId={}, splitRatio={}", storeId, splitRatio);
} else {
log.warn("店铺分账比例更新失败storeId={}, splitRatio={}", storeId, splitRatio);
}
return result;
} catch (Exception e) {
log.error("更新店铺分账比例时发生异常storeId={}, splitRatio={}", storeId, splitRatio, e);
return false;
}
}
// @Override
// public Page<ShopStoreBase> getMobileStoreList(Integer page, Integer rows) {
// QueryWrapper<ShopStoreBase> queryWrapper=new QueryWrapper<>();