Commit e746cc29 authored by rico.liu's avatar rico.liu

update func repeat ques

parent 40da77f4
...@@ -78,6 +78,7 @@ def get_point_category_params_data(category): ...@@ -78,6 +78,7 @@ def get_point_category_params_data(category):
res = pd.DataFrame() res = pd.DataFrame()
id_list = [] id_list = []
spu_id_list = []
state_list = [] state_list = []
product_name_list = [] product_name_list = []
father_brand_list = [] father_brand_list = []
...@@ -114,6 +115,7 @@ def get_point_category_params_data(category): ...@@ -114,6 +115,7 @@ def get_point_category_params_data(category):
process_index+=1 process_index+=1
id_list.append(prodcut_id) id_list.append(prodcut_id)
spu_id_list.append(df_sku[df_sku['sku'] == prodcut_id]['spuid'].tolist()[0])
state_list.append(df_sku[df_sku['sku'] == prodcut_id]['state'].tolist()[0]) state_list.append(df_sku[df_sku['sku'] == prodcut_id]['state'].tolist()[0])
product_name_list.append(df_sku[df_sku['sku'] == prodcut_id]['skuname'].tolist()[0]) product_name_list.append(df_sku[df_sku['sku'] == prodcut_id]['skuname'].tolist()[0])
...@@ -134,6 +136,7 @@ def get_point_category_params_data(category): ...@@ -134,6 +136,7 @@ def get_point_category_params_data(category):
res['产品编码'] = id_list res['产品编码'] = id_list
res['SPUID'] = spu_id_list
res['产品状态'] = state_list res['产品状态'] = state_list
res['产品名称'] = product_name_list res['产品名称'] = product_name_list
res['产品父品牌'] = father_brand_list res['产品父品牌'] = father_brand_list
...@@ -159,7 +162,7 @@ def get_point_category_params_data(category): ...@@ -159,7 +162,7 @@ def get_point_category_params_data(category):
res.to_excel(writer,f"{category_sheet_name}参数数据") res.to_excel(writer,f"{category_sheet_name}参数数据")
cursor_zdindex.execute(f"select goods_id,goods_name,platform_id,goods_url,index_price_wave from zd_week_price where periods in (select top 1 max(periods) from zd_entry_goods_price) and sub_category_code = {category_code} ") cursor_zdindex.execute(f"select goods_id,goods_name,platform_id,goods_url,index_price_wave,final_price from zd_week_price where periods in (select top 1 max(periods) from zd_entry_goods_price) and sub_category_code = {category_code} ")
data = (cursor_zdindex.fetchall()) data = (cursor_zdindex.fetchall())
price_df = pd.DataFrame(data,columns=[tuple[0] for tuple in cursor_zdindex.description]) price_df = pd.DataFrame(data,columns=[tuple[0] for tuple in cursor_zdindex.description])
price_df.to_excel(writer,f"{category_sheet_name}价格链接数据") price_df.to_excel(writer,f"{category_sheet_name}价格链接数据")
...@@ -169,7 +172,7 @@ def get_point_category_params_data(category): ...@@ -169,7 +172,7 @@ def get_point_category_params_data(category):
conn_zi_new.close() conn_zi_new.close()
category_list = category_list = ['笔记本'] category_list = category_list = ['台式机']
for category in category_list: for category in category_list:
get_point_category_params_data(category) get_point_category_params_data(category)
\ No newline at end of file
...@@ -100,11 +100,16 @@ def upload_params_data(category,path,record_code_list): ...@@ -100,11 +100,16 @@ def upload_params_data(category,path,record_code_list):
db_params['subtitle'] = db_params['subtitle'].apply(lambda x: x.strip()) db_params['subtitle'] = db_params['subtitle'].apply(lambda x: x.strip())
subtitle_list = db_params['subtitle'].tolist() subtitle_list = db_params['subtitle'].tolist()
cursor_zdindex.execute(f"select top 1 max(periods) from zd_entry_goods_price")
periods = cursor_zdindex.fetchone()[0]
subtitle_id_dict = dict(zip(db_params['subtitle'].tolist(),db_params['subtitleid'].tolist())) subtitle_id_dict = dict(zip(db_params['subtitle'].tolist(),db_params['subtitleid'].tolist()))
subtitle_type_dict = dict(zip(db_params['subtitle'].tolist(),db_params['skuorspu'].tolist())) subtitle_type_dict = dict(zip(db_params['subtitle'].tolist(),db_params['skuorspu'].tolist()))
#
cursor_zi_new.execute(f"select id,sku,skuname,createddate from p_sku where state = 1 or state = 2 or state = 4")
sku_df = pd.DataFrame(cursor_zi_new.fetchall(), columns=[tuple[0] for tuple in cursor_zi_new.description])
#获取类别ID #获取类别ID
categoryid = db_params['categoryid'].tolist()[0] categoryid = db_params['categoryid'].tolist()[0]
...@@ -161,12 +166,15 @@ def upload_params_data(category,path,record_code_list): ...@@ -161,12 +166,15 @@ def upload_params_data(category,path,record_code_list):
cursor_zi_new.execute(f"select pid from p_brand where id = {brand_code}") cursor_zi_new.execute(f"select pid from p_brand where id = {brand_code}")
father_brand_code = cursor_zi_new.fetchone()[0] father_brand_code = cursor_zi_new.fetchone()[0]
cursor_zi_new.execute(f"select id,spuid from p_sku where sku = '{sku}'") #cursor_zi_new.execute(f"select id,spuid from p_sku where sku = '{sku}'")
try: searchsku_df = sku_df[sku_df['sku'] == sku][['id']]
skuid,spuid = cursor_zi_new.fetchone() if searchsku_df.empty:
except:
print(f"{sku}已不存在在产品库中") print(f"{sku}已不存在在产品库中")
continue continue
else:
skuid = searchsku_df['id'].values[0]
spuname = '' spuname = ''
skuname = '' skuname = ''
...@@ -376,26 +384,66 @@ def upload_params_data(category,path,record_code_list): ...@@ -376,26 +384,66 @@ def upload_params_data(category,path,record_code_list):
try: try:
cursor_zi_new.execute(f"update p_sku set skuname = '{skuname}' where sku = '{sku}'") cursor_zi_new.execute(f"update p_sku set skuname = '{skuname}' where sku = '{sku}'")
except: except:
cursor_zi_new.execute(f"select sku from p_sku where skuname = '{skuname}'")
correct_sku = cursor_zi_new.fetchone()[0]
skuname_double = skuname + f"(sku:{sku};重复sku:{correct_sku})"
cursor_zi_new.execute(f"update p_sku set skuname = '{skuname_double}',state = '6' where sku = '{sku}'")
#更新价格库数据
cursor_zdindex.execute(f"select top 1 max(periods) from zd_entry_goods_price")
periods = cursor_zdindex.fetchone()[0]
cursor_zdindex.execute(f"update zd_entry_goods_price set goods_id = '{correct_sku}' where periods = '{periods}' and goods_id = '{sku}'") #被修改的sku信息
cursor_zdindex.execute(f"update zd_electricity_price set goods_id = '{correct_sku}' where periods = '{periods}' and goods_id = '{sku}'") cursor_zi_new.execute(f"select createddate,state from p_sku where sku = '{sku}'")
cursor_zdindex.execute(f"update zd_purchase_price set goods_id = '{correct_sku}' where periods = '{periods}' and goods_id = '{sku}'") deal_sku_create_date,deal_state = tuple(cursor_zi_new.fetchone())
#重复的sku信息
cursor_zi_new.execute(f"select sku,createddate,state from p_sku where skuname = '{skuname}'")
repeat_sku,repeat_sku_create_date,repeat_state = tuple(cursor_zi_new.fetchone())
if deal_state == 6:
pass
elif deal_state == 2:#认新产品
if deal_sku_create_date >= repeat_sku_create_date:#处理产品建库更晚、更新
skuname_double = skuname + f"(sku:{repeat_sku};重复sku:{sku})"
cursor_zi_new.execute(f"update p_sku set skuname = '{skuname_double}',state = '6' where sku = '{repeat_sku}'")
cursor_zi_new.execute(f"update p_sku set skuname = '{skuname}' where sku = '{sku}'")
#更新价格库数据
cursor_zdindex.execute(f"update zd_entry_goods_price set goods_id = '{sku}' where periods = '{periods}' and goods_id = '{repeat_sku}'")
cursor_zdindex.execute(f"update zd_electricity_price set goods_id = '{sku}' where periods = '{periods}' and goods_id = '{repeat_sku}'")
cursor_zdindex.execute(f"update zd_purchase_price set goods_id = '{sku}' where periods = '{periods}' and goods_id = '{repeat_sku}'")
else:#处理产品建库更早、更老
skuname_double = skuname + f"(sku:{sku};重复sku:{repeat_sku})"
cursor_zi_new.execute(f"update p_sku set skuname = '{skuname_double}',state = '6' where sku = '{sku}'")
#更新价格库数据
cursor_zdindex.execute(f"update zd_entry_goods_price set goods_id = '{repeat_sku}' where periods = '{periods}' and goods_id = '{sku}'")
cursor_zdindex.execute(f"update zd_electricity_price set goods_id = '{repeat_sku}' where periods = '{periods}' and goods_id = '{sku}'")
cursor_zdindex.execute(f"update zd_purchase_price set goods_id = '{repeat_sku}' where periods = '{periods}' and goods_id = '{sku}'")
else:#deal_state == 1 or deal_state == 4 认老产品
if deal_sku_create_date >= repeat_sku_create_date:#处理产品建库更晚、更新
skuname_double = skuname + f"(sku:{sku};重复sku:{repeat_sku})"
cursor_zi_new.execute(f"update p_sku set skuname = '{skuname_double}',state = '6' where sku = '{sku}'")
#更新价格库数据
cursor_zdindex.execute(f"update zd_entry_goods_price set goods_id = '{repeat_sku}' where periods = '{periods}' and goods_id = '{sku}'")
cursor_zdindex.execute(f"update zd_electricity_price set goods_id = '{repeat_sku}' where periods = '{periods}' and goods_id = '{sku}'")
cursor_zdindex.execute(f"update zd_purchase_price set goods_id = '{repeat_sku}' where periods = '{periods}' and goods_id = '{sku}'")
else:#处理产品建库更早、更老
skuname_double = skuname + f"(sku:{repeat_sku};重复sku:{sku})"
cursor_zi_new.execute(f"update p_sku set skuname = '{skuname_double}',state = '6' where sku = '{repeat_sku}'")
cursor_zi_new.execute(f"update p_sku set skuname = '{skuname}' where sku = '{sku}'")
#更新价格库数据
cursor_zdindex.execute(f"update zd_entry_goods_price set goods_id = '{sku}' where periods = '{periods}' and goods_id = '{repeat_sku}'")
cursor_zdindex.execute(f"update zd_electricity_price set goods_id = '{sku}' where periods = '{periods}' and goods_id = '{repeat_sku}'")
cursor_zdindex.execute(f"update zd_purchase_price set goods_id = '{sku}' where periods = '{periods}' and goods_id = '{repeat_sku}'")
for subtitle in subtitle_list: for subtitle in subtitle_list:
value = str(row[subtitle]).strip() value = str(row[subtitle]).strip()
subtitleid = subtitle_id_dict[subtitle] subtitleid = subtitle_id_dict[subtitle]
...@@ -576,8 +624,8 @@ def check_configure_price(category,path,params_list): ...@@ -576,8 +624,8 @@ def check_configure_price(category,path,params_list):
category = '复印纸' category = '笔记本'
path = '/Users/rico/WorkSpace/1_Project/Company/中电中采/4_中电商品库功能类/更新库内参数并重新命名/复印纸参数确认(校验通过).xlsx' path = '/Users/rico/Downloads/历史数据笔记本参数确认(1)(校验通过).xlsx'
record_code_list = [] record_code_list = []
flag,return_record_code_list = upload_params_data(category,path,record_code_list) flag,return_record_code_list = upload_params_data(category,path,record_code_list)
......
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