- 新增商品服务定价配置表,支持多规格服务价格体系 - 新增步梯搬运费配置功能,可按楼层阶梯收费 - 重构支付订单台账,新增核心数据统计卡片 - 优化下单流程,支持定价配置校验与增项计算 - 整合财务配置,移除独立充值配置菜单
85 行
4.4 KiB
PHP
85 行
4.4 KiB
PHP
<?php
|
|
require __DIR__ . '/../server/application/common/library/ProductPricing.php';
|
|
|
|
use app\common\library\ProductPricing;
|
|
|
|
function expectSame($expected, $actual)
|
|
{
|
|
if ($expected !== $actual) {
|
|
throw new RuntimeException(var_export([$expected, $actual], true));
|
|
}
|
|
}
|
|
|
|
$dict = [
|
|
'install' => ['name' => '安装', 'unit' => '台', 'can_be_main' => 1, 'support_fixed' => 1],
|
|
'repair' => ['name' => '维修', 'unit' => '台', 'can_be_main' => 1, 'support_fixed' => 1],
|
|
'remove' => ['name' => '拆旧', 'unit' => '份', 'can_be_main' => 1, 'can_be_addon' => 1, 'support_fixed' => 1],
|
|
'measure' => ['name' => '测量', 'unit' => '次', 'can_be_main' => 1, 'support_fixed' => 0],
|
|
];
|
|
|
|
$config = ProductPricing::validate([
|
|
'default' => 'measure',
|
|
'services' => [
|
|
'install' => ['mode' => 'fixed', 'price' => '80.00', 'addons' => ['remove' => '35.25']],
|
|
'repair' => ['mode' => 'fixed', 'price' => '65.00'],
|
|
'remove' => ['mode' => 'fixed', 'price' => '50.00'],
|
|
'measure' => ['mode' => 'quote'],
|
|
],
|
|
'specs' => [7 => ['install' => ['price' => '110.00', 'addons' => ['remove' => '40.25']]]],
|
|
], $dict, [7]);
|
|
$config['revision'] = 3;
|
|
|
|
expectSame('measure', ProductPricing::options($config, $dict, 7)['default']);
|
|
expectSame(11000, ProductPricing::options($config, $dict, 7)['services']['install']['cents']);
|
|
expectSame(6500, ProductPricing::options($config, $dict, 7)['services']['repair']['cents']);
|
|
expectSame([], ProductPricing::options($config, $dict, 7)['services']['repair']['addons']);
|
|
expectSame(3525, ProductPricing::options($config, $dict, 0)['services']['install']['addons']['remove']['cents']);
|
|
expectSame(26025, ProductPricing::priceLine($config, $dict, 7, 'install', 2, [['code' => 'remove', 'num' => 1, 'price' => 1]], true)['total_cents']);
|
|
$converted = $config;
|
|
$converted['spec_configs'] = ProductPricing::expandLegacySpecs($config);
|
|
unset($converted['specs']);
|
|
expectSame(26025, ProductPricing::priceLine($converted, $dict, 7, 'install', 2, [['code' => 'remove', 'num' => 1]], true)['total_cents']);
|
|
foreach ([['repair', 'remove'], ['remove', 'remove'], ['unknown', 'remove'], ['measure', 'remove']] as [$main, $addon]) {
|
|
try {
|
|
ProductPricing::priceLine($config, $dict, 7, $main, 1, [['code' => $addon, 'num' => 1]], true);
|
|
} catch (InvalidArgumentException $e) {
|
|
continue;
|
|
}
|
|
throw new RuntimeException("Invalid selection accepted: $main / $addon");
|
|
}
|
|
$independent = ProductPricing::validate([
|
|
'default' => 'install',
|
|
'services' => [
|
|
'install' => ['mode' => 'fixed', 'price' => '80', 'addons' => ['remove' => '50']],
|
|
'repair' => ['mode' => 'fixed', 'price' => '65'],
|
|
],
|
|
'spec_configs' => [
|
|
7 => ['default' => 'install', 'services' => ['install' => ['mode' => 'fixed', 'price' => '110']]],
|
|
8 => ['default' => 'measure', 'services' => ['measure' => ['mode' => 'quote']]],
|
|
],
|
|
], $dict, [7, 8, 9]);
|
|
$independent['revision'] = 4;
|
|
expectSame(['install'], array_keys(ProductPricing::options($independent, $dict, 7)['services']));
|
|
expectSame([], ProductPricing::options($independent, $dict, 7)['services']['install']['addons']);
|
|
expectSame(11000, ProductPricing::priceLine($independent, $dict, 7, '', 1, [], true)['total_cents']);
|
|
expectSame('measure', ProductPricing::options($independent, $dict, 8)['default']);
|
|
expectSame('quote', ProductPricing::options($independent, $dict, 8)['services']['measure']['mode']);
|
|
expectSame(['install', 'repair'], array_keys(ProductPricing::options($independent, $dict, 9)['services']));
|
|
expectSame(13000, ProductPricing::priceLine($independent, $dict, 9, '', 1, [['code' => 'remove']], true)['total_cents']);
|
|
foreach ([['repair', []], ['install', [['code' => 'remove']]]] as [$service, $addons]) {
|
|
try {
|
|
ProductPricing::priceLine($independent, $dict, 7, $service, 1, $addons, true);
|
|
} catch (InvalidArgumentException $e) {
|
|
continue;
|
|
}
|
|
throw new RuntimeException('Parent service or addon leaked into an independent spec');
|
|
}
|
|
$editedParent = $independent;
|
|
$editedParent['services']['install']['cents'] = 10000;
|
|
expectSame(11000, ProductPricing::priceLine($editedParent, $dict, 7, '', 1, [], true)['total_cents']);
|
|
expectSame(10000, ProductPricing::priceLine($editedParent, $dict, 9, '', 1, [], true)['total_cents']);
|
|
unset($editedParent['spec_configs'][7]);
|
|
expectSame(10000, ProductPricing::priceLine($editedParent, $dict, 7, '', 1, [], true)['total_cents']);
|
|
|
|
echo "Product pricing tests passed\n";
|