- 报销金额公式:空包费改为加(任务付款+快递费+佣金+京喜差价−扣款+空包费) - 去掉「以旧换新超买家实付」「查不到标签待复查」两项校验 - 种菜额度不再上传看板:按《种菜明细报表生成逻辑》(业务交付包 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
160 lines
9.6 KiB
PHP
160 lines
9.6 KiB
PHP
<?php
|
||
|
||
namespace Tests\Unit\EcommerceFinance;
|
||
|
||
use Modules\EcommerceFinance\Services\PlantingReimbursementAuditor as Auditor;
|
||
use PHPUnit\Framework\TestCase;
|
||
|
||
class PlantingReimbursementAuditorTest extends TestCase
|
||
{
|
||
private function row(string $orderNo, float $amount, array $patch = []): array
|
||
{
|
||
return array_replace([
|
||
'work_order_no' => 'GD' . $orderNo, 'online_order_no' => $orderNo, 'shop_name' => '京喜-星光闪闪京喜自营工厂店',
|
||
'initiator' => '星璃', 'payee_name' => '王敏佳', 'payee_account' => '6214000011112222', 'payee_bank' => '招商银行',
|
||
'payee_mobile' => '13800000000', 'task_payment' => (string) $amount, 'task_freight' => '0.00', 'task_commission' => '0.00',
|
||
'jingxi_price_diff' => '0.00', 'task_deduction' => '0.00', 'task_empty_package_fee' => '0.00',
|
||
'reimbursement_amount' => (string) $amount, 'actual_paid_amount' => (string) $amount, 'erp_order_label' => '',
|
||
'paid_at' => '2026-11-11 10:00:00', 'status' => '处理中',
|
||
], $patch);
|
||
}
|
||
|
||
private function audit(array $rows, array $refs = []): array
|
||
{
|
||
return (new Auditor())->audit($rows, $refs + [
|
||
'reimbursed' => [],
|
||
'commission_people' => ['白菜' => true],
|
||
'roster' => ['王敏佳' => true, '姚佳炜' => true, '李润' => true],
|
||
'roster_exceptions' => ['柴嘉伟(建行)', '柴嘉伟'],
|
||
'profit_centers' => ['京喜-星光闪闪京喜自营工厂店' => '运营中心A', '天猫-欧意朗旗舰店' => '运营中心A', '天猫-HX旗舰店101' => '运营中心G'],
|
||
], '2026-11-12');
|
||
}
|
||
|
||
private function decisions(array $result): array
|
||
{
|
||
return array_column($result['rows'], 'decision', 'online_order_no');
|
||
}
|
||
|
||
private function quota(string $workOrder, array $types = [], string $message = '未超额', array $patch = []): array
|
||
{
|
||
return [$workOrder => array_replace([
|
||
'work_order_no' => $workOrder, 'ider' => '星璃', 'position_level' => 'P2', 'rule_label' => '平台+职级:京喜/P2',
|
||
'amount' => '300.00', 'day_total' => '300.00', 'day_limit' => '500.00', 'month_total' => '300.00', 'month_limit' => null,
|
||
'risk_level' => $types === [] ? 'ok' : 'danger', 'risk_types' => $types, 'risk_message' => $message,
|
||
], $patch)];
|
||
}
|
||
|
||
public function test_quota_over_limit_cancels_all_flagged_orders(): void
|
||
{
|
||
$rows = [];
|
||
$quota = [];
|
||
foreach ([1, 2, 3] as $i) {
|
||
$rows[] = $this->row("10{$i}", 300, ['paid_at' => "2026-11-11 1{$i}:00:00"]);
|
||
$quota += $this->quota("GD10{$i}", ['每日超额'], '当日累计 900.00 超过上限 500.00');
|
||
}
|
||
$rows[] = $this->row('104', 100);
|
||
$quota += $this->quota('GD104');
|
||
|
||
$result = $this->audit($rows, ['quota' => $quota]);
|
||
|
||
// 提示超额就全部取消,不再按付款先后保留到日限额。
|
||
$this->assertSame(['101' => 'cancel', '102' => 'cancel', '103' => 'cancel', '104' => 'pass'], $this->decisions($result));
|
||
$this->assertStringContainsString('当日累计 900.00 超过上限 500.00', $result['rows'][0]['issue_text']);
|
||
$this->assertStringContainsString('平台+职级:京喜/P2', $result['rows'][0]['issue_text']);
|
||
$this->assertSame('100.00', $result['summary']['total']);
|
||
$this->assertStringContainsString('@星璃 以上订单本次不予报销', $result['summary']['notices'][0]['message']);
|
||
}
|
||
|
||
public function test_quota_configuration_problems_cancel_and_missing_quota_is_recheck(): void
|
||
{
|
||
$quota = $this->quota('GD1', ['职级为空'], '职级为空,暂不判断平台规则;当日累计 10.00,本月累计 10.00', ['position_level' => null, 'risk_level' => 'warning'])
|
||
+ $this->quota('GD2', ['未匹配负责人'], '商品ID未匹配负责人,暂不判断额度', ['ider' => null, 'risk_level' => 'warning'])
|
||
+ $this->quota('GD3', ['职级未配置'], '职级 高级 未配置额度规则', ['risk_level' => 'warning'])
|
||
+ $this->quota('GD4', ['额度规则未配置'], '未命中ID负责人、店铺或平台规则', ['risk_level' => 'warning']);
|
||
$result = $this->audit([$this->row('1', 10), $this->row('2', 10), $this->row('3', 10), $this->row('4', 10), $this->row('5', 10)], ['quota' => $quota]);
|
||
|
||
$this->assertSame(['1' => 'cancel', '2' => 'cancel', '3' => 'cancel', '4' => 'cancel', '5' => 'recheck'], $this->decisions($result));
|
||
$this->assertStringContainsString('职级为空', $result['rows'][0]['issue_text']);
|
||
$this->assertStringContainsString('未匹配负责人', $result['rows'][1]['issue_text']);
|
||
|
||
// 额度数据取不到:全部待复查,不能直接报。
|
||
$unavailable = $this->audit([$this->row('1', 10)], ['quota' => null, 'quota_error' => '经营分析副本库查询失败']);
|
||
$this->assertSame(['1' => 'recheck'], $this->decisions($unavailable));
|
||
$this->assertStringContainsString('经营分析副本库查询失败', $unavailable['rows'][0]['issue_text']);
|
||
}
|
||
|
||
public function test_rule_failures_cancel_and_exceptions_pass(): void
|
||
{
|
||
$result = $this->audit([
|
||
$this->row('201', 100, ['shop_name' => '天猫-欧意朗旗舰店', 'initiator' => '白菜', 'payee_name' => '姚佳炜']),
|
||
$this->row('202', 100, ['initiator' => '观海', 'task_commission' => '5.00', 'reimbursement_amount' => '105.00']),
|
||
$this->row('203', 89.5, ['shop_name' => '天猫-欧意朗旗舰店', 'erp_order_label' => '工单同步,以旧换新', 'actual_paid_amount' => '50.00']),
|
||
$this->row('210', 20, ['task_empty_package_fee' => '2.50', 'reimbursement_amount' => '22.50']),
|
||
$this->row('211', 20, ['task_empty_package_fee' => '2.50', 'reimbursement_amount' => '17.50']),
|
||
$this->row('204', 10, ['shop_name' => '天猫-HX旗舰店101', 'payee_name' => '柴嘉伟(建行)']),
|
||
$this->row('205', 10, ['payee_name' => '离职的人']),
|
||
$this->row('206', 10, ['reimbursement_amount' => '12.00']),
|
||
$this->row('207', 10, ['work_order_no' => 'GD207A']),
|
||
$this->row('207', 10, ['work_order_no' => 'GD207B']),
|
||
$this->row('208', 10, ['shop_name' => '拼多多-新店']),
|
||
], ['reimbursed' => ['201' => '2026-11-03']]);
|
||
|
||
$rows = [];
|
||
foreach ($result['rows'] as $row) {
|
||
$rows[$row['work_order_no']] = $row;
|
||
}
|
||
$this->assertSame('cancel', $rows['GD201']['decision']);
|
||
$this->assertStringContainsString('2026-11-03', $rows['GD201']['issue_text']);
|
||
$this->assertSame('cancel', $rows['GD202']['decision']);
|
||
$this->assertStringContainsString('报销佣金人员', $rows['GD202']['issue_text']);
|
||
// 以旧换新、报销金额大于买家实付不再校验。
|
||
$this->assertSame('pass', $rows['GD203']['decision']);
|
||
// 空包费是加:20 + 2.50 = 22.50。
|
||
$this->assertSame('pass', $rows['GD210']['decision']);
|
||
$this->assertSame('cancel', $rows['GD211']['decision']);
|
||
$this->assertStringContainsString('+空包费', $rows['GD211']['issue_text']);
|
||
$this->assertSame('pass', $rows['GD204']['decision']);
|
||
$this->assertSame('cancel', $rows['GD205']['decision']);
|
||
$this->assertSame('cancel', $rows['GD206']['decision']);
|
||
$this->assertSame('pass', $rows['GD207A']['decision']);
|
||
$this->assertSame('cancel', $rows['GD207B']['decision']);
|
||
// 查不到利润中心:待复查(先到工作平台补齐)。
|
||
$this->assertSame('recheck', $rows['GD208']['decision']);
|
||
$this->assertStringContainsString('利润中心', $rows['GD208']['issue_text']);
|
||
}
|
||
|
||
public function test_missing_roster_skips_payee_check(): void
|
||
{
|
||
$result = $this->audit([$this->row('1', 10, ['payee_name' => '任何人'])], ['roster' => null]);
|
||
|
||
$this->assertSame(['1' => 'pass'], $this->decisions($result));
|
||
}
|
||
|
||
public function test_summary_groups_ding_lines_cards_and_pivots(): void
|
||
{
|
||
$result = $this->audit([
|
||
$this->row('1', 60, ['shop_name' => '天猫-欧意朗旗舰店', 'initiator' => '白菜', 'payee_name' => '姚佳炜']),
|
||
$this->row('2', 40.5, ['shop_name' => '天猫-欧意朗旗舰店', 'initiator' => '白菜', 'payee_name' => '姚佳炜']),
|
||
$this->row('3', 10, ['shop_name' => '天猫-HX旗舰店101', 'initiator' => '观海', 'payee_name' => '李润']),
|
||
$this->row('4', 20, ['initiator' => '观海', 'payee_name' => '李润']),
|
||
]);
|
||
$summary = $result['summary'];
|
||
|
||
$this->assertSame('2026-11-11', $summary['bill_date']);
|
||
$this->assertSame('11.11种菜报销', $summary['purpose']);
|
||
$this->assertSame('100.50', $summary['group_amounts']['三大天猫']);
|
||
$this->assertSame('30.00', $summary['group_amounts']['其他']);
|
||
$this->assertSame('130.50', $summary['total']);
|
||
$this->assertSame([['运营中心A', '欧意朗', 10050], ['运营中心A', '其他', 2000], ['运营中心G', '其他', 1000]], array_map(
|
||
static fn (array $line): array => [$line['department'], $line['shop'], $line['cents']],
|
||
$summary['ding_lines'],
|
||
));
|
||
$this->assertCount(1, $summary['pivots']['三大天猫']);
|
||
$this->assertCount(2, $summary['pivots']['其他']);
|
||
$this->assertCount(2, $summary['cards']['其他']);
|
||
$this->assertSame('招商银行', $summary['cards']['三大天猫'][0]['payee_bank']);
|
||
$this->assertSame(['count' => 4, 'amount' => '130.50'], $summary['source']);
|
||
$this->assertSame([true, true, true, true, true, true], array_column($summary['checks'], 'ok'));
|
||
}
|
||
}
|