Commit 55942907 authored by Jialin's avatar Jialin

代码更新

parent 1241ae1d
...@@ -38,8 +38,8 @@ def duplicate_product_update(filepath,category,sheet_name=0): ...@@ -38,8 +38,8 @@ def duplicate_product_update(filepath,category,sheet_name=0):
# db_params['subtitle'] = db_params['subtitle'].apply(lambda x: x.strip()) # db_params['subtitle'] = db_params['subtitle'].apply(lambda x: x.strip())
# 找到正确的类别id # 找到正确的类别id
cursor_zi_test.execute(f"select id from p_category where name='{category}'") cursor_zi_new.execute(f"select id from p_category where name='{category}'")
category_id = cursor_zi_test.fetchall() category_id = cursor_zi_new.fetchall()
if len(category_id)>1: if len(category_id)>1:
print(f"品牌名:'{category}' 在p_category中不是唯一的,请检查",file=f) print(f"品牌名:'{category}' 在p_category中不是唯一的,请检查",file=f)
return return
...@@ -49,16 +49,16 @@ def duplicate_product_update(filepath,category,sheet_name=0): ...@@ -49,16 +49,16 @@ def duplicate_product_update(filepath,category,sheet_name=0):
category_id = category_id[0][0] category_id = category_id[0][0]
# 找到该类别下的品牌名,放入existed_brand_list # 找到该类别下的品牌名,放入existed_brand_list
cursor_zi_test.execute(f"select distinct brandid from p_spu where categoryid={category_id}") cursor_zi_new.execute(f"select distinct brandid from p_spu where categoryid={category_id}")
brand_id_fetch=cursor_zi_test.fetchall() brand_id_fetch=cursor_zi_new.fetchall()
brand_id_list=[] brand_id_list=[]
for brand_id_tuple in brand_id_fetch: for brand_id_tuple in brand_id_fetch:
brand_id_list.append(brand_id_tuple[0]) brand_id_list.append(brand_id_tuple[0])
existed_brand_list = [] existed_brand_list = []
for brand_id in brand_id_list: for brand_id in brand_id_list:
cursor_zi_test.execute(f"select name from p_brand where id={brand_id}") cursor_zi_new.execute(f"select name from p_brand where id={brand_id}")
existed_brand_name = cursor_zi_test.fetchone() existed_brand_name = cursor_zi_new.fetchone()
if existed_brand_name: if existed_brand_name:
existed_brand_list.append(existed_brand_name[0]) existed_brand_list.append(existed_brand_name[0])
...@@ -77,10 +77,10 @@ def duplicate_product_update(filepath,category,sheet_name=0): ...@@ -77,10 +77,10 @@ def duplicate_product_update(filepath,category,sheet_name=0):
# 找到正确的品牌id # 找到正确的品牌id
if correct_brand not in existed_brand_list: if correct_brand not in existed_brand_list:
cursor_zi_test.execute(f"insert into p_brand (name) values ('{correct_brand}')") # 除了名称,啥都没加 cursor_zi_new.execute(f"insert into p_brand (name) values ('{correct_brand}')") # 除了名称,啥都没加
print(f"'{correct_brand}' 被添加到了p_brand",file=f) print(f"'{correct_brand}' 被添加到了p_brand",file=f)
cursor_zi_test.execute(f"select id from p_brand where name='{correct_brand}'") #and id not in (select distinct pid from p_brand) cursor_zi_new.execute(f"select id from p_brand where name='{correct_brand}'") #and id not in (select distinct pid from p_brand)
correct_brand_id = cursor_zi_test.fetchall() correct_brand_id = cursor_zi_new.fetchall()
if len(correct_brand_id)>1: if len(correct_brand_id)>1:
print(f"品牌名:'{correct_brand}' 在p_brand中不唯一,请检查",file=f) print(f"品牌名:'{correct_brand}' 在p_brand中不唯一,请检查",file=f)
return return
...@@ -89,15 +89,15 @@ def duplicate_product_update(filepath,category,sheet_name=0): ...@@ -89,15 +89,15 @@ def duplicate_product_update(filepath,category,sheet_name=0):
# 一个品牌一个品牌地改 # 一个品牌一个品牌地改
for wrong_brand in brand_tobe_modified: for wrong_brand in brand_tobe_modified:
print(f"正在修改'{wrong_brand}':",file=f) print(f"正在修改'{wrong_brand}':",file=f)
cursor_zi_test.execute(f"select id from p_brand where name='{wrong_brand}'") cursor_zi_new.execute(f"select id from p_brand where name='{wrong_brand}'")
wrong_brand_id=cursor_zi_test.fetchone() wrong_brand_id=cursor_zi_new.fetchone()
if not wrong_brand_id: if not wrong_brand_id:
print(f"更改前的品牌:'{wrong_brand}' 不在p_brand中,请检查",file=f) print(f"更改前的品牌:'{wrong_brand}' 不在p_brand中,请检查",file=f)
return return
wrong_brand_id=wrong_brand_id[0] wrong_brand_id=wrong_brand_id[0]
cursor_zi_test.execute(f"select distinct spuname, id from p_spu where brandid={wrong_brand_id}")# 我们把所有类别的该品牌id的spuname都挑出来了,spuname一起改 cursor_zi_new.execute(f"select distinct spuname, id from p_spu where brandid={wrong_brand_id}")# 我们把所有类别的该品牌id的spuname都挑出来了,spuname一起改
wrong_list=cursor_zi_test.fetchall()#找出所有的错误品牌的spuname,挨个改 wrong_list=cursor_zi_new.fetchall()#找出所有的错误品牌的spuname,挨个改
if not wrong_list: if not wrong_list:
print(f"!!!!! 品牌id:'{wrong_brand_id}' 不在p_spu里,该品牌下spu或以被修改",file=f) print(f"!!!!! 品牌id:'{wrong_brand_id}' 不在p_spu里,该品牌下spu或以被修改",file=f)
continue continue
...@@ -108,8 +108,8 @@ def duplicate_product_update(filepath,category,sheet_name=0): ...@@ -108,8 +108,8 @@ def duplicate_product_update(filepath,category,sheet_name=0):
print(f" 正在更改的spuid:'{wrong_tuple[1]}'",file=f) print(f" 正在更改的spuid:'{wrong_tuple[1]}'",file=f)
wrong_spuname=wrong_tuple[0] wrong_spuname=wrong_tuple[0]
correct_spuname=wrong_spuname.replace(wrong_brand, correct_brand) # 生成新的spuname correct_spuname=wrong_spuname.replace(wrong_brand, correct_brand) # 生成新的spuname
cursor_zi_test.execute(f"select id from p_spu where spuname='{correct_spuname}'") cursor_zi_new.execute(f"select id from p_spu where spuname='{correct_spuname}'")
spu_id_tuple=cursor_zi_test.fetchall() spu_id_tuple=cursor_zi_new.fetchall()
if len(spu_id_tuple)>1: if len(spu_id_tuple)>1:
print(f"spuname:'{correct_spuname}'在p_spu表中不是唯一的,请检查",file=f) print(f"spuname:'{correct_spuname}'在p_spu表中不是唯一的,请检查",file=f)
return return
...@@ -125,8 +125,8 @@ def duplicate_product_update(filepath,category,sheet_name=0): ...@@ -125,8 +125,8 @@ def duplicate_product_update(filepath,category,sheet_name=0):
change_name=1 change_name=1
# 到这一步,我们已经取出了正确的spuid # 到这一步,我们已经取出了正确的spuid
wrong_spuid=wrong_tuple[1] wrong_spuid=wrong_tuple[1]
cursor_zi_test.execute(f"select skuname, sku from p_sku where spuid={wrong_spuid}") cursor_zi_new.execute(f"select skuname, sku from p_sku where spuid={wrong_spuid}")
wrong_sku_list=cursor_zi_test.fetchall() # 提取所有spuid是错误spuid的skuname, sku wrong_sku_list=cursor_zi_new.fetchall() # 提取所有spuid是错误spuid的skuname, sku
# 接下来就是sku的命名过程 # 接下来就是sku的命名过程
print(f" 接下来是skuname更改:",file=f) print(f" 接下来是skuname更改:",file=f)
...@@ -134,58 +134,58 @@ def duplicate_product_update(filepath,category,sheet_name=0): ...@@ -134,58 +134,58 @@ def duplicate_product_update(filepath,category,sheet_name=0):
wrong_skuname=wrong_sku_tuple[0] wrong_skuname=wrong_sku_tuple[0]
wrong_skucode=wrong_sku_tuple[1] wrong_skucode=wrong_sku_tuple[1]
correct_skuname=wrong_skuname.replace(wrong_brand, correct_brand) correct_skuname=wrong_skuname.replace(wrong_brand, correct_brand)
cursor_zi_test.execute(f"select skuname, sku from p_sku where skuname='{correct_skuname}'") cursor_zi_new.execute(f"select skuname, sku from p_sku where skuname='{correct_skuname}'")
skuname=cursor_zi_test.fetchone() #我们只取了一个,因为我们觉得一个skuname应该只存在一个 skuname=cursor_zi_new.fetchone() #我们只取了一个,因为我们觉得一个skuname应该只存在一个
if skuname: if skuname:
#如果有返回结果,就代表有重复的sku #如果有返回结果,就代表有重复的sku
sku_name=skuname[0] # 正确的产品名称 sku_name=skuname[0] # 正确的产品名称
sku_code=skuname[1] # 正确的产品编码 sku_code=skuname[1] # 正确的产品编码
sku_name_repeated= sku_name + f"(sku:{wrong_skucode};重复sku:{sku_code})" sku_name_repeated= sku_name + f"(sku:{wrong_skucode};重复sku:{sku_code})"
cursor_zi_test.execute( cursor_zi_new.execute(
f"update p_sku set state=6, skuname='{sku_name_repeated}' where sku='{wrong_skucode}'") f"update p_sku set state=6, skuname='{sku_name_repeated}' where sku='{wrong_skucode}'")
print(f" if successful:p_sku, '{wrong_skucode}'的 skuname updated to '{sku_name_repeated}', state updated to 6",file=f) print(f" if successful:p_sku, '{wrong_skucode}'的 skuname updated to '{sku_name_repeated}', state updated to 6",file=f)
cursor_zi_test.execute( cursor_zi_new.execute(
f"update Productcode_Sku set sku='{sku_code}' where sku='{wrong_skucode}' ") f"update Productcode_Sku set sku='{sku_code}' where sku='{wrong_skucode}' ")
print(f" if successful:Productcode_Sku, sku updated from '{wrong_skucode}' into '{sku_code}'",file=f) print(f" if successful:Productcode_Sku, sku updated from '{wrong_skucode}' into '{sku_code}'",file=f)
# cursor_zdindex.execute("select top 1 max(periods) from zd_electricity_price") cursor_zdindex.execute("select top 1 max(periods) from zd_electricity_price")
# zd_e_p = cursor_zdindex.fetchone()[0] zd_e_p = cursor_zdindex.fetchone()[0]
# cursor_zdindex.execute( cursor_zdindex.execute(
# f"update zd_electricity_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_e_p} ") f"update zd_electricity_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_e_p} ")
# print(f" zd_electricity_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f) print(f" if successful:zd_electricity_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f)
# cursor_zdindex.execute("select top 1 max(periods) from zd_purchase_price") cursor_zdindex.execute("select top 1 max(periods) from zd_purchase_price")
# zd_p_p = cursor_zdindex.fetchone()[0] zd_p_p = cursor_zdindex.fetchone()[0]
# cursor_zdindex.execute( cursor_zdindex.execute(
# f"update zd_purchase_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_p_p} ") f"update zd_purchase_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_p_p} ")
# print(f" zd_purchase_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f) print(f" if successful:zd_purchase_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f)
# cursor_zdindex.execute("select top 1 max(periods) from zd_entry_goods_price") cursor_zdindex.execute("select top 1 max(periods) from zd_entry_goods_price")
# zd_e_g_p = cursor_zdindex.fetchone()[0] zd_e_g_p = cursor_zdindex.fetchone()[0]
# cursor_zdindex.execute( cursor_zdindex.execute(
# f"update zd_entry_goods_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_e_g_p} ") f"update zd_entry_goods_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_e_g_p} ")
# print(f" zd_entry_goods_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f) print(f" if successful:zd_entry_goods_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f)
# cursor_zdindex.execute("select top 1 max(periods) from zd_week_price") cursor_zdindex.execute("select top 1 max(periods) from zd_week_price")
# zd_w_p = cursor_zdindex.fetchone()[0] zd_w_p = cursor_zdindex.fetchone()[0]
# cursor_zdindex.execute( cursor_zdindex.execute(
# f"update zd_week_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_w_p} ") f"update zd_week_price set goods_id='{sku_code}' where goods_id = '{wrong_skucode}' and periods = {zd_w_p} ")
# print(f" zd_week_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f) print(f" if successful:zd_week_price, goods_id updated from '{wrong_skucode}' into '{sku_code}'",file=f)
else: else:
#如果新的skuname没有重复,直接修改该sku的skuname(spuid已经被修改了) #如果新的skuname没有重复,直接修改该sku的skuname(spuid已经被修改了)
cursor_zi_test.execute(f"update p_sku set skuname='{correct_skuname}' where skuname='{wrong_skuname}' and spuid={wrong_spuid}") cursor_zi_new.execute(f"update p_sku set skuname='{correct_skuname}' where skuname='{wrong_skuname}' and spuid={wrong_spuid}")
print(f" p_sku, skuname updated from '{wrong_skuname}' into '{correct_skuname}' where spuid='{wrong_spuid}'",file=f) print(f" p_sku, skuname updated from '{wrong_skuname}' into '{correct_skuname}' where spuid='{wrong_spuid}'",file=f)
# 改完skuname后,更改spuid # 改完skuname后,更改spuid
cursor_zi_test.execute( cursor_zi_new.execute(
f"update p_sku set spuid={spu_id} where spuid={wrong_spuid}") # 我们只更改了p_sku表里的spuid,其他表有没有不知道 f"update p_sku set spuid={spu_id} where spuid={wrong_spuid}") # 我们只更改了p_sku表里的spuid,其他表有没有不知道
print(f" if successful:更改了p_sku中的spuid,从'{wrong_spuid}'改到了'{spu_id}'",file=f) print(f" if successful:更改了p_sku中的spuid,从'{wrong_spuid}'改到了'{spu_id}'",file=f)
if change_name==1: if change_name==1:
# 如果,需要改名字,我们把spu表的spuname改了 # 如果,需要改名字,我们把spu表的spuname改了
cursor_zi_test.execute( cursor_zi_new.execute(
f"update p_spu set spuname='{correct_spuname}' where spuname='{wrong_spuname}'") f"update p_spu set spuname='{correct_spuname}' where spuname='{wrong_spuname}'")
print( print(
f" if successful: 更改了 p_spu 中的 spuname to '{correct_spuname}' where spuname='{wrong_spuname}'",file=f) f" if successful: 更改了 p_spu 中的 spuname to '{correct_spuname}' where spuname='{wrong_spuname}'",file=f)
# 改完所有的spuid后我们改brandid # 改完所有的spuid后我们改brandid
cursor_zi_test.execute( cursor_zi_new.execute(
f"update p_spu set brandid={correct_brand_id} where brandid={wrong_brand_id}") # 我们把所有类别的该品牌id都改了 f"update p_spu set brandid={correct_brand_id} where brandid={wrong_brand_id}") # 我们把所有类别的该品牌id都改了
print(f"if successful:更改了p_spu中的brandid, 从'{wrong_brand_id}'改到了'{correct_brand_id}'",file=f) print(f"if successful:更改了p_spu中的brandid, 从'{wrong_brand_id}'改到了'{correct_brand_id}'",file=f)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment