店铺收款账户账单新增 vipshop-jx 页签:导航配置、列定义、控制器与前端路由;读取共享账单表 ec_account_bills 中的唯品会JX(JITX)原始账单(店铺/类型/二次备注/销售订单号/含税金额),按金额正负拆出收入与支出,订单日期由销售订单号前 6 位还原(原始账单无日期列)。DB 页签日期统一按 Y-m-d H:i:s 返回,JX 页签汇总口径为收支净额,并补齐单元与功能测试。
95 lines
3.9 KiB
PHP
95 lines
3.9 KiB
PHP
<?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');
|
||
|
||
$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->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' => '订单'],
|
||
]);
|
||
}
|
||
|
||
private function allowPage(): void
|
||
{
|
||
$this->user->attachPermission(
|
||
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
||
);
|
||
}
|
||
}
|