feat: 重构商品定价系统,新增步梯搬运费配置与支付台账统计

- 新增商品服务定价配置表,支持多规格服务价格体系
- 新增步梯搬运费配置功能,可按楼层阶梯收费
- 重构支付订单台账,新增核心数据统计卡片
- 优化下单流程,支持定价配置校验与增项计算
- 整合财务配置,移除独立充值配置菜单
这个提交包含在:
2026-11-18 08:52:12 +08:00
父节点 0370cb9bd6
当前提交 19651c0899
共有 38 个文件被更改,包括 6435 次插入 和 2440 次删除

查看文件

@@ -3,6 +3,7 @@
namespace app\api\controller;
use think\Db;
use app\common\library\ProductPricing;
/**
* 首页 / 服务类目 / 服务项目 / 费用试算
@@ -37,7 +38,7 @@ class Home extends Base
$candidateServices = Db::name('service')
->alias('s')
->join('service_cat c', 's.cat_id = c.id', 'LEFT')
->field('s.id,s.cat_id,s.name,s.price_type,s.base_price,s.max_price,s.unit,s.image,s.sales,s.weigh,c.name as cat_name,c.icon as cat_icon')
->field('s.id,s.cat_id,s.name,s.price_type,s.base_price,s.max_price,s.pricing_config,s.unit,s.image,s.sales,s.weigh,c.name as cat_name,c.icon as cat_icon')
->where('s.status', 'normal')
->where('s.cat_id', '<>', 15) // 排除“其它”类目
->select();
@@ -388,7 +389,7 @@ class Home extends Base
$query = Db::name('service')
->alias('s')
->join('service_cat c', 's.cat_id = c.id', 'LEFT')
->field('s.id,s.cat_id,s.name,s.price_type,s.service_types,s.base_price,s.max_price,s.unit,s.image,s.sales,s.weigh,c.name as cat_name,c.icon as cat_icon')
->field('s.id,s.cat_id,s.name,s.price_type,s.service_types,s.base_price,s.max_price,s.pricing_config,s.unit,s.image,s.sales,s.weigh,c.name as cat_name,c.icon as cat_icon')
->where('s.status', 'normal')
->where('s.cat_id', '<>', 15);
@@ -671,7 +672,8 @@ class Home extends Base
'addon_prices' => $spAddons,
];
}
$this->success('', ['list' => $ret]);
$service = Db::name('service')->where('id', $serviceId)->where('status', 'normal')->find();
$this->success('', ['list' => $service ? $this->configuredSpecs($service, $ret) : []]);
}
/**
@@ -708,7 +710,7 @@ class Home extends Base
'addon_prices' => $spAddons,
];
}
$detail['specs'] = $specList;
$detail['specs'] = $this->configuredSpecs($service, $specList);
$this->success('', ['detail' => $detail]);
}
@@ -797,6 +799,8 @@ class Home extends Base
'service_type' => trim((string)$this->request->param('service_type', '')),
'is_custom' => (int)$this->request->param('is_custom', 0),
'base_price' => $this->request->param('base_price', null),
'pricing_revision' => $this->request->param('pricing_revision'),
'extras' => $this->request->param('extras/a', []),
], (int)$this->request->param('coupon_id', 0), $this->uid(),
(string)$this->request->param('price_type', ''),
(float)$this->request->param('user_price', 0),
@@ -829,10 +833,12 @@ class Home extends Base
// 支持多商品组合与增项计算(一口价模式下强制从 fa_service 与 fa_service_spec 读取真实价格,严禁采信前端传入 base_price)
$base = 0;
$pricedLines = [];
$dictionary = null;
if (!empty($goodsList) && is_array($goodsList)) {
$serviceCache = [];
$specCache = [];
foreach ($goodsList as $g) {
foreach ($goodsList as $index => $g) {
if (is_string($g)) {
$rawG = htmlspecialchars_decode($g);
$decoded = json_decode($rawG, true);
@@ -856,6 +862,14 @@ class Home extends Base
$dbSvc = $serviceCache[$sid];
}
if ($dbSvc && ($config = ProductPricing::read($dbSvc))) {
$dictionary = $dictionary ?? ProductPricing::dictionary();
$line = self::configuredLine($dbSvc, $config, $dictionary, $g, $isFixedLike);
$pricedLines[$index] = $line;
$base += $line['total_cents'] / 100;
continue;
}
if ($isFixedLike) {
// 纯空占位行(下单页首次加载尚未选服务时试算)容忍返回 0;只要带了 is_custom、自填名称、自定义价格或处于创单严格校验则强制拦截
$hasCustomInput = $isCustom
@@ -980,6 +994,9 @@ class Home extends Base
}
}
}
} elseif ($service && ($config = ProductPricing::read($service))) {
$pricedLines[0] = self::configuredLine($service, $config, ProductPricing::dictionary(), $params, $isFixedLike);
$base = $pricedLines[0]['total_cents'] / 100;
} elseif ($service) {
if ($isFixedLike && $service['price_type'] === 'quote') {
throw new \InvalidArgumentException('该服务项目不支持一口价模式,请切换为师傅报价或自主定价');
@@ -1095,8 +1112,8 @@ class Home extends Base
$urgentAmount = 0;
} else {
$floor = max(0, (int)$params['floor']);
$freeFloor = ($service && (int)$service['free_floor'] > 0) ? (int)$service['free_floor'] : 2;
$floorFee = ($service && (float)$service['floor_fee'] > 0) ? (float)$service['floor_fee'] : 10.0;
$freeFloor = isset($service['free_floor']) && (int)$service['free_floor'] >= 0 ? (int)$service['free_floor'] : 2;
$floorFee = isset($service['floor_fee']) && (float)$service['floor_fee'] >= 0 ? (float)$service['floor_fee'] : 10.0;
if ((int)$params['has_elevator'] === 0 && $floor > $freeFloor) {
$floorAmount = ($floor - $freeFloor) * $floorFee;
@@ -1125,6 +1142,7 @@ class Home extends Base
}
return [
'lines' => $pricedLines,
'price_type' => $type,
'user_price' => $type === 'custom' ? round($base, 2) : 0,
'base_amount' => $type === 'quote' ? 0 : round($base, 2),
@@ -1140,6 +1158,33 @@ class Home extends Base
];
}
private static function configuredLine(array $product, array $config, array $dictionary, array $input, $fixed)
{
$specId = (int)($input['spec_id'] ?? 0);
$specName = '';
if ($specId !== 0) {
$spec = Db::name('service_spec')->where([
'id' => $specId, 'service_id' => $product['id'], 'status' => 'normal',
])->field('name')->find();
if (!$spec) {
throw new \InvalidArgumentException('商品规格不可用,请重新选择');
}
$specName = $spec['name'];
}
if (isset($input['pricing_revision']) && (int)$input['pricing_revision'] !== $config['revision']) {
throw new \InvalidArgumentException('商品价格配置已更新,请重新选择商品');
}
$extras = $input['extras'] ?? $input['addons'] ?? [];
if (!is_array($extras) || (!empty($input['addon_services']) && !$extras)) {
throw new \InvalidArgumentException('增值服务选项已更新,请重新选择商品');
}
$line = ProductPricing::priceLine($config, $dictionary, $specId, (string)($input['service_type'] ?? ''),
max(1, (int)($input['num'] ?? $input['goods_num'] ?? 1)), $extras, $fixed);
$line['spec_name'] = $specName;
$line['item_name'] = $product['name'];
return $line;
}
/**
* 首页轮播(后台 fa_banner 可管,支持活动 / 平台实力 / 服务主题)
*/
@@ -1286,7 +1331,7 @@ class Home extends Base
$ret = [];
foreach ($list as $row) {
$formatted = $this->formatService($row);
$formatted['specs'] = isset($specsMap[$row['id']]) ? $specsMap[$row['id']] : [];
$formatted['specs'] = $this->configuredSpecs($row, $specsMap[$row['id']] ?? []);
$ret[] = $formatted;
}
return $ret;
@@ -1319,6 +1364,35 @@ class Home extends Base
/**
* 单项格式化(价格文案统一由此输出)
*/
private static function pricingDictionary()
{
static $dictionary = null;
if ($dictionary === null) {
$dictionary = ProductPricing::dictionary();
}
return $dictionary;
}
private function configuredSpecs(array $product, array $specs)
{
$config = ProductPricing::read($product);
if (!$config) {
return $specs;
}
foreach ($specs as &$spec) {
$options = ProductPricing::options($config, self::pricingDictionary(), $spec['id']);
$spec['service_types'] = ProductPricing::publicServices($options);
$spec['service_prices'] = array_column($spec['service_types'], 'price', 'code');
$spec['addon_prices'] = [];
$default = $options['services'][$options['default']] ?? [];
$spec['base_price'] = ($default['cents'] ?? 0) / 100;
$spec['price_type'] = $default['mode'] ?? 'quote';
$spec['pricing_revision'] = $config['revision'];
}
unset($spec);
return $specs;
}
public function formatService($row)
{
$type = $row['price_type'];
@@ -1388,6 +1462,18 @@ class Home extends Base
}));
}
$config = ProductPricing::read($row);
if ($config) {
$options = ProductPricing::options($config, self::pricingDictionary(), 0);
$serviceTypes = ProductPricing::publicServices($options);
// Incremental clients read each service's own add-ons.
$addons = [];
$default = $options['services'][$options['default']] ?? null;
$type = $default['mode'] ?? 'quote';
$row['base_price'] = ($default['cents'] ?? 0) / 100;
$priceText = $type === 'quote' ? '师傅报价' : '¥' . $row['base_price'];
}
$catIcon = isset($row['cat_icon']) && $row['cat_icon'] ? $row['cat_icon'] : '';
$img = $row['image'] ? $row['image'] : $catIcon;
@@ -1410,6 +1496,7 @@ class Home extends Base
'need_model' => isset($row['need_model']) ? (int)$row['need_model'] : 1,
'description' => isset($row['description']) ? $row['description'] : '',
'tag' => isset($row['tag']) && $row['tag'] ? $row['tag'] : '明码标价',
'pricing_revision' => $config['revision'] ?? null,
'service_types' => $serviceTypes,
'addons' => $addons,
];