修复拼多多完整账单导入和日期筛选 #242
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,19 +16,19 @@
|
||||
</el-select>
|
||||
<input v-else v-model.trim="filters.bill_item" placeholder="账单项目" />
|
||||
</label>
|
||||
<div class="tw-filter-field tw-date">
|
||||
<div class="tw-filter-field tw-date" :class="{ 'is-pinduoduo-date': isPinduoduo }">
|
||||
<span class="tw-filter-label">{{ ['jd-transactions','jd-wallet'].includes(billType) ? '费用结算时间' : '发生时间' }}</span>
|
||||
<div class="tw-date-row">
|
||||
<span class="tw-date-control has-picker">
|
||||
<span class="tw-date-control has-picker" @click="isPinduoduo && openDatePicker('startDate')">
|
||||
<flat-picker ref="startDate" :value="filters.start" :config="startDateConfig" aria-label="开始日期" placeholder="开始日期" @on-change="(_, value) => changeDate('start', value)" />
|
||||
<button v-if="filters.start" type="button" class="tw-date-clear" title="清除开始日期" aria-label="清除开始日期" @click="changeDate('start', '')"><span class="material-icons-outlined" aria-hidden="true">close</span></button>
|
||||
<button type="button" class="tw-date-picker" title="选择开始日期" aria-label="选择开始日期" @click="openDatePicker('startDate')"><span class="material-icons-outlined" aria-hidden="true">calendar_today</span></button>
|
||||
<button v-if="filters.start" type="button" class="tw-date-clear" title="清除开始日期" aria-label="清除开始日期" @click.stop="changeDate('start', '')"><span class="material-icons-outlined" aria-hidden="true">close</span></button>
|
||||
<button type="button" class="tw-date-picker" title="选择开始日期" aria-label="选择开始日期" @click.stop="openDatePicker('startDate')"><span class="material-icons-outlined" aria-hidden="true">calendar_today</span></button>
|
||||
</span>
|
||||
<b>至</b>
|
||||
<span class="tw-date-control has-picker">
|
||||
<span class="tw-date-control has-picker" @click="isPinduoduo && openDatePicker('endDate')">
|
||||
<flat-picker ref="endDate" :value="filters.end" :config="endDateConfig" aria-label="结束日期" placeholder="结束日期" @on-change="(_, value) => changeDate('end', value)" />
|
||||
<button v-if="filters.end" type="button" class="tw-date-clear" title="清除结束日期" aria-label="清除结束日期" @click="changeDate('end', '')"><span class="material-icons-outlined" aria-hidden="true">close</span></button>
|
||||
<button type="button" class="tw-date-picker" title="选择结束日期" aria-label="选择结束日期" @click="openDatePicker('endDate')"><span class="material-icons-outlined" aria-hidden="true">calendar_today</span></button>
|
||||
<button v-if="filters.end" type="button" class="tw-date-clear" title="清除结束日期" aria-label="清除结束日期" @click.stop="changeDate('end', '')"><span class="material-icons-outlined" aria-hidden="true">close</span></button>
|
||||
<button type="button" class="tw-date-picker" title="选择结束日期" aria-label="选择结束日期" @click.stop="openDatePicker('endDate')"><span class="material-icons-outlined" aria-hidden="true">calendar_today</span></button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@ -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}
|
||||
|
||||
@ -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<list<string>> $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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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/);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user