商品利润镜像:字段映射只保留原表实际存在的列 #448
@ -60,14 +60,20 @@ class GoodsProfitAfsRepository
|
||||
|
||||
$headers = (array) config('order_after_sales_cost.headers', []);
|
||||
$map = [];
|
||||
$existing = array_map(
|
||||
'strtolower',
|
||||
Schema::connection($this->connectionName())->getColumnListing(self::MAIN_TABLE),
|
||||
);
|
||||
|
||||
foreach ($this->connection()->table(self::SCHEMA_TABLE)->orderBy('id')->get(['column', 'name']) as $schema) {
|
||||
$label = self::normalizeLabel((string) $schema->name);
|
||||
$field = $headers[$label] ?? null;
|
||||
$column = (string) $schema->column;
|
||||
|
||||
// 同一科目出现多次(如 800105佣金 / 800105平台佣金)时保留第一次映射。
|
||||
if ($field !== null && ! isset($map[$field])) {
|
||||
$map[$field] = (string) $schema->column;
|
||||
// schemas 里有 170 条,但原表只有 160 列,提前过滤掉不存在的列。
|
||||
if ($field !== null && ! isset($map[$field]) && in_array(strtolower($column), $existing, true)) {
|
||||
$map[$field] = $column;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user