应付配置的附加费调整

This commit is contained in:
liuminghui
2026-11-18 13:34:00 +08:00
parent ccfb05bf50
commit a72417b2c1
30 changed files with 1338 additions and 107 deletions
@@ -29,6 +29,7 @@ import com.bms.price.domain.ChannelProductMap;
import com.bms.price.domain.PayProduct;
import com.bms.price.domain.PayProductTerm;
import com.bms.price.domain.PaySaveCommand;
import com.bms.price.domain.PaySurcharge;
import com.bms.price.pay.PayDetailExporter;
import com.bms.price.pay.PayChargeMode;
import com.bms.price.pay.PayTemplateWorkbook;
@@ -136,6 +137,24 @@ public class PayProductController extends BaseController
return success(payProductService.saveManual(product));
}
/** 这一版从附加费配置勾选的费用 */
@PreAuthorize("@ss.hasPermi('price:pay:surcharge')")
@GetMapping("/term/{termId}/config-surcharges")
public AjaxResult configSurcharges(@PathVariable Long termId)
{
return success(payProductService.listConfigSurcharges(termId));
}
/** 保存这一版勾选的附加费和计费参数 */
@PreAuthorize("@ss.hasPermi('price:pay:surcharge')")
@Log(title = "应付价卡附加费", businessType = BusinessType.UPDATE)
@PutMapping("/term/{termId}/config-surcharges")
public AjaxResult saveConfigSurcharges(@PathVariable Long termId, @RequestBody List<PaySurcharge> rows)
{
payProductService.saveConfigSurcharges(termId, rows);
return success();
}
@PreAuthorize("@ss.hasPermi('price:pay:query')")
@GetMapping("/{productId}")
public AjaxResult getInfo(@PathVariable Long productId)
@@ -87,6 +87,7 @@ public class SurchargeController extends BaseController
+ " or @ss.hasPermi('price:set:query') or @ss.hasPermi('price:set:add') or @ss.hasPermi('price:set:edit')"
+ " or @ss.hasPermi('price:billing:bill')"
+ " or @ss.hasPermi('price:pay:query') or @ss.hasPermi('price:pay:edit') or @ss.hasPermi('price:pay:import')"
+ " or @ss.hasPermi('price:pay:surcharge')"
+ " or @ss.hasPermi('price:airBill:fee')")
@GetMapping("/options")
public AjaxResult listOptions(PrcSurcharge surcharge)
@@ -63,9 +63,27 @@ public class PaySurcharge
/** 邮编列表、重量阈值或尺寸表达式。续重时这里是公斤阈值 */
private String calcParam;
/** 偏远邮编规则。续重行的阈值在 calcParam,邮编放这里,避免互相覆盖 */
/** 偏远邮编规则。导入价卡仍可能把邮编写在这里 */
private String postcodeParam;
/** 来自附加费配置的长,厘米。本表不保存 */
private BigDecimal lengthCm;
/** 来自附加费配置的宽,厘米。本表不保存 */
private BigDecimal widthCm;
/** 来自附加费配置的高,厘米。本表不保存 */
private BigDecimal heightCm;
/** 来自附加费配置的超重阈值,公斤。本表不保存 */
private BigDecimal overWeightKg;
/** 来自附加费配置的续重起始重量,公斤。本表不保存 */
private BigDecimal extraWeightKg;
/** 来自附加费配置的命中邮编。本表不保存 */
private String postcodeText;
/** 适用重量下限,空表示不限。首重从 0 开始 */
private BigDecimal weightMin;
@@ -21,6 +21,18 @@ public class PrcSurcharge extends BaseEntity
/** 渠道产品(字典 payment_product_type.dict_value) */
private String dictValue;
private BigDecimal chargeValue;
/** 超尺寸长,厘米 */
private BigDecimal lengthCm;
/** 超尺寸宽,厘米 */
private BigDecimal widthCm;
/** 超尺寸高,厘米 */
private BigDecimal heightCm;
/** 超重阈值,公斤 */
private BigDecimal overWeightKg;
/** 超重续收起始重量,公斤 */
private BigDecimal extraWeightKg;
/** 命中邮编,多个用逗号分隔 */
private String postcodeText;
private String currency;
/** 字典 bms_round_mode:UP / DOWN / HALF_UP */
private String roundMode;
@@ -0,0 +1,66 @@
package com.bms.price.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
/**
* 产品与附加费配置的关联。应付、应收以及后续类型都按产品编号和类型查询。
*/
@Data
public class PrcSurchargeBind
{
public static final String TYPE_AP = "AP";
public static final String TYPE_AR = "AR";
private Long bindId;
private Long productId;
/** AP 应付,AR 应收,以及后续其它类型 */
private String productType;
private Long scId;
private Integer sortNo;
private String createdBy;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
private String updatedBy;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
/** 关联查询带出的附加费配置 */
private String scName;
private String chargeType;
private BigDecimal chargeValue;
private String currency;
/** on 启用,of 停用,vd 作废 */
private String ssCode;
private String blockTitle;
private String scNote;
private BigDecimal lengthCm;
private BigDecimal widthCm;
private BigDecimal heightCm;
private BigDecimal overWeightKg;
private BigDecimal extraWeightKg;
private String postcodeText;
}
@@ -58,6 +58,10 @@ public interface PayProductMapper
int deleteSurchargesByTerm(@Param("termIds") List<Long> termIds);
int deleteSurchargesByTermSection(@Param("termId") Long termId, @Param("sectionName") String sectionName);
int refreshSurchargeCount(@Param("productId") Long productId);
int deleteExtraLinesByTerm(@Param("termIds") List<Long> termIds);
Long selectTemplateIdByType(@Param("dictValue") String dictValue, @Param("productType") String productType);
@@ -0,0 +1,23 @@
package com.bms.price.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.price.domain.PrcSurchargeBind;
/**
* 产品与附加费配置的关联。
*/
public interface PrcSurchargeBindMapper
{
List<PrcSurchargeBind> selectByProduct(@Param("productId") Long productId, @Param("productType") String productType);
List<PrcSurchargeBind> selectByProductIds(@Param("productIds") List<Long> productIds);
int deleteByProduct(@Param("productId") Long productId, @Param("productType") String productType);
int deleteByProductIds(@Param("productIds") List<Long> productIds);
int insertBinds(@Param("list") List<PrcSurchargeBind> list);
int rebindScId(@Param("oldScId") Long oldScId, @Param("newScId") Long newScId);
}
@@ -24,4 +24,10 @@ public interface PrcSurchargeMapper
/** 状态原地更新(不新增数据):停用置 of,版本化作废旧记录置 vd */
public int updateSsCodeByIds(@Param("scIds") Long[] scIds, @Param("ssCode") String ssCode, @Param("operator") String operator);
/** 附加费改版后,应付价卡上的选择改指向新记录,并带上新的金额和说明。 */
public int rebindPayConfig(@Param("oldScId") Long oldScId, @Param("newScId") Long newScId,
@Param("feeName") String feeName, @Param("zoneName") String zoneName, @Param("amount") java.math.BigDecimal amount,
@Param("currency") String currency, @Param("feeDesc") String feeDesc, @Param("calcRule") String calcRule,
@Param("chargeText") String chargeText, @Param("priceUnit") String priceUnit);
}
@@ -338,7 +338,7 @@ public final class LabelArCostCalculator
String name = blank(fee.getFeeName());
if (PaySurchargeRules.POSTCODE.equals(rule))
{
String param = blank(fee.getPostcodeParam()).isEmpty() ? fee.getCalcParam() : fee.getPostcodeParam();
String param = PaySurchargeRules.feePostcodes(fee);
if (postcode == null || postcode.isBlank())
{
result.getSkipped().add(name + ":订单没有邮编");
@@ -358,9 +358,9 @@ public final class LabelArCostCalculator
}
else if (PaySurchargeRules.WEIGHT.equals(rule))
{
if (PaySurchargeRules.matchesWeight(fee.getCalcParam(), weight))
if (PaySurchargeRules.matchesFeeWeight(fee, weight))
{
addFlat(result.getFees(), fee, currency, "计费重超过 " + fee.getCalcParam() + "kg");
addFlat(result.getFees(), fee, currency, "计费重超过 " + PaySurchargeRules.weightText(fee) + "kg");
}
}
// 超出尺寸费用
@@ -370,7 +370,7 @@ public final class LabelArCostCalculator
{
result.getSkipped().add(name + ":订单没有长宽高");
}
else if (PaySurchargeRules.matchesSize(fee.getCalcParam(), length, width, height))
else if (PaySurchargeRules.matchesFeeSize(fee, length, width, height))
{
PayCostLine matched = matchedFee(fee, freight, currency, "尺寸命中 " + fee.getCalcParam());
if (matched != null)
@@ -459,12 +459,8 @@ public final class LabelArCostCalculator
{
return;
}
BigDecimal threshold;
try
{
threshold = new BigDecimal(fee.getCalcParam() == null ? "" : fee.getCalcParam().trim());
}
catch (NumberFormatException ex)
BigDecimal threshold = PaySurchargeRules.extraStartKg(fee);
if (threshold == null)
{
return;
}
@@ -517,16 +513,10 @@ public final class LabelArCostCalculator
{
continue;
}
try
BigDecimal start = PaySurchargeRules.extraStartKg(fee);
if (start != null && start.compareTo(threshold) == 0)
{
if (fee.getCalcParam() != null && new BigDecimal(fee.getCalcParam().trim()).compareTo(threshold) == 0)
{
return true;
}
}
catch (NumberFormatException ex)
{
continue;
return true;
}
}
return false;
@@ -593,11 +583,7 @@ public final class LabelArCostCalculator
/** 价卡这一档写了邮编时,订单邮编必须落在里面。续重的重量门槛不算邮编。 */
private static boolean feePostcodeMatches(PaySurcharge fee, String rule, String postcode)
{
String param = blank(fee.getPostcodeParam());
if (param.isEmpty() && !PaySurchargeRules.EXTRA_KG.equals(rule))
{
param = blank(fee.getCalcParam());
}
String param = PaySurchargeRules.EXTRA_KG.equals(rule) ? blank(fee.getPostcodeParam()) : PaySurchargeRules.feePostcodes(fee);
if (param.isEmpty())
{
return false;
@@ -363,7 +363,7 @@ public final class PayCostCalculator
}
else
{
String param = blank(fee.getPostcodeParam()).isEmpty() ? fee.getCalcParam() : fee.getPostcodeParam();
String param = PaySurchargeRules.feePostcodes(fee);
if (postcode == null || postcode.isBlank())
{
result.getSkipped().add(name + ":订单没有邮编");
@@ -400,9 +400,9 @@ public final class PayCostCalculator
}
else if (PaySurchargeRules.WEIGHT.equals(rule))
{
if (PaySurchargeRules.matchesWeight(fee.getCalcParam(), weight))
if (PaySurchargeRules.matchesFeeWeight(fee, weight))
{
addFlat(result.getFees(), fee, currency, "计费重超过 " + fee.getCalcParam() + "kg");
addFlat(result.getFees(), fee, currency, "计费重超过 " + PaySurchargeRules.weightText(fee) + "kg");
}
}
// 超出尺寸费用
@@ -509,12 +509,8 @@ public final class PayCostCalculator
{
return;
}
BigDecimal threshold;
try
{
threshold = new BigDecimal(fee.getCalcParam() == null ? "" : fee.getCalcParam().trim());
}
catch (NumberFormatException ex)
BigDecimal threshold = PaySurchargeRules.extraStartKg(fee);
if (threshold == null)
{
return;
}
@@ -567,16 +563,10 @@ public final class PayCostCalculator
{
continue;
}
try
BigDecimal start = PaySurchargeRules.extraStartKg(fee);
if (start != null && start.compareTo(threshold) == 0)
{
if (fee.getCalcParam() != null && new BigDecimal(fee.getCalcParam().trim()).compareTo(threshold) == 0)
{
return true;
}
}
catch (NumberFormatException ex)
{
continue;
return true;
}
}
return false;
@@ -601,7 +591,7 @@ public final class PayCostCalculator
List<Map<String, Object>> details = ruleDetails(product, PaySurchargeRules.SIZE);
if (details.isEmpty())
{
return PaySurchargeRules.matchesSize(fee.getCalcParam(), length, width, height);
return PaySurchargeRules.matchesFeeSize(fee, length, width, height);
}
for (Map<String, Object> detail : details)
{
@@ -711,11 +701,7 @@ public final class PayCostCalculator
/** 价卡这一档写了邮编时,订单邮编必须落在里面。续重的重量门槛不算邮编。 */
private static boolean feePostcodeMatches(PaySurcharge fee, String rule, String postcode)
{
String param = blank(fee.getPostcodeParam());
if (param.isEmpty() && !PaySurchargeRules.EXTRA_KG.equals(rule))
{
param = blank(fee.getCalcParam());
}
String param = PaySurchargeRules.EXTRA_KG.equals(rule) ? blank(fee.getPostcodeParam()) : PaySurchargeRules.feePostcodes(fee);
if (param.isEmpty())
{
return false;
@@ -180,25 +180,27 @@ public class PayOrderFeeCalculator
}
/**
* 运费仍按订单日期取版本。附加费明细改用这个产品今天生效的版本。
* 运费仍按订单日期取版本。附加费只取该价卡产品已绑定且启用的附加费配置。
*
* @param channelId 渠道 ID
* @param priced 订单日期已经命中的价卡,方法会改写它的附加费
*/
private void applyCurrentSurcharge(String channelId, PayProduct priced)
{
PayProduct source = priced;
try
{
PayProduct current = payProductService.selectPriceForDate(channelId, new Date());
if (current != null && current.getSurcharges() != null)
if (current != null)
{
priced.setSurcharges(current.getSurcharges());
source = current;
}
}
catch (ServiceException ignored)
{
// 今天没有生效版本时,附加费明细仍用订单日期命中的那一版
// 今天没有生效版本时,改查订单日期命中的那一版有没有绑定
}
priced.setSurcharges(payProductService.boundSurcharges(source));
}
/**
@@ -505,6 +505,82 @@ public final class PaySurchargeRules
}
}
/** 配置了长宽高时按三边箱规判断,否则仍认导入价卡里的尺寸表达式。 */
public static boolean matchesFeeSize(PaySurcharge fee, BigDecimal length, BigDecimal width, BigDecimal height)
{
if (fee != null && fee.getLengthCm() != null && fee.getWidthCm() != null && fee.getHeightCm() != null)
{
if (length == null || width == null || height == null)
{
return false;
}
return exceedsBox(desc(length, width, height), fee.getLengthCm(), fee.getWidthCm(), fee.getHeightCm());
}
return matchesSize(fee == null ? null : fee.getCalcParam(), length, width, height);
}
/** 配置了超重公斤时按该值判断,否则仍认导入价卡里的重量文本。 */
public static boolean matchesFeeWeight(PaySurcharge fee, BigDecimal weight)
{
if (fee != null && fee.getOverWeightKg() != null)
{
return weight != null && weight.compareTo(fee.getOverWeightKg()) > 0;
}
return matchesWeight(fee == null ? null : fee.getCalcParam(), weight);
}
/** 续重起始公斤。配置列优先,导入价卡仍从原条件文本读取。 */
public static BigDecimal extraStartKg(PaySurcharge fee)
{
if (fee == null)
{
return null;
}
if (fee.getExtraWeightKg() != null)
{
return fee.getExtraWeightKg();
}
if (fee.getCalcParam() == null || fee.getCalcParam().isBlank())
{
return null;
}
try
{
return new BigDecimal(fee.getCalcParam().trim());
}
catch (NumberFormatException ex)
{
return null;
}
}
/** 命中邮编。独立字段优先,其次是原来的邮编列和导入文本。 */
public static String feePostcodes(PaySurcharge fee)
{
if (fee == null)
{
return "";
}
if (fee.getPostcodeText() != null && !fee.getPostcodeText().isBlank())
{
return fee.getPostcodeText().trim();
}
if (fee.getPostcodeParam() != null && !fee.getPostcodeParam().isBlank())
{
return fee.getPostcodeParam().trim();
}
return fee.getCalcParam() == null ? "" : fee.getCalcParam().trim();
}
public static String weightText(PaySurcharge fee)
{
if (fee != null && fee.getOverWeightKg() != null)
{
return fee.getOverWeightKg().stripTrailingZeros().toPlainString();
}
return fee == null || fee.getCalcParam() == null ? "" : fee.getCalcParam();
}
public static boolean matchesWeight(String param, BigDecimal weight)
{
if (param == null || param.isBlank() || weight == null)
@@ -11,6 +11,7 @@ import com.bms.price.domain.ChannelProductMap;
import com.bms.price.domain.PayProduct;
import com.bms.price.domain.PayProductTerm;
import com.bms.price.domain.PaySaveCommand;
import com.bms.price.domain.PaySurcharge;
/**
* 应付价卡配置:预览后保存,列表查询和导出。
@@ -136,6 +137,18 @@ public interface IPayProductService
/** 产品及其重量段、附加费、邮编配置 */
PayProduct selectPayProductDetail(Long productId);
/** 这一版价卡上,从附加费配置勾选进来的费用 */
List<PaySurcharge> listConfigSurcharges(Long termId);
/**
* 应付计费用的附加费。只取这个产品在关联表里绑定、并且仍在启用的附加费配置。
* 没有绑定时返回空列表,价卡里导入的附加费不参与计算。
*/
List<PaySurcharge> boundSurcharges(PayProduct product);
/** 按附加费配置重写这一版勾选的费用,导入进来的附加费不动 */
void saveConfigSurcharges(Long termId, List<PaySurcharge> rows);
/** 确认这一版有源文件,返回原始文件名 */
String sourceFileName(Long productId);
@@ -229,21 +229,23 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService
* @param product 当前价卡版本
* @return 名称能对上的邮编组,没有时为空列表
*/
/** 运费仍按订单日期取版本。附加费条件和附加费明细改用产品当前生效版本。 */
/** 运费仍按订单日期取版本。附加费只取该价卡产品已绑定且启用的附加费配置。 */
private void applyCurrentSurcharge(String channelId, PayProduct priced)
{
PayProduct source = priced;
try
{
PayProduct current = payProductService.selectPriceForDate(channelId, new Date());
if (current != null && current.getSurcharges() != null)
if (current != null)
{
priced.setSurcharges(current.getSurcharges());
source = current;
}
}
catch (ServiceException ignored)
{
// 今天没有生效版本时,附加费明细仍用订单日期命中的那一版
// 今天没有生效版本时,改查订单日期命中的那一版有没有绑定
}
priced.setSurcharges(payProductService.boundSurcharges(source));
}
private List<PayPostcodeGroup> linkedGroups(PayProduct product)
@@ -41,12 +41,14 @@ import com.bms.price.domain.PaySurcharge;
import com.bms.price.domain.PayWeightBand;
import com.bms.price.domain.PrcPriceSet;
import com.bms.price.domain.PrcSurcharge;
import com.bms.price.domain.PrcSurchargeBind;
import com.bms.masterdata.domain.ServiceChannel;
import com.bms.masterdata.mapper.ServiceChannelMapper;
import com.bms.price.mapper.ChannelProductMapMapper;
import com.bms.price.mapper.PayProductMapper;
import com.bms.price.mapper.PayProductTermMapper;
import com.bms.price.mapper.PrcPriceSetMapper;
import com.bms.price.mapper.PrcSurchargeBindMapper;
import com.bms.price.mapper.PrcSurchargeMapper;
import com.bms.price.pay.PayParseProgressListener;
import com.bms.price.pay.PayChargeMode;
@@ -84,6 +86,9 @@ public class PayProductServiceImpl implements IPayProductService
@Autowired
private PrcSurchargeMapper prcSurchargeMapper;
@Autowired
private PrcSurchargeBindMapper surchargeBindMapper;
@Autowired
private ChannelProductMapMapper channelProductMapMapper;
@@ -1002,15 +1007,302 @@ public class PayProductServiceImpl implements IPayProductService
product.setWeightBands(payProductMapper.selectWeightBandsByTerm(termIds));
product.setSurcharges(payProductMapper.selectSurchargesByTerm(termIds));
product.setExtraLines(payProductMapper.selectExtraLinesByTerm(termIds));
appendBoundSurcharges(product);
return product;
}
List<Long> ids = Collections.singletonList(productId);
product.setWeightBands(payProductMapper.selectWeightBands(ids));
product.setSurcharges(payProductMapper.selectSurcharges(ids));
product.setExtraLines(payProductMapper.selectExtraLines(ids));
appendBoundSurcharges(product);
return product;
}
private static final String CONFIG_SECTION = "附加费配置";
@Override
public List<PaySurcharge> listConfigSurcharges(Long termId)
{
PayProductTerm term = requireTerm(termId);
PayProduct product = payProductMapper.selectPayProductById(term.getProductId());
if (product == null)
{
throw new ServiceException("价卡不存在");
}
List<PaySurcharge> picked = new ArrayList<>();
for (PrcSurchargeBind bind : surchargeBindMapper.selectByProduct(product.getProductId(), bindType(product)))
{
picked.add(toBoundFee(bind));
}
return picked;
}
@Override
public List<PaySurcharge> boundSurcharges(PayProduct product)
{
List<PaySurcharge> fees = new ArrayList<>();
if (product == null || product.getProductId() == null)
{
return fees;
}
for (PrcSurchargeBind bind : surchargeBindMapper.selectByProduct(product.getProductId(), bindType(product)))
{
if (bind == null || bind.getSsCode() == null || !"on".equalsIgnoreCase(bind.getSsCode()))
{
continue;
}
fees.add(toBoundFee(bind, product.getCurrency()));
}
return fees;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveConfigSurcharges(Long termId, List<PaySurcharge> rows)
{
PayProductTerm term = requireTerm(termId);
PayProduct product = payProductMapper.selectPayProductById(term.getProductId());
if (product == null)
{
throw new ServiceException("价卡不存在");
}
List<PrcSurchargeBind> saving = new ArrayList<>();
Set<Long> seen = new LinkedHashSet<>();
int sort = 1;
String type = bindType(product);
for (PaySurcharge input : rows == null ? List.<PaySurcharge>of() : rows)
{
if (input == null || input.getScId() == null)
{
throw new ServiceException("请选择附加费");
}
if (!seen.add(input.getScId()))
{
throw new ServiceException("同一附加费不能重复添加");
}
PrcSurcharge config = prcSurchargeMapper.selectPrcSurchargeById(input.getScId());
if (config == null || !"on".equalsIgnoreCase(config.getSsCode()))
{
throw new ServiceException("附加费不存在或已停用");
}
if (config.getChargeValue() == null)
{
throw new ServiceException(config.getScName() + "还没有计费数值,请先到附加费配置里填写");
}
PaySurcharge check = new PaySurcharge();
check.setFeeName(config.getScName());
check.setCurrency(isBlank(config.getCurrency()) ? product.getCurrency() : config.getCurrency());
check.setCalcRule(calcRuleOf(config.getChargeType()));
check.setFeeDesc(config.getScNote());
applyConfigParam(check, config);
PrcSurchargeBind bind = new PrcSurchargeBind();
bind.setProductId(product.getProductId());
bind.setProductType(type);
bind.setScId(config.getScId());
bind.setSortNo(sort++);
bind.setCreatedBy(SecurityUtils.getUsername());
saving.add(bind);
}
surchargeBindMapper.deleteByProduct(product.getProductId(), type);
if (!saving.isEmpty())
{
surchargeBindMapper.insertBinds(saving);
}
payProductMapper.deleteSurchargesByTermSection(termId, CONFIG_SECTION);
payProductMapper.refreshSurchargeCount(product.getProductId());
}
/** 条件只认附加费配置上的字段,价卡行只记下说明文字。 */
private void applyConfigParam(PaySurcharge fee, PrcSurcharge config)
{
String rule = fee.getCalcRule();
String currency = isBlank(fee.getCurrency()) ? DEFAULT_CURRENCY : fee.getCurrency();
if ("SIZE".equals(rule))
{
BigDecimal length = positive(config.getLengthCm(), fee.getFeeName() + "的长");
BigDecimal width = positive(config.getWidthCm(), fee.getFeeName() + "的宽");
BigDecimal height = positive(config.getHeightCm(), fee.getFeeName() + "的高");
fee.setChargeText("超过 " + plain(length) + "×" + plain(width) + "×" + plain(height) + "cm");
fee.setPriceUnit(currency + "/ITEM");
return;
}
if ("WEIGHT".equals(rule))
{
BigDecimal threshold = positiveOrZero(config.getOverWeightKg(), fee.getFeeName() + "的超重重量");
fee.setChargeText("超过 " + plain(threshold) + "kg");
fee.setPriceUnit(currency + "/ITEM");
return;
}
if ("EXTRA_KG".equals(rule))
{
BigDecimal threshold = positiveOrZero(config.getExtraWeightKg(), fee.getFeeName() + "的续重起始重量");
fee.setChargeText("超出 " + plain(threshold) + "kg 后续收");
fee.setPriceUnit(currency + "/KG");
return;
}
if ("POSTCODE".equals(rule))
{
String postcodes = joinPostcodes(config.getPostcodeText());
if (postcodes.isEmpty())
{
throw new ServiceException(fee.getFeeName() + "请先到附加费配置里填写邮编");
}
fee.setChargeText(cut("邮编 " + postcodes, 500));
fee.setPriceUnit(currency + "/ITEM");
return;
}
fee.setPriceUnit(currency + "/ITEM");
fee.setChargeText(isBlank(fee.getFeeDesc()) ? "" : cut(fee.getFeeDesc(), 500));
}
private void appendBoundSurcharges(PayProduct product)
{
if (product == null || product.getProductId() == null)
{
return;
}
List<PaySurcharge> fees = product.getSurcharges();
if (fees == null)
{
fees = new ArrayList<>();
product.setSurcharges(fees);
}
fees.removeIf(fee -> fee != null && CONFIG_SECTION.equals(fee.getSectionName()));
for (PrcSurchargeBind bind : surchargeBindMapper.selectByProduct(product.getProductId(), bindType(product)))
{
fees.add(toBoundFee(bind, product.getCurrency()));
}
}
private PaySurcharge toBoundFee(PrcSurchargeBind bind)
{
return toBoundFee(bind, null);
}
private PaySurcharge toBoundFee(PrcSurchargeBind bind, String productCurrency)
{
PaySurcharge fee = new PaySurcharge();
fee.setProductId(bind.getProductId());
fee.setSectionName(CONFIG_SECTION);
fee.setFeeName(bind.getScName());
fee.setScId(bind.getScId());
fee.setZoneName(blankTo(bind.getBlockTitle(), ""));
fee.setAmount(bind.getChargeValue());
fee.setCurrency(isBlank(bind.getCurrency()) ? productCurrency : bind.getCurrency().trim().toUpperCase(Locale.ROOT));
fee.setFeeDesc(bind.getScNote());
fee.setCalcRule(calcRuleOf(bind.getChargeType()));
fee.setSortNo(bind.getSortNo());
fee.setLengthCm(bind.getLengthCm());
fee.setWidthCm(bind.getWidthCm());
fee.setHeightCm(bind.getHeightCm());
fee.setOverWeightKg(bind.getOverWeightKg());
fee.setExtraWeightKg(bind.getExtraWeightKg());
fee.setPostcodeText(bind.getPostcodeText());
PrcSurcharge config = new PrcSurcharge();
config.setChargeType(bind.getChargeType());
config.setLengthCm(bind.getLengthCm());
config.setWidthCm(bind.getWidthCm());
config.setHeightCm(bind.getHeightCm());
config.setOverWeightKg(bind.getOverWeightKg());
config.setExtraWeightKg(bind.getExtraWeightKg());
config.setPostcodeText(bind.getPostcodeText());
config.setScNote(bind.getScNote());
applyConfigParam(fee, config);
return fee;
}
private static String bindType(PayProduct product)
{
if (product == null || isBlank(product.getProductType()))
{
return PAY_TYPE_AP;
}
return product.getProductType().trim().toUpperCase(Locale.ROOT);
}
private PayProductTerm requireTerm(Long termId)
{
if (termId == null)
{
throw new ServiceException("请先为价卡设置有效期");
}
PayProductTerm term = payProductTermMapper.selectById(termId);
if (term == null || term.getPriceSetId() != null)
{
throw new ServiceException("价卡版本不存在");
}
return term;
}
private static String calcRuleOf(String chargeType)
{
if (chargeType == null)
{
return "MANUAL";
}
String code = chargeType.trim().toUpperCase(Locale.ROOT);
if ("FIXED".equals(code))
{
return "ALWAYS";
}
if ("RATE".equals(code))
{
return "MANUAL";
}
if ("ALWAYS".equals(code) || "POSTCODE".equals(code) || "ZONE".equals(code) || "EXTRA_KG".equals(code)
|| "WEIGHT".equals(code) || "SIZE".equals(code) || "RETURN".equals(code) || "MANUAL".equals(code))
{
return code;
}
return "MANUAL";
}
private static BigDecimal positive(BigDecimal value, String label)
{
if (value == null || value.compareTo(BigDecimal.ZERO) <= 0)
{
throw new ServiceException(label + "要大于 0,请先到附加费配置里填写");
}
return value;
}
private static BigDecimal positiveOrZero(BigDecimal value, String label)
{
if (value == null)
{
throw new ServiceException("请先到附加费配置里填写" + label);
}
if (value.compareTo(BigDecimal.ZERO) < 0)
{
throw new ServiceException(label + "不能小于 0");
}
return value;
}
private static String joinPostcodes(String raw)
{
if (raw == null)
{
return "";
}
String normalized = raw.replace(',', ',').replace('、', ',').replace(';', ',').replace(';', ',').replace('\n', ',').replace('\r', ',');
LinkedHashSet<String> tokens = new LinkedHashSet<>();
for (String part : normalized.split(","))
{
String value = part.trim();
if (!value.isEmpty())
{
tokens.add(value);
}
}
return String.join(",", tokens);
}
private static String plain(BigDecimal value)
{
return value.stripTrailingZeros().toPlainString();
}
@Override
public PayProduct selectPayProductDetailByTerm(Long termId)
{
@@ -1041,6 +1333,7 @@ public class PayProductServiceImpl implements IPayProductService
product.setWeightBands(payProductMapper.selectWeightBandsByTerm(termIds));
product.setSurcharges(payProductMapper.selectSurchargesByTerm(termIds));
product.setExtraLines(payProductMapper.selectExtraLinesByTerm(termIds));
appendBoundSurcharges(product);
return product;
}
@@ -1626,6 +1919,7 @@ public class PayProductServiceImpl implements IPayProductService
payProductTermMapper.deleteByProductIds(ids);
payProductMapper.deleteWeightBands(ids);
payProductMapper.deleteSurcharges(ids);
surchargeBindMapper.deleteByProductIds(ids);
payProductMapper.deleteExtraLines(ids);
return payProductMapper.deletePayProducts(ids);
}
@@ -1658,11 +1952,19 @@ public class PayProductServiceImpl implements IPayProductService
for (PaySurcharge fee : payProductMapper.selectSurcharges(ids))
{
PayProduct owner = map.get(fee.getProductId());
if (owner != null)
if (owner != null && (fee == null || !CONFIG_SECTION.equals(fee.getSectionName())))
{
owner.getSurcharges().add(fee);
}
}
for (PrcSurchargeBind bind : surchargeBindMapper.selectByProductIds(ids))
{
PayProduct owner = map.get(bind.getProductId());
if (owner != null && bindType(owner).equals(bind.getProductType()))
{
owner.getSurcharges().add(toBoundFee(bind, owner.getCurrency()));
}
}
for (PayExtraLine line : payProductMapper.selectExtraLines(ids))
{
PayProduct owner = map.get(line.getProductId());
@@ -1,5 +1,7 @@
package com.bms.price.service.impl;
import java.math.BigDecimal;
import java.util.LinkedHashSet;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -8,6 +10,7 @@ import com.bms.common.exception.ServiceException;
import com.bms.common.utils.MessageUtils;
import com.bms.common.utils.StringUtils;
import com.bms.price.domain.PrcSurcharge;
import com.bms.price.mapper.PrcSurchargeBindMapper;
import com.bms.price.mapper.PrcSurchargeMapper;
import com.bms.price.mapper.PrcSurchargeRelMapper;
import com.bms.price.service.IPrcSurchargeService;
@@ -33,6 +36,9 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
@Autowired
private PrcSurchargeRelMapper surchargeRelMapper;
@Autowired
private PrcSurchargeBindMapper surchargeBindMapper;
@Override
public PrcSurcharge selectPrcSurchargeById(Long scId)
{
@@ -48,6 +54,7 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
@Override
public int insertPrcSurcharge(PrcSurcharge surcharge)
{
applyCalcParam(surcharge);
validate(surcharge);
applyInsertDefaults(surcharge);
return surchargeMapper.insertPrcSurcharge(surcharge);
@@ -60,12 +67,17 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
@Transactional
public int updatePrcSurcharge(PrcSurcharge surcharge)
{
applyCalcParam(surcharge);
validate(surcharge);
PrcSurcharge old = surchargeMapper.selectPrcSurchargeById(surcharge.getScId());
if (old == null)
{
throw new ServiceException("附加费不存在或已被作废,无法修改");
}
if (StringUtils.isEmpty(surcharge.getDictValue()))
{
surcharge.setDictValue(old.getDictValue());
}
// 无实际变化:不置作废、不插新记录,返回 -1 由 Controller 提示"未修改"
if (isUnchanged(old, surcharge))
{
@@ -81,6 +93,12 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
fresh.setChargeType(surcharge.getChargeType());
fresh.setDictValue(surcharge.getDictValue());
fresh.setChargeValue(surcharge.getChargeValue());
fresh.setLengthCm(surcharge.getLengthCm());
fresh.setWidthCm(surcharge.getWidthCm());
fresh.setHeightCm(surcharge.getHeightCm());
fresh.setOverWeightKg(surcharge.getOverWeightKg());
fresh.setExtraWeightKg(surcharge.getExtraWeightKg());
fresh.setPostcodeText(surcharge.getPostcodeText());
fresh.setCurrency(surcharge.getCurrency());
fresh.setRoundMode(surcharge.getRoundMode());
fresh.setSsCode(old.getSsCode());
@@ -92,6 +110,7 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
int rows = surchargeMapper.insertPrcSurcharge(fresh);
// 3. 产品关联重指向新记录,保持产品附加费配置不失效
surchargeRelMapper.rebindRelScId(surcharge.getScId(), fresh.getScId(), operator);
syncPayCards(surcharge.getScId(), fresh);
return rows;
}
@@ -103,6 +122,12 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
&& eq(old.getChargeType(), updated.getChargeType())
&& eq(old.getDictValue(), updated.getDictValue())
&& eqDecimal(old.getChargeValue(), updated.getChargeValue())
&& eqDecimal(old.getLengthCm(), updated.getLengthCm())
&& eqDecimal(old.getWidthCm(), updated.getWidthCm())
&& eqDecimal(old.getHeightCm(), updated.getHeightCm())
&& eqDecimal(old.getOverWeightKg(), updated.getOverWeightKg())
&& eqDecimal(old.getExtraWeightKg(), updated.getExtraWeightKg())
&& eq(old.getPostcodeText(), updated.getPostcodeText())
&& eq(old.getCurrency(), updated.getCurrency())
&& eq(old.getRoundMode(), updated.getRoundMode())
&& eq(old.getCountryCode(), updated.getCountryCode())
@@ -190,4 +215,154 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
throw new ServiceException(MessageUtils.message("price.surcharge.chargeValue.negative"));
}
}
/** 只保留当前计费方式用到的字段,其余条件清空。 */
private void applyCalcParam(PrcSurcharge row)
{
String type = row.getChargeType() == null ? "" : row.getChargeType().trim().toUpperCase();
BigDecimal length = null;
BigDecimal width = null;
BigDecimal height = null;
BigDecimal overWeight = null;
BigDecimal extraWeight = null;
String postcodes = null;
if ("SIZE".equals(type))
{
length = requiredSize(row.getLengthCm(), "长");
width = requiredSize(row.getWidthCm(), "宽");
height = requiredSize(row.getHeightCm(), "高");
row.setBlockTitle(null);
}
else if ("WEIGHT".equals(type))
{
overWeight = requiredWeight(row.getOverWeightKg(), "超过重量");
row.setBlockTitle(null);
}
else if ("EXTRA_KG".equals(type))
{
extraWeight = requiredWeight(row.getExtraWeightKg(), "续重起始重量");
row.setBlockTitle(null);
}
else if ("POSTCODE".equals(type))
{
postcodes = joinPostcodes(row.getPostcodeText());
if (postcodes.isEmpty())
{
throw new ServiceException("请填写邮编,多个用逗号分隔");
}
row.setBlockTitle(null);
}
else if (!"ZONE".equals(type))
{
row.setBlockTitle(null);
}
row.setLengthCm(length);
row.setWidthCm(width);
row.setHeightCm(height);
row.setOverWeightKg(overWeight);
row.setExtraWeightKg(extraWeight);
row.setPostcodeText(postcodes);
}
private static BigDecimal requiredSize(BigDecimal value, String label)
{
if (value == null || value.compareTo(BigDecimal.ZERO) <= 0)
{
throw new ServiceException(label + "要大于 0");
}
return value;
}
private static BigDecimal requiredWeight(BigDecimal value, String label)
{
if (value == null)
{
throw new ServiceException("请填写" + label);
}
if (value.compareTo(BigDecimal.ZERO) < 0)
{
throw new ServiceException(label + "不能小于 0");
}
return value;
}
/** 价卡上的附加费改指向新配置,金额和条件说明跟着新记录走。 */
private void syncPayCards(Long oldScId, PrcSurcharge fresh)
{
String rule = calcRule(fresh.getChargeType());
String currency = StringUtils.isEmpty(fresh.getCurrency()) ? null : fresh.getCurrency().trim().toUpperCase();
String priceUnit = currency == null ? null : ("EXTRA_KG".equals(rule) ? currency + "/KG" : currency + "/ITEM");
surchargeMapper.rebindPayConfig(oldScId, fresh.getScId(), fresh.getScName(),
fresh.getBlockTitle() == null ? "" : fresh.getBlockTitle(), fresh.getChargeValue(), currency,
fresh.getScNote(), rule, chargeText(fresh, rule), priceUnit);
surchargeBindMapper.rebindScId(oldScId, fresh.getScId());
}
private static String calcRule(String chargeType)
{
if (chargeType == null)
{
return "MANUAL";
}
String code = chargeType.trim().toUpperCase();
if ("FIXED".equals(code))
{
return "ALWAYS";
}
if ("RATE".equals(code))
{
return "MANUAL";
}
return code;
}
private static String chargeText(PrcSurcharge row, String rule)
{
String text;
if ("SIZE".equals(rule))
{
text = "超过 " + plain(row.getLengthCm()) + "×" + plain(row.getWidthCm()) + "×" + plain(row.getHeightCm()) + "cm";
}
else if ("WEIGHT".equals(rule))
{
text = "超过 " + plain(row.getOverWeightKg()) + "kg";
}
else if ("EXTRA_KG".equals(rule))
{
text = "超出 " + plain(row.getExtraWeightKg()) + "kg 后续收";
}
else if ("POSTCODE".equals(rule))
{
text = "邮编 " + (row.getPostcodeText() == null ? "" : row.getPostcodeText());
}
else
{
text = row.getScNote() == null ? "" : row.getScNote();
}
return text.length() > 500 ? text.substring(0, 500) : text;
}
private static String plain(BigDecimal value)
{
return value == null ? "" : value.stripTrailingZeros().toPlainString();
}
private static String joinPostcodes(String raw)
{
if (raw == null)
{
return "";
}
LinkedHashSet<String> tokens = new LinkedHashSet<>();
String normalized = raw.replace(',', ',').replace('、', ',').replace(';', ',').replace(';', ',').replace('\n', ',').replace('\r', ',');
for (String part : normalized.split(","))
{
String value = part.trim();
if (!value.isEmpty())
{
tokens.add(value);
}
}
return String.join(",", tokens);
}
}
@@ -370,28 +370,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by product_id, sort_no, band_id
</select>
<sql id="surchargeColumns">
s.surcharge_id as surchargeId, s.product_id as productId, s.term_id as termId, s.version_no as versionNo,
s.section_name as sectionName, s.fee_name as feeName, s.sc_id as scId, s.zone_name as zoneName,
s.charge_text as chargeText, s.amount, s.currency, s.price_unit as priceUnit, s.fee_desc as feeDesc,
s.period_text as periodText, s.effective_start as effectiveStart, s.effective_end as effectiveEnd,
s.charge_timing as chargeTiming, s.calc_rule as calcRule, s.calc_param as calcParam,
s.weight_min as weightMin, s.weight_max as weightMax, s.postcode_param as postcodeParam,
cfg.length_cm as lengthCm, cfg.width_cm as widthCm, cfg.height_cm as heightCm,
cfg.over_weight_kg as overWeightKg, cfg.extra_weight_kg as extraWeightKg, cfg.postcode_text as postcodeText,
s.sort_no as sortNo
</sql>
<select id="selectSurcharges" resultType="com.bms.price.domain.PaySurcharge">
select surcharge_id as surchargeId, product_id as productId, term_id as termId, version_no as versionNo, section_name as sectionName, fee_name as feeName,
sc_id as scId, zone_name as zoneName, charge_text as chargeText, amount, currency, price_unit as priceUnit, fee_desc as feeDesc,
period_text as periodText, effective_start as effectiveStart, effective_end as effectiveEnd,
charge_timing as chargeTiming, calc_rule as calcRule, calc_param as calcParam,
weight_min as weightMin, weight_max as weightMax, postcode_param as postcodeParam, sort_no as sortNo
from pay_surcharge
where product_id in
select <include refid="surchargeColumns"/>
from pay_surcharge s
left join prc_surcharge cfg on cfg.sc_id = s.sc_id and s.section_name = '附加费配置' and ifnull(cfg.is_del, '0') = '0'
where s.product_id in
<foreach collection="productIds" item="id" open="(" separator="," close=")">#{id}</foreach>
order by product_id, sort_no, surcharge_id
order by s.product_id, s.sort_no, s.surcharge_id
</select>
<select id="selectSurchargesByTerm" resultType="com.bms.price.domain.PaySurcharge">
select surcharge_id as surchargeId, product_id as productId, term_id as termId, version_no as versionNo, section_name as sectionName, fee_name as feeName,
sc_id as scId, zone_name as zoneName, charge_text as chargeText, amount, currency, price_unit as priceUnit, fee_desc as feeDesc,
period_text as periodText, effective_start as effectiveStart, effective_end as effectiveEnd,
charge_timing as chargeTiming, calc_rule as calcRule, calc_param as calcParam,
weight_min as weightMin, weight_max as weightMax, postcode_param as postcodeParam, sort_no as sortNo
from pay_surcharge
where term_id in
select <include refid="surchargeColumns"/>
from pay_surcharge s
left join prc_surcharge cfg on cfg.sc_id = s.sc_id and s.section_name = '附加费配置' and ifnull(cfg.is_del, '0') = '0'
where s.term_id in
<foreach collection="termIds" item="id" open="(" separator="," close=")">#{id}</foreach>
order by product_id, sort_no, surcharge_id
order by s.product_id, s.sort_no, s.surcharge_id
</select>
<select id="selectExtraLines" resultType="com.bms.price.domain.PayExtraLine">
@@ -418,6 +424,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
delete from pay_surcharge where term_id in
<foreach collection="termIds" item="id" open="(" separator="," close=")">#{id}</foreach>
</delete>
<delete id="deleteSurchargesByTermSection">
delete from pay_surcharge
where term_id = #{termId}
and section_name = #{sectionName}
</delete>
<update id="refreshSurchargeCount">
update pay_product
set surcharge_count = (
select count(1) from pay_surcharge where product_id = #{productId}
) + (
select count(1) from prc_surcharge_bind where product_id = #{productId}
),
update_time = sysdate()
where product_id = #{productId}
</update>
<delete id="deleteExtraLinesByTerm">
delete from pay_extra_line where term_id in
<foreach collection="termIds" item="id" open="(" separator="," close=")">#{id}</foreach>
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.price.mapper.PrcSurchargeBindMapper">
<sql id="bindColumns">
b.bind_id as bindId, b.product_id as productId, b.product_type as productType, b.sc_id as scId, b.sort_no as sortNo,
b.created_by as createdBy, b.create_time as createTime, b.updated_by as updatedBy, b.update_time as updateTime,
c.sc_name as scName, c.charge_type as chargeType, c.charge_value as chargeValue, c.currency, c.ss_code as ssCode,
c.block_title as blockTitle, c.sc_note as scNote,
c.length_cm as lengthCm, c.width_cm as widthCm, c.height_cm as heightCm,
c.over_weight_kg as overWeightKg, c.extra_weight_kg as extraWeightKg, c.postcode_text as postcodeText
</sql>
<select id="selectByProduct" resultType="com.bms.price.domain.PrcSurchargeBind">
select <include refid="bindColumns"/>
from prc_surcharge_bind b
inner join prc_surcharge c on c.sc_id = b.sc_id and ifnull(c.is_del, '0') = '0'
where b.product_id = #{productId}
and b.product_type = #{productType}
order by b.sort_no, b.bind_id
</select>
<select id="selectByProductIds" resultType="com.bms.price.domain.PrcSurchargeBind">
select <include refid="bindColumns"/>
from prc_surcharge_bind b
inner join prc_surcharge c on c.sc_id = b.sc_id and ifnull(c.is_del, '0') = '0'
where b.product_id in
<foreach collection="productIds" item="id" open="(" separator="," close=")">#{id}</foreach>
order by b.product_id, b.sort_no, b.bind_id
</select>
<delete id="deleteByProduct">
delete from prc_surcharge_bind
where product_id = #{productId}
and product_type = #{productType}
</delete>
<delete id="deleteByProductIds">
delete from prc_surcharge_bind
where product_id in
<foreach collection="productIds" item="id" open="(" separator="," close=")">#{id}</foreach>
</delete>
<insert id="insertBinds">
insert into prc_surcharge_bind (product_id, product_type, sc_id, sort_no, created_by, create_time)
values
<foreach collection="list" item="row" separator=",">
(#{row.productId}, #{row.productType}, #{row.scId}, ifnull(#{row.sortNo}, 0), #{row.createdBy}, sysdate())
</foreach>
</insert>
<update id="rebindScId">
update prc_surcharge_bind
set sc_id = #{newScId}, update_time = sysdate()
where sc_id = #{oldScId}
</update>
</mapper>
@@ -11,6 +11,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="chargeType" column="charge_type" />
<result property="dictValue" column="dict_value" />
<result property="chargeValue" column="charge_value" />
<result property="lengthCm" column="length_cm" />
<result property="widthCm" column="width_cm" />
<result property="heightCm" column="height_cm" />
<result property="overWeightKg" column="over_weight_kg" />
<result property="extraWeightKg" column="extra_weight_kg" />
<result property="postcodeText" column="postcode_text" />
<result property="currency" column="currency" />
<result property="roundMode" column="round_mode" />
<result property="ssCode" column="ss_code" />
@@ -26,7 +32,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectPrcSurchargeVo">
select sc_id, sc_name, fee_type, charge_type, dict_value, charge_value, currency, round_mode,
select sc_id, sc_name, fee_type, charge_type, dict_value, charge_value,
length_cm, width_cm, height_cm, over_weight_kg, extra_weight_kg, postcode_text, currency, round_mode,
ss_code, is_del, country_code, block_title, sc_note, tms_id, created_by, create_time, updated_by, update_time
from prc_surcharge
</sql>
@@ -92,6 +99,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="chargeType != null and chargeType != ''">charge_type,</if>
<if test="dictValue != null">dict_value,</if>
<if test="chargeValue != null">charge_value,</if>
<if test="lengthCm != null">length_cm,</if>
<if test="widthCm != null">width_cm,</if>
<if test="heightCm != null">height_cm,</if>
<if test="overWeightKg != null">over_weight_kg,</if>
<if test="extraWeightKg != null">extra_weight_kg,</if>
<if test="postcodeText != null">postcode_text,</if>
<if test="currency != null and currency != ''">currency,</if>
<if test="roundMode != null and roundMode != ''">round_mode,</if>
<if test="ssCode != null and ssCode != ''">ss_code,</if>
@@ -108,6 +121,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="chargeType != null and chargeType != ''">#{chargeType},</if>
<if test="dictValue != null">#{dictValue},</if>
<if test="chargeValue != null">#{chargeValue},</if>
<if test="lengthCm != null">#{lengthCm},</if>
<if test="widthCm != null">#{widthCm},</if>
<if test="heightCm != null">#{heightCm},</if>
<if test="overWeightKg != null">#{overWeightKg},</if>
<if test="extraWeightKg != null">#{extraWeightKg},</if>
<if test="postcodeText != null">#{postcodeText},</if>
<if test="currency != null and currency != ''">#{currency},</if>
<if test="roundMode != null and roundMode != ''">#{roundMode},</if>
<if test="ssCode != null and ssCode != ''">#{ssCode},</if>
@@ -132,4 +151,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</update>
<update id="rebindPayConfig">
update pay_surcharge
set sc_id = #{newScId},
fee_name = #{feeName},
zone_name = #{zoneName},
amount = #{amount},
currency = ifnull(#{currency}, currency),
fee_desc = #{feeDesc},
calc_rule = #{calcRule},
charge_text = #{chargeText},
price_unit = ifnull(#{priceUnit}, price_unit)
where sc_id = #{oldScId}
and section_name = '附加费配置'
</update>
</mapper>
@@ -0,0 +1,18 @@
-- 应付配置增加附加费按钮
INSERT INTO `bms`.`sys_menu` (`menu_id`, `menu_name`, `parent_id`, `order_num`, `path`, `component`, `is_frame`, `is_cache`, `menu_type`, `visible`, `status`, `perms`, `icon`, `create_by`, `create_time`)
SELECT 2678, '附加费', 2508, 8, '', '', 1, 0, 'F', '0', '0', 'price:pay:surcharge', '#', 'admin', sysdate()
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `bms`.`sys_menu` WHERE `menu_id` = 2678 OR `perms` = 'price:pay:surcharge');
-- 管理员拥有应付配置附加费按钮
INSERT INTO `bms`.`sys_role_menu` (`role_id`, `menu_id`)
SELECT 1, 2678
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `bms`.`sys_role_menu` WHERE `role_id` = 1 AND `menu_id` = 2678);
-- 能看应付配置的角色同时拥有附加费按钮
INSERT INTO `bms`.`sys_role_menu` (`role_id`, `menu_id`)
SELECT DISTINCT rm.`role_id`, 2678
FROM `bms`.`sys_role_menu` rm
WHERE rm.`menu_id` = 2508
AND NOT EXISTS (SELECT 1 FROM `bms`.`sys_role_menu` x WHERE x.`role_id` = rm.`role_id` AND x.`menu_id` = 2678);
@@ -0,0 +1,17 @@
-- `pay_surcharge` 表中删除重复的`length_cm` 属性
ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `length_cm`;
-- `pay_surcharge` 表中删除重复的`width_cm` 属性
ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `width_cm`;
-- `pay_surcharge` 表中删除重复的`height_cm` 属性
ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `height_cm`;
-- `pay_surcharge` 表中删除重复的`over_weight_kg` 属性
ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `over_weight_kg`;
-- `pay_surcharge` 表中删除重复的`extra_weight_kg` 属性
ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `extra_weight_kg`;
-- `pay_surcharge` 表中删除重复的`postcode_text` 属性
ALTER TABLE `bms`.`pay_surcharge` DROP COLUMN `postcode_text`;
+25
View File
@@ -0,0 +1,25 @@
-- 新建产品与附加费配置的关联表,按产品编号和类型查询
CREATE TABLE `bms`.`prc_surcharge_bind` (
`bind_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '关联ID',
`product_id` bigint(20) NOT NULL COMMENT '产品ID,对应 pay_product.product_id',
`product_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '产品类型:AP应付、AR应收,以及后续其它类型',
`sc_id` bigint(20) NOT NULL COMMENT '附加费配置ID,对应 prc_surcharge.sc_id',
`sort_no` int(11) NOT NULL DEFAULT 0 COMMENT '排序',
`created_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建人',
`create_time` datetime NULL COMMENT '创建时间',
`updated_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '更新人',
`update_time` datetime NULL COMMENT '更新时间',
PRIMARY KEY (`bind_id`),
UNIQUE KEY `uk_surcharge_bind_product` (`product_id`, `product_type`, `sc_id`),
KEY `idx_surcharge_bind_sc` (`sc_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='产品附加费关联,应付应收及其它类型按产品编号和类型匹配';
-- 把价卡上已经绑定的附加费配置迁入关联表
INSERT INTO `bms`.`prc_surcharge_bind` (`product_id`, `product_type`, `sc_id`, `sort_no`, `created_by`, `create_time`)
SELECT s.`product_id`, ifnull(p.`product_type`, 'AP'), s.`sc_id`, ifnull(s.`sort_no`, 0), 'admin', sysdate()
FROM `bms`.`pay_surcharge` s
INNER JOIN `bms`.`pay_product` p ON p.`product_id` = s.`product_id`
WHERE s.`section_name` = '附加费配置' AND s.`sc_id` IS NOT NULL;
-- 删除已经迁入关联表的价卡附加费明细
DELETE FROM `bms`.`pay_surcharge` WHERE `section_name` = '附加费配置';
@@ -0,0 +1,17 @@
-- `prc_surcharge` 表中添加`length_cm` 属性
ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `length_cm` decimal(10,2) NULL COMMENT '超尺寸长,厘米' AFTER `charge_value`;
-- `prc_surcharge` 表中添加`width_cm` 属性
ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `width_cm` decimal(10,2) NULL COMMENT '超尺寸宽,厘米' AFTER `length_cm`;
-- `prc_surcharge` 表中添加`height_cm` 属性
ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `height_cm` decimal(10,2) NULL COMMENT '超尺寸高,厘米' AFTER `width_cm`;
-- `prc_surcharge` 表中添加`over_weight_kg` 属性
ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `over_weight_kg` decimal(12,3) NULL COMMENT '超重阈值,公斤,超过才收取' AFTER `height_cm`;
-- `prc_surcharge` 表中添加`extra_weight_kg` 属性
ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `extra_weight_kg` decimal(12,3) NULL COMMENT '超重续收起始重量,公斤' AFTER `over_weight_kg`;
-- `prc_surcharge` 表中添加`postcode_text` 属性
ALTER TABLE `bms`.`prc_surcharge` ADD COLUMN `postcode_text` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '命中邮编,多个用逗号分隔' AFTER `extra_weight_kg`;
+17
View File
@@ -60,6 +60,23 @@ export function previewPayTemplate(file, chargeType) {
})
}
/** 这一版价卡已勾选的附加费配置 */
export function listPayConfigSurcharges(termId) {
return request({
url: '/price/pay/term/' + termId + '/config-surcharges',
method: 'get'
})
}
/** 保存这一版勾选的附加费和计费条件 */
export function savePayConfigSurcharges(termId, data) {
return request({
url: '/price/pay/term/' + termId + '/config-surcharges',
method: 'put',
data
})
}
/** 按所选计费模式手工新增一条价卡 */
export function savePayManual(data) {
return request({
@@ -0,0 +1,252 @@
<template>
<el-dialog v-model="visible" :title="title" width="980px" append-to-body destroy-on-close>
<div v-loading="loading" class="board">
<section class="pick">
<div class="pane-title">附加费</div>
<el-select v-model="pickedId" filterable clearable placeholder="选择附加费配置" style="width: 100%">
<el-option v-for="item in available" :key="item.scId" :label="optionLabel(item)" :value="item.scId" />
</el-select>
<el-button type="primary" plain class="add" @click="addPicked">添加</el-button>
<p class="hint">从附加费配置里选择。长宽高、重量和邮编在配置里维护,这里只选用。</p>
</section>
<section class="chosen">
<div class="pane-title">已选附加费</div>
<el-empty v-if="!chosen.length" description="还没有选择附加费" :image-size="64" />
<div v-for="row in chosen" :key="row.scId" class="card">
<div class="card-head">
<strong>{{ row.feeName }}</strong>
<el-tag size="small" effect="plain">{{ chargeLabel(row.calcRule) }}</el-tag>
<span class="meta">{{ valueText(row) }}</span>
<el-button link type="danger" @click="removeRow(row)">移除</el-button>
</div>
<div v-if="row.zoneName" class="scope">分区 {{ row.zoneName }}</div>
<div class="scope">{{ conditionText(row) }}</div>
</div>
</section>
</div>
<template #footer>
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="save">保存</el-button>
</template>
</el-dialog>
</template>
<script setup>
import { listSurchargeOptions } from '@/api/price/surcharge'
import { listPayConfigSurcharges, savePayConfigSurcharges } from '@/api/price/pay'
const emit = defineEmits(['saved'])
const { proxy } = getCurrentInstance()
const visible = ref(false)
const loading = ref(false)
const saving = ref(false)
const title = ref('附加费')
const termId = ref(null)
const pickedId = ref(null)
const options = ref([])
const chosen = ref([])
const chargeLabelMap = {
MANUAL: '暂不计费',
ALWAYS: '每票都收',
POSTCODE: '命中邮编',
ZONE: '命中分区',
EXTRA_KG: '超重续收',
WEIGHT: '超重',
SIZE: '超尺寸',
RETURN: '退件'
}
const available = computed(() => {
const used = new Set(chosen.value.map(row => String(row.scId)))
return options.value.filter(item => item?.scId != null && !used.has(String(item.scId)))
})
function chargeLabel(rule) {
return chargeLabelMap[rule] || rule || '暂不计费'
}
function toRule(chargeType) {
const code = String(chargeType || '').trim().toUpperCase()
if (code === 'FIXED') return 'ALWAYS'
if (!code || code === 'RATE') return 'MANUAL'
return chargeLabelMap[code] ? code : 'MANUAL'
}
function optionLabel(item) {
const value = item.chargeValue == null ? '' : ` ${item.chargeValue}${item.currency ? ' ' + item.currency : ''}`
return `${item.scName} · ${chargeLabel(toRule(item.chargeType))}${value}`
}
function valueText(row) {
if (row.amount == null || row.amount === '') return ''
return `${row.amount} ${row.currency || ''}`.trim()
}
function rowFromConfig(item) {
return {
scId: item.scId,
feeName: item.scName,
calcRule: toRule(item.chargeType),
amount: item.chargeValue,
currency: item.currency,
zoneName: item.blockTitle || '',
lengthCm: item.lengthCm,
widthCm: item.widthCm,
heightCm: item.heightCm,
overWeightKg: item.overWeightKg,
extraWeightKg: item.extraWeightKg,
postcodeText: item.postcodeText || ''
}
}
function addPicked() {
const item = options.value.find(row => String(row.scId) === String(pickedId.value))
if (!item) {
proxy.$modal.msgWarning('请选择附加费')
return
}
chosen.value.push(rowFromConfig(item))
pickedId.value = null
}
function removeRow(row) {
chosen.value = chosen.value.filter(item => item !== row)
}
function conditionText(row) {
if (row.calcRule === 'SIZE') {
if (Number(row.lengthCm) > 0 && Number(row.widthCm) > 0 && Number(row.heightCm) > 0) {
return `长 ${row.lengthCm} cm,宽 ${row.widthCm} cm,高 ${row.heightCm} cm`
}
return '长宽高还没在附加费配置里填写'
}
if (row.calcRule === 'WEIGHT') {
return row.overWeightKg == null ? '超过重量还没在附加费配置里填写' : `超过 ${row.overWeightKg} kg`
}
if (row.calcRule === 'EXTRA_KG') {
return row.extraWeightKg == null ? '续重起始重量还没在附加费配置里填写' : `超出 ${row.extraWeightKg} kg 后续收`
}
if (row.calcRule === 'POSTCODE') {
return String(row.postcodeText || '').trim() ? `邮编 ${row.postcodeText}` : '邮编还没在附加费配置里填写'
}
return '按附加费配置直接计费'
}
function invalid(row) {
const text = conditionText(row)
return text.includes('还没') ? row.feeName + text : ''
}
async function open(row) {
if (!row?.termId) {
proxy.$modal.msgWarning('请先为这张价卡设置有效期')
return
}
title.value = row.productName || '附加费'
termId.value = row.termId
pickedId.value = null
chosen.value = []
options.value = []
visible.value = true
loading.value = true
try {
const [configs, selected] = await Promise.all([
listSurchargeOptions({ ssCode: 'on' }),
listPayConfigSurcharges(row.termId)
])
options.value = configs.data || []
chosen.value = (selected.data || []).map(item => ({
scId: item.scId,
feeName: item.feeName,
calcRule: item.calcRule,
amount: item.amount,
currency: item.currency,
zoneName: item.zoneName || '',
lengthCm: item.lengthCm,
widthCm: item.widthCm,
heightCm: item.heightCm,
overWeightKg: item.overWeightKg,
extraWeightKg: item.extraWeightKg,
postcodeText: item.postcodeText || ''
}))
} finally {
loading.value = false
}
}
async function save() {
for (const row of chosen.value) {
const message = invalid(row)
if (message) {
proxy.$modal.msgWarning(message)
return
}
}
saving.value = true
try {
await savePayConfigSurcharges(termId.value, chosen.value.map(row => ({ scId: row.scId })))
proxy.$modal.msgSuccess('附加费已保存')
visible.value = false
emit('saved')
} finally {
saving.value = false
}
}
defineExpose({ open })
</script>
<style scoped>
.board {
display: flex;
gap: 16px;
min-height: 420px;
}
.pick {
width: 300px;
flex: none;
}
.chosen {
flex: 1;
min-width: 0;
max-height: 520px;
overflow: auto;
}
.pane-title {
margin-bottom: 10px;
font-weight: 600;
}
.add {
margin-top: 10px;
}
.hint,
.scope {
margin: 10px 0 0;
color: var(--el-text-color-secondary);
font-size: 12px;
line-height: 1.6;
}
.card {
margin-bottom: 10px;
padding: 10px 12px;
border: 1px solid var(--el-border-color);
border-radius: 6px;
}
.card-head {
display: flex;
align-items: center;
gap: 8px;
}
.card-head strong {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.meta {
margin-left: auto;
color: var(--el-text-color-secondary);
}
</style>
@@ -75,7 +75,7 @@
/>
</el-tab-pane>
<el-tab-pane :label="feeTabLabel(pane)" name="fee">
<el-tab-pane v-if="showFees" :label="feeTabLabel(pane)" name="fee">
<div class="pay-edit-bar">
<el-input v-model="pane.feeKeyword" clearable placeholder="筛选附加费用、地区、价格、货币或费用解释" class="pay-filter" @input="pane.feePageNo = 1" />
<el-select v-model="pane.feeBill" clearable placeholder="计费条件" class="pay-bill-filter" @change="pane.feePageNo = 1">
@@ -274,6 +274,8 @@ import PaySurchargePickerDialog from './PaySurchargePickerDialog.vue'
const { order_charge_type } = useDict('order_charge_type')
const showFees = false
function chargeTypeText(value) {
const hit = (order_charge_type.value || []).find(item => item.value === value)
if (hit) return hit.label
@@ -76,7 +76,6 @@
<template #default="{ row }">{{ row.effectiveDate || preview.effectiveDate || '-' }}</template>
</el-table-column>
<el-table-column prop="weightCount" label="重量段" width="80" align="right" />
<el-table-column prop="surchargeCount" label="附加费" width="80" align="right" />
<el-table-column label="识别" width="120">
<template #default="{ row }">
<el-tag :type="statusType(row.parseStatus)" size="small">{{ statusText(row.parseStatus) }}</el-tag>
@@ -64,6 +64,7 @@
<template #col-action="{ row }">
<el-button link type="primary" icon="View" @click="openDetail(row)" v-hasPermi="['price:pay:query']">查看</el-button>
<el-button link type="primary" @click="surchargeRef.open(row)" v-hasPermi="['price:pay:surcharge']">附加费</el-button>
<el-button link type="primary" icon="Calendar" @click="openTermDialog(row)" v-hasPermi="['price:pay:edit']">有效期</el-button>
<el-button link type="primary" icon="Clock" @click="openHistory(row)" v-hasPermi="['price:pay:query']">历史</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(row.productId)" v-hasPermi="['price:pay:remove']">删除</el-button>
@@ -72,6 +73,7 @@
<pay-import-dialog ref="importRef" @saved="tableRef.refresh()" />
<pay-create-dialog ref="createRef" @saved="tableRef.refresh()" />
<pay-card-surcharge-dialog ref="surchargeRef" @saved="tableRef.refresh()" />
<el-dialog v-model="bindVisible" title="绑定渠道" width="640px" append-to-body @closed="resetBind">
<el-form label-width="70px">
<el-form-item label="产品">
@@ -210,6 +212,7 @@ import { listChannelOptions } from '@/api/masterdata/serviceChannel'
import { useDict } from '@/utils/dict'
import PayImportDialog from './components/PayImportDialog.vue'
import PayCreateDialog from './components/PayCreateDialog.vue'
import PayCardSurchargeDialog from './components/PayCardSurchargeDialog.vue'
import PayConfigDetail from './components/PayConfigDetail.vue'
const { proxy } = getCurrentInstance()
@@ -217,6 +220,7 @@ const { order_charge_type } = useDict('order_charge_type')
const tableRef = ref()
const importRef = ref()
const createRef = ref()
const surchargeRef = ref()
const detailVisible = ref(false)
const detailLoading = ref(false)
const savingRowKey = ref('')
@@ -273,7 +277,7 @@ const columns = [
{ label: '识别结果', prop: 'parseStatus', align: 'center', width: 120 },
{ label: '来源文件', prop: 'sourceFile', align: 'center', minWidth: 180, showOverflowTooltip: true },
{ label: '创建时间', prop: 'createTime', align: 'center', width: 160, parseTime: true },
{ label: '操作', prop: 'action', align: 'center', width: 280, fixed: 'right', showInToolbar: false }
{ label: '操作', prop: 'action', align: 'center', width: 340, fixed: 'right', showInToolbar: false }
]
const searchColumns = [
@@ -1,6 +1,6 @@
<template>
<el-dialog :title="title" v-model="visible" width="720px" append-to-body>
<basic-form ref="formRef" v-model="form" :schemas="schemas" label-width="100px" />
<el-dialog :title="title" v-model="visible" width="760px" append-to-body>
<basic-form ref="formRef" v-model="form" class="surcharge-form" :schemas="schemas" label-width="118px" />
<template #footer>
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="visible = false">取 消</el-button>
@@ -15,7 +15,6 @@ import { listRegionOptions } from '@/api/data/region'
const emit = defineEmits(['success'])
const { proxy } = getCurrentInstance()
const { payment_product_type } = useDict('payment_product_type')
const formRef = ref()
const visible = ref(false)
@@ -45,17 +44,12 @@ const countrySelectOptions = computed(() => {
})))
})
const channelProductOptions = computed(() =>
(payment_product_type.value || []).map(item => ({
label: item.label,
value: item.value
}))
)
const blockSelectOptions = computed(() =>
(blockOptions.value || []).map(title => ({ label: title, value: title }))
)
const chargeType = computed(() => String(form.value.chargeType || '').toUpperCase())
const schemas = computed(() => [
{
label: '附加费名称',
@@ -89,14 +83,67 @@ const schemas = computed(() => [
rules: [{ required: true, message: '请选择计费方式', trigger: 'change' }]
},
{
label: '渠道产品',
prop: 'dictValue',
component: 'select',
placeholder: '请选择渠道产品',
options: channelProductOptions.value,
label: '长(cm)',
prop: 'lengthCm',
component: 'inputNumber',
span: 12,
width: '100%',
props: { filterable: true, clearable: true }
show: chargeType.value === 'SIZE',
props: { min: 0, precision: 2, controls: false, align: 'left' },
rules: chargeType.value === 'SIZE' ? [{ required: true, message: '请填写长', trigger: 'blur' }] : undefined
},
{
label: '宽(cm)',
prop: 'widthCm',
component: 'inputNumber',
span: 12,
width: '100%',
show: chargeType.value === 'SIZE',
props: { min: 0, precision: 2, controls: false, align: 'left' },
rules: chargeType.value === 'SIZE' ? [{ required: true, message: '请填写宽', trigger: 'blur' }] : undefined
},
{
label: '高(cm)',
prop: 'heightCm',
component: 'inputNumber',
span: 12,
width: '100%',
show: chargeType.value === 'SIZE',
props: { min: 0, precision: 2, controls: false, align: 'left' },
rules: chargeType.value === 'SIZE' ? [{ required: true, message: '请填写高', trigger: 'blur' }] : undefined
},
{
label: '超过重量(kg)',
prop: 'overWeightKg',
component: 'inputNumber',
placeholder: '超过这个重量才收取',
span: 12,
width: '100%',
show: chargeType.value === 'WEIGHT',
props: { min: 0, precision: 3, controls: false, align: 'left' },
rules: chargeType.value === 'WEIGHT' ? [{ required: true, message: '请填写超过重量', trigger: 'blur' }] : undefined
},
{
label: '续重起始(kg)',
prop: 'extraWeightKg',
component: 'inputNumber',
placeholder: '超过这个重量后按超出公斤计',
span: 12,
width: '100%',
show: chargeType.value === 'EXTRA_KG',
props: { min: 0, precision: 3, controls: false, align: 'left' },
rules: chargeType.value === 'EXTRA_KG' ? [{ required: true, message: '请填写续重起始重量', trigger: 'blur' }] : undefined
},
{
label: '邮编',
prop: 'postcodeText',
component: 'textarea',
placeholder: '多个可用逗号分隔',
span: 24,
width: '100%',
show: chargeType.value === 'POSTCODE',
props: { rows: 2, maxlength: 1000 },
rules: chargeType.value === 'POSTCODE' ? [{ required: true, message: '请填写邮编', trigger: 'blur' }] : undefined
},
{
label: '计费数值',
@@ -104,7 +151,7 @@ const schemas = computed(() => [
component: 'inputNumber',
span: 12,
width: '100%',
props: { min: 0, precision: 6, step: 1, controlsPosition: 'right' },
props: { min: 0, precision: 6, controls: false, align: 'left' },
rules: [{ required: true, message: '计费数值不能为空', trigger: 'blur' }]
},
{
@@ -144,6 +191,7 @@ const schemas = computed(() => [
options: blockSelectOptions.value,
span: 12,
width: '100%',
show: chargeType.value === 'ZONE',
disabled: !form.value.countryCode || loadingBlocks.value,
props: { filterable: true, clearable: true }
},
@@ -163,14 +211,19 @@ function emptyForm() {
scId: undefined,
scName: undefined,
feeType: 'SURCHARGE',
dictValue: undefined,
chargeType: 'MANUAL',
chargeValue: 0,
currency: 'CNY',
roundMode: 'HALF_UP',
countryCode: undefined,
blockTitle: undefined,
scNote: undefined
scNote: undefined,
lengthCm: undefined,
widthCm: undefined,
heightCm: undefined,
overWeightKg: undefined,
extraWeightKg: undefined,
postcodeText: undefined
}
}
@@ -252,7 +305,7 @@ function submitForm() {
if (!valid) return
const payload = { ...form.value }
if (!payload.countryCode) payload.countryCode = undefined
if (!payload.dictValue) payload.dictValue = undefined
delete payload.dictValue
if (!payload.blockTitle) payload.blockTitle = undefined
if (!payload.chargeType) payload.chargeType = 'MANUAL'
if (payload.chargeValue != null) payload.chargeValue = Number(payload.chargeValue)
@@ -273,5 +326,33 @@ watch(() => form.value.countryCode, (code, prev) => {
loadBlockOptions(code, false)
})
watch(() => form.value.chargeType, (type, prev) => {
if (suppressCountryWatch.value || !prev || type === prev) return
form.value.lengthCm = undefined
form.value.widthCm = undefined
form.value.heightCm = undefined
form.value.overWeightKg = undefined
form.value.extraWeightKg = undefined
form.value.postcodeText = undefined
if (String(type || '').toUpperCase() !== 'ZONE') form.value.blockTitle = undefined
nextTick(() => formRef.value?.clearValidate())
})
defineExpose({ open })
</script>
<style scoped>
.surcharge-form :deep(.el-form-item__content) {
flex: 1;
min-width: 0;
}
.surcharge-form :deep(.el-input),
.surcharge-form :deep(.el-select),
.surcharge-form :deep(.el-input-number),
.surcharge-form :deep(.el-textarea) {
width: 100%;
}
.surcharge-form :deep(.el-input-number .el-input__inner) {
text-align: left;
}
</style>
@@ -98,7 +98,6 @@ const columns = [
{ label: '附加费名称', prop: 'scName', align: 'center', minWidth: 140, showOverflowTooltip: true },
{ label: '费用类型', prop: 'feeType', align: 'center', width: 110, dict: 'bms_fee_type' },
{ label: '计费方式', prop: 'chargeType', align: 'center', width: 110 },
{ label: '渠道产品', prop: 'dictValue', align: 'center', minWidth: 130, showOverflowTooltip: true },
{ label: '计费数值', prop: 'chargeValue', align: 'center', width: 140 },
{ label: '取值方式', prop: 'roundMode', align: 'center', width: 110, dict: 'bms_round_mode' },
{ label: '适用国家', prop: 'countryCode', align: 'center', minWidth: 120, showOverflowTooltip: true },
@@ -119,14 +118,6 @@ const searchColumns = [
placeholder: '计费方式',
width: '150px'
},
{
label: '渠道产品',
prop: 'dictValue',
component: 'select',
dict: 'payment_product_type',
placeholder: '渠道产品',
width: '160px'
},
{ label: '取值方式', prop: 'roundMode', component: 'select', dict: 'bms_round_mode', placeholder: '取值方式', width: '150px' },
{
label: '状态',