---以下语句是修复导入商品或门店数据的功能，如果导入作业勾选了不修复。请认真分析执行或者全部执行如下语句（注意机构价格表需要手动添入机构编码）

--1、商品档案进货规格、配送规格以及包装率
UPDATE t_bd_item_info SET purchase_spec = 1 WHERE purchase_spec <= 0 OR purchase_spec is NULL
UPDATE t_bd_item_info SET shipment_spec = 1 WHERE shipment_spec <= 0 OR shipment_spec is NULL
UPDATE t_bd_item_info SET package_ratio = 1 WHERE package_ratio <=0 OR package_ratio IS NULL

--2、商品档案按比率提成时不允许超过1
UPDATE t_bd_item_info SET return_rate = 0 WHERE return_rate is NULL OR return_rate < 0
UPDATE t_bd_item_info SET return_rate = 0 WHERE return_rate >= 1 AND dpfm_type = 0
--3、更新商品档案税率(进项税和销项税)
UPDATE t_bd_item_info SET purchase_tax = 0.13 WHERE purchase_tax IS NULL OR purchase_tax < 0
UPDATE t_bd_item_info SET sale_tax = 0.13 WHERE sale_tax IS NULL OR sale_tax < 0

--4、修复商品的附加属性
UPDATE dbo.t_bd_item_info 
SET pro_code1 = ISNULL(pro_code1, ''), pro_code2 = ISNULL(pro_code2, '')
, pro_code3 = ISNULL(pro_code3, ''), pro_code4 = ISNULL(pro_code4, ''), pro_code5 = ISNULL(pro_code5, '')
, pro_code6 = ISNULL(pro_code6, ''), pro_code7 = ISNULL(pro_code7, ''), pro_code8 = ISNULL(pro_code8, '')
, pro_code9 = ISNULL(pro_code9, '') 
where ( ( pro_code1 is null ) or ( pro_code2 is null ) or ( pro_code3 is null ) or ( pro_code4 is null ) or ( pro_code5 is null ) or ( pro_code6 is null ) or ( pro_code7 is null ) or ( pro_code8 is null ) or ( pro_code9 is null ) ) 

--5、更新是否管理库存(捆绑商品、联营商品不需要管理库存)
UPDATE t_bd_item_info SET item_stock = '0' WHERE (item_sup_flag = 'C' OR combine_sta = '1') and (item_stock is null or item_stock != '0') 

--6、小象称重5才执行   混售商品不管理库存且库存方式为标准
if exists(select 1 from t_sys_system where sys_var_id like '%TradeVersions%' and sys_var_value = 'A')
	UPDATE t_bd_item_info SET item_stock = '0',stock_type='B' WHERE  combine_sta = 'A'

--7、销售方式
UPDATE t_bd_item_info SET item_sup_flag  = sup.sale_way 
FROM t_bd_supcust_info sup 
WHERE main_supcust = sup.supcust_no AND sup.supcust_flag = 'S' AND ( item_sup_flag IS NULL OR item_sup_flag <> sup.sale_way )




--8、处理机构价格修复问题
--补全机构价格表信息(区分是否为加盟店)
/*
INSERT INTO t_pc_branch_price (branch_no,item_no,price, base_price,sale_price,vip_price,scheme_price,vip_price2,vip_price3,
vip_price4,vip_price5,price_list,sale_flag,base_price1, base_price2, base_price3, base_price4, base_price5, base_price6, base_price7, base_price8)
SELECT b.branch_no ,a.item_no, price = (CASE b.trade_type WHEN '8' THEN a.scheme_price ELSE a.price END),
a.base_price,a.sale_price,a.vip_price,a.scheme_price,a.vip_price2,a.vip_price3,
a.vip_price4,a.vip_price5,'111111111',a.sale_flag,base_price1, base_price2, base_price3, base_price4, base_price5, base_price6, base_price7, base_price8
FROM t_bd_item_info a, t_bd_branch_info b 
WHERE b.trade_type in ('0','1', '2', '3', '8') 
and b.branch_no='门店编码（' and not exists (select 1 from t_pc_branch_price c where c.branch_no = b.branch_no and c.item_no = a.item_no)
 */