来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
99 lines
3.7 KiB
PL/PgSQL
99 lines
3.7 KiB
PL/PgSQL
-- 拍照验收由分公司分类配置;历史分类默认保持“需要拍照”
|
|
|
|
ALTER TABLE product_catalog
|
|
ADD COLUMN IF NOT EXISTS requires_photo_inspection BOOLEAN NOT NULL DEFAULT true;
|
|
|
|
ALTER TABLE categories
|
|
ADD COLUMN IF NOT EXISTS requires_photo_inspection BOOLEAN NOT NULL DEFAULT true;
|
|
|
|
UPDATE product_catalog
|
|
SET requires_photo_inspection = true
|
|
WHERE item_type = 'category' AND requires_photo_inspection IS NULL;
|
|
|
|
UPDATE categories
|
|
SET requires_photo_inspection = true
|
|
WHERE requires_photo_inspection IS NULL;
|
|
|
|
COMMENT ON COLUMN product_catalog.requires_photo_inspection
|
|
IS '分类商品验收是否必须拍照;仅分类行使用';
|
|
COMMENT ON COLUMN categories.requires_photo_inspection
|
|
IS '该分类商品验收是否必须拍照';
|
|
|
|
CREATE OR REPLACE FUNCTION sync_product_catalog_to_legacy()
|
|
RETURNS TRIGGER AS $$
|
|
DECLARE
|
|
v_branch VARCHAR(50);
|
|
BEGIN
|
|
IF TG_OP = 'DELETE' THEN
|
|
v_branch := COALESCE(OLD.branch_code, (
|
|
SELECT branch_code FROM branches WHERE status = 1 ORDER BY branch_code LIMIT 1
|
|
));
|
|
IF OLD.item_type = 'category' THEN
|
|
DELETE FROM categories
|
|
WHERE category_code = OLD.code AND branch_code = v_branch;
|
|
ELSE
|
|
DELETE FROM skus WHERE sku_code = OLD.code;
|
|
END IF;
|
|
RETURN OLD;
|
|
END IF;
|
|
|
|
v_branch := COALESCE(NEW.branch_code, (
|
|
SELECT branch_code FROM branches WHERE status = 1 ORDER BY branch_code LIMIT 1
|
|
));
|
|
|
|
IF NEW.item_type = 'category' THEN
|
|
INSERT INTO categories (
|
|
branch_code, category_code, parent_code, category_name, level, sort_order,
|
|
loss_threshold, is_fresh, requires_photo_inspection, status, created_at
|
|
) VALUES (
|
|
v_branch,
|
|
NEW.code, NEW.parent_code, NEW.name, COALESCE(NEW.level, 1), COALESCE(NEW.sort_order, 0),
|
|
COALESCE(NEW.loss_threshold, 5.00), COALESCE(NEW.is_fresh, true),
|
|
COALESCE(NEW.requires_photo_inspection, true), COALESCE(NEW.status, 1),
|
|
COALESCE(NEW.created_at, NOW())
|
|
)
|
|
ON CONFLICT (branch_code, category_code) DO UPDATE SET
|
|
parent_code = EXCLUDED.parent_code,
|
|
category_name = EXCLUDED.category_name,
|
|
level = EXCLUDED.level,
|
|
sort_order = EXCLUDED.sort_order,
|
|
loss_threshold = EXCLUDED.loss_threshold,
|
|
is_fresh = EXCLUDED.is_fresh,
|
|
requires_photo_inspection = EXCLUDED.requires_photo_inspection,
|
|
status = EXCLUDED.status;
|
|
ELSE
|
|
INSERT INTO skus (
|
|
branch_code, sku_code, sku_name, category_code, unit, spec, barcode, image_url,
|
|
image_data, image_mime_type, is_prepackaged, brand, tax_code, tax_rate,
|
|
default_loss_threshold, sale_price, cost_price, status, created_at
|
|
) VALUES (
|
|
v_branch, NEW.code, NEW.name, NEW.parent_code, COALESCE(NEW.unit, '斤'), NEW.spec, NEW.barcode, NEW.image_url,
|
|
NEW.image_data, NEW.image_mime_type, COALESCE(NEW.is_prepackaged, false), NEW.brand,
|
|
NULLIF(TRIM(NEW.tax_code), ''), NEW.tax_rate,
|
|
NEW.default_loss_threshold, COALESCE(NEW.sale_price, 0), COALESCE(NEW.cost_price, 0),
|
|
COALESCE(NEW.status, 1), COALESCE(NEW.created_at, NOW())
|
|
)
|
|
ON CONFLICT (sku_code) DO UPDATE SET
|
|
branch_code = EXCLUDED.branch_code,
|
|
sku_name = EXCLUDED.sku_name,
|
|
category_code = EXCLUDED.category_code,
|
|
unit = EXCLUDED.unit,
|
|
spec = EXCLUDED.spec,
|
|
barcode = EXCLUDED.barcode,
|
|
image_url = EXCLUDED.image_url,
|
|
image_data = EXCLUDED.image_data,
|
|
image_mime_type = EXCLUDED.image_mime_type,
|
|
is_prepackaged = EXCLUDED.is_prepackaged,
|
|
brand = EXCLUDED.brand,
|
|
tax_code = EXCLUDED.tax_code,
|
|
tax_rate = EXCLUDED.tax_rate,
|
|
default_loss_threshold = EXCLUDED.default_loss_threshold,
|
|
sale_price = EXCLUDED.sale_price,
|
|
cost_price = EXCLUDED.cost_price,
|
|
status = EXCLUDED.status;
|
|
END IF;
|
|
|
|
RETURN NEW;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|