diff --git a/modules/EcommerceFinance/Services/PinduoduoSettlementBillImporter.php b/modules/EcommerceFinance/Services/PinduoduoSettlementBillImporter.php index 0219e0f7..635f46f6 100644 --- a/modules/EcommerceFinance/Services/PinduoduoSettlementBillImporter.php +++ b/modules/EcommerceFinance/Services/PinduoduoSettlementBillImporter.php @@ -41,6 +41,8 @@ class PinduoduoSettlementBillImporter 'source_modified_by' => ['修改人'], ]; + private const OPTIONAL_HEADERS = ['signed_amount']; + private readonly ConnectionInterface $connection; public function __construct(DatabaseManager $databases) @@ -275,10 +277,13 @@ class PinduoduoSettlementBillImporter $income = $this->money($values['income_amount'], $rowNumber, '收入金额', false); $expense = $this->money($values['expense_amount'], $rowNumber, '支出金额', true); - $signed = $this->money($values['signed_amount'], $rowNumber, '金额', false, true); $calculated = bcsub($income, $expense, 2); - if (bccomp($calculated, $signed, 2) !== 0) { - throw new RuntimeException("第 {$rowNumber} 行收入、支出与金额不一致。"); + $signed = $calculated; + if (array_key_exists('signed_amount', $headerMap)) { + $signed = $this->money($values['signed_amount'], $rowNumber, '金额', false, true); + if (bccomp($calculated, $signed, 2) !== 0) { + throw new RuntimeException("第 {$rowNumber} 行收入、支出与金额不一致。"); + } } $batch[] = [ @@ -512,7 +517,8 @@ class PinduoduoSettlementBillImporter break; } } - if (! array_key_exists($field, $mapping)) { + if (! array_key_exists($field, $mapping) + && ! in_array($field, self::OPTIONAL_HEADERS, true)) { return null; } } diff --git a/resources/assets/js/components/business/AccountBills.vue b/resources/assets/js/components/business/AccountBills.vue index c3377271..b656287a 100644 --- a/resources/assets/js/components/business/AccountBills.vue +++ b/resources/assets/js/components/business/AccountBills.vue @@ -16,19 +16,19 @@ -
+
{{ ['jd-transactions','jd-wallet'].includes(billType) ? '费用结算时间' : '发生时间' }}
- + - - + + 至 - + - - + +
@@ -81,6 +81,7 @@ export default { data(){return{loading:false,loadError:false,sync:null,rows:[],sourceColumns:[],configuredColumns:[],columnsTitle:'',sourceGroups:[],summary:{income:0,expense:0,balance:0,count:0},total:0,currentPage:1,lastPage:1,perPage:20,filters:emptyFilters(this.billType),queryFilters:emptyFilters(this.billType),resultFilters:null,filterOptions:{shops:[],bill_items:[]},filterOptionsLoading:false,filterOptionsError:false,requestSerial:0,sort:{key:'occurred_at',dir:'desc'},exportMode:'filtered-visible'};}, computed:{ isDouyin(){return this.billType==='douyin';}, + isPinduoduo(){return this.billType==='pinduoduo';}, usesMirrorOptions(){return ['douyin','pinduoduo','dewu','jd-transactions','jd-wallet'].indexOf(this.billType)!==-1;}, invalidDateRange(){return Boolean(this.filters.start&&this.filters.end&&this.filters.start>this.filters.end);}, startDateConfig(){return {...dateConfig,maxDate:this.filters.end||null};}, @@ -129,6 +130,12 @@ export default { .tw-date-picker{flex:none} .tw-date-clear{display:flex;align-items:center;justify-content:center;width:1.5rem;flex:none;padding:0;border:1px solid #d8d2c7;border-left:0;border-right:0;background:#fff;color:#595959;cursor:pointer} .tw-date-clear .material-icons-outlined{font-size:1rem} +.tw-date.is-pinduoduo-date .tw-date-control{position:relative;overflow:hidden;height:2.125rem;border:1px solid #d8d2c7;border-radius:.5rem;background:#fff;cursor:pointer} +.tw-date.is-pinduoduo-date .tw-date-control:focus-within{border-color:#856632;box-shadow:0 0 0 3px rgba(133,102,50,.2)} +.tw-date.is-pinduoduo-date .tw-date-control.has-picker input{width:100%;height:100%;padding:0 4rem 0 .625rem;border:0;border-radius:0;background:transparent;box-shadow:none;cursor:pointer} +.tw-date.is-pinduoduo-date .tw-date-picker,.tw-date.is-pinduoduo-date .tw-date-clear{position:absolute;top:0;height:2rem;border-top:0;border-bottom:0} +.tw-date.is-pinduoduo-date .tw-date-picker{right:0;border-right:0;border-radius:0} +.tw-date.is-pinduoduo-date .tw-date-clear{right:2.125rem;border-left:0;z-index:1} @container(max-width:1200px){ .table-workspace .tw-filter{grid-template-columns:repeat(2,minmax(0,1fr))} .table-workspace .tw-date{grid-column:1/-1} diff --git a/tests/Feature/Console/PinduoduoSettlementBillImporterTest.php b/tests/Feature/Console/PinduoduoSettlementBillImporterTest.php index 87b614e1..5a7b9f35 100644 --- a/tests/Feature/Console/PinduoduoSettlementBillImporterTest.php +++ b/tests/Feature/Console/PinduoduoSettlementBillImporterTest.php @@ -51,7 +51,7 @@ class PinduoduoSettlementBillImporterTest extends TestCase $this->row('REC-EXPENSE', '2026-08-02 12:00:00', '0', '25.00', '-25.00', '拼多多货款账户', '退款'), $this->row('REC-ZERO', '2026-08-03 12:00:00', '0', '0', '0'), $this->row('REC-MARKETING', '2026-08-04 12:00:00', '0', '3.00', '-3.00', '拼多多营销账户'), - ]); + ], false); $importer = app(PinduoduoSettlementBillImporter::class); $result = $importer->import( @@ -81,6 +81,11 @@ class PinduoduoSettlementBillImporterTest extends TestCase $this->assertDatabaseHas('pdd_settlement_bill_rows', [ 'record_code' => 'REC-MARKETING', 'account_name' => '拼多多营销账户', + 'signed_amount' => -3, + ], 'business_mirror'); + $this->assertDatabaseHas('pdd_settlement_bill_rows', [ + 'record_code' => 'REC-INCOME', + 'signed_amount' => 100, ], 'business_mirror'); $repository = app(PinduoduoSettlementBillRepository::class); @@ -328,17 +333,26 @@ class PinduoduoSettlementBillImporterTest extends TestCase } /** @param list> $rows */ - private function xlsx(array $rows): string + private function xlsx(array $rows, bool $includeSignedAmount = true): string { $temporary = tempnam(sys_get_temp_dir(), 'pdd-authoritative-'); $path = $temporary . '.xlsx'; rename($temporary, $path); $spreadsheet = new Spreadsheet(); - $spreadsheet->getActiveSheet()->fromArray(array_merge([[ + $headers = [ '记录编码', '店铺', '自定义备注', '账单项目', '商户订单号', '线上单号', '财务类型', '业务描述', '类型', '发生时间', '收入金额', '支出金额', '金额', '备注', '修改时间', '修改人', - ]], $rows)); + ]; + if (! $includeSignedAmount) { + array_splice($headers, 12, 1); + $rows = array_map(static function (array $row): array { + array_splice($row, 12, 1); + + return $row; + }, $rows); + } + $spreadsheet->getActiveSheet()->fromArray(array_merge([$headers], $rows)); (new Xlsx($spreadsheet))->save($path); $spreadsheet->disconnectWorksheets(); $this->files[] = $path; diff --git a/tests/Unit/View/AccountBillsTableTest.php b/tests/Unit/View/AccountBillsTableTest.php index 9c0ac911..321f0af4 100644 --- a/tests/Unit/View/AccountBillsTableTest.php +++ b/tests/Unit/View/AccountBillsTableTest.php @@ -11,6 +11,9 @@ class AccountBillsTableTest extends TestCase $source = file_get_contents(__DIR__ . '/../../../resources/assets/js/components/business/AccountBills.vue'); $this->assertStringContainsString("isDouyin(){return this.billType==='douyin';}", $source); + $this->assertStringContainsString("isPinduoduo(){return this.billType==='pinduoduo';}", $source); + $this->assertStringContainsString("{ 'is-pinduoduo-date': isPinduoduo }", $source); + $this->assertStringContainsString('.tw-date.is-pinduoduo-date .tw-date-control', $source); $this->assertStringContainsString("['douyin','pinduoduo','dewu','jd-transactions','jd-wallet'].indexOf(this.billType)!==-1", $source); $this->assertStringContainsString('v-if="usesMirrorOptions && !filterOptionsError"', $source); $this->assertStringContainsString('page-key="store-receiving-bills"', $source); diff --git a/tests/scripts/account-bills-filter-export.test.cjs b/tests/scripts/account-bills-filter-export.test.cjs index 91717f85..d1eca47c 100644 --- a/tests/scripts/account-bills-filter-export.test.cjs +++ b/tests/scripts/account-bills-filter-export.test.cjs @@ -7,7 +7,7 @@ const compiler = require('vue-template-compiler'); const source = fs.readFileSync('resources/assets/js/components/business/AccountBills.vue', 'utf8'); const sfc = compiler.parseComponent(source); -function component(get) { +function component(get, billType = 'douyin') { const navigations = []; const context = { TableColumnSettings: {}, Select: { name: 'ElSelect' }, Option: { name: 'ElOption' }, flatPicker: {}, Mandarin: {}, @@ -15,7 +15,7 @@ function component(get) { }; vm.createContext(context); const definition = vm.runInContext(sfc.script.content.replace(/^import .*;$/gm, '').replace('export default', 'globalThis.definition =') + '\ndefinition;', context); - const instance = { ...definition.data.call({ billType: 'douyin' }), apiBase: '/bills/douyin', billType: 'douyin', $nextTick: () => {} }; + const instance = { ...definition.data.call({ billType }), apiBase: `/bills/${billType}`, billType, $nextTick: () => {} }; for (const [name, method] of Object.entries(definition.methods)) instance[name] = method.bind(instance); for (const [name, getter] of Object.entries(definition.computed)) Object.defineProperty(instance, name, { get: getter.bind(instance) }); instance.configuredColumns = [{ field: 'record_code', visible: true }]; @@ -121,3 +121,12 @@ test('calendar selection submits both bounds, resets pagination and preserves da instance.openDatePicker('startDate'); assert.equal(opened, true); }); + +test('pinduoduo alone enables the stable full-control date picker treatment', () => { + const { instance: pinduoduo } = component(async () => response(), 'pinduoduo'); + const { instance: douyin } = component(async () => response(), 'douyin'); + assert.equal(pinduoduo.isPinduoduo, true); + assert.equal(douyin.isPinduoduo, false); + assert.match(sfc.template.content, /is-pinduoduo-date/); + assert.match(source, /\.tw-date\.is-pinduoduo-date \.tw-date-control/); +});