fix: 调整OA平台使用费科目分类 #829

Merged
yueyang merged 1 commits from fix/yueyang-oa-platform-usage-mapping into main 2026-11-02 17:48:24 +08:00
3 changed files with 80 additions and 3 deletions

View File

@ -0,0 +1,74 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
private function connection(): string
{
return (string) config('upstream_mirrors.connection', 'business_mirror');
}
public function up(): void
{
if (app()->environment('testing')
|| (string) config('system_database.mode', 'bootstrap') === 'bootstrap') {
return;
}
$schema = Schema::connection($this->connection());
if (! $schema->hasTable('oa_process_account_mapping')) {
return;
}
$mapping = json_decode(
(string) file_get_contents(base_path('resources/data/oa_process_account_mapping.json')),
true,
512,
JSON_THROW_ON_ERROR,
);
$codes = array_column($mapping, 'account_code');
if ($mapping === [] || count($codes) !== count(array_unique($codes))) {
throw new \RuntimeException('流程科目映射快照为空或科目编码重复。');
}
$database = $schema->getConnection();
$now = now();
foreach (array_chunk($mapping, 100) as $chunk) {
$database->table('oa_process_account_mapping')->upsert(
array_map(static fn (array $row): array => [
'account_code' => (string) $row['account_code'],
'account_name' => (string) $row['account_name'],
'expense_category' => (string) $row['expense_category'],
'second_level' => $row['second_level']
?? ((string) $row['expense_category'] . '(未细分)'),
'third_level' => $row['third_level'] ?? '未细分',
'in_fee_ratio' => (bool) $row['in_fee_ratio'],
'allocation' => $row['allocation'] ?? null,
'created_at' => $now,
'updated_at' => $now,
], $chunk),
['account_code'],
[
'account_name',
'expense_category',
'second_level',
'third_level',
'in_fee_ratio',
'allocation',
'updated_at',
],
);
}
$database->table('oa_process_account_mapping')
->whereNotIn('account_code', $codes)
->delete();
}
public function down(): void
{
// 已确认的业务映射在回滚时保留。
}
};

View File

@ -752,9 +752,9 @@
{
"account_code": "1123.11",
"account_name": "预付账款_平台使用费",
"expense_category": "往来",
"second_level": "往来",
"third_level": "充值",
"expense_category": "摊销",
"second_level": "摊销",
"third_level": "平台使用费",
"in_fee_ratio": false,
"allocation": "分摊",
"source_row": 77

View File

@ -251,6 +251,9 @@ class ManagementExpensesPageDataTest extends TestCase
$this->assertSame('摊销', $mappingByCode['1123.09.99']['expense_category']);
$this->assertSame('摊销', $mappingByCode['1123.09.99']['second_level']);
$this->assertSame('租赁', $mappingByCode['1123.09.99']['third_level']);
$this->assertSame('摊销', $mappingByCode['1123.11']['expense_category']);
$this->assertSame('摊销', $mappingByCode['1123.11']['second_level']);
$this->assertSame('平台使用费', $mappingByCode['1123.11']['third_level']);
$this->assertSame('空包费', $mappingByCode['1221.07']['third_level']);
$this->assertTrue($mappingByCode['1221.07']['in_fee_ratio']);
$this->assertSame('管理费用', $mappingByCode['5602.11.03.19']['expense_category']);