fix: 种菜订单收入差异改按最终报销金额 #1634
@ -92,12 +92,12 @@ class PlantingReimbursementIncomeCheck
|
||||
$other[] = self::SOURCE_LABELS[$source] . ' ' . $bill['bill_item'] . ' ' . self::decimal($net) . '元(' . $bill['record_code'] . ')';
|
||||
}
|
||||
}
|
||||
$difference = self::cents($row['task_payment']) - $income;
|
||||
$difference = self::cents($row['reimbursement_amount'] ?? null) - $income;
|
||||
$note = '';
|
||||
$valid = $sources !== [] && $number !== '' && $start !== null && is_numeric($row['task_payment'] ?? null);
|
||||
$valid = $sources !== [] && $number !== '' && $start !== null && is_numeric($row['reimbursement_amount'] ?? null);
|
||||
if (! $valid) {
|
||||
$result = '需核实';
|
||||
$note = $sources === [] ? '平台账单来源未配置' : '线上订单号、付款时间或任务付款金额缺失,请核实';
|
||||
$note = $sources === [] ? '平台账单来源未配置' : '线上订单号、付款时间或最终报销金额缺失,请核实';
|
||||
} elseif ($count > 0) {
|
||||
$result = $difference > 1 ? '多报销' : ($difference < -1 ? '少报销' : '一致');
|
||||
if ($result === '多报销') {
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
<div><span>任务空包费(元)</span><strong>{{ number_format($plantingSummary['task_empty_package_fee'] / 100, 2) }}</strong></div>
|
||||
<div class="is-key"><span>最终报销金额(元)</span><strong>{{ number_format($plantingSummary['reimbursement_amount'] / 100, 2) }}</strong></div>
|
||||
</div>
|
||||
<details class="pw-rules"><summary>核对口径</summary><p>仅核对已完成的种菜报销,同一工单取最新一版。订单号清理开头引号及空格后完整匹配;账单范围为工单付款月上月25日至今天,仅总账备注“订单收入”,按流水号去重后合计收入减支出。差异为任务付款金额减订单收入,超过±0.01元才判定多报销或少报销;平台补贴和优惠券不抵消多报销。无收入时结合平台状态和账单覆盖日期提示核实。顶部卡片与发起人汇总按日期和文本筛选统计全部结论。</p></details>
|
||||
<details class="pw-rules"><summary>核对口径</summary><p>仅核对已完成的种菜报销,同一工单取最新一版。订单号清理开头引号及空格后完整匹配;账单范围为工单付款月上月25日至今天,仅总账备注“订单收入”,按流水号去重后合计收入减支出。差异为最终报销金额减订单收入合计,超过±0.01元才判定多报销或少报销;平台补贴和优惠券不抵消多报销。无收入时结合平台状态和账单覆盖日期提示核实。顶部卡片与发起人汇总按日期和文本筛选统计全部结论。</p></details>
|
||||
<section class="pw-panel" aria-label="种菜报销明细">
|
||||
<div class="pw-table-scroll"><table><thead><tr>
|
||||
@foreach($columns as $key => $label)<th data-column-key="{{ $key }}">{{ $label }}</th>@endforeach
|
||||
|
||||
@ -4,6 +4,7 @@ namespace Tests\Feature\Business;
|
||||
|
||||
use App\Models\Auth\Permission;
|
||||
use Modules\EcommerceFinance\Repositories\PlantingReimbursementRepository;
|
||||
use Modules\EcommerceFinance\Repositories\PlantingReimbursementIncomeRepository;
|
||||
use Modules\EcommerceFinance\Services\PlantingLossCalculator as Calculator;
|
||||
use Modules\EcommerceFinance\View\PlantingLossPageData;
|
||||
use Modules\EcommerceFinance\View\PlantingReimbursementPageData;
|
||||
@ -167,4 +168,40 @@ class PlantingWorkOrderPagesTest extends FeatureTestCase
|
||||
// 导出失败时拒绝输出半份文件。
|
||||
$response->assertStatus(503);
|
||||
}
|
||||
|
||||
public function test_final_reimbursement_drives_income_summary_filters_and_export(): void
|
||||
{
|
||||
$rows = [];
|
||||
$bills = [];
|
||||
foreach (['30.00', '10.00', '17.50'] as $i => $amount) {
|
||||
$rows[] = $this->row(['completed_at' => '2026-11-12 10:00:00', 'paid_at' => '2026-11-10 10:00:00',
|
||||
'platform' => '淘宝天猫', 'online_order_no' => 'ORDER' . $i, 'work_order_no' => 'GD' . $i,
|
||||
'initiator' => '测试发起人', 'task_payment' => '100.00', 'reimbursement_amount' => $amount]);
|
||||
$bills[] = ['source' => 'taobao-alipay', 'record_code' => 'B' . $i, 'online_order_no' => 'ORDER' . $i,
|
||||
'occurred_at' => '2026-11-11 10:00:00', 'ledger_remark' => '订单收入', 'bill_item' => '订单收入',
|
||||
'income' => '17.50', 'expense' => '0.00'];
|
||||
}
|
||||
$this->mockData($rows);
|
||||
$billsRepository = \Mockery::mock(PlantingReimbursementIncomeRepository::class);
|
||||
$billsRepository->shouldReceive('status')->andReturn(['jd_through' => null, 'douyin_failed' => false]);
|
||||
$billsRepository->shouldReceive('records')->andReturnUsing(static function () use ($bills) { yield from $bills; });
|
||||
$this->app->instance(PlantingReimbursementIncomeCheck::class, new PlantingReimbursementIncomeCheck($billsRepository));
|
||||
|
||||
$query = ['month' => '2026-11', 'completed_from' => '2026-11-01', 'income_result' => '多报销'];
|
||||
$this->loginAs()->get($this->url('planting-reimbursements', $query))->assertOk()
|
||||
->assertSee('差异为最终报销金额减订单收入合计')
|
||||
->assertSee('GD0')->assertDontSee('GD1')->assertDontSee('GD2')
|
||||
->assertViewHas('content', static fn (array $content): bool => $content['plantingIncomeSummary']['多报销'] === ['count' => 1, 'difference' => 1250]
|
||||
&& $content['plantingIncomeSummary']['少报销'] === ['count' => 1, 'difference' => -750]
|
||||
&& $content['plantingIncomeSummary']['一致']['count'] === 1
|
||||
&& $content['plantingIncomeInitiators']['测试发起人'] === ['count' => 1, 'difference' => 1250]);
|
||||
|
||||
$response = $this->loginAs()->get(route('business.planting-data.planting-reimbursements.export', ['company_id' => $this->company->id] + $query + [
|
||||
'columns' => 'work_order_no,task_payment,reimbursement_amount,income_total,income_difference,income_result',
|
||||
]));
|
||||
$response->assertOk();
|
||||
$this->assertStringContainsString('GD0,100.00,30.00,17.50,12.50,多报销', $response->streamedContent());
|
||||
$this->assertStringNotContainsString('GD1', $response->streamedContent());
|
||||
$this->assertStringNotContainsString('GD2', $response->streamedContent());
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ class PlantingReimbursementIncomeCheckTest extends TestCase
|
||||
private function row(array $patch = []): array
|
||||
{
|
||||
return array_replace(['platform' => '头条放心购', 'shop_name' => '抖音-测试', 'online_order_no' => " ' 1234567890123456789",
|
||||
'paid_at' => '2026-11-12 12:00:00', 'task_payment' => '668.00', 'platform_order_status' => 'TRADE_FINISHED'], $patch);
|
||||
'paid_at' => '2026-11-12 12:00:00', 'task_payment' => '700.00', 'reimbursement_amount' => '668.00', 'platform_order_status' => 'TRADE_FINISHED'], $patch);
|
||||
}
|
||||
|
||||
private function check(array $rows, array $records, ?array $expectedOrders = null): array
|
||||
@ -56,7 +56,7 @@ class PlantingReimbursementIncomeCheckTest extends TestCase
|
||||
{
|
||||
$rows = $bills = [];
|
||||
foreach (['100.01', '99.99', '100.02', '99.98', '0.00', '-2.00'] as $i => $payment) {
|
||||
$rows[] = $this->row(['online_order_no' => (string) $i, 'task_payment' => $payment]);
|
||||
$rows[] = $this->row(['online_order_no' => (string) $i, 'reimbursement_amount' => $payment]);
|
||||
$bills[] = $this->bill(['record_code' => (string) $i, 'online_order_no' => (string) $i, 'income' => $i < 4 ? '100.00' : '0.00', 'expense' => $i === 5 ? '2.00' : '0.00']);
|
||||
}
|
||||
$result = $this->check($rows, $bills);
|
||||
@ -87,4 +87,21 @@ class PlantingReimbursementIncomeCheckTest extends TestCase
|
||||
$this->assertSame(1, $result[1]['income_count']);
|
||||
$this->assertSame('2025-12-25', Check::billFrom($this->row(['paid_at' => '2026-01-15'])));
|
||||
}
|
||||
|
||||
public function test_final_reimbursement_amount_is_required_without_falling_back_to_task_payment(): void
|
||||
{
|
||||
$rows = [
|
||||
$this->row(['reimbursement_amount' => null]),
|
||||
$this->row(['reimbursement_amount' => '']),
|
||||
$this->row(['reimbursement_amount' => '无']),
|
||||
$this->row(['task_payment' => null, 'reimbursement_amount' => '628.00']),
|
||||
];
|
||||
$result = $this->check($rows, [$this->bill()]);
|
||||
$this->assertSame(['需核实', '需核实', '需核实', '一致'], array_column($result, 'income_result'));
|
||||
foreach (array_slice($result, 0, 3) as $row) {
|
||||
$this->assertNull($row['income_difference']);
|
||||
$this->assertStringContainsString('最终报销金额缺失', $row['income_note']);
|
||||
}
|
||||
$this->assertSame('0.00', $result[3]['income_difference']);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user