- 报销金额公式:空包费改为加(任务付款+快递费+佣金+京喜差价−扣款+空包费) - 去掉「以旧换新超买家实付」「查不到标签待复查」两项校验 - 种菜额度不再上传看板:按《种菜明细报表生成逻辑》(业务交付包 2026-11-27)自算, 商品ID→ID负责人、职级、店铺信息直接只读查经营分析副本库(JSReportReplica.rpt), 金额取实付金额字段(同看板);单笔/每日/月度超额、未匹配负责人、职级为空、职级未配置、 额度规则未配置全部取消;额度数据取不到时整批待复查 - 额度规则 309 条(脉象导出)随代码初始化,工作台可新增/修改/删除/整体导入/导出 - 利润中心直接读工作平台店铺信息(rpt.fys_shopInfo),查不到改为待复查;去掉店铺信息、看板上传 - 种菜任务工单导入模板执行人统一填李斯 - 每日群汇总推送改到 11:20(部署脚本 cron) - 用看板 11 月 1–27 日 13,941 单对照:规则来源、日/月累计、风险类型逐单一致 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNTa9ohkCsVFACqjz3KMcG
165 lines
9.7 KiB
PHP
165 lines
9.7 KiB
PHP
<?php
|
||
|
||
namespace Tests\Unit\EcommerceFinance;
|
||
|
||
use Modules\EcommerceFinance\Services\PlantingQuotaCalculator as Calculator;
|
||
use PHPUnit\Framework\TestCase;
|
||
|
||
class PlantingQuotaCalculatorTest extends TestCase
|
||
{
|
||
private function row(string $workOrder, string $amount, array $patch = []): array
|
||
{
|
||
return array_replace([
|
||
'work_order_no' => $workOrder, 'status_code' => 'WAIT_CONFIRM', 'paid_at' => '2026-11-26 16:03:21',
|
||
'shop_name' => '天猫-亿家达旗舰店', 'platform' => '淘宝天猫', 'platform_product_id' => '1001',
|
||
'actual_paid_amount' => $amount, 'reimbursement_amount' => $amount,
|
||
], $patch);
|
||
}
|
||
|
||
private function rule(string $type, array $patch = []): array
|
||
{
|
||
return array_replace([
|
||
'rule_type' => $type, 'platform' => '', 'shop_name' => '', 'channel' => '', 'position_level' => '', 'ider' => '',
|
||
'month_limit' => null, 'day_limit' => null, 'single_limit' => null, 'is_enabled' => true,
|
||
], $patch);
|
||
}
|
||
|
||
private function calc(array $rows, array $rules, array $owners = [], array $levels = [], array $shops = []): array
|
||
{
|
||
return (new Calculator())->calculate(
|
||
$rows,
|
||
$shops + ['天猫-亿家达旗舰店' => ['platform' => '天猫', 'shop_head' => '店长甲'], '天猫-欧意朗旗舰店' => ['platform' => '天猫', 'shop_head' => '無尘']],
|
||
$owners + ['1001' => ['ider' => '無尘', 'curr_cater' => '無尘'], '2001' => ['ider' => '子远', 'curr_cater' => '子龙']],
|
||
$levels + ['無尘' => 'M4', '子远' => 'P2', '店长甲' => 'P3'],
|
||
$rules,
|
||
);
|
||
}
|
||
|
||
/** 交付文档附录 B 的实测样本:4 单同域累加 320 未超日限额;子远命中 ID负责人规则,单笔 10 → 单笔超额。 */
|
||
public function test_matches_delivery_document_sample(): void
|
||
{
|
||
$rules = [
|
||
$this->rule('platform', ['platform' => '天猫', 'position_level' => 'P2', 'day_limit' => '500', 'single_limit' => '300']),
|
||
$this->rule('platform', ['platform' => '天猫', 'position_level' => 'M4', 'day_limit' => '1500', 'single_limit' => '500']),
|
||
$this->rule('ider', ['ider' => '子远', 'single_limit' => '10']),
|
||
];
|
||
$rows = [];
|
||
foreach (['GD662946294', 'GD662946295', 'GD662946296', 'GD662946297'] as $workOrder) {
|
||
$rows[] = $this->row($workOrder, '80', ['shop_name' => '天猫-欧意朗旗舰店']);
|
||
}
|
||
$rows[] = $this->row('GD662974885', '30', ['shop_name' => '天猫-欧意朗旗舰店', 'platform_product_id' => "1100551039905\n2001"]);
|
||
|
||
$result = $this->calc($rows, $rules);
|
||
|
||
$this->assertSame('ok', $result['GD662946294']['risk_level']);
|
||
$this->assertSame('320.00', $result['GD662946294']['day_total']);
|
||
$this->assertSame('1500.00', $result['GD662946294']['day_limit']);
|
||
$this->assertSame('平台+职级:天猫/M4', $result['GD662946294']['rule_label']);
|
||
$this->assertSame('無尘|platform|天猫|M4', $result['GD662946294']['scope_key']);
|
||
|
||
$ziyuan = $result['GD662974885'];
|
||
$this->assertSame('danger', $ziyuan['risk_level']);
|
||
$this->assertSame(['单笔超额'], $ziyuan['risk_types']);
|
||
$this->assertSame('子远', $ziyuan['ider']);
|
||
$this->assertSame('子龙', $ziyuan['curr_cater']);
|
||
$this->assertSame('2001', $ziyuan['product_id']);
|
||
$this->assertSame('ID负责人:子远', $ziyuan['rule_label']);
|
||
$this->assertSame('单笔 30.00 超过上限 10.00', $ziyuan['risk_message']);
|
||
$this->assertSame('20.00', $ziyuan['over_amount']);
|
||
}
|
||
|
||
public function test_daily_and_monthly_totals_include_other_statuses_and_days(): void
|
||
{
|
||
$rules = [$this->rule('platform', ['platform' => '天猫', 'position_level' => 'M4', 'day_limit' => '100', 'month_limit' => '250'])];
|
||
$result = $this->calc([
|
||
$this->row('A', '60', ['paid_at' => '2026-11-26 09:00:00']),
|
||
$this->row('B', '50', ['paid_at' => '2026-11-26 18:00:00', 'status_code' => 'CONFIRMED']),
|
||
$this->row('C', '100', ['paid_at' => '2026-11-03 10:00:00', 'status_code' => 'CONFIRMED']),
|
||
$this->row('D', '500', ['paid_at' => '2026-11-26 10:00:00', 'status_code' => 'DISABLED']),
|
||
$this->row('E', '40', ['paid_at' => '2026/11/2 8:05']),
|
||
], $rules);
|
||
|
||
$this->assertArrayNotHasKey('D', $result);
|
||
// 日累计 = 当天全部单合计(含已完成),每单相同;作废的不算。
|
||
$this->assertSame('110.00', $result['A']['day_total']);
|
||
$this->assertSame('110.00', $result['B']['day_total']);
|
||
$this->assertSame(['每日超额'], $result['A']['risk_types']);
|
||
$this->assertSame('250.00', $result['C']['month_total']);
|
||
$this->assertSame('ok', $result['C']['risk_level']);
|
||
$this->assertSame('2026-11-02 08:05:00', $result['E']['paid_at']);
|
||
|
||
$result = $this->calc([
|
||
$this->row('A', '60', ['paid_at' => '2026-11-26 09:00:00']),
|
||
$this->row('C', '200', ['paid_at' => '2026-11-03 10:00:00']),
|
||
], $rules);
|
||
$this->assertSame(['月度超额'], $result['A']['risk_types']);
|
||
$this->assertSame('本月累计 260.00 超过上限 250.00', $result['A']['risk_message']);
|
||
$this->assertSame(['每日超额', '月度超额'], $result['C']['risk_types']);
|
||
}
|
||
|
||
public function test_owner_fallback_and_configuration_risks(): void
|
||
{
|
||
$rules = [
|
||
$this->rule('platform', ['platform' => '天猫', 'position_level' => 'P3', 'single_limit' => '300']),
|
||
$this->rule('platform', ['platform' => '天猫', 'position_level' => 'P2', 'single_limit' => '300']),
|
||
];
|
||
$result = $this->calc([
|
||
// 商品没负责人 → 店长兜底,部门负责人为空。
|
||
$this->row('SHOPHEAD', '10', ['platform_product_id' => '9999']),
|
||
// 店铺查不到、商品也没负责人 → 未匹配负责人,不判额度。
|
||
$this->row('NOOWNER', '999', ['shop_name' => '拼多多-新店', 'platform' => '拼多多', 'platform_product_id' => '9999']),
|
||
$this->row('NOLEVEL', '10', ['platform_product_id' => '3001']),
|
||
$this->row('BADLEVEL', '10', ['platform_product_id' => '3002']),
|
||
$this->row('NORULE', '10', ['platform_product_id' => '3003']),
|
||
], $rules, ['3001' => ['ider' => '新人', 'curr_cater' => null], '3002' => ['ider' => '高手', 'curr_cater' => null], '3003' => ['ider' => '主管', 'curr_cater' => null]], ['高手' => '高级', '主管' => 'M2']);
|
||
|
||
$this->assertSame('店长甲', $result['SHOPHEAD']['ider']);
|
||
$this->assertNull($result['SHOPHEAD']['curr_cater']);
|
||
$this->assertSame('ok', $result['SHOPHEAD']['risk_level']);
|
||
$this->assertSame(['未匹配负责人'], $result['NOOWNER']['risk_types']);
|
||
$this->assertSame('warning', $result['NOOWNER']['risk_level']);
|
||
$this->assertSame('拼多多', $result['NOOWNER']['platform']);
|
||
$this->assertSame(['职级为空'], $result['NOLEVEL']['risk_types']);
|
||
$this->assertStringStartsWith('职级为空', $result['NOLEVEL']['risk_message']);
|
||
$this->assertSame(['职级未配置'], $result['BADLEVEL']['risk_types']);
|
||
$this->assertSame(['额度规则未配置'], $result['NORULE']['risk_types']);
|
||
$this->assertSame('未命中ID负责人、店铺或平台规则;平台 天猫,职级 M2', $result['NORULE']['risk_message']);
|
||
}
|
||
|
||
public function test_rule_priority_channel_and_disabled_rules(): void
|
||
{
|
||
$rules = [
|
||
$this->rule('platform', ['platform' => '天猫', 'position_level' => 'M4', 'channel' => '天猫', 'single_limit' => '1']),
|
||
$this->rule('platform', ['platform' => '天猫', 'position_level' => 'M4', 'single_limit' => '500']),
|
||
$this->rule('shop', ['shop_name' => '天猫-亿家达旗舰店', 'single_limit' => '200']),
|
||
$this->rule('shop_level', ['shop_name' => '天猫-亿家达旗舰店', 'position_level' => 'M4', 'single_limit' => '50', 'is_enabled' => false]),
|
||
];
|
||
$result = $this->calc([$this->row('A', '100')], $rules);
|
||
// 停用的店铺+职级不参与,命中店铺规则(优先于平台规则)。
|
||
$this->assertSame('店铺:天猫-亿家达旗舰店', $result['A']['rule_label']);
|
||
$this->assertSame('無尘|SHOP|天猫-亿家达旗舰店|M4', $result['A']['scope_key']);
|
||
|
||
$result = $this->calc([$this->row('A', '100', ['shop_name' => '天猫-欧意朗旗舰店'])], $rules);
|
||
// 平台规则优先渠道为空的那条。
|
||
$this->assertSame('平台+职级:天猫/M4', $result['A']['rule_label']);
|
||
$this->assertSame('ok', $result['A']['risk_level']);
|
||
}
|
||
|
||
public function test_amount_platform_and_band_normalization(): void
|
||
{
|
||
$this->assertSame(4150, Calculator::amount(['actual_paid_amount' => '41.5', 'reimbursement_amount' => '99']));
|
||
$this->assertSame(9900, Calculator::amount(['actual_paid_amount' => '', 'reimbursement_amount' => '99']));
|
||
$this->assertSame(0, Calculator::amount(['actual_paid_amount' => '0', 'reimbursement_amount' => '99']));
|
||
$this->assertSame('京喜', Calculator::platform('京喜京东'));
|
||
$this->assertSame('京东', Calculator::platform('京东自营'));
|
||
$this->assertSame('天猫', Calculator::platform('淘宝天猫'));
|
||
$this->assertSame('拼多多', Calculator::platform('pdd'));
|
||
$this->assertSame('阿里巴巴', Calculator::platform('1688'));
|
||
$this->assertSame('未归属', Calculator::platform('快手'));
|
||
$this->assertSame('P2', Calculator::band('P2-运营'));
|
||
$this->assertSame('M4', Calculator::band('m4'));
|
||
$this->assertNull(Calculator::band('高级'));
|
||
$this->assertNull(Calculator::band('M6'));
|
||
}
|
||
}
|