科目映射表:区分条件留空显示并导出为「-」,导入按不限处理

This commit is contained in:
yueyang 2026-09-29 17:40:36 +08:00
parent 9b05d99cd8
commit 9f73d1915c
4 changed files with 33 additions and 7 deletions

View File

@ -333,7 +333,12 @@ class AccountMappingActions extends Controller
foreach ($rules as $rule) {
$row = [];
foreach (array_keys(AccountMappingStore::LABELS) as $field) {
$row[] = $this->csvText($rule[$field] ?? '');
$value = (string) ($rule[$field] ?? '');
// 商品名称关键词留空时导出成「-」,与页面一致(导回来会按空处理)
if ($field === 'goods' && trim($value) === '') {
$value = '-';
}
$row[] = $this->csvText($value);
}
fputcsv($csv, $row);
}

View File

@ -300,6 +300,13 @@ class AccountMappingStore
$out['basis'] = self::CATEGORY_BASIS[$out['category']] ?? self::BASIS_OUT;
}
// 区分条件里的「-」「—」表示“不限”,按空处理:否则匹配时会拿它去找关键词,规则永远命中不了
foreach (['memo', 'goods'] as $field) {
if (in_array($out[$field], ['-', '—', '-'], true)) {
$out[$field] = '';
}
}
return $out;
}

View File

@ -541,8 +541,8 @@
+ '<td class="am-index">' + (index + 1) + '</td>'
+ '<td class="am-edit-cell"><input data-f="platform" value="' + esc(draft.platform) + '" list="amPlatformList"></td>'
+ '<td class="am-edit-cell"><input data-f="item" value="' + esc(draft.item) + '"></td>'
+ '<td class="am-edit-cell"><input data-f="memo" value="' + esc(draft.memo) + '" placeholder="业务备注关键词"></td>'
+ '<td class="am-edit-cell"><input data-f="goods" value="' + esc(draft.goods) + '" placeholder="商品名称关键词"></td>'
+ '<td class="am-edit-cell"><input data-f="memo" value="' + esc(draft.memo) + '" placeholder="不限就填 -"></td>'
+ '<td class="am-edit-cell"><input data-f="goods" value="' + esc(draft.goods) + '" placeholder="不限就填 -"></td>'
+ '<td class="am-edit-cell"><select data-f="invoice">' + optionsHtml(OPTIONS.invoices || [], draft.invoice) + '</select></td>'
+ '<td class="am-edit-cell"><select data-f="category">' + optionsHtml(OPTIONS.categories || [], draft.category) + '</select></td>'
+ '<td class="am-edit-cell">' + acctEditor('dAcct', 'dSub') + '</td>'
@ -558,8 +558,8 @@
+ '<td class="am-index">' + (index + 1) + '</td>'
+ '<td>' + esc(r.platform) + '</td>'
+ '<td><span class="am-caret">▶</span> <span title="' + esc(r.item) + '">' + esc(r.item) + '</span></td>'
+ '<td><span title="' + esc(r.memo) + '">' + esc(r.memo) + '</span></td>'
+ '<td><span title="' + esc(r.goods) + '">' + esc(r.goods) + '</span></td>'
+ '<td><span title="' + esc(r.memo) + '">' + esc(r.memo || '-') + '</span></td>'
+ '<td><span title="' + esc(r.goods) + '">' + esc(r.goods || '-') + '</span></td>'
+ '<td>' + esc(r.invoice || '—') + '</td>'
+ '<td>' + esc(r.category) + '</td>'
+ '<td>' + acct(r.dAcct, r.dSub) + '</td>'
@ -822,8 +822,8 @@
+ '<td>新</td>'
+ '<td class="am-edit-cell"><input data-f="platform" value="' + esc(draft.platform) + '" placeholder="平台"></td>'
+ '<td class="am-edit-cell"><input data-f="item" value="' + esc(draft.item) + '" placeholder="账单项目上的名称"></td>'
+ '<td class="am-edit-cell"><input data-f="memo" value="' + esc(draft.memo) + '" placeholder="业务备注关键词"></td>'
+ '<td class="am-edit-cell"><input data-f="goods" value="' + esc(draft.goods) + '" placeholder="商品名称关键词"></td>'
+ '<td class="am-edit-cell"><input data-f="memo" value="' + esc(draft.memo) + '" placeholder="不限就填 -"></td>'
+ '<td class="am-edit-cell"><input data-f="goods" value="' + esc(draft.goods) + '" placeholder="不限就填 -"></td>'
+ '<td class="am-edit-cell"><select data-f="invoice">' + optionsHtml(OPTIONS.invoices || [], draft.invoice) + '</select></td>'
+ '<td class="am-edit-cell"><select data-f="category">' + optionsHtml(OPTIONS.categories || [], draft.category) + '</select></td>'
+ '<td class="am-edit-cell">' + acctEditor('dAcct', 'dSub') + '</td>'

View File

@ -136,6 +136,20 @@ class AccountMappingMatcherTest extends FeatureTestCase
$this->assertContains('duplicate_pair', $this->issueCodes([$second['id'], $third['id']]), '条件相同的两条要报重复');
}
/** 「-」表示不限:存进去按空处理,匹配时不会拿它当关键词去找 */
public function test_dash_means_no_condition(): void
{
$rule = $this->rule(['item' => '在线支付', 'memo' => '-', 'goods' => '-']);
$this->assertSame('', $rule['memo']);
$this->assertSame('', $rule['goods']);
$hit = $this->matcher->match('测试平台', '在线支付', ['推广充值'], 'P4P充值包');
$this->assertNotNull($hit);
$this->assertFalse($hit['matched']);
$this->assertSame($rule['id'], $hit['rule']['id']);
}
/** 校验:同项目下有兜底规则时给出提示,提醒它只做兜底 */
public function test_validator_hints_fallback_rule(): void
{