feat(order): 订单新增 oaid_order_source_code 字段落库,取号链路 plattradeno 优先取该字段
This commit is contained in:
parent
b07d7bca33
commit
73d12cdf1a
@ -81,6 +81,11 @@ module.exports = app => {
|
||||
allowNull: true,
|
||||
comment: '来源平台名称',
|
||||
},
|
||||
oaid_order_source_code: {
|
||||
type: STRING(50),
|
||||
allowNull: true,
|
||||
comment: 'OAID订单来源编码',
|
||||
},
|
||||
create_channel: {
|
||||
type: STRING(20),
|
||||
allowNull: false,
|
||||
|
||||
@ -1306,6 +1306,7 @@ class DeliveryOrderService extends Service {
|
||||
orderFlag,
|
||||
sourcePlatformCode,
|
||||
sourcePlatformName,
|
||||
oaidOrderSourceCode,
|
||||
placeOrderTime,
|
||||
payTime,
|
||||
payNo,
|
||||
@ -1357,6 +1358,7 @@ class DeliveryOrderService extends Service {
|
||||
order_flag: orderFlag || '',
|
||||
source_platform_code: sourcePlatformCode || '',
|
||||
source_platform_name: sourcePlatformName || '',
|
||||
oaid_order_source_code: oaidOrderSourceCode || '',
|
||||
create_channel: String(createChannel || 'MANUAL').trim().toUpperCase() || 'MANUAL',
|
||||
sys_platform_code: platformSnapshot.sysPlatformCode,
|
||||
sys_platform_name: platformSnapshot.sysPlatformName,
|
||||
|
||||
@ -17,6 +17,7 @@ const WAYBILL_ORDER_DELIVERY_MIN_ATTRIBUTES = Object.freeze([
|
||||
'delivery_order_code',
|
||||
'source_platform_code',
|
||||
'source_platform_name',
|
||||
'oaid_order_source_code',
|
||||
'sys_platform_code',
|
||||
'sys_platform_name',
|
||||
'order_type',
|
||||
|
||||
@ -749,7 +749,7 @@ class ExpressPlatformService extends MainService {
|
||||
const order = order_tmp.order_delivery;
|
||||
console.log('order', order);
|
||||
const expressListItem = ExpressList.find(item => item.code === listByWarehousePlatformCode.sys_express_code) || {};
|
||||
let plattradeno = order.source_order_codes;
|
||||
let plattradeno = order.oaid_order_source_code || order.source_order_codes || '';
|
||||
if (listByWarehousePlatformCode.platform_code === 'DY' && order.from_key === 23060081 && !!order.pay_no && plattradeno.indexOf(',') > -1) {
|
||||
plattradeno = order.pay_no;
|
||||
}
|
||||
@ -2437,7 +2437,7 @@ class ExpressPlatformService extends MainService {
|
||||
object_id: `${order_tmp.order_delivery.warehouse_id}_${order_tmp.order_delivery.id}_${order_tmp.business_key}`,
|
||||
order_info: {
|
||||
order_channels_type: 'PDD',
|
||||
trade_order_list: [`${order_tmp.order_delivery.warehouse_id}_${order_tmp.order_delivery.id}_${order_tmp.business_key}`],
|
||||
trade_order_list: [ `${order_tmp.order_delivery.warehouse_id}_${order_tmp.order_delivery.id}_${order_tmp.business_key}` ],
|
||||
},
|
||||
package_info: {
|
||||
items: (order_tmp.order_delivery && order_tmp.order_delivery.orderItems || []).map(item => ({
|
||||
|
||||
73
script/fix-order-oaid-column.cjs
Normal file
73
script/fix-order-oaid-column.cjs
Normal file
@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 幂等补齐订单分表的 oaid_order_source_code 列。
|
||||
*
|
||||
* 背景:该列由订单模型(app/model/order_delivery.js)定义,分表工厂
|
||||
* (order_delivery_factory.js)在首次访问某张分表时自动同步;history /
|
||||
* outsourced 等长期不被访问的表可能滞后,可用本脚本提前补齐。
|
||||
*
|
||||
* 用法:
|
||||
* 开发:node script/fix-order-oaid-column.cjs
|
||||
* 生产:PowerShell 中 $env:NODE_ENV='production'; node script/fix-order-oaid-column.cjs
|
||||
*
|
||||
* 安全:只 ADD 缺失列(VARCHAR(50) NULL,与模型定义一致),不触碰 id /
|
||||
* AUTO_INCREMENT,不修改已有列,可重复执行。
|
||||
*/
|
||||
(async () => {
|
||||
try {
|
||||
const configs = require('../database/config.js');
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const cfg = configs[env];
|
||||
if (!cfg) {
|
||||
console.error('NO_CONFIG_FOR_ENV');
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const mysql = require('mysql2/promise');
|
||||
const conn = await mysql.createConnection({
|
||||
host: cfg.host,
|
||||
port: cfg.port || 3306,
|
||||
user: cfg.username,
|
||||
password: cfg.password,
|
||||
database: cfg.database,
|
||||
});
|
||||
|
||||
const [ tables ] = await conn.query(
|
||||
`SELECT TABLE_NAME FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = ? AND TABLE_NAME LIKE 'wms_order_delivery\\_%'
|
||||
ORDER BY TABLE_NAME`,
|
||||
[ cfg.database ]
|
||||
);
|
||||
|
||||
console.log(`环境: ${env}, 库: ${cfg.host}:${cfg.port}/${cfg.database}`);
|
||||
console.log(`订单分表数量: ${tables.length}\n`);
|
||||
|
||||
const columnSql = 'ADD COLUMN oaid_order_source_code VARCHAR(50) NULL COMMENT \'OAID订单来源编码\'';
|
||||
let added = 0;
|
||||
let ok = 0;
|
||||
|
||||
for (const row of tables) {
|
||||
const tableName = row.TABLE_NAME || row.table_name;
|
||||
const [ columns ] = await conn.query(
|
||||
`SELECT COLUMN_NAME FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = 'oaid_order_source_code'`,
|
||||
[ cfg.database, tableName ]
|
||||
);
|
||||
if (columns.length === 0) {
|
||||
await conn.query(`ALTER TABLE \`${tableName}\` ${columnSql}`);
|
||||
console.log(`[ADD] ${tableName} 已补齐列`);
|
||||
added += 1;
|
||||
} else {
|
||||
ok += 1;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\n完成: 已存在 ${ok} 张, 新增 ${added} 张`);
|
||||
await conn.end();
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('ERROR', err.message);
|
||||
process.exit(3);
|
||||
}
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user