166 lines
7.4 KiB
PHP
166 lines
7.4 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature\Business;
|
||
|
||
use App\Models\Auth\Permission;
|
||
use Modules\EcommerceFinance\Models\AccountBill;
|
||
use Tests\Feature\FeatureTestCase;
|
||
|
||
/**
|
||
* 店铺收款账户账单 › 小红书账户(bill_type = xiaohongshu,读取 ec_account_bills)。
|
||
*/
|
||
class XiaohongshuReceivingBillsTest extends FeatureTestCase
|
||
{
|
||
public function test_xiaohongshu_tab_uses_jushuitan_headers_and_net_summary(): void
|
||
{
|
||
$this->allowPage();
|
||
$tabs = collect(config('business_navigation'))
|
||
->firstWhere('slug', 'billing-transactions')['pages'];
|
||
$receivingTabs = collect($tabs)->firstWhere('slug', 'store-receiving-bills')['tabs'];
|
||
$slugs = array_column($receivingTabs, 'slug');
|
||
$this->assertSame('vipshop-jx', $slugs[array_search('xiaohongshu', $slugs, true) - 1]);
|
||
|
||
$this->bill('2000000001351148890', '佣金', '结算入账', '2026-10-29 07:55:02', 0, 33.15);
|
||
$this->bill('2000000001351148888', '商品实付', '结算入账', '2026-10-29 07:55:02', 642.92, 0);
|
||
$this->bill('vipshop-jx', '销售', '结算入账', '2026-10-29 07:55:02', 999, 0);
|
||
|
||
$response = $this->loginAs()
|
||
->getJson(route('ecommerce-finance.account-bills.index', [
|
||
'bill_type' => 'xiaohongshu',
|
||
'start' => '2026-10-01',
|
||
'end' => '2026-10-31',
|
||
'limit' => 20,
|
||
]))
|
||
->assertOk()
|
||
->assertJsonPath('columns.title', '小红书账户')
|
||
->assertJsonPath('total', 2)
|
||
->assertJsonPath('summary.count', 2)
|
||
->assertJsonPath('summary.income', 642.92)
|
||
->assertJsonPath('summary.expense', 33.15)
|
||
->assertJsonPath('summary.opening_balance', 0)
|
||
->assertJsonPath('summary.opening_balance_date', null)
|
||
->assertJsonPath('summary.opening_balance_source', 'initial_zero')
|
||
->assertJsonPath('summary.balance', 609.77)
|
||
->assertJsonPath('data.0.occurred_at', '2026-10-29 07:55:02');
|
||
|
||
$this->assertSame(
|
||
[
|
||
'记录编码', '店铺', '账单项目', '线上单号', '交易类型', '订单号', '售后单号',
|
||
'下单时间', '结算时间', '收入金额', '支出金额', '账单备注', '创建时间', '修改时间', '修改人',
|
||
],
|
||
array_column($response->json('columns.columns'), 'label'),
|
||
);
|
||
}
|
||
|
||
public function test_xiaohongshu_filter_options_and_export_stay_inside_the_account(): void
|
||
{
|
||
$this->allowPage();
|
||
$this->bill('2000000001351148890', '佣金', '结算入账', '2026-10-29 07:55:02', 0, 33.15);
|
||
$this->bill('2000000001351148888', '商品实付', '退款', '2026-10-29 07:55:02', 642.92, 0);
|
||
$this->bill('vipshop-jx', '销售', '结算入账', '2026-10-29 07:55:02', 999, 0);
|
||
|
||
$options = $this->loginAs()
|
||
->getJson(route('ecommerce-finance.account-bills.filter-options', ['bill_type' => 'xiaohongshu']))
|
||
->assertOk()
|
||
->json();
|
||
$this->assertSame(['小红书-索菲亚生活家具'], $options['shops']);
|
||
$this->assertSame(['佣金', '商品实付'], $options['bill_items']);
|
||
$this->assertSame([], $options['ledger_remarks']);
|
||
|
||
$export = $this->loginAs()->get(route('ecommerce-finance.account-bills.export', [
|
||
'bill_type' => 'xiaohongshu',
|
||
'bill_item' => '佣金',
|
||
'start' => '2026-10-01',
|
||
'end' => '2026-10-31',
|
||
]));
|
||
|
||
$export->assertOk()->assertDownload('xiaohongshu_account_bills.csv');
|
||
|
||
$filtered = $this->loginAs()
|
||
->getJson(route('ecommerce-finance.account-bills.index', [
|
||
'bill_type' => 'xiaohongshu',
|
||
'bill_item' => '佣金',
|
||
'start' => '2026-10-01',
|
||
'end' => '2026-10-31',
|
||
]))
|
||
->assertOk();
|
||
$this->assertSame(1, $filtered->json('total'));
|
||
$this->assertSame('2000000001351148890', $filtered->json('data.0.record_code'));
|
||
}
|
||
|
||
public function test_xiaohongshu_opening_balance_rolls_from_previous_month(): void
|
||
{
|
||
$this->allowPage();
|
||
$this->bill('XS-OCT-INCOME', '商品实付', '结算入账', '2026-10-20 12:00:00', 100, 0);
|
||
$this->bill('XS-OCT-EXPENSE', '佣金', '结算入账', '2026-10-21 12:00:00', 0, 20);
|
||
$this->bill('XS-NOV-INCOME', '商品实付', '结算入账', '2026-11-05 12:00:00', 50, 0);
|
||
$this->bill('XS-NOV-EXPENSE', '佣金', '结算入账', '2026-11-06 12:00:00', 0, 10);
|
||
|
||
$october = $this->loginAs()
|
||
->getJson(route('ecommerce-finance.account-bills.index', [
|
||
'bill_type' => 'xiaohongshu',
|
||
'start' => '2026-10-01',
|
||
'end' => '2026-10-31',
|
||
]))
|
||
->assertOk();
|
||
$this->assertSame(0.0, (float) $october->json('summary.opening_balance'));
|
||
$this->assertSame(80.0, (float) $october->json('summary.balance'));
|
||
$this->assertSame('initial_zero', $october->json('summary.opening_balance_source'));
|
||
|
||
$november = $this->loginAs()
|
||
->getJson(route('ecommerce-finance.account-bills.index', [
|
||
'bill_type' => 'xiaohongshu',
|
||
'start' => '2026-11-01',
|
||
'end' => '2026-11-30',
|
||
]))
|
||
->assertOk();
|
||
$this->assertSame(80.0, (float) $november->json('summary.opening_balance'));
|
||
$this->assertSame('2026-10-31', $november->json('summary.opening_balance_date'));
|
||
$this->assertSame('previous_period', $november->json('summary.opening_balance_source'));
|
||
$this->assertSame(50.0, (float) $november->json('summary.income'));
|
||
$this->assertSame(10.0, (float) $november->json('summary.expense'));
|
||
$this->assertSame(120.0, (float) $november->json('summary.balance'));
|
||
}
|
||
|
||
private function bill(
|
||
string $recordCode,
|
||
string $billItem,
|
||
string $transactionType,
|
||
string $occurredAt,
|
||
float $income,
|
||
float $expense,
|
||
): void {
|
||
AccountBill::create([
|
||
'company_id' => $this->company->id,
|
||
'bill_type' => $recordCode === 'vipshop-jx' ? 'vipshop-jx' : 'xiaohongshu',
|
||
'record_code' => $recordCode,
|
||
'store_name' => $recordCode === 'vipshop-jx' ? '唯品会JITX_测试店' : '小红书-索菲亚生活家具',
|
||
'order_no' => $recordCode === 'vipshop-jx' ? 'SO-1' : 'P807944039495145531',
|
||
'amount' => $income - $expense,
|
||
'bill_item' => $billItem,
|
||
'occurred_at' => $occurredAt,
|
||
'income' => $income,
|
||
'expense' => $expense,
|
||
'payload' => $recordCode === 'vipshop-jx'
|
||
? ['second_remark' => '销售', 'settle_period' => '2026-10']
|
||
: [
|
||
'online_order_no' => 'P807944039495145531',
|
||
'transaction_type' => $transactionType,
|
||
'after_sale_no' => '-',
|
||
'ordered_at' => '2026-10-19 14:40:39',
|
||
'bill_remark' => $billItem,
|
||
'source_created_at' => '2026-10-31 06:00:44',
|
||
'source_updated_at' => '2026-11-05 14:39:13',
|
||
],
|
||
'modifier' => 'api',
|
||
]);
|
||
}
|
||
|
||
private function allowPage(): void
|
||
{
|
||
$this->user->attachPermission(
|
||
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
||
);
|
||
}
|
||
}
|