-- clear_shop.sql — 清空指定门店的所有业务数据
-- 用法（调用方负责传入 @shop_code 变量）:
--   SET @shop_code = 'S001'; SOURCE clear_shop.sql;
-- 或由脚本拼接:
--   echo "SET @shop_code='S001';" | cat - clear_shop.sql | mysql ...

SET @sid = (SELECT id FROM shops WHERE code = @shop_code LIMIT 1);

SET FOREIGN_KEY_CHECKS = 0;

DELETE FROM inventory_check_items WHERE shop_id = @sid;
DELETE FROM inventory_checks       WHERE shop_id = @sid;
DELETE FROM inventory_logs         WHERE shop_id = @sid;
DELETE FROM inventories            WHERE shop_id = @sid;
DELETE FROM stock_out_items        WHERE shop_id = @sid;
DELETE FROM stock_out_orders       WHERE shop_id = @sid;
DELETE FROM stock_in_items         WHERE shop_id = @sid;
DELETE FROM stock_in_orders        WHERE shop_id = @sid;
DELETE FROM finance_records        WHERE shop_id = @sid;
DELETE FROM number_rules           WHERE shop_id = @sid;
DELETE FROM product_images         WHERE shop_id = @sid;
DELETE FROM partners               WHERE shop_id = @sid;
DELETE FROM warehouses             WHERE shop_id = @sid;
DELETE FROM product_spec_options   WHERE shop_id = @sid;
DELETE FROM product_series_options WHERE shop_id = @sid;
DELETE FROM product_name_options   WHERE shop_id = @sid;
DELETE FROM products               WHERE shop_id = @sid;
DELETE FROM product_categories     WHERE shop_id = @sid;
DELETE FROM users                  WHERE shop_id = @sid;
DELETE FROM shops                  WHERE id      = @sid;

SET FOREIGN_KEY_CHECKS = 1;
