diff --git a/bms-back/bms-common/src/main/java/com/bms/common/enums/PaymentMesEnum.java b/bms-back/bms-common/src/main/java/com/bms/common/enums/PaymentMesEnum.java index c8bbf81d..ffa53218 100644 --- a/bms-back/bms-common/src/main/java/com/bms/common/enums/PaymentMesEnum.java +++ b/bms-back/bms-common/src/main/java/com/bms/common/enums/PaymentMesEnum.java @@ -44,7 +44,7 @@ public enum PaymentMesEnum BMS_PAY_PICK_CH("BMS_PAY_PICK_CH", "渠道绑定产品", "请先勾选渠道"), BMS_PAY_PICK_SIDE("BMS_PAY_PICK_SIDE", "渠道绑定产品", "请至少选择应付或应收产品"), BMS_PAY_BIND_NONE("BMS_PAY_BIND_NONE", "渠道绑定产品", "没有可绑定的渠道"), - BMS_PAY_CH_PROD("BMS_PAY_CH_PROD", "渠道应付产品", "渠道还没有选择应付产品"), + BMS_PAY_CH_PROD("BMS_PAY_CH_PROD", "渠道应付价卡", "渠道还没有选择应付价卡"), BMS_PAY_OUT_TERM("BMS_PAY_OUT_TERM", "应付价格有效期", "订单时间没有落在价格有效期内"), BMS_PAY_TWO_VER("BMS_PAY_TWO_VER", "应付价格对比", "请选择两个价格版本"), BMS_PAY_AR_AP("BMS_PAY_AR_AP", "收付类型", "收付类型只能是应收AR或应付AP"), diff --git a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcPayBillFee.java b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcPayBillFee.java index d7f53081..7db13883 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcPayBillFee.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/domain/PrcPayBillFee.java @@ -63,6 +63,10 @@ public class PrcPayBillFee implements Serializable @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date updateTime; + /** 订单计费日,只在折算汇率时使用,不入库 */ + @JsonIgnore + private Date bizDate; + /** 写日志时带上的变更前费用项,不入库 */ @JsonIgnore private String logBeforeName; diff --git a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillFeeMapper.java b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillFeeMapper.java index 043cd4e9..4f2b8228 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillFeeMapper.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillFeeMapper.java @@ -94,6 +94,9 @@ public interface PrcPayBillFeeMapper /** 明细还没挂上应付主表时,按订单补上主表 ID。单次不超过 1000 个订单。 */ public int bindPayBillId(@Param("billIds") List billIds); + /** 这些订单上未删除的应付明细。带上订单计费日,汇总时用来取汇率。 */ + public List selectOpenFees(@Param("billIds") List billIds); + /** * 这条提单费用分摊到的订单里,取一个已经生成应付账单的订单号。 * 是否出账看 prc_order_bill_ext.is_meet:1 已生成。 diff --git a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillMapper.java b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillMapper.java index 10bfd992..2aa4af89 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillMapper.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcPayBillMapper.java @@ -1,5 +1,6 @@ package com.bms.price.mapper; +import java.math.BigDecimal; import java.util.List; import org.apache.ibatis.annotations.Param; import com.bms.price.domain.PrcPayBill; @@ -63,6 +64,9 @@ public interface PrcPayBillMapper */ int refreshPayTotal(@Param("billIds") List billIds); + /** 把折成人民币后的应付汇总写到主表,明细金额和币种不动。 */ + int updateCnyPayTotal(@Param("billId") Long billId, @Param("payTotal") BigDecimal payTotal); + /** 订单还没有应付主表时补一行,总额随后按明细重算。单次不超过 1000 个订单。 */ int insertMissingPayBills(@Param("billIds") List billIds, @Param("operator") String operator); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/IPrcPayBillFeeService.java b/bms-back/bms-system/src/main/java/com/bms/price/service/IPrcPayBillFeeService.java index b3a1a722..ad0bfe64 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/IPrcPayBillFeeService.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/IPrcPayBillFeeService.java @@ -10,7 +10,7 @@ public interface IPrcPayBillFeeService { /** * 分批写入应付明细,并回写这些订单的应付总额。 - * 明细每批最多 1000 条。总额是该订单未删除明细的金额之和,同时写入 prc_pay_bill.pay_total 和订单应付总额。 + * 明细每批最多 1000 条,金额和币种按原样写入 prc_pay_bill_fee。汇总时外币按汇率折成人民币,只回写 prc_pay_bill.pay_total。 * * @param fees 本次新增的应付明细 */ diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java index 50b66c5e..4c2d2dba 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderCostServiceImpl.java @@ -75,9 +75,6 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService @Autowired private PayPostcodeMapper payPostcodeMapper; - @Autowired - private PayFeeMoney payFeeMoney; - /** * 重算一票订单的尾程应付并落库。 * 先找渠道和计费日对应的价卡版本,再用重量、尺寸、邮编算出费用,写回订单应付。 @@ -152,7 +149,6 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService { throw new ServiceException(result.getMessage() == null ? PaymentMesEnum.BMS_PAY_NO_COST.getCnMes() : result.getMessage()); } - applyCny(result, bizDate); String operator = SecurityUtils.getUsername(); PrcPayBill payBill = saveBill(bill, result, operator); saveFees(bill.getBillId(), payBill.getPayBillId(), result); @@ -645,7 +641,7 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService row.setScId(scId); String userId = PayFeeMoney.userId(); row.setAmount(fee.getAmount()); - row.setCurrency(PayFeeMoney.CNY); + row.setCurrency(fee.getCurrency()); row.setFeeSource("CALC"); row.setCreateBy(userId); row.setUpdateBy(userId); @@ -688,25 +684,6 @@ public class PayOrderCostServiceImpl implements IPayOrderCostService result.setFeeLogType(recalc ? PayBillFeeLogService.RECALC : PayBillFeeLogService.ADD); } - /** 按计费日汇率把本次尾程费用折成人民币,明细三位,合计两位。 */ - private void applyCny(PayOrderCostResult result, Date bizDate) - { - BigDecimal sum = BigDecimal.ZERO; - List fees = result.getFees() == null ? List.of() : result.getFees(); - for (PayCostLine fee : fees) - { - BigDecimal cny = payFeeMoney.toCny(fee.getAmount(), fee.getCurrency(), bizDate); - fee.setAmount(cny); - fee.setCurrency(PayFeeMoney.CNY); - if (cny != null) - { - sum = sum.add(cny); - } - } - result.setCurrency(PayFeeMoney.CNY); - result.setPayTotal(PayFeeMoney.total(sum)); - } - /** 计算费用,空来源按计算费用处理。 */ private static boolean calcFee(PrcPayBillFee fee) { diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderListServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderListServiceImpl.java index d2cc56c1..a85c0cb4 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderListServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PayOrderListServiceImpl.java @@ -1,6 +1,7 @@ package com.bms.price.service.impl; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -73,9 +74,6 @@ public class PayOrderListServiceImpl implements IPayOrderListService @Autowired private PayBillFeeLogService payBillFeeLogService; - @Autowired - private PayFeeMoney payFeeMoney; - @Autowired @Lazy private PayOrderRecalcAsyncRunner payOrderRecalcAsyncRunner; @@ -336,8 +334,8 @@ public class PayOrderListServiceImpl implements IPayOrderListService { throw new ServiceException("币种过长"); } - BigDecimal amount = payFeeMoney.toCny(line.getAmount(), currency, order.getBizDate()); - if (amount.abs().compareTo(new BigDecimal("9999999999.999")) > 0) + BigDecimal amount = line.getAmount().setScale(2, RoundingMode.HALF_UP); + if (amount.abs().compareTo(new BigDecimal("9999999999.99")) > 0) { throw new ServiceException("金额超出范围"); } @@ -360,7 +358,7 @@ public class PayOrderListServiceImpl implements IPayOrderListService fee.setScId(manualScId()); fee.setFeeLevel(level); fee.setAmount(amount); - fee.setCurrency(PayFeeMoney.CNY); + fee.setCurrency(currency); fee.setRemark(remark == null || remark.isEmpty() ? null : remark); fee.setFeeSource("MANUAL"); fee.setCreateBy(userId); diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcPayBillFeeServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcPayBillFeeServiceImpl.java index 697bdaba..902a0d5d 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcPayBillFeeServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcPayBillFeeServiceImpl.java @@ -1,16 +1,19 @@ package com.bms.price.service.impl; +import java.math.BigDecimal; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.bms.common.utils.SecurityUtils; import com.bms.price.domain.PrcPayBillFee; -import com.bms.price.mapper.PrcOrderBillMapper; import com.bms.price.mapper.PrcPayBillFeeMapper; import com.bms.price.mapper.PrcPayBillMapper; +import com.bms.price.pay.PayFeeMoney; import com.bms.price.service.IPrcPayBillFeeService; /** @@ -28,7 +31,7 @@ public class PrcPayBillFeeServiceImpl implements IPrcPayBillFeeService private PrcPayBillMapper payBillMapper; @Autowired - private PrcOrderBillMapper orderBillMapper; + private PayFeeMoney payFeeMoney; @Override @Transactional(rollbackFor = Exception.class) @@ -76,8 +79,38 @@ public class PrcPayBillFeeServiceImpl implements IPrcPayBillFeeService List chunk = ids.subList(from, Math.min(from + BATCH_SIZE, ids.size())); payBillMapper.insertMissingPayBills(chunk, operator); payBillFeeMapper.bindPayBillId(chunk); - payBillMapper.refreshPayTotal(chunk); - orderBillMapper.refreshPayTotalFromFees(chunk); + writeCnyTotals(chunk); + } + } + + /** 不改 prc_pay_bill_fee。按计费日汇率把明细折成人民币后相加,四舍五入到两位,只写入 prc_pay_bill.pay_total。 */ + private void writeCnyTotals(List billIds) + { + Map sums = new LinkedHashMap<>(); + for (Long billId : billIds) + { + sums.put(billId, BigDecimal.ZERO); + } + List fees = payBillFeeMapper.selectOpenFees(billIds); + if (fees != null) + { + for (PrcPayBillFee fee : fees) + { + if (fee == null || fee.getBillId() == null || fee.getAmount() == null) + { + continue; + } + BigDecimal cny = payFeeMoney.toCny(fee.getAmount(), fee.getCurrency(), fee.getBizDate()); + if (cny == null) + { + continue; + } + sums.merge(fee.getBillId(), cny, BigDecimal::add); + } + } + for (Map.Entry entry : sums.entrySet()) + { + payBillMapper.updateCnyPayTotal(entry.getKey(), PayFeeMoney.total(entry.getValue())); } } diff --git a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/SrvBillAirAllocServiceImpl.java b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/SrvBillAirAllocServiceImpl.java index 40627d9c..8a0aa2ff 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/service/impl/SrvBillAirAllocServiceImpl.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/service/impl/SrvBillAirAllocServiceImpl.java @@ -64,9 +64,6 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService @Autowired private PayBillFeeLogService payBillFeeLogService; - @Autowired - private PayFeeMoney payFeeMoney; - @Override public List preview(List billCodes) { @@ -110,8 +107,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService { List rows = orders.get(fee.getBillCode()); fee.setOrderCount(rows.size()); - BigDecimal cnyPrice = payFeeMoney.toCny(fee.getPrice(), fee.getCurrency(), fee.getCreateTime()); - List shares = split(cnyPrice, rows, true); + List shares = split(fee.getPrice(), rows, true); for (int i = 0; i < rows.size(); i++) { batch.add(toOrderFee(fee, rows.get(i), shares.get(i), payBillIds)); @@ -252,7 +248,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService row.setFeeLevel(fee.getFeeLevel()); String userId = PayFeeMoney.userId(); row.setAmount(amount); - row.setCurrency(PayFeeMoney.CNY); + row.setCurrency(fee.getCurrency().trim()); row.setRoundMode("HALF_UP"); row.setRemark(remark(fee)); row.setFeeSource(FEE_SOURCE); @@ -297,7 +293,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService } /** - * 把已经折成人民币的费用价格拆到每一票订单,结果保留三位,合计等于费用价格。 + * 把费用价格拆到每一票订单,结果保留两位,合计等于费用价格。 * 按订单数量:每一票先向下取整,差额补在最后一票。 * 按重量:按订单重量占这些订单总重量的比例分摊。前面的订单向下取整,差额补在最后一票有重量的订单上。 * 订单重量优先取计费重,没有计费重时取实际重量,再没有取收货重量。 @@ -309,12 +305,12 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService */ private static List split(BigDecimal price, List orders, boolean byWeight) { - BigDecimal total = price.setScale(PayFeeMoney.LINE_SCALE, RoundingMode.HALF_UP); + BigDecimal total = price.setScale(2, RoundingMode.HALF_UP); int count = orders.size(); List shares = new ArrayList<>(count); if (!byWeight) { - BigDecimal each = total.divide(BigDecimal.valueOf(count), PayFeeMoney.LINE_SCALE, RoundingMode.DOWN); + BigDecimal each = total.divide(BigDecimal.valueOf(count), 2, RoundingMode.DOWN); BigDecimal used = ZERO; for (int i = 0; i < count - 1; i++) { @@ -342,7 +338,7 @@ public class SrvBillAirAllocServiceImpl implements ISrvBillAirAllocService shares.add(null); continue; } - BigDecimal share = total.multiply(weight(orders.get(i))).divide(sum, PayFeeMoney.LINE_SCALE, RoundingMode.DOWN); + BigDecimal share = total.multiply(weight(orders.get(i))).divide(sum, 2, RoundingMode.DOWN); shares.add(share); used = used.add(share); } diff --git a/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillFeeMapper.xml b/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillFeeMapper.xml index 0e81af17..93f8c205 100644 --- a/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillFeeMapper.xml +++ b/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillFeeMapper.xml @@ -24,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -192,6 +193,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and statement_line_id is not null + + update prc_pay_bill_fee set is_deleted = '1', diff --git a/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillMapper.xml b/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillMapper.xml index b98fd0f4..eaff30bf 100644 --- a/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillMapper.xml +++ b/bms-back/bms-system/src/main/resources/mapper/price/PrcPayBillMapper.xml @@ -138,6 +138,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{billId} + + update prc_pay_bill + set pay_total = #{payTotal}, + currency = 'CNY', + update_time = sysdate() + where bill_id = #{billId} + + update prc_pay_bill set pay_calc_status = #{status}, diff --git a/bms-front/src/views/price/billing/components/BillDetail.vue b/bms-front/src/views/price/billing/components/BillDetail.vue index 7ddae305..7ce289eb 100644 --- a/bms-front/src/views/price/billing/components/BillDetail.vue +++ b/bms-front/src/views/price/billing/components/BillDetail.vue @@ -100,7 +100,7 @@
费用明细
- +
增加费用 @@ -215,7 +215,8 @@ const props = defineProps({ title: { type: String, default: '计费详情' }, loading: { type: Boolean, default: false }, detail: { type: Object, default: null }, - readonly: { type: Boolean, default: false } + readonly: { type: Boolean, default: false }, + showIncome: { type: Boolean, default: true } }) const emit = defineEmits(['update:modelValue', 'updated']) @@ -240,7 +241,7 @@ const payFees = computed(() => { }) watch(() => props.detail, () => { - feeTab.value = 'income' + feeTab.value = props.showIncome ? 'income' : 'pay' historyOpen.value = false }) diff --git a/bms-front/src/views/price/billing/payOrder/index.vue b/bms-front/src/views/price/billing/payOrder/index.vue index c4ff0a05..c4c4041e 100644 --- a/bms-front/src/views/price/billing/payOrder/index.vue +++ b/bms-front/src/views/price/billing/payOrder/index.vue @@ -74,7 +74,7 @@ - +