Commit b089b3f6 by 张富康

fix(sql): 修正库存类型插入逻辑

- 修改插入语句,新增对商品类型的判断条件
- 根据goods_type字段设置inventory_type,goods_type为10时为1,否则为2
- 添加关联dj_car_life_upgrade_goods和dj_car_life_goods_info表以获取goods_type
- 保持原有套餐编码和删除标记过滤条件不变
- 优化SQL格式,提高可读性
1 parent aef44931
...@@ -10,8 +10,7 @@ WHERE ...@@ -10,8 +10,7 @@ WHERE
AND r.event_type = 1; AND r.event_type = 1;
INSERT INTO dj_car_life_merchant_goods_inventory_type_ref INSERT INTO dj_car_life_merchant_goods_inventory_type_ref
( (merchant_goods_id,
merchant_goods_id,
package_code, package_code,
inventory_type, inventory_type,
merchant_id, merchant_id,
...@@ -19,22 +18,25 @@ INSERT INTO dj_car_life_merchant_goods_inventory_type_ref ...@@ -19,22 +18,25 @@ INSERT INTO dj_car_life_merchant_goods_inventory_type_ref
created_date, created_date,
updated_by, updated_by,
updated_date, updated_date,
deleted_flag deleted_flag)
) SELECT r.merchant_goods_id,
SELECT
r.merchant_goods_id,
NULL AS package_code, NULL AS package_code,
2 AS inventory_type, IF(gi.goods_type = 10, 1, 2) AS inventory_type,
r.merchant_id, r.merchant_id,
'system' AS created_by, 'system' AS created_by,
NOW() AS created_date, NOW() AS created_date,
'system' AS updated_by, 'system' AS updated_by,
NOW() AS updated_date, NOW() AS updated_date,
'N' AS deleted_flag 'N' AS deleted_flag
FROM dj_car_life_merchant_goods_ref r inner join dj_car_life_merchant_goods_info i on r.merchant_goods_id = i.id FROM dj_car_life_merchant_goods_ref r
WHERE INNER JOIN dj_car_life_merchant_goods_info i
(i.package_code IS NULL OR i.package_code = '') -- 套餐编码为空 ON r.merchant_goods_id = i.id
AND r.deleted_flag = 'N'; -- 源数据未删除 LEFT JOIN dj_car_life_upgrade_goods ug
ON ug.id = i.upgrade_goods_id
LEFT JOIN dj_car_life_goods_info gi
ON gi.goods_code = ug.goods_code
WHERE (i.package_code IS NULL OR i.package_code = '')
AND r.deleted_flag = 'N';
### 璐琦 -----------------start------------------- ### 璐琦 -----------------start-------------------
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!