125 lines
5.3 KiB
PHP
125 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Modules\EcommerceFinance\Repositories\PromotionExpenseMirrorRepository;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class PromotionExpensePageTest extends FeatureTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$schema = Schema::connection('business_mirror');
|
|
if (! $schema->hasTable(PromotionExpenseMirrorRepository::TABLE)) {
|
|
$schema->create(PromotionExpenseMirrorRepository::TABLE, function (Blueprint $table): void {
|
|
$table->bigIncrements('id');
|
|
$table->date('report_date');
|
|
$table->string('platform', 64);
|
|
$table->string('store_name', 255);
|
|
$table->unsignedBigInteger('source_rows')->default(0);
|
|
$table->decimal('push_fee', 20, 2)->default(0);
|
|
$table->decimal('shared_push_fee', 20, 2)->default(0);
|
|
$table->decimal('push_fee_total', 20, 2)->default(0);
|
|
$table->decimal('marketing_fee', 20, 2)->default(0);
|
|
$table->decimal('shared_marketing_fee', 20, 2)->default(0);
|
|
$table->decimal('marketing_fee_total', 20, 2)->default(0);
|
|
$table->decimal('total_fee', 20, 2)->default(0);
|
|
$table->timestamp('synced_at')->nullable();
|
|
});
|
|
}
|
|
if (! $schema->hasTable(PromotionExpenseMirrorRepository::STATE_TABLE)) {
|
|
$schema->create(PromotionExpenseMirrorRepository::STATE_TABLE, function (Blueprint $table): void {
|
|
$table->string('dataset_key', 191)->primary();
|
|
$table->string('source_key', 64);
|
|
$table->string('source_object', 191);
|
|
$table->string('target_table', 64);
|
|
$table->string('status', 24);
|
|
$table->dateTime('initial_completed_at')->nullable();
|
|
$table->dateTime('last_attempted_at')->nullable();
|
|
$table->dateTime('last_succeeded_at')->nullable();
|
|
$table->unsignedBigInteger('mirror_row_count')->default(0);
|
|
$table->string('last_error_code', 120)->nullable();
|
|
$table->timestamps();
|
|
});
|
|
}
|
|
}
|
|
|
|
public function test_page_and_export_use_the_automatic_promotion_expense_mirror(): void
|
|
{
|
|
Carbon::setTestNow(Carbon::parse('2026-11-27 10:00:00', 'Asia/Shanghai'));
|
|
DB::connection('business_mirror')->table(PromotionExpenseMirrorRepository::TABLE)->insert([
|
|
[
|
|
'report_date' => '2026-10-31',
|
|
'platform' => '淘系',
|
|
'store_name' => '天猫-甲店',
|
|
'source_rows' => 100,
|
|
'push_fee' => 1000,
|
|
'shared_push_fee' => 2000,
|
|
'push_fee_total' => 3000,
|
|
'marketing_fee' => 300,
|
|
'shared_marketing_fee' => 200,
|
|
'marketing_fee_total' => 500,
|
|
'total_fee' => 3500,
|
|
],
|
|
[
|
|
'report_date' => '2026-11-25',
|
|
'platform' => '抖音',
|
|
'store_name' => '抖音-乙店',
|
|
'source_rows' => 200,
|
|
'push_fee' => 4000,
|
|
'shared_push_fee' => 1000,
|
|
'push_fee_total' => 5000,
|
|
'marketing_fee' => 800,
|
|
'shared_marketing_fee' => 200,
|
|
'marketing_fee_total' => 1000,
|
|
'total_fee' => 6000,
|
|
],
|
|
]);
|
|
DB::connection('business_mirror')->table(PromotionExpenseMirrorRepository::STATE_TABLE)->insert([
|
|
'dataset_key' => PromotionExpenseMirrorRepository::DATASET_KEY,
|
|
'source_key' => 'operations_replica',
|
|
'source_object' => 'rpt.dws_sn_sales_full_info_di',
|
|
'target_table' => PromotionExpenseMirrorRepository::TABLE,
|
|
'status' => 'succeeded',
|
|
'initial_completed_at' => '2026-11-27 03:10:00',
|
|
'last_attempted_at' => '2026-11-27 03:10:00',
|
|
'last_succeeded_at' => '2026-11-27 03:10:00',
|
|
'mirror_row_count' => 2,
|
|
'created_at' => '2026-11-27 03:10:00',
|
|
'updated_at' => '2026-11-27 03:10:00',
|
|
]);
|
|
|
|
$this->loginAs()
|
|
->get(route('business.pages.show', [
|
|
'section' => 'financial-operations',
|
|
'page' => 'promotion-expenses',
|
|
'month' => '2026-11',
|
|
]))
|
|
->assertOk()
|
|
->assertSeeText('月度推广费用对比')
|
|
->assertSeeText('抖音-乙店')
|
|
->assertSeeText('¥5,000.00')
|
|
->assertSeeText('¥1,000.00')
|
|
->assertSeeText('¥6,000.00')
|
|
->assertSeeText('200 条')
|
|
->assertSeeText('2026-11-25');
|
|
|
|
$response = $this->get(route('business.financial-operations.promotion-expenses.export', [
|
|
'month' => '2026-11',
|
|
'platform' => '抖音',
|
|
]));
|
|
$response->assertOk();
|
|
$this->assertStringContainsString(
|
|
'聚水潭推广费用_2026-11.csv',
|
|
rawurldecode((string) $response->headers->get('content-disposition')),
|
|
);
|
|
$this->assertStringContainsString('抖音,抖音-乙店,200,4000.00', $response->streamedContent());
|
|
}
|
|
}
|