CaiWuXiTong/tests/Feature/Business/VipshopJxReceivingBillsTest.php
qiuxiang 7de1d30605 唯品会JX账户新增订单结算时间列
唯品会JX账户账单在销售订单号后新增「订单结算时间」,取账单结算期间(YYYY-MM,当前系统内全部为 2026-07);列定义在 AccountBillColumns,导出与页面同一份定义。现网 8518 行的 payload 已补 settle_period=2026-07(先备份原 payload,校验无冲突后按 JSON_SET 更新,金额与笔数不变)。
2026-09-29 09:18:21 +08:00

100 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Modules\EcommerceFinance\Models\AccountBill;
use Tests\Feature\FeatureTestCase;
/**
* 店铺收款账户账单 › 唯品会JX账户(bill_type = vipshop-jx,读取 ec_account_bills)。
*/
class VipshopJxReceivingBillsTest extends FeatureTestCase
{
public function test_vipshop_jx_tab_reads_only_its_own_bill_type(): void
{
$this->allowPage();
$this->bill('vipshop-jx', '26060921475309', '销售', '2026-06-09 00:00:00', 82.48, 0);
$this->bill('vipshop-jx', '26070393670736', '客退', '2026-07-03 00:00:00', 0, 68.60);
$this->bill('vipshop', '26060100000001', '订单退款', '2026-06-01 00:00:00', 0, 999.00);
$response = $this->loginAs()
->getJson(route('ecommerce-finance.account-bills.index', [
'bill_type' => 'vipshop-jx',
'limit' => 20,
]))
->assertOk()
->assertJsonPath('columns.title', '唯品会JX账户')
->assertJsonPath('total', 2)
->assertJsonPath('summary.count', 2)
->assertJsonPath('summary.income', 82.48)
->assertJsonPath('summary.expense', 68.60)
// 该页签没有账户余额列,汇总口径为收支净额。
->assertJsonPath('summary.balance', 13.88)
// 日期按 Y-m-d H:i:s 返回,前端直接展示,不再出现 ISO8601(UTC)。
->assertJsonPath('data.0.occurred_at', '2026-07-03 00:00:00')
->assertJsonPath('data.1.occurred_at', '2026-06-09 00:00:00')
// 订单结算时间来自账单结算期间(现系统内全部为 2026-07)
->assertJsonPath('data.0.payload.settle_period', '2026-07')
->assertJsonPath('data.1.payload.settle_period', '2026-07');
$this->assertSame(
['记录编码', '店铺', '类型', '二次备注', '销售订单号', '订单结算时间', '订单日期(按订单号)', '含税金额', '收入金额', '支出金额'],
array_column($response->json('columns.columns'), 'label'),
);
}
public function test_vipshop_jx_filter_options_and_export_stay_inside_the_tab(): void
{
$this->allowPage();
$this->bill('vipshop-jx', '26060921475309', '销售', '2026-06-09 00:00:00', 82.48, 0);
$this->bill('vipshop-jx', '26070393670736', '客退', '2026-07-03 00:00:00', 0, 68.60);
$this->bill('vipshop', '26060100000001', '订单退款', '2026-06-01 00:00:00', 0, 999.00);
$this->loginAs()
->getJson(route('ecommerce-finance.account-bills.filter-options', ['bill_type' => 'vipshop-jx']))
->assertOk()
->assertExactJson([
'shops' => ['唯品会JITX_测试店'],
'bill_items' => ['客退', '销售'],
]);
$export = $this->loginAs()->get(route('ecommerce-finance.account-bills.export', [
'bill_type' => 'vipshop-jx',
'bill_item' => '销售',
]));
$export->assertOk()->assertDownload('vipshop-jx_account_bills.csv');
$csv = $export->streamedContent();
$this->assertStringContainsString('26060921475309', $csv);
$this->assertStringContainsString('订单结算时间', $csv);
$this->assertStringContainsString('2026-07', $csv);
$this->assertStringNotContainsString('26070393670736', $csv);
$this->assertStringNotContainsString('999.00', $csv);
}
private function bill(string $billType, string $orderNo, string $item, string $occurredAt, float $income, float $expense): void
{
AccountBill::create([
'company_id' => $this->company->id,
'bill_type' => $billType,
'record_code' => $orderNo . '-' . $item,
'store_name' => $billType === 'vipshop-jx' ? '唯品会JITX_测试店' : '唯品会MP-测试店',
'order_no' => $orderNo,
'amount' => $income - $expense,
'bill_item' => $item,
'occurred_at' => $occurredAt,
'income' => $income,
'expense' => $expense,
'payload' => ['second_remark' => '订单', 'settle_period' => '2026-07'],
]);
}
private function allowPage(): void
{
$this->user->attachPermission(
Permission::where('name', 'read-admin-panel')->firstOrFail()
);
}
}