\App\Console\CommandsRegionFillExtra

地区增强字段补全命令

职责:读 china_zipcode_adcode.json(省市区县 code→zipCode/pinyin),按 12 位 code 前 6 位匹配, 补 postal_code + 缺失的 pinyin(pinyin_prefix 同步首字母生成)。

┌────────────────── 分区导航(按此顺序阅读)──────────────────┐ 分区 1 · 命令签名与说明 $signature / $description 分区 2 · 执行入口 handle └────────────────────────────────────────────────────────────┘

Summary

Methods
Properties
Constants
handle()
No public properties found
REGION_TABLE
forgetRegionCaches()
syncRegionSequence()
batchInsert()
flushInsert()
nullableColumns()
$signature
$description
N/A
No private methods found
No private properties found
N/A

Constants

REGION_TABLE

REGION_TABLE = 'td_sys_region'

地区表名(裸表名,SQL 拼接处走 DbSchema::prefix)

Properties

$signature

$signature

命令签名:region:fill-extra,--json 指定邮编/拼音 JSON(必须)

$description

$description

命令说明

Methods

handle()

handle() : int

执行补全。

流程:① 校验 --json 文件存在且可解析 ② 逐条把 6 位 code 转 12 位(前 6 位 + 6 个 0)并按 code 定位行 ③ 缺才补 postal_code(仅纯 6 位数字)与 pinyin / pinyin_prefix

Returns

int —

forgetRegionCaches()

forgetRegionCaches() : void

手动失效地区缓存(DB 直插/直改不触发模型事件时的单源收口)。 sys:region:tree 含地区全字段,缺失失效会让旧值残留。

syncRegionSequence()

syncRegionSequence() : void

同步地区序列(仅 pgsql;表名走 DbSchema::prefix(),勿硬编码 schema)

batchInsert()

batchInsert(array  $rows, int  $count, int  $batchSize = 2000) : void

批量攒插:行攒满 $batchSize 即插入并清空(内存恒定,防单条长事务)

Parameters

array $rows
int $count
int $batchSize

flushInsert()

flushInsert(array  $rows, int  $count) : void

尾部 flush:不足一批的剩余行落库

Parameters

array $rows
int $count

nullableColumns()

nullableColumns() : array<string,bool>

当前库表列 → 是否可空(按定义顺序;Schema 抽象,PG/sqlite 通吃—— 此前 RegionDump 的 information_schema 版仅 PG 可用,统一为可移植实现)。

Returns

array

列名 → true=可空(空值语义由调用方按列决定)