1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080 |
- # -*- codeing = utf-8 -*-
- # @Time : 2022/10/26 12:26
- # @Author : Clown
- # @File : demo_20221026.py
- # @Software : PyCharm
- import re
- import pandas as pd
- import hashlib
- import requests
- import json
- import math
- from dateutil.parser import parse
- import time
- import random
- from datetime import datetime, timedelta
- # 登录
- def getToken():
- url = 'https://cloud.xc-fintech.com/api/v1/login'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'}
- json_params = {"employee_relation_id": "7008629262119084032"}
- resp = requests.post ( url, headers = headers, json = json_params ).json ()
- print ( json.dumps ( resp, ensure_ascii = False ) )
- return resp['app_id'], resp['token']
- # 下载或查询【订货商品】页面商品信息 mode:download下载 select查询
- # 信息包含【商品系统id,商品编码,商品名称,所属分类,是否有图,定价模式】
- def selectAllGoodsInfo(app_id, token, mode):
- # mode:download下载 select查询
- df_out = []
- url = 'https://cloud.xc-fintech.com/api/v1/good_centre/goods'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- page_size = 10
- total_count = 100
- current_page = 1
- while page_size * current_page - total_count < 0:
- # time.sleep(random.uniform(1,2))
- try:
- json_params = {"app_id": app_id,
- "sell_type": "2",
- "create_time_order": "desc",
- "current_page": current_page,
- "page_size": page_size}
- proxies = {'http': None, 'https': None}
- resp1 = requests.post ( url, headers = headers, json = json_params, proxies = proxies )
- resp = resp1.json ()
- current_page += 1
- for good_info in resp['detail']:
- good_info_dict = {}
- good_info_dict['商品系统id'] = good_info['goods_id']
- good_info_dict['商品编码'] = good_info['goods_no']
- good_info_dict['商品名称'] = good_info['goods_name']
- good_info_dict['所属分类'] = good_info['classify_name']
- good_info_dict['是否有图'] = f"有{len ( good_info['pic_show_url'] )}张图"
- if good_info['price_mode'] == 2:
- good_info_dict['定价模式'] = '分区定价'
- elif good_info['price_mode'] == 1:
- good_info_dict['定价模式'] = '统一定价'
- publish_state = {'1': '上架', '0': '下架'}
- good_info_dict['上下架状态'] = publish_state[str ( good_info['publish_state'] )]
- df_out.append ( good_info_dict )
- total_count = resp['total_count']
- if current_page % 5 == 0:
- time.sleep ( random.uniform ( 1, 4 ) )
- print ( f'\r当前已下载第{current_page}页', end = '' )
- except:
- resp1.close ()
- time.sleep ( 2 )
- if mode == 'download':
- excel_out = pd.DataFrame ( df_out )
- excel_out.to_excel ( 'selectAllGoodsInfo.xlsx', index = False )
- elif mode == 'select':
- return df_out
- # 下载【订货商品】【定价】页面售价,采购价,限购量信息
- def selectAllGoodsInfoInDetailPrice(app_id, token, downloadPath):
- df_in = selectAllGoodsInfo ( app_id, token, 'select' )
- time.sleep ( random.uniform ( 1, 3 ) )
- cnt_all = len ( df_in )
- print ( f'已完成df_in执行,共计商品{cnt_all}个' )
- df_out = []
- cnt = 1
- for goods_info in df_in:
- goods_id = goods_info['商品系统id']
- a = 0
- while a == 0:
- try:
- goods_units_info = selectGoodsInfoDetail ( app_id, token, 'select', '', '', goods_id )
- goods_info.update ( goods_units_info )
- # print('goods_info.update')
- # 获取商品区域售价
- url_goods_price = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/query'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token,
- 'Content-Type': 'application/json; charset=UTF-8'}
- json_goods_price = {"subscribe_type": "1",
- "goods_id": goods_id,
- "app_id": app_id}
- proxies = {'http': None, 'https': None}
- resp_goods_price_0 = requests.post ( url_goods_price, headers = headers, json = json_goods_price,
- proxies = proxies, timeout = 3 )
- resp_goods_price = resp_goods_price_0.json ()
- if goods_info['定价模式'] == '分区定价':
- for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
- dict_l1 = {}
- store_area_id = area_price_1['store_area_id']
- store_area_name = area_price_1['store_area_name']
- dict_l1['区域id'] = store_area_id
- dict_l1['区域名称(1级)'] = store_area_name
- try:
- # 供应商你信息
- dict_l1['供应商id'] = area_price_1['sup_id']
- dict_l1['供应商名称'] = area_price_1['sup_name']
- # 起订限订量
- dict_l1['起订量'] = area_price_1['spu_order_price']['buy_limit_min']
- try:
- dict_l1['限订量'] = area_price_1['spu_order_price']['buy_limit_max']
- except:
- dict_l1['限订量'] = ''
- # 单位对应采购价
- supply_price_list1 = area_price_1['supply_price_list']
- m = 1
- min_unit = ''
- for supply_price in supply_price_list1:
- if supply_price['is_min_unit']:
- dict_l1['最小单位采购价'] = int ( supply_price['supply_price_desc']['min'] ) / 100
- min_unit = supply_price['unit']
- else:
- dict_l1[f'副单位{m}采购价'] = int ( supply_price['supply_price_desc']['min'] ) / 100
- m += 1
- # 单位对应售价
- unit_price_list1 = area_price_1['spu_order_price']['unit_price_list']
- n = 1
- for unit_price in unit_price_list1:
- if unit_price['is_min_unit'] and unit_price['unit'] == min_unit:
- dict_l1['最小单位售价'] = int ( unit_price['actual_amount'] ) / 100
- else:
- dict_l1[f'副单位{n}售价'] = int ( unit_price['actual_amount'] ) / 100
- n += 1
- except:
- ...
- dict_l1.update ( goods_info )
- df_out.append ( dict_l1 )
- else:
- df_out.append ( goods_info )
- a = 1
- except:
- resp_goods_price_0.close ()
- a = 0
- time.sleep ( 2 )
- print ( 'mark' )
- print ( f'\r已完成{cnt}个产品下载,完成进度{int ( cnt / cnt_all * 100 )}%', end = '' )
- cnt += 1
- if cnt % 5 == 0:
- time.sleep ( random.uniform ( 0.5, 2.5 ) )
- if cnt % 100 == 0:
- time.sleep ( random.uniform ( 10, 15 ) )
- # columns = ['商品系统id','商品编码','商品名称','所属分类','是否有图','定价模式',]
- df_out = pd.DataFrame ( df_out )
- df_out.to_excel ( downloadPath, index = False )
- # 查询商品goods_no:为商品编码,返回上下架状态publish_state,及goods_id系统内商品id
- def selectGoodsInfoPubAndId(app_id, token, goods_no):
- # goods_no = "P9265021186"
- url = 'https://cloud.xc-fintech.com/api/v1/good_centre/goods'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_params = {"app_id": app_id,
- "sell_type": "2",
- "goods_no": goods_no,
- "create_time_order": "desc",
- "current_page": 1,
- "page_size": 10}
- resp = requests.post ( url, headers = headers, json = json_params ).json ()
- # print (json.dumps (resp, ensure_ascii=False))
- publish_state = resp['detail'][0]['publish_state']
- publish_state_dict = {'1': '上架', '0': '下架'}
- publish_state_info = publish_state_dict[str ( publish_state )]
- # print(publish_state_info)
- return publish_state, resp['detail'][0]['goods_id']
- # 【单品上下架】操作,【publish_state:0上架,1下架】
- def updatePublishState(app_id, token, publish_state, goods_id):
- on_off_dict = {'1': 'off_shelf',
- '0': 'on_shelf'}
- turn_on_off = on_off_dict[str ( publish_state )]
- url = f'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/{turn_on_off}'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_params = {"app_id": app_id,
- "goods_id": goods_id}
- resp = requests.post ( url, headers = headers, json = json_params ).json ()
- return_result = resp['goods_id'] = goods_id
- return return_result
- # 【批量上下架】操作,【publish_state:0上架,1下架】goods_id_list:是列表
- def updatePublishStateBatch(app_id, token, publish_state, goods_id_list):
- on_off_dict = {'1': 'batch_off_shelf',
- '0': 'batch_on_shelf'}
- turn_on_off = on_off_dict[str ( publish_state )]
- url = f'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/{turn_on_off}'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_params = {"app_id": app_id,
- "goods_id_list": goods_id_list}
- resp = requests.post ( url, headers = headers, json = json_params ).json ()
- print ( resp )
- return_result = resp['message'] = '操作成功'
- return return_result
- # 下载或查询供应商列表 mode:download下载 select查询 查询返回列表格式[{'供应商id':'xxxx', '供应商全名':'xxxxx', '简称':'xxxx'}]
- def selectSupplierlist(app_id, token, mode):
- url = 'https://cloud.xc-fintech.com/api/v1/supplier/query'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- page_size = 10
- total_count = 10
- current_page = 0
- df_out = []
- while page_size * current_page - total_count < 0:
- current_page += 1
- json_params = {"type": 1,
- "app_id": app_id,
- "current_page": current_page,
- "page_size": page_size}
- resp = requests.post ( url, headers = headers, json = json_params ).json ()
- total_count = resp['total_count']
- for sup_info in resp['detail']:
- sup_info_dict = {}
- sup_info_dict['供应商id'] = sup_info['supplier_id']
- sup_info_dict['供应商全名'] = sup_info['sup_name']
- sup_info_dict['供应商编号'] = sup_info['sup_no']
- try:
- sup_info_dict['简称'] = sup_info['remark']
- except:
- sup_info_dict['简称'] = ''
- df_out.append ( sup_info_dict )
- # print(json.dumps(resp,ensure_ascii=False))
- if mode == 'download':
- excel_out = pd.DataFrame ( df_out )
- excel_out.to_excel ( 'SupplierInfoList.xlsx', sheet_name = 'sheet1' )
- elif mode == 'select':
- return df_out
- # 获取【区域管理】层级树返回selectAreaTree1.xlsx文件
- def selectAreaTree(app_id, token):
- url = 'https://cloud.xc-fintech.com/split/store/area/tree'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_params = {"parent_id": "0",
- "app_id": app_id}
- resp = requests.post ( url, headers = headers, json = json_params ).json ()['tree'][0]
- df_out = []
- for children1 in resp['children']:
- # 省
- level1 = {}
- level1['父级id'] = children1['id']
- level1['父级名称'] = children1['name']
- # 市
- childrens2 = children1['children']
- level0 = {'子级id': children1['id'],
- '子级名称': children1['name'],
- '父级id2': children1['id']}
- level0.update ( level1 )
- df_out.append ( level0 )
- if len ( childrens2 ) > 0:
- for children2 in childrens2:
- level2 = {}
- level2['子级id'] = children2['id']
- level2['子级名称'] = children2['name']
- level2['父级id2'] = children2['parentId']
- parentId = children2['parentId']
- level2.update ( level1 )
- df_out.append ( level2 )
- childrens3 = children2['children']
- if len ( childrens3 ) > 0:
- for children3 in childrens3:
- level3 = {}
- level3['子级id'] = children3['id']
- level3['子级名称'] = children3['name']
- level3['父级id2'] = parentId
- level3.update ( level1 )
- df_out.append ( level3 )
- excel_out = pd.DataFrame ( df_out )
- excel_out.to_excel ( 'selectAreaTree1.xlsx', sheet_name = 'sheet1' )
- # 【单个更新】供应商供货区域
- def updateSupplierAreaInfo(app_id, token, supUploadInfoDict):
- sup_id = supUploadInfoDict['sup_id'] # 供应商id
- store_area_id_list = supUploadInfoDict['store_area_id_list'] # 供应商服务区域对应id(全域)
- url = 'https://cloud.xc-fintech.com/api/v1/supplier/area/save'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_params = {'app_id': app_id,
- 'sup_id': sup_id,
- 'store_area_id_list': store_area_id_list}
- resp = requests.post ( url, headers = headers, json = json_params ).json ()
- return_result = resp['sup_id'] = sup_id
- return return_result
- # 读取供应商供货区域导入表
- def readUploadFile(uploadFile):
- df_in = pd.read_excel ( uploadFile, dtype = str )
- sup_ids = list ( df_in['供应商id'] )
- sup_ids = list ( set ( sup_ids ) )
- waite_list = []
- for sup_id in sup_ids:
- sup_info_dict = {}
- sup_info_dict['sup_id'] = sup_id
- store_area_id_list = list ( df_in[df_in['供应商id'] == sup_id]['供货区域'] )
- sup_info_dict['store_area_id_list'] = store_area_id_list
- waite_list.append ( sup_info_dict )
- # for i in waite_list:
- # print(i)
- return waite_list
- # 【批量更新】供应商供货区域
- def updateSuppliersAreaInfo(app_id, token, uploadFile):
- waite_list = readUploadFile ( uploadFile )
- error_cnt = 0
- error_list = []
- for supUploadInfoDict in waite_list:
- return_result = updateSupplierAreaInfo ( app_id, token, supUploadInfoDict )
- if return_result:
- ...
- else:
- error_list.append ( supUploadInfoDict['sup_id'] )
- error_cnt += 1
- if error_cnt == 0:
- print ( 'all Down' )
- else:
- print ( 'error_list:', error_list )
- # 供应商供货清单
- def goodsInSupplierList(app_id, token, selectSupplierlist, mode):
- url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/supply_goods/freight/template/query'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- df_out = []
- for supplierInfo in selectSupplierlist:
- supplierId = supplierInfo['供应商id']
- try:
- supplierName = supplierInfo['供应商全名']
- except:
- supplierName = ''
- page_size = 40
- total_count = 40
- current_page = 0
- while page_size * current_page - total_count < 0:
- current_page += 1
- json_params = {"sup_id": supplierId,
- "app_id": app_id,
- "current_page": current_page,
- "page_size": page_size}
- resp = requests.post ( url, headers = headers, json = json_params ).json ()
- total_count = resp['total_count']
- if total_count == 0:
- good_info_dict = {}
- good_info_dict['供应商id'] = supplierId
- good_info_dict['供应商全名'] = supplierName
- good_info_dict['商品系统id'] = ''
- good_info_dict['商品编码'] = ''
- good_info_dict['商品名称'] = ''
- good_info_dict['最小单位'] = ''
- df_out.append ( good_info_dict )
- else:
- for good_info in resp['goods_list']:
- good_info_dict = {}
- good_info_dict['供应商id'] = supplierId
- good_info_dict['供应商全名'] = supplierName
- good_info_dict['商品系统id'] = good_info['goods_id']
- good_info_dict['商品编码'] = good_info['goods_no']
- good_info_dict['商品名称'] = good_info['goods_name']
- spu_unit_list = good_info['spu_unit_list']
- try:
- for unit_info in spu_unit_list:
- if unit_info['is_min_unit']:
- good_info_dict['最小单位'] = unit_info['unit']
- else:
- good_info_dict['副单位'] = unit_info['unit']
- except:
- good_info_dict['最小单位'] = '无最小单位'
- df_out.append ( good_info_dict )
- excel_out = pd.DataFrame ( df_out )
- if mode == 'download':
- excel_out.to_excel ( 'goodsInSupplierList.xlsx', sheet_name = 'sheet1' )
- print ( 'all Down' )
- elif mode == 'select':
- goods_in_suped = list ( excel_out['商品系统id'] )
- print ( goods_in_suped )
- return goods_in_suped
- # 【批量更新】供应商供货管理中供货列表
- def addGoodsToSupplierSupList(app_id, token, uploadFile):
- url = 'https://cloud.xc-fintech.com/api/v1/supplier/sup_goods/batch_establish'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- df_in = pd.read_excel ( uploadFile, dtype = str )
- sup_ids = list ( df_in['供应商id'] )
- sup_ids = list ( set ( sup_ids ) )
- # waite_list = []
- for sup_id in sup_ids:
- goods_in_suped = goodsInSupplierList ( app_id, token, [{'供应商id': sup_id}], 'select' )
- sup_info_dict = {}
- sup_info_dict['supplier_id'] = sup_id
- goods_in_sup = list ( df_in[df_in['供应商id'] == sup_id]['供货商品'] )
- goods_in_sup = list ( set ( goods_in_sup ).difference ( set ( goods_in_suped ) ) )
- sup_info_dict['goods_list'] = goods_in_sup
- sup_info_dict['app_id'] = app_id
- if 1 == 1:
- if len ( goods_in_sup ) > 0:
- resp = requests.post ( url, headers = headers, json = sup_info_dict ).json ()['message']
- if resp == '操作成功':
- print ( sup_id, '\033[1;32m 新增商品成功 \033[0m' )
- else:
- print ( resp )
- print ( sup_id, '\033[1;31m 新增商品失败 \033[0m' )
- else:
- print ( sup_id, '\033[1;33m 无有效商品需更新 \033[0m' )
- # print(goods_in_sup)
- # 【批量更新】供应商供货管理中商品供货【1】或缺货【2】
- def updateGoodsSupStatus(app_id, token, uploadFile):
- df_in = pd.read_excel ( uploadFile, dtype = str )
- n = 0
- for supplier_id in df_in['供应商id']:
- info = df_in.loc[n]
- goods_id = info['商品id']
- status = info['供缺货操作']
- n += 1
- url = 'https://cloud.xc-fintech.com/api/v1/supplier/sup_goods/status/set'
- json_params = {"supplier_id": str ( supplier_id ),
- "goods_id": str ( goods_id ),
- "status": int ( status ),
- "app_id": app_id}
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token,
- 'Content-Type': 'application/json; charset=UTF-8'}
- resp = requests.post ( url, headers = headers, json = json_params ).text
- print ( resp )
- # 【批量更新】供应商供货管理中 区域商品建议售价及采购价 (仅需要输入需要更新的区域,如需清除区域定价,直接输入0,并在【订货商品】页面进行不供货设置
- def updateGoodsAreaSupplierPrice(app_id, token, uploadFile):
- updateSingleGoodsPriceInGoodsInfoCentre ( app_id, token, uploadFile, 0 )
- df_in = pd.read_excel ( uploadFile )
- sup_ids = list ( set ( df_in['供应商id'] ) )
- # print(sup_ids)
- for sup_id in sup_ids:
- goods_ids_l = df_in[df_in['供应商id'] == sup_id]
- goods_ids = list ( set ( goods_ids_l['商品id'] ) )
- # print(goods_ids)
- for goods_id in goods_ids:
- area_prices = goods_ids_l[goods_ids_l['商品id'] == goods_id]
- area_prices = area_prices.to_dict ( 'records' )
- area_prices_dict = {}
- for area_price in area_prices:
- supply_price_list = []
- if area_price['副单位'] is not None:
- b = {'is_min_unit': False,
- 'unit': area_price['副单位'],
- 'suggested_order_price': area_price['副单位售价'] * 100,
- 'supply_price': area_price['副单位采购价'] * 100}
- supply_price_list.append ( b )
- if area_price['副单位1'] is not None:
- c = {'is_min_unit': False,
- 'unit': area_price['副单位1'],
- 'suggested_order_price': area_price['副单位1售价'] * 100,
- 'supply_price': area_price['副单位1采购价'] * 100}
- supply_price_list.append(c)
- a = {'is_min_unit': True,
- 'unit': area_price['最小单位'],
- 'suggested_order_price': area_price['最小单位售价'] * 100,
- 'supply_price': area_price['最小单位采购价'] * 100}
- supply_price_list.append ( a )
- area_prices_dict[str ( area_price['供货区域'] )] = supply_price_list
- # print(area_prices_dict)
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- # 获取当前供应商供应商品的明细信息
- # sup_id = '6976780582995234816'
- # goods_id = '6952558678100807680'
- url_get = 'https://cloud.xc-fintech.com/api/v1/goods_centre/supply_goods/detail'
- json_params_get = {"app_id": app_id, "sup_id": sup_id, "goods_id": goods_id}
- resp = requests.post ( url_get, headers = headers, json = json_params_get ).json ()
- # print(resp)
- publish_state = resp['publish_state'] # 上下架状态
- price_mode = resp['price_mode']
- unit_list = resp['unit_list']
- supply_price_list_false = []
- for unit in unit_list:
- unit.pop ( 'is_use' )
- supply_price_list_false.append ( unit )
- area_price_list = []
- for areas_price_1 in resp['area_price_list']:
- area_price_1 = {}
- area_price_1['store_area_name'] = areas_price_1['store_area_name']
- area_price_1['store_area_id'] = areas_price_1['store_area_id']
- # print(area_price_1['store_area_id'])
- try:
- supply_price_list = area_prices_dict[area_price_1['store_area_id']]
- # print ('1', supply_price_list)
- except:
- try:
- supply_price_list = areas_price_1['sku_price_list'][0]['supply_price_list']
- except:
- supply_price_list = supply_price_list_false
- area_price_1['sku_price_list'] = [{'sku_id': 0,
- 'supply_price_list': supply_price_list
- }]
- area_price_list.append ( area_price_1 )
- if len ( areas_price_1['area_price_list'] ) > 0:
- for areas_price_2 in areas_price_1['area_price_list']:
- area_price_2 = {}
- area_price_2['store_area_name'] = areas_price_2['store_area_name']
- area_price_2['store_area_id'] = areas_price_2['store_area_id']
- try:
- supply_price_list = area_prices_dict[areas_price_2['store_area_id']]
- # print ('2', supply_price_list)
- except:
- supply_price_list = supply_price_list_false
- # supply_price_list = areas_price_2['sku_price_list'][0]['supply_price_list']
- area_price_2['sku_price_list'] = [{'sku_id': 0,
- 'supply_price_list': supply_price_list
- }]
- area_price_list.append ( area_price_2 )
- if len ( areas_price_2['area_price_list'] ) > 0:
- for areas_price_3 in areas_price_2['area_price_list']:
- area_price_3 = {}
- area_price_3['store_area_name'] = areas_price_3['store_area_name']
- area_price_3['store_area_id'] = areas_price_3['store_area_id']
- try:
- supply_price_list = area_prices_dict[area_price_1['store_area_id']]
- # print ('3', supply_price_list)
- except:
- supply_price_list = supply_price_list_false
- # supply_price_list = areas_price_3['sku_price_list'][0]['supply_price_list']
- area_price_3['sku_price_list'] = [{'sku_id': 0,
- 'supply_price_list': supply_price_list
- }]
- area_price_list.append ( area_price_3 )
- # print(area_price_list)
- # 构建json_params_up
- # price_mode = '2'
- supply_rela_list = [{'sku_id': 0, 'm_supply_count': '', 'init_stock': ''}] # 默认
- # area_price = {'store_area_name':'上海',
- # 'store_area_id':'5843112869169733638',
- # 'sku_price_list':[{'sku_id':0,
- # 'supply_price_list':[{'is_min_unit':True,
- # 'unit':'箱',
- # 'suggested_order_price':99900,
- # 'supply_price':34000
- # }]
- # }]}
- # area_price_list = []
- json_params_up = {'app_id': app_id,
- 'goods_id': goods_id,
- 'price_mode': 2,
- 'sup_id': sup_id,
- 'supply_rela_list': supply_rela_list,
- 'area_price_list': area_price_list}
- # print(json_params_up)
- if publish_state == 1:
- # 下架
- if updatePublishState ( app_id, token, 1, goods_id ):
- url_up = 'https://cloud.xc-fintech.com/api/v1/supplier/sup_goods/establish'
- resp_up = requests.post ( url_up, headers = headers, json = json_params_up ).json ()
- print ( resp_up )
- print ( sup_id, goods_id, resp_up['sup_id'] == sup_id )
- # 上架
- updatePublishState ( app_id, token, 0, goods_id )
- else:
- print ( sup_id, goods_id, '无法操作下架' )
- else:
- url_up = 'https://cloud.xc-fintech.com/api/v1/supplier/sup_goods/establish'
- resp_up = requests.post ( url_up, headers = headers, json = json_params_up ).json ()
- print ( sup_id, goods_id, resp_up )
- print ( sup_id, goods_id, resp_up['sup_id'] == sup_id )
- updateSingleGoodsPriceInGoodsInfoCentre ( app_id, token, uploadFile, 1 )
- # 【单独更新】订货商品中改价界面的参数,配合updateGoodsAreaSupplierPrice执行,主要在调整供应商端采购价和建议售价时,完成订货商品【供货方】调整
- # mode = 0时为【供货方】调整为【不供货】,mode = 1时为【供货方】调整为表中指定供应商
- def updateSingleGoodsPriceInGoodsInfoCentre(app_id, token, uploadFile, mode):
- df_in = pd.read_excel ( uploadFile )
- goods_ids = list ( set ( df_in['商品id'] ) )
- df_in_dict = {}
- for goods_id in goods_ids:
- df_in_dict[str ( goods_id )] = {}
- area_ids_l = df_in[df_in['商品id'] == goods_id]
- area_ids = list ( set ( area_ids_l['供货区域'] ) )
- for area_id in area_ids:
- df_in_dict[str ( goods_id )][str ( area_id )] = {}
- sup_ids_l = area_ids_l[area_ids_l['供货区域'] == area_id]
- sup_ids_l = sup_ids_l.to_dict ( 'records' )
- try:
- if len ( sup_ids_l ) > 1:
- print ( f'商品【{goods_id}】在【{area_id}】存在多个供应商,请检查此字段【订货商品【供货方】是否立即调整】是否有调整' )
- except:
- print ( '一品一地多供点检出错' )
- sup_info = sup_ids_l[0]
- unit_price_list = []
- if str ( sup_info['副单位'] ) != 'nan':
- b = {'is_min_unit': False,
- 'unit': sup_info['副单位'],
- 'actual_amount': int ( sup_info['副单位售价'] * 100 )}
- unit_price_list.append ( b )
- if str ( sup_info['副单位1'] ) != 'nan':
- c = {'is_min_unit': False,
- 'unit': sup_info['副单位1'],
- 'actual_amount': int ( sup_info['副单位1售价'] * 100 )}
- unit_price_list.append ( c )
- a = {'is_min_unit': True,
- 'unit': sup_info['最小单位'],
- 'actual_amount': int ( sup_info['最小单位售价'] * 100 )}
- unit_price_list.append ( a )
- if str ( sup_info['限订量'] ) != 'nan':
- buy_limit_max = sup_info['限订量']
- else:
- buy_limit_max = ''
- if sup_info['订货商品【供货方】是否立即调整'] != 'nan':
- isAddToListRightNow = sup_info['订货商品【供货方】是否立即调整']
- else:
- isAddToListRightNow = 0
- df_in_dict[str ( goods_id )][str ( area_id )] = {'sup_id': str ( sup_info['供应商id'] ),
- 'buy_limit_min': sup_info['起订量'],
- 'buy_limit_max': buy_limit_max,
- 'unit_price_list': unit_price_list,
- 'isAddToListRightNow': isAddToListRightNow}
- df_in_dict[str ( goods_id )][str ( area_id )][str ( sup_info['供应商id'] )] = {
- 'sup_id': str ( sup_info['供应商id'] ),
- 'buy_limit_min': sup_info['起订量'],
- 'buy_limit_max': buy_limit_max,
- 'unit_price_list': unit_price_list,
- 'isAddToListRightNow': isAddToListRightNow}
- # 以上对导入表进行字典化整理df_in_dict
- print ( len ( goods_ids ) )
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token,
- 'Content-Type': 'application/json; charset=UTF-8'}
- for goods_id in goods_ids:
- # 查询商品相关规格信息
- url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/' + str ( goods_id )
- json = {"app_id": app_id}
- resp_goodsInfo = requests.post ( url, headers = headers, json = json ).json ()
- unit_list = []
- publish_state = resp_goodsInfo['publish_state']
- for unit_info in resp_goodsInfo['spu_unit_list']:
- unit_info_dict = {}
- unit_info_dict['is_min_unit'] = unit_info['is_min_unit']
- unit_info_dict['unit'] = unit_info['unit']
- unit_list.append ( unit_info_dict )
- if publish_state == 1:
- # 下架
- updatePublishState ( app_id, token, 1, goods_id )
- # 返回规格数据unit_list
- # 按goods_id搜索当前商品定价界面相关信息
- url_goods_price = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/query'
- json_goods_price = {"subscribe_type": "1",
- "goods_id": goods_id,
- "app_id": app_id}
- resp_goods_price = requests.post ( url_goods_price, headers = headers, json = json_goods_price ).json ()
- if mode == 0:
- # area_price_list为构建的请求参数中的列表参数
- area_price_list = []
- for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
- dict_l1 = {}
- store_area_id = area_price_1['store_area_id']
- store_area_name = area_price_1['store_area_name']
- is_extend = area_price_1['is_extend']
- dict_l1['is_extend'] = is_extend
- dict_l1['store_area_id'] = store_area_id
- dict_l1['store_area_name'] = store_area_name
- # dict_l1['is_supply'] = True
- # dict_l1['spu_order_price'] = {}
- try:
- sup_id = area_price_1['sup_id']
- # print(sup_id)
- except:
- ...
- # 判断是否在上载的表里
- try:
- # 如果'在'则进行【不供货】调整
- sup_id_in = df_in_dict[str ( goods_id )][str ( store_area_id )][str ( sup_id )]['sup_id']
- dict_l1['is_supply'] = False
- print ( goods_id, '|区域', store_area_id, '已设置值不供货' )
- # dict_l1['spu_order_price']['buy_limit_min'] = df_in_dict[str (goods_id)][store_area_id][sup_id]['buy_limit_min']
- # dict_l1['spu_order_price']['buy_limit_max'] = df_in_dict[str (goods_id)][store_area_id][sup_id]['buy_limit_max']
- # dict_l1['spu_order_price']['unit_price_list'] = df_in_dict[str (goods_id)][store_area_id][sup_id][
- # 'unit_price_list']
- except:
- # 判断是否已分配供应商
- dict_l1['is_supply'] = True
- dict_l1['spu_order_price'] = {}
- try:
- dict_l1['sup_id'] = sup_id
- dict_l1['spu_order_price']['buy_limit_min'] = area_price_1['spu_order_price']['buy_limit_min']
- try:
- dict_l1['spu_order_price']['buy_limit_max'] = area_price_1['spu_order_price'][
- 'buy_limit_max']
- except:
- dict_l1['spu_order_price']['buy_limit_max'] = ''
- dict_l1['spu_order_price']['unit_price_list'] = area_price_1['spu_order_price'][
- 'unit_price_list']
- except:
- dict_l1['spu_order_price']['unit_price_list'] = unit_list
- dict_l1['spu_order_price']['buy_limit_min'] = ''
- dict_l1['spu_order_price']['buy_limit_max'] = ''
- area_price_list.append ( dict_l1 )
- store_area_list2 = area_price_1['store_area_list']
- if len ( store_area_list2 ) > 0:
- for area_price_2 in store_area_list2:
- dict_l2 = {}
- store_area_id = area_price_2['store_area_id']
- store_area_name = area_price_2['store_area_name']
- is_extend = area_price_2['is_extend']
- dict_l2['is_extend'] = is_extend
- dict_l2['store_area_id'] = store_area_id
- dict_l2['store_area_name'] = store_area_name
- # dict_l2['spu_order_price'] = {}
- # dict_l2['is_supply'] = True
- # try:
- # dict_l2['sup_id'] = df_in_dict[str (goods_id)][store_area_id][sup_id]['sup_id']
- # dict_l2['is_supply'] = False
- # # dict_l2['spu_order_price']['buy_limit_min'] = df_in_dict[str (goods_id)][store_area_id][
- # # 'buy_limit_min']
- # # dict_l2['spu_order_price']['buy_limit_max'] = df_in_dict[str (goods_id)][store_area_id][
- # # 'buy_limit_max']
- # # dict_l2['spu_order_price']['unit_price_list'] = df_in_dict[str (goods_id)][store_area_id][
- # # 'unit_price_list']
- # except:
- dict_l2['spu_order_price'] = {}
- dict_l2['is_supply'] = True
- dict_l2['spu_order_price']['unit_price_list'] = unit_list
- dict_l2['spu_order_price']['buy_limit_min'] = ''
- dict_l2['spu_order_price']['buy_limit_max'] = ''
- area_price_list.append ( dict_l2 )
- store_area_list3 = area_price_2['store_area_list']
- if len ( store_area_list3 ) > 0:
- for area_price_3 in store_area_list3:
- dict_l3 = {}
- store_area_id = area_price_3['store_area_id']
- store_area_name = area_price_3['store_area_name']
- is_extend = area_price_3['is_extend']
- dict_l3['is_extend'] = is_extend
- dict_l3['is_supply'] = True
- dict_l3['store_area_id'] = store_area_id
- dict_l3['store_area_name'] = store_area_name
- dict_l3['spu_order_price'] = {}
- # try:
- # dict_l3['sup_id'] = df_in_dict[str (goods_id)][store_area_id]['sup_id']
- # dict_l3['spu_order_price']['buy_limit_min'] = df_in_dict[str (goods_id)][store_area_id][
- # 'buy_limit_min']
- # dict_l3['spu_order_price']['buy_limit_max'] = df_in_dict[str (goods_id)][store_area_id][
- # 'buy_limit_max']
- # dict_l3['spu_order_price']['unit_price_list'] = \
- # df_in_dict[str (goods_id)][store_area_id][
- # 'unit_price_list']
- # except:
- dict_l3['spu_order_price']['unit_price_list'] = unit_list
- dict_l3['spu_order_price']['buy_limit_min'] = ''
- dict_l3['spu_order_price']['buy_limit_max'] = ''
- area_price_list.append ( dict_l3 )
- brand_list = [{'brand_id': '0',
- 'area_price_list': area_price_list}]
- json_params_full_update = {'app_id': app_id,
- 'goods_id': goods_id,
- 'subscribe_type': '1',
- 'brand_list': brand_list}
- url_full_update = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/full_update'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token,
- 'Content-Type': 'application/json; charset=UTF-8'}
- resp_full_update = requests.post ( url_full_update, headers = headers, json = json_params_full_update ).text
- print ( resp_full_update )
- if mode == 1:
- area_price_list = []
- for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
- dict_l1 = {}
- store_area_id = area_price_1['store_area_id']
- store_area_name = area_price_1['store_area_name']
- is_extend = area_price_1['is_extend']
- dict_l1['is_extend'] = is_extend
- dict_l1['is_supply'] = True
- dict_l1['store_area_id'] = store_area_id
- dict_l1['store_area_name'] = store_area_name
- dict_l1['spu_order_price'] = {}
- try:
- dict_l1['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
- dict_l1['spu_order_price']['buy_limit_min'] = df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_min']
- dict_l1['spu_order_price']['buy_limit_max'] = df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_max']
- dict_l1['spu_order_price']['unit_price_list'] = df_in_dict[str ( goods_id )][store_area_id][
- 'unit_price_list']
- except:
- # 判断是否已分配供应商
- try:
- dict_l1['sup_id'] = area_price_1['sup_id']
- dict_l1['spu_order_price']['buy_limit_min'] = area_price_1['spu_order_price']['buy_limit_min']
- try:
- dict_l1['spu_order_price']['buy_limit_max'] = area_price_1['spu_order_price'][
- 'buy_limit_max']
- except:
- dict_l1['spu_order_price']['buy_limit_max'] = ''
- dict_l1['spu_order_price']['unit_price_list'] = area_price_1['spu_order_price'][
- 'unit_price_list']
- except:
- dict_l1['spu_order_price']['unit_price_list'] = unit_list
- dict_l1['spu_order_price']['buy_limit_min'] = ''
- dict_l1['spu_order_price']['buy_limit_max'] = ''
- area_price_list.append ( dict_l1 )
- store_area_list2 = area_price_1['store_area_list']
- if len ( store_area_list2 ) > 0:
- for area_price_2 in store_area_list2:
- dict_l2 = {}
- store_area_id = area_price_2['store_area_id']
- store_area_name = area_price_2['store_area_name']
- is_extend = area_price_2['is_extend']
- dict_l2['is_extend'] = is_extend
- dict_l2['is_supply'] = True
- dict_l2['store_area_id'] = store_area_id
- dict_l2['store_area_name'] = store_area_name
- dict_l2['spu_order_price'] = {}
- try:
- dict_l2['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
- dict_l2['spu_order_price']['buy_limit_min'] = df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_min']
- dict_l2['spu_order_price']['buy_limit_max'] = df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_max']
- dict_l2['spu_order_price']['unit_price_list'] = df_in_dict[str ( goods_id )][store_area_id][
- 'unit_price_list']
- except:
- dict_l2['spu_order_price']['unit_price_list'] = unit_list
- dict_l2['spu_order_price']['buy_limit_min'] = ''
- dict_l2['spu_order_price']['buy_limit_max'] = ''
- area_price_list.append ( dict_l2 )
- store_area_list3 = area_price_2['store_area_list']
- if len ( store_area_list3 ) > 0:
- for area_price_3 in store_area_list3:
- dict_l3 = {}
- store_area_id = area_price_3['store_area_id']
- store_area_name = area_price_3['store_area_name']
- is_extend = area_price_3['is_extend']
- dict_l3['is_extend'] = is_extend
- dict_l3['is_supply'] = True
- dict_l3['store_area_id'] = store_area_id
- dict_l3['store_area_name'] = store_area_name
- dict_l3['spu_order_price'] = {}
- try:
- dict_l3['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
- dict_l3['spu_order_price']['buy_limit_min'] = \
- df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_min']
- dict_l3['spu_order_price']['buy_limit_max'] = \
- df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_max']
- dict_l3['spu_order_price']['unit_price_list'] = \
- df_in_dict[str ( goods_id )][store_area_id][
- 'unit_price_list']
- except:
- dict_l3['spu_order_price']['unit_price_list'] = unit_list
- dict_l3['spu_order_price']['buy_limit_min'] = ''
- dict_l3['spu_order_price']['buy_limit_max'] = ''
- area_price_list.append ( dict_l3 )
- brand_list = [{'brand_id': '0',
- 'area_price_list': area_price_list}]
- json_params_full_update = {'app_id': app_id,
- 'goods_id': goods_id,
- 'subscribe_type': '1',
- 'brand_list': brand_list}
- url_full_update = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/full_update'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token,
- 'Content-Type': 'application/json; charset=UTF-8'}
- resp_full_update = requests.post ( url_full_update, headers = headers, json = json_params_full_update ).text
- print ( resp_full_update )
- if publish_state == 1:
- # 上架
- updatePublishState ( app_id, token, 0, goods_id )
- print ( '----------【不供货】操作----------' )
- # 【批量更新】订货商品中改价界面的参数
- def updateGoodsPriceInGoodsInfoCentre(app_id, token, uploadFile):
- df_in = pd.read_excel ( uploadFile )
- goods_ids = list ( set ( df_in['商品id'] ) )
- df_in_dict = {}
- for goods_id in goods_ids:
- df_in_dict[str ( goods_id )] = {}
- area_ids_l = df_in[df_in['商品id'] == goods_id]
- area_ids = list ( set ( area_ids_l['区域id'] ) )
- for area_id in area_ids:
- df_in_dict[str ( goods_id )][str ( area_id )] = {}
- sup_ids_l = area_ids_l[area_ids_l['区域id'] == area_id]
- sup_ids_l = sup_ids_l.to_dict ( 'records' )
- try:
- if len ( sup_ids_l ) > 1:
- print ( f'商品【{goods_id}】在【{area_id}】存在多个供应商,请检查此字段【订货商品【供货方】是否立即调整】是否有调整' )
- except:
- print ( '一品一地多供点检出错' )
- sup_info = sup_ids_l[0]
- unit_price_list = []
- if str ( sup_info['副单位'] ) != 'nan':
- b = {'is_min_unit': False,
- 'unit': sup_info['副单位'],
- 'actual_amount': int ( sup_info['副单位售价'] * 100 )}
- unit_price_list.append ( b )
- if str ( sup_info['副单位1'] ) != 'nan':
- c = {'is_min_unit': False,
- 'unit': sup_info['副单位1'],
- 'actual_amount': int ( sup_info['副单位1售价'] * 100 )}
- unit_price_list.append ( c )
- a = {'is_min_unit': True,
- 'unit': sup_info['最小单位'],
- 'actual_amount': int ( sup_info['最小单位售价'] * 100 )}
- unit_price_list.append ( a )
- if str ( sup_info['限订量'] ) != 'nan':
- buy_limit_max = sup_info['限订量']
- else:
- buy_limit_max = ''
- df_in_dict[str ( goods_id )][str ( area_id )] = {'sup_id': str ( sup_info['供应商id'] ),
- 'buy_limit_min': sup_info['起订量'],
- 'buy_limit_max': buy_limit_max,
- 'unit_price_list': unit_price_list}
- # 以上对导入表进行字典化整理df_in_dict
- print ( len ( goods_ids ) )
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token,
- 'Content-Type': 'application/json; charset=UTF-8'}
- for goods_id in goods_ids:
- # 查询商品相关规格信息
- url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/' + str ( goods_id )
- json = {"app_id": app_id}
- resp_goodsInfo = requests.post ( url, headers = headers, json = json ).json ()
- unit_list = []
- publish_state = resp_goodsInfo['publish_state']
- for unit_info in resp_goodsInfo['spu_unit_list']:
- unit_info_dict = {}
- unit_info_dict['is_min_unit'] = unit_info['is_min_unit']
- unit_info_dict['unit'] = unit_info['unit']
- unit_list.append ( unit_info_dict )
- if publish_state == 1:
- # 下架
- updatePublishState ( app_id, token, 1, goods_id )
- # 返回规格数据unit_list
- # 按goods_id搜索当前商品定价界面相关信息
- url_goods_price = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/query'
- json_goods_price = {"subscribe_type": "1",
- "goods_id": goods_id,
- "app_id": app_id}
- resp_goods_price = requests.post ( url_goods_price, headers = headers, json = json_goods_price ).json ()
- area_price_list = []
- for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
- dict_l1 = {}
- store_area_id = area_price_1['store_area_id']
- store_area_name = area_price_1['store_area_name']
- is_extend = area_price_1['is_extend']
- dict_l1['is_extend'] = is_extend
- dict_l1['is_supply'] = True
- dict_l1['store_area_id'] = store_area_id
- dict_l1['store_area_name'] = store_area_name
- dict_l1['spu_order_price'] = {}
- # in_put_area_dict_l1 = {'is_extend': is_extend,
- # 'is_supply': True,
- # 'spu_order_price': {'buy_limit_min': buy_limit_min,
- # 'buy_limit_max': buy_limit_max,
- # 'unit_price_list': unit_price_list},
- # 'store_area_id': store_area_id,
- # 'store_area_name': store_area_name,
- # 'sup_id': sup_id}
- # in_put_area_dict_l1 = {'is_extend': is_extend,
- # 'is_supply': True,
- # 'spu_order_price': {'buy_limit_min': '',
- # 'buy_limit_max': '',
- # 'unit_price_list': unit_price_list},
- # 'store_area_id': store_area_id,
- # 'store_area_name': store_area_name,
- # }
- # 判断是否在上载的表里
- try:
- dict_l1['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
- dict_l1['spu_order_price']['buy_limit_min'] = df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_min']
- dict_l1['spu_order_price']['buy_limit_max'] = df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_max']
- dict_l1['spu_order_price']['unit_price_list'] = df_in_dict[str ( goods_id )][store_area_id][
- 'unit_price_list']
- except:
- # 判断是否已分配供应商
- try:
- dict_l1['sup_id'] = area_price_1['sup_id']
- dict_l1['spu_order_price']['buy_limit_min'] = area_price_1['spu_order_price']['buy_limit_min']
- try:
- dict_l1['spu_order_price']['buy_limit_max'] = area_price_1['spu_order_price']['buy_limit_max']
- except:
- dict_l1['spu_order_price']['buy_limit_max'] = ''
- dict_l1['spu_order_price']['unit_price_list'] = area_price_1['spu_order_price']['unit_price_list']
- except:
- dict_l1['spu_order_price']['unit_price_list'] = unit_list
- dict_l1['spu_order_price']['buy_limit_min'] = ''
- dict_l1['spu_order_price']['buy_limit_max'] = ''
- area_price_list.append ( dict_l1 )
- store_area_list2 = area_price_1['store_area_list']
- if len ( store_area_list2 ) > 0:
- for area_price_2 in store_area_list2:
- dict_l2 = {}
- store_area_id = area_price_2['store_area_id']
- store_area_name = area_price_2['store_area_name']
- is_extend = area_price_2['is_extend']
- dict_l2['is_extend'] = is_extend
- dict_l2['is_supply'] = True
- dict_l2['store_area_id'] = store_area_id
- dict_l2['store_area_name'] = store_area_name
- dict_l2['spu_order_price'] = {}
- try:
- dict_l2['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
- dict_l2['spu_order_price']['buy_limit_min'] = df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_min']
- dict_l2['spu_order_price']['buy_limit_max'] = df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_max']
- dict_l2['spu_order_price']['unit_price_list'] = df_in_dict[str ( goods_id )][store_area_id][
- 'unit_price_list']
- except:
- dict_l2['spu_order_price']['unit_price_list'] = unit_list
- dict_l2['spu_order_price']['buy_limit_min'] = ''
- dict_l2['spu_order_price']['buy_limit_max'] = ''
- area_price_list.append ( dict_l2 )
- store_area_list3 = area_price_2['store_area_list']
- if len ( store_area_list3 ) > 0:
- for area_price_3 in store_area_list3:
- dict_l3 = {}
- store_area_id = area_price_3['store_area_id']
- store_area_name = area_price_3['store_area_name']
- is_extend = area_price_3['is_extend']
- dict_l3['is_extend'] = is_extend
- dict_l3['is_supply'] = True
- dict_l3['store_area_id'] = store_area_id
- dict_l3['store_area_name'] = store_area_name
- dict_l3['spu_order_price'] = {}
- try:
- dict_l3['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
- dict_l3['spu_order_price']['buy_limit_min'] = \
- df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_min']
- dict_l3['spu_order_price']['buy_limit_max'] = \
- df_in_dict[str ( goods_id )][store_area_id][
- 'buy_limit_max']
- dict_l3['spu_order_price']['unit_price_list'] = \
- df_in_dict[str ( goods_id )][store_area_id][
- 'unit_price_list']
- except:
- dict_l3['spu_order_price']['unit_price_list'] = unit_list
- dict_l3['spu_order_price']['buy_limit_min'] = ''
- dict_l3['spu_order_price']['buy_limit_max'] = ''
- area_price_list.append ( dict_l3 )
- brand_list = [{'brand_id': '0',
- 'area_price_list': area_price_list}]
- json_params_full_update = {'app_id': app_id,
- 'goods_id': goods_id,
- 'subscribe_type': '1',
- 'brand_list': brand_list}
- url_full_update = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/full_update'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token,
- 'Content-Type': 'application/json; charset=UTF-8'}
- resp_full_update = requests.post ( url_full_update, headers = headers, json = json_params_full_update ).text
- print ( resp_full_update )
- if publish_state == 1:
- # 上架
- updatePublishState ( app_id, token, 0, goods_id )
- '''
- goods_id = "6997811305520701440"
- url_full_update = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/full_update'
- headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token,
- 'Content-Type': 'application/json; charset=UTF-8'}
- area_price_list=[]
- #按goods_id搜索当前商品定价界面相关信息
- url_goods_price = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/query'
- json_goods_price = {"subscribe_type":"1",
- "goods_id":goods_id,
- "app_id":app_id}
- resp_goods_price = requests.post(url_goods_price,headers=headers,json=json_goods_price).json()
- for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
- store_area_list2 = area_price_1['store_area_list']
- if len(store_area_list2)>0:
- for area_price_2 in store_area_list2:
- store_area_list3 = area_price_2['store_area_list']
- if len(store_area_list3)>0:
- for area_price_3 in store_area_list3:
- ...
- in_put_area_F_dict = {'is_extend': False,
- 'is_supply': True,
- 'spu_order_price': {'buy_limit_min': 1,
- 'buy_limit_max': '',
- 'unit_price_list': [{'actual_amount': 37280,
- 'is_min_unit': True,
- 'unit': '桶'}]},
- 'store_area_id': '5843111700124934144',
- 'store_area_name': '河北省',
- 'sup_id': '6976010005263032320'}
- in_put_area_S_dict = {'is_extend': True,
- 'is_supply': True,
- 'spu_order_price': {'buy_limit_min': 1,
- 'buy_limit_max': '',
- 'unit_price_list': [{'actual_amount': '',
- 'is_min_unit': True,
- 'unit': '桶'}]},
- 'store_area_id': '6990852309777522688',
- 'store_area_name': '河北省a顶灿'}
- brand_list= [{'brand_id':'0',
- 'area_price_list':area_price_list}]
- json_params_full_update = {'app_id':app_id,
- 'goods_id':goods_id,
- 'subscribe_type':'1',
- 'brand_list':brand_list}
- '''
- # 获取【订货橱窗】中的商品信息
- def goodsInGoodsCentre(app_id, token, downloadPath):
- # 第一步构造 目录列表包含信息['品牌id','品牌名称','L1橱窗id','L1橱窗名称','L2橱窗id','L2橱窗名称','publish_goods_count']
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- # 获取所有品牌名称及id
- brand_url = 'https://cloud.xc-fintech.com/api/v1/brand/list'
- brand_json_params = {"current_page": 1,
- "page_size": 999,
- "app_id": app_id}
- brand_list = requests.post ( brand_url, headers = headers, json = brand_json_params ).json ()['detail']
- # print(brand_list)
- df_out = []
- i = 0
- for brand_info in brand_list:
- brand_id = brand_info['brand_id']
- brand_name = brand_info['brand_name']
- # 创建表信息
- brand_info_dict = {'品牌id': brand_id, '品牌名称': brand_name}
- # 获取当前品牌下各分类名称及id
- shop_window_url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/shop_window/tree/query'
- shop_window_json_params = {"app_id": app_id,
- "sell_type": 2,
- "brand_id": brand_id}
- try:
- shop_window_list = \
- requests.post ( shop_window_url, headers = headers, json = shop_window_json_params ).json ()[
- 'shop_window_detail']
- shop_window_list_out = []
- for shop_window_info in shop_window_list:
- try:
- childs = shop_window_info['child']
- for child in childs:
- shop_window_id = child['shop_window_id']
- shop_window_name = child['shop_window_name']
- publish_goods_count = child['publish_goods_count']
- shop_window_info_dict = {'橱窗id': shop_window_id, '橱窗名称': shop_window_name,
- 'publish_goods_count': publish_goods_count}
- shop_window_info_dict.update ( brand_info_dict )
- shop_window_list_out.append ( shop_window_info_dict )
- except:
- shop_window_name = shop_window_info['shop_window_name']
- shop_window_id = shop_window_info['shop_window_id']
- # 创建表信息
- publish_goods_count = shop_window_info['publish_goods_count']
- shop_window_info_dict = {'橱窗id': shop_window_id, '橱窗名称': shop_window_name,
- 'publish_goods_count': publish_goods_count}
- shop_window_info_dict.update ( brand_info_dict )
- shop_window_list_out.append ( shop_window_info_dict )
- for shop_window_info_dict in shop_window_list_out:
- page_size = 40
- page_count = math.ceil ( shop_window_info_dict['publish_goods_count'] / page_size )
- for current_page in range ( 1, page_count + 1 ):
- goodsInGoodsCentre_url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/shop_window/goods'
- goodsInGoodsCentre_json_params = {"sell_type": 2,
- "shop_window_id": shop_window_info_dict['橱窗id'],
- "current_page": current_page,
- "page_size": page_size,
- "app_id": app_id}
- goodsInGoodsCentre = requests.post ( goodsInGoodsCentre_url, headers = headers,
- json = goodsInGoodsCentre_json_params ).json ()['detail']
- for goodsInfo in goodsInGoodsCentre:
- goods_id = goodsInfo['goods_id']
- goods_name = goodsInfo['goods_name']
- goods_no = goodsInfo['goods_no']
- publish_state_judge = {'1': '上架', '0': '下架'}
- publish_state = publish_state_judge[str ( goodsInfo['publish_state'] )]
- i += 1
- # 查看商品适用于哪些门店
- apply_store_url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods_shop_window/apply_store/query'
- apply_store_json_params = {"goods_id": goods_id,
- "shop_window_id": shop_window_info_dict['橱窗id'],
- "app_id": app_id}
- apply_store_info = requests.post ( apply_store_url, headers = headers,
- json = apply_store_json_params ).json ()
- apply_type_mark = apply_store_info['data']['apply_type']
- if apply_type_mark == 1:
- apply_type = '全部门店适用'
- elif apply_type_mark == 2:
- apply_type = '部分门店适用'
- elif apply_type_mark == 3:
- apply_type = '部分门店不适用'
- else:
- apply_type = '未知'
- # 创建表信息
- goodsInfo_dict = {'商品id': goods_id,
- '商品编号': goods_no,
- '商品名称': goods_name,
- '商品状态': publish_state,
- '适用门店类型': apply_type}
- goodsInfo_dict.update ( shop_window_info_dict )
- try:
- for apply_store_id in apply_store_info['data']['apply_store_id_list']:
- apply_store_dict = selectStoreNoByStoreId ( app_id, token, apply_store_id )
- # store_info_dict = {'门店编号':store_no,'门店名称':store_name,'所属品牌':brand_name}
- apply_store_dict['相关门店id'] = apply_store_id
- apply_store_dict.update ( goodsInfo_dict )
- df_out.append ( apply_store_dict )
- except:
- df_out.append ( goodsInfo_dict )
- print ( brand_info_dict, '完成' )
- except:
- print ( brand_info_dict, '出错' )
- df_headers = ['品牌id', '品牌名称', '橱窗id', '橱窗名称', '商品id', '商品编号', '商品名称', '商品状态', '适用门店类型', '相关门店id', '门店编号', '门店名称',
- '所属品牌']
- df_out = pd.DataFrame ( df_out, columns = df_headers )
- df_out.to_excel ( downloadPath + '/goodsInGoodsCentre.xlsx' )
- # 获取【订货橱窗】中商品对应的【适用门店】
- def selectGoodInGoodsCentreSUPshops(app_id, token, goods_id, shop_window_id):
- url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods_shop_window/apply_store/query'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_params = {"goods_id": goods_id,
- "shop_window_id": shop_window_id,
- "app_id": app_id}
- resp = requests.post ( url, headers = headers, json = json_params ).json ()
- print(resp)
- return resp
- # 更新【订货橱窗】中的商品对应的【适用门店】
- def updateGoodsInGoodsCentreSUPshops(app_id, token, uploadFile):
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- df_in = pd.read_excel ( uploadFile )
- goods_ids = list ( set ( df_in['商品id'] ) )
- for goods_id in goods_ids:
- shop_window_ids_df = df_in[df_in['商品id'] == goods_id]
- shop_window_ids = list ( set ( shop_window_ids_df['橱窗id'] ) )
- for shop_window_id in shop_window_ids:
- # brand_id = list (set (shop_window_ids_df[shop_window_ids_df['橱窗id'] == shop_window_id]['品牌id']))[0]
- # apply_store_ids = list(set(shop_window_ids_df[shop_window_ids_df['橱窗id']==shop_window_id]['门店编号']))
- # apply_store_ids1 = selectStoreIdByStoreNo (app_id, token, apply_store_ids,brand_id) #门店编码转门店id
- # apply_type = list(set(shop_window_ids_df[shop_window_ids_df['橱窗id']==shop_window_id]['适用类型']))[0] #适用类型
- apply_store_ids_df = shop_window_ids_df[shop_window_ids_df['橱窗id'] == shop_window_id]
- apply_types = list (
- set ( shop_window_ids_df[shop_window_ids_df['橱窗id'] == shop_window_id]['适用类型'] ) ) # 适用类型
- for apply_type in apply_types:
- time.sleep(random.uniform(2,4))
- brand_id = list ( set ( shop_window_ids_df[shop_window_ids_df['橱窗id'] == shop_window_id]['品牌id'] ) )[0]
- apply_store_ids = list ( set ( apply_store_ids_df[apply_store_ids_df['适用类型'] == apply_type]['门店编号'] ) )
- apply_store_ids1 = selectStoreIdByStoreNo ( app_id, token, apply_store_ids, brand_id ) # 门店编码转门店id
- goods_info = selectGoodInGoodsCentreSUPshops ( app_id, token, goods_id, shop_window_id )
- goods_info_apply_type = goods_info['data']['apply_type']
- url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods_shop_window/apply_store/set'
- # 在当前适用类型下追加
- if int ( goods_info_apply_type ) == int ( apply_type ):
- apply_store_id_list = goods_info['data']['apply_store_id_list']
- apply_store_ids2 = list ( set ( apply_store_ids1 ) | set ( apply_store_id_list ) )
- json_params = {"apply_type": apply_type,
- "shop_window_id": shop_window_id,
- "goods_id": goods_id,
- "apply_store_id_list": apply_store_ids2,
- "app_id": app_id}
- no = 1
- # 在当前适用类型下移除门店
- elif int ( goods_info_apply_type ) != int ( apply_type ) and int (
- goods_info_apply_type ) != 1 and int (
- apply_type ) != 1:
- apply_store_id_list = goods_info['data']['apply_store_id_list']
- for apply_store_id in apply_store_ids1:
- try:
- apply_store_id_list.remove ( apply_store_id )
- except:
- ...
- json_params = {"apply_type": goods_info_apply_type,
- "shop_window_id": shop_window_id,
- "goods_id": goods_id,
- "apply_store_id_list": apply_store_id_list,
- "app_id": app_id}
- no = 2
- # 初始进行适用类型划分
- elif int ( goods_info_apply_type ) == 1:
- json_params = {"apply_type": apply_type,
- "shop_window_id": shop_window_id,
- "goods_id": goods_id,
- "apply_store_id_list": apply_store_ids1,
- "app_id": app_id}
- no = 3
- # 恢复全部门店可见
- elif int ( apply_type ) == 1:
- json_params = {"apply_type": apply_type,
- "shop_window_id": shop_window_id,
- "goods_id": goods_id,
- "app_id": app_id}
- no = 4
- try:
- resp = requests.post ( url, json = json_params, headers = headers ).json ()['message']
- print ( goods_id, shop_window_id, apply_type, resp, no )
- except:
- print ( '参数有误!' )
- # 按门店编号查门店id
- def selectStoreIdByStoreNo(app_id, token, store_no, brand_id):
- if str ( type ( store_no ) ) != "<class 'list'>":
- url = 'https://cloud.xc-fintech.com/split/get_store_list'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_params = {"app_id": app_id,
- "store_no": store_no,
- "page": 0, "page_size": 10,
- "open_align": True,
- "business_scene_list": []}
- store_id = requests.post ( url, headers = headers, json = json_params ).json ()['store_list'][0]['store_id']
- else:
- url = 'https://cloud.xc-fintech.com/split/get_store_list'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_params = {"app_id": app_id,
- "page": 0, "page_size": 9999,
- "brand_id": brand_id}
- store_list = requests.post ( url, headers = headers, json = json_params ).json ()['store_list']
- df_in0 = pd.DataFrame ( store_list ).set_index ( 'store_no' )
- df_in1 = pd.DataFrame ( store_no, columns = ['store_no'] )
- df_in1['store_no'] = df_in1['store_no'].astype ( str )
- df_out = df_in1.join ( df_in0, on = 'store_no', how = 'inner' )
- store_id = list ( set ( df_out['store_id'] ) )
- return store_id
- # 按门店id查门店信息
- def selectStoreNoByStoreId(app_id, token, store_id):
- url = 'https://cloud.xc-fintech.com/split/get_store_list'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_params = {"app_id": app_id,
- "store_id": store_id,
- "page": 0, "page_size": 10,
- "open_align": False,
- "business_scene_list": []}
- store_info = requests.post ( url, headers = headers, json = json_params ).json ()['store_list'][0]
- store_no = store_info['store_no']
- brand_name = store_info['brand_name']
- store_name = store_info['store_name']
- store_info_dict = {'门店编号': store_no,
- '门店名称': store_name,
- '所属品牌': brand_name}
- # print(json.dumps(store_info,ensure_ascii=False))
- return store_info_dict
- # 查询所有门店信息
- def selectAllStoreInfo(app_id, token, downloadPath):
- template_dict = selectServiceRate ( app_id, token )
- df_out = []
- url = 'https://cloud.xc-fintech.com/split/get_store_list'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_0 = {"app_id": app_id, "page": 0, "page_size": 40, "open_align": True, "align_status": 2,
- "business_scene_list": ["meituan", "eleme", "meituan_group_purchase", "dou_yin_life"]}
- n = 0
- x = requests.post ( url, headers = headers, json = json_0 ).json ()['total_count'] / 40
- while n <= x:
- print ( n )
- json_1 = {"app_id": app_id, "page": n, "page_size": 40, "open_align": True, "align_status": 2,
- "business_scene_list": ["meituan", "eleme", "meituan_group_purchase", "dou_yin_life"]}
- n += 1
- resp = requests.post ( url, headers = headers, json = json_1 ).json ()
- print ( json.dumps ( resp, ensure_ascii = False ) )
- store_list = resp['store_list']
- for store_info in store_list:
- try:
- store_info_dic = {
- 'store_no': store_info['store_no'],
- 'store_name': store_info['store_name'],
- 'brand_name': store_info['brand_name'],
- 'store_id': store_info['store_id'],
- 'store_area_name': store_info['store_area_name'],
- 'store_area_no': store_info['store_area_no'],
- 'brand_id': store_info['brand_id']}
- except:
- store_info_dic = {
- 'store_no': store_info['store_no'],
- 'store_name': store_info['store_name'],
- 'store_id': store_info['store_id']
- }
- try:
- store_info_dic['order_template_name'] = template_dict[store_info['order_template_id']]
- except:
- ...
- try:
- trade_mch_list = store_info['trade_mch_list']
- trade_mch_dict = {}
- for trade_mch_info in trade_mch_list:
- scene = trade_mch_info['scene']
- trade_mch_dict[scene] = trade_mch_info['mch_no']
- store_info_dic.update ( trade_mch_dict )
- except:
- ...
- df_out.append ( store_info_dic )
- df_out = pd.DataFrame ( df_out )
- df_out.to_excel ( downloadPath )
- # 查询费率模板
- def selectServiceRate(app_id, token):
- url = 'https://cloud.xc-fintech.com/split/store/area/template'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- params = {"template_type": 1,
- "app_id": app_id}
- template_dict = {}
- try:
- resp = requests.post ( url, headers = headers, json = params ).json ()['template_list']
- for i in resp:
- name = i['template_name']
- rate = name.split ( '取' )[1].split ( '服' )[0]
- template_dict[i['template_id']] = rate
- except:
- ...
- return template_dict
- # 查询供应商供货管理中的采购价及建议售价,需上传文件(可参考文件uploadGoods.xlsx)
- def selectGoodsPriceInSup(app_id, token, uploadFile, downloadPath):
- # uploadFile = io_path + '/uploadGoods.xlsx'
- df_in = pd.read_excel ( uploadFile, dtype = str )
- n = 0
- df_out = []
- for sup_id in df_in['供应商id']:
- goods_id = df_in.loc[n]['商品id']
- n += 1
- url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/supply_goods/detail'
- json = {"app_id": app_id,
- "sup_id": sup_id,
- "goods_id": goods_id}
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- resp = requests.post ( url, headers = headers, json = json ).json ()['area_price_list']
- for a in resp:
- store_area_id = a['store_area_id']
- try:
- unit = a['sku_price_list'][0]['supply_price_list'][0]['unit']
- supply_price = a['sku_price_list'][0]['supply_price_list'][0]['supply_price']
- except:
- unit = ''
- supply_price = ''
- l = [sup_id, goods_id, store_area_id, unit, supply_price]
- df_out.append ( l )
- df_out = pd.DataFrame ( df_out, columns = ['sup_id', 'goods_id', 'store_area_id', 'unit', 'supply_price'] )
- df_out.to_excel ( downloadPath )
- # 查询下载商品具体信息mode(select【需传入goods_id】,download【需传入uploadFile,downloadPath】)
- def selectGoodsInfoDetail(app_id, token, mode, uploadFile, downloadPath, goods_id):
- if mode == 'download':
- df_in = pd.read_excel ( uploadFile, dtype = str )
- goods_ids = list ( set ( df_in['商品id'] ) )
- df_out = []
- for goods_id in goods_ids:
- df_dict = {}
- url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/' + goods_id
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json = {"app_id": app_id}
- resp = requests.post ( url, headers = headers, json = json ).json ()
- df_dict['商品id'] = goods_id
- df_dict['商品编码'] = resp['goods_no']
- df_dict['商品名称'] = resp['name']
- df_dict['上下架状态'] = resp['publish_state']
- units_info = resp['spu_unit_list']
- n = 1
- for unit_info in units_info:
- if unit_info['is_min_unit']:
- df_dict['最小单位'] = unit_info['unit']
- # df_dict['最小单位换算值'] = unit_info['rela_num']
- else:
- df_dict[f'副单位{n}'] = unit_info['unit']
- df_dict[f'副单位{n}换算值'] = unit_info['rela_num']
- n += 1
- df_out.append ( df_dict )
- df_out = pd.DataFrame ( df_out,
- columns = ['商品id', '商品编码', '商品名称', '上下架状态', '最小单位', '副单位1', '副单位1换算值', '副单位2',
- '副单位2换算值'] )
- df_out.to_excel ( downloadPath )
- elif mode == 'select':
- df_dict = {}
- url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/' + goods_id
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json = {"app_id": app_id}
- resp = requests.post ( url, headers = headers, json = json ).json ()
- df_dict['上下架状态'] = resp['publish_state']
- units_info = resp['spu_unit_list']
- n = 1
- for unit_info in units_info:
- if unit_info['is_min_unit']:
- df_dict['最小单位'] = unit_info['unit']
- df_dict['最小单位开关'] = str ( unit_info['orderable'] )
- else:
- df_dict[f'副单位{n}'] = unit_info['unit']
- df_dict[f'副单位{n}开关'] = str ( unit_info['orderable'] )
- df_dict[f'副单位{n}换算值'] = unit_info['rela_num']
- n += 1
- return df_dict
- def selectGoodsOrderByGoodsOrderId(app_id, token, orderId, goodsInfoDf):
- order_list = []
- sup_list = []
- url = f'https://cloud.xc-fintech.com/api/v1/goods_order/{int ( orderId )}/query'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- json_p = {"app_id": app_id}
- resp = requests.post ( url, headers = headers, json = json_p ).json ()
- try:
- goods_order = resp['goods_order']
- goods_order_id = str ( orderId )
- store_id = goods_order['store_id']
- store_info = selectStoreNoByStoreId ( app_id, token, store_id )
- store_no = str ( store_info['门店编号'] )
- store_name = store_info['门店名称']
- store_brand = store_info['所属品牌']
- store_area_name = goods_order['store_area_name']
- # print(store_area_name)
- receiver = goods_order['receiver']
- receiver_mobile = goods_order['receiver_mobile']
- receiver_address = goods_order['receiver_address']
- try:
- receiver_province_name = goods_order['receiver_province_name']
- receiver_city_name = goods_order['receiver_city_name']
- receiver_district_name = goods_order['receiver_district_name']
- except:
- try:
- area_dict = {'无锡市':'江苏省',
- '盐城市':'江苏省',
- '苏州市':'江苏省',
- '南京市':'江苏省',
- '泰州市':'江苏省',
- '华江':'上海',
- '浦东新区':'上海',
- '青浦区':'上海',
- '奉贤区':'上海',
- '嘉定区':'上海',
- '拉萨市':'西藏自治区',
- '岳阳市':'湖南省'}
- receiver_province_name = area_dict[store_area_name]
- receiver_city_name = ''
- receiver_district_name = ''
- except Exception as e:
- print(e)
- receiver_province_name = receiver_address[:2]
- receiver_city_name = ''
- receiver_district_name = ''
- print ( orderId, receiver_province_name, receiver_address )
- create_time = goods_order['create_time']
- temp_time = str ( int ( parse ( create_time ).timestamp () ) )
- amount = goods_order['amount'] / 100
- goods_order_detail_list = goods_order['goods_order_detail_list']
- for goods_order_detail in goods_order_detail_list:
- goods_id = goods_order_detail['goods_id']
- goods_name = goods_order_detail['goods_name']
- goods_count = goods_order_detail['goods_count']
- unit = goods_order_detail['unit']
- store_unit_amount = goods_order_detail['store_unit_amount'] / 100
- store_total_amount = goods_order_detail['store_total_amount'] / 100
- df_out = goodsInfoDf[goodsInfoDf['商品系统id'] == str ( goods_id )]
- df_out = df_out[df_out['区域名称(1级)'] == str ( receiver_province_name )]
- df_out = pd.DataFrame ( df_out ).to_dict ( 'records' )
- if len ( df_out ) == 1:
- dict_out = df_out[0]
- min_unit = dict_out['最小单位']
- classify_name = dict_out['所属分类']
- goods_no = dict_out['商品编码']
- sup_id = dict_out['供应商id']
- sup_name = dict_out['供应商名称']
- min_sup_sale = dict_out['最小单位采购价']
- sup_sale = dict_out['副单位1采购价']
- send_id = str ( sup_id[:9] ) + temp_time
- if min_unit == unit:
- goods_count_min = goods_count
- sup_sale_out = float ( min_sup_sale )
- sup_unit = unit
- else:
- rela_num = int ( dict_out['副单位1换算值'] )
- sup_sale_out = float ( sup_sale )
- sup_unit = f'{unit}({rela_num}{min_unit})'
- goods_count_min = rela_num * goods_count
- sup_sale_total = float ( sup_sale_out ) * goods_count
- else:
- if goods_name == '运费补差价':
- min_unit = '单'
- classify_name = '运费'
- goods_no = 'P12345'
- sup_id = '4976010005263032320'
- sup_name = '上海餐小白贸易有限公司'
- send_id = str ( sup_id[:9] ) + temp_time
- goods_count_min = goods_count
- sup_sale_out = 0
- sup_sale_total = 0
- sup_unit = '单'
- else:
- min_unit = 'error'
- classify_name = 'error'
- goods_no = 'error'
- sup_id = 'error'
- sup_name = 'error'
- send_id = 'error'
- goods_count_min = 'error'
- sup_sale_out = 'error'
- sup_sale_total = 'error'
- sup_unit = 'error'
- print ( goods_order_id, goods_id, '异常' )
- dict_out_order = {'订货单号': goods_order_id,
- '订货门店编号': store_no,
- '订货门店': store_name,
- '所属区域': store_area_name,
- '加盟商级别': '-',
- '品牌': store_brand,
- '收货人': receiver,
- '收货人电话': receiver_mobile,
- '收货地址': f'{receiver_province_name}/{receiver_city_name}/{receiver_district_name}/{receiver_address}',
- '下单时间': create_time,
- '订货单状态': '-',
- '关闭/完成时间': '-',
- '订货单总金额(包含运费)': amount,
- '商品分类': classify_name,
- '商品编号': goods_no,
- '商品名称': goods_name,
- '商品厂商': '-',
- '规格货号': '-',
- '规格内容': '-',
- '商品单位': unit,
- '商品数量': goods_count,
- '最小单位': min_unit,
- '最小单位数量': goods_count_min,
- '销售单价': store_unit_amount,
- '小计': store_total_amount,
- '退款金额': 0,
- '发货单号': send_id,
- '发货方编号': sup_id,
- '发货方名称': sup_name,
- '发货单状态': '-',
- '运单号': '-',
- '发货时间': '-',
- '签收时间': '-'}
- dict_out_sup = {'订货门店编号': store_no,
- '订货门店名称': store_name,
- '品牌': store_brand,
- '所属省市区': f'{receiver_province_name}{receiver_city_name}{receiver_district_name}',
- '发货单号': send_id,
- '订货单号': goods_order_id,
- '发货方': sup_name,
- '发货单金额': '-',
- '结算金额': '-',
- '服务费': '-',
- '交易手续费': '-',
- '通道手续费': '-',
- '发货单状态': '-',
- '创建时间': create_time,
- '下单时间': create_time,
- '发货时间': '-',
- '签收时间': '-',
- '商品分类': classify_name,
- '商品编号': goods_no,
- '商品名称': goods_name,
- '商品厂商': '-',
- '货号': '-',
- '规格': '-',
- '数量': goods_count,
- '订货单价': store_unit_amount,
- '订货小计': store_total_amount,
- '采购单价': sup_sale_out,
- '采购小计': sup_sale_total,
- '单位': sup_unit,
- '收货人': receiver,
- '收货人电话': receiver_mobile,
- '收货地址': f'{receiver_province_name}/{receiver_city_name}/{receiver_district_name}/{receiver_address}',
- }
- order_list.append ( dict_out_order )
- sup_list.append ( dict_out_sup )
- except:
- print ( orderId, json.dumps ( resp, ensure_ascii = False ) )
- return order_list, sup_list
- def readExcelByPd(upLoadFilePath):
- df_in = pd.read_excel ( upLoadFilePath, dtype = str )
- # receiver_province_name = '江苏省'
- # goods_id = '4993092771502759936'
- # df_out = df_in[df_in['商品系统id']==str(goods_id)]
- # df_out = df_out[df_out['区域名称(1级)']==str(receiver_province_name)]
- # df_out = pd.DataFrame(df_out).to_dict('records')
- # if len(df_out) == 1:
- # dict_out = df_out[0]
- # print(dict_out)
- return df_in
- def selectGoodsOrderByGoodsOrderIds(app_id, token, outDfPath, upLoadFile_goods, upLoadFile_orderids):
- goodsInfoDf = readExcelByPd ( upLoadFile_goods )
- orderidsDF = readExcelByPd ( upLoadFile_orderids )
- orderIds = list ( set ( orderidsDF['订货单号'] ) )
- order_df_out = []
- sup_df_out = []
- for orderId in orderIds:
- order_list, sup_list = selectGoodsOrderByGoodsOrderId ( app_id, token, orderId, goodsInfoDf )
- order_df_out = order_df_out + order_list
- sup_df_out = sup_df_out + sup_list
- order_df_out = pd.DataFrame ( order_df_out )
- sup_df_out = pd.DataFrame ( sup_df_out )
- writer = pd.ExcelWriter ( outDfPath )
- orderidsDF.to_excel ( writer, sheet_name = '查询订货单号', columns = ['订货单号'], index = False )
- order_df_out.to_excel ( writer, sheet_name = '订货单', index = False )
- sup_df_out.to_excel ( writer, sheet_name = '发货单', index = False )
- writer.save ()
- # 创建发货单下载请求 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- def createInvoiceDownload(app_id, token, start_date, end_date, mode='pay'):
- '''
- mode参数
- 'pay'指定为下单时间
- 'supplier_split'指定为供应商预结算时间
- '''
- url = 'https://cloud.xc-fintech.com/api/v1/file/create'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- params = {"download_file_type": 40,
- "sale_type_list": [1, 2, 3, 5, 6],
- f"start_{mode}_time": f"{start_date} 00:00:00",
- f"end_{mode}_time": f"{end_date} 23:59:59",
- "app_id": app_id}
- resp = requests.post ( url, json = params, headers = headers ).text
- log_time = datetime.now ().strftime ( '%Y-%m-%d %H:%M:%S' )
- print ( log_time, len ( resp ) )
- # 查询发货单下载列表,循环检查 发货单是否可以进行下载
- def selectInvoiceDownloadList(app_id, token) -> str:
- '''
- 【返回值】为 task_id -> str
- '''
- url = 'https://cloud.xc-fintech.com/api/v1/file/buffer_area/list'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token}
- params = {"file_type": 40,
- "current_page": 1,
- "page_size": 5,
- "app_id": app_id}
- a = 2
- n = 0
- task_ids = []
- while a == 2 and n <= 10:
- try:
- resp = requests.post(url, json = params, headers = headers, timeout = 2)
- resp_json = resp.json ()
- task_list = resp_json['task_list']
- handle_status = task_list[0]['handle_status']
- task_id = task_list[0]['task_id']
- task_ids.append ( task_id )
- a = handle_status
- time.sleep(10)
- except:
- resp.close ()
- time.sleep (10)
- a = 2
- n += 1
- print(n,end ='-')
- return task_ids[0]
- # 下载发货单
- def invoiceDownload(app_id, token, task_id, save_path, start_date, end_date, mode = 'pay') -> str:
- '''
- 【save_path参数】例:'C:/Users/ClownHe/Desktop/店务通数据'
- 【mode参数】'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- 【返回值】为 df_path -> str格式
- '''
- url = 'https://cloud.xc-fintech.com/api/v1/file/download'
- headers = {
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
- 'Authorization': token,
- 'Accept':'application/json, text/plain, */*',
- 'Accept-Encoding':'gzip, deflate, br'}
- params = {"task_id":task_id,
- "app_id":app_id,
- "token":token}
- df_data = requests.post(url,headers=headers,json=params).content
- with open(save_path + f'/{start_date}至{end_date}发货单({mode}).xlsx', mode = 'wb') as f:
- f.write(df_data)
- print(f'【已下载】{start_date}至{end_date}发货单({mode}).xlsx')
- df_path = save_path + f'/{start_date}至{end_date}发货单({mode}).xlsx'
- return df_path
- # 运行发货单下载 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- def runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode = 'pay') -> str:
- '''
- 【save_path参数】例:'C:/Users/ClownHe/Desktop/店务通数据'
- 【mode参数】'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- 【返回值】为 df_path -> str格式
- '''
- createInvoiceDownload(app_id, token, start_date, end_date, mode)
- time.sleep(0.5)
- task_id = selectInvoiceDownloadList(app_id, token)
- print(task_id)
- df_path = invoiceDownload(app_id, token, task_id, save_path, start_date, end_date, mode)
- print(df_path)
- if 1==1:
- dfFormatting(df_path)
- return df_path
- def dfFormatting(df_in_path):
- df_in = pd.read_excel(df_in_path)
- df_in['一级区域'] = df_in['一级区域'].fillna('')
- df_in['二级区域'] = df_in['二级区域'].fillna('')
- df_in['三级区域'] = df_in['三级区域'].fillna('')
- df_in['所属省市区'] = df_in['一级区域'] + df_in['二级区域'] + df_in['三级区域']
- df_in['商品分类'] = df_in['二级分类'].fillna(df_in['一级分类'])
- df_in['发货单号'] = df_in['发货单号'].astype(str)
- df_in['订货单号'] = df_in['订货单号'].astype(str)
- # print(df_in.info())
- df_out = df_in[
- ['订货门店编号', '订货门店名称', '品牌', '所属省市区', '发货单号', '订货单号', '发货方', '发货单金额', '结算金额', '服务费', '交易手续费', '通道手续费', '发货单状态',
- '创建时间', '下单时间', '发货时间', '签收时间', '商品分类', '商品编号', '商品名称', '商品厂商', '货号', '规格', '数量', '订货单价', '订货小计', '采购单价',
- '采购小计', '单位', '收货人', '收货人电话', '收货地址']]
- df_out.to_excel(df_in_path,index = False)
- if __name__ == '__main__':
- if 1==1:
- app_id, token = getToken ()
- print ( app_id, token )
- # app_id = '7005337094168150016'
- # token ='20230207-bff9c872aa2842d2b03f75e25bfb37a0'
- goods_no = 'P4464051565'
- io_path = 'C:/Users/ClownHe/Desktop/店务通数据'
- if 1 == 0:
- # 获取商品上下架状态及商品id
- publish_state, goods_id = selectGoodsInfoPubAndId ( app_id, token, goods_no )
- # 操作商品上下架,并返回操作结果
- return_result = updatePublishState ( app_id, token, publish_state, goods_id )
- if return_result:
- print ( '已完成操作' )
- readUploadFile ( 'uploadfileForSupArea.xlsx' )
- selectSupplierlist ( app_id, token, 'download' )
- selectAllGoodsInfo ( app_id, token, 'download' )
- selectAreaTree ( app_id, token )
- updateSuppliersAreaInfo ( app_id, token, 'uploadfileForSupArea.xlsx' )
- # 以下两步操作,导出供应商在供商品
- selectSupplierlist = selectSupplierlist ( app_id, token, 'select' )
- goodsInSupplierList ( app_id, token, selectSupplierlist, 'download' )
- publish_state, goods_id = selectGoodsInfoPubAndId ( app_id, token, goods_no )
- print ( publish_state, goods_id )
- addGoodsToSupplierSupList ( app_id, token, io_path + '/addGoodsToSupplierSupList.xlsx' )
- selectSupplierlist = selectSupplierlist ( app_id, token, 'select' )
- goodsInSupplierList ( app_id, token, selectSupplierlist, 'download' )
- updateGoodsAreaSupplierPrice ( app_id, token, io_path + '/updateGoodsAreaSupplierPrice.xlsx' )
- goodsInGoodsCentre ( app_id, token, io_path )
- selectGoodsInfoDetail ( app_id, token, io_path + '/selectGoodsInfoDetailUP.xlsx',
- io_path + '/selectGoodsInfoDetail.xlsx' )
- updateGoodsSupStatus ( app_id, token, io_path + '/updateGoodsSupStatus-模板.xlsx' )
- updateGoodsPriceInGoodsInfoCentre ( app_id, token, io_path + '/updateGoodsPriceInGoodsInfoCentre.xlsx' )
- selectAllGoodsInfoInDetailPrice ( app_id, token, io_path + '/selectAllGoodsInfoInDetailPrice.xlsx' )
- updateGoodsAreaSupplierPrice ( app_id, token, io_path + '/updateGoodsAreaSupplierPrice.xlsx' )
- selectAllStoreInfo ( app_id, token, io_path + '/selectAllStoreInfo.xlsx' )
- selectAllGoodsInfoInDetailPrice ( app_id, token,
- io_path + '/selectAllGoodsInfoInDetailPrice(20230524.9.57).xlsx' )
- goodsInGoodsCentre ( app_id, token, io_path )
- # 以下三步完成单品绑定供应商,变更供货,实现价格更新
- addGoodsToSupplierSupList ( app_id, token, io_path + '/addGoodsToSupplierSupList.xlsx' )
- updateGoodsSupStatus ( app_id, token, io_path + '/updateGoodsSupStatus.xlsx' )
- updateGoodsAreaSupplierPrice ( app_id, token, io_path + '/updateGoodsAreaSupplierPrice.xlsx' )
- readExcelByPd ( io_path + '/selectAllGoodsInfoInDetailPrice(20230524.9.57).xlsx' )
- # 按 订货单号 查询订单信息 及发货信息
- upLoadFile_goods = '/selectAllGoodsInfoInDetailPrice(20230524.13.00).xlsx'
- upLoadFile_orderids = '/订货单号查询(截至2023-05-24 12-10-02).xlsx'
- selectGoodsOrderByGoodsOrderIds ( app_id, token,
- io_path + '/selectGoodsOrderByGoodsOrderIds.xlsx',
- io_path + upLoadFile_goods,
- io_path + upLoadFile_orderids )
- selectSupplierlist = [{'供应商id': '7036927150058246144', '供应商全名': '上海炳优实业有限公司', '简称': ''}]
- goodsInSupplierList ( app_id, token, selectSupplierlist, 'download' )
- for i in [0, 1, 2, 3]:
- updateGoodsAreaSupplierPrice ( app_id, token, io_path + f'/updateGoodsAreaSupplierPrice{i}.xlsx' )
- time.sleep ( 4 )
- # 运行发货单下载 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- start_date = '2023-10-01'
- end_date = '2023-10-27'
- mode = 'supplier_split' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- save_path = io_path
- runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
- if 1==0:
- goodsInGoodsCentre(app_id, token, io_path)
- if 1==0:
- updateGoodsInGoodsCentreSUPshops(app_id, token, io_path + '/updateGoodsInGoodsCentreSUPshops.xlsx')
- if 1==1:
- # 操作区
- # 运行发货单下载 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- start_date = '2024-03-01'
- end_date = '2024-03-31'
- mode = 'supplier_split' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- save_path = io_path
- runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
- start_date = '2024-04-01'
- end_date = '2024-04-05'
- mode = 'supplier_split' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间 11
- save_path = io_path
- runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
- start_date = '2024-03-30'
- end_date = '2024-04-05'
- mode = 'supplier_split' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- save_path = io_path
- runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
- start_date = '2024-03-01'
- end_date = '2024-03-31'
- mode = 'pay' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- save_path = io_path
- runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
- start_date = '2024-04-01'
- end_date = '2024-04-05'
- mode = 'pay' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- save_path = io_path
- runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
- # upLoadFile_goods = '/selectAllGoodsInfoInDetailPrice(20231012.16.50).xlsx'
- # upLoadFile_orderids = '/活动赠送产品订单查询10.12v1.xlsx'
- # selectGoodsOrderByGoodsOrderIds(app_id, token,
- # io_path + '/selectGoodsOrderByGoodsOrderIds(赠品)1.xlsx',
- # io_path + upLoadFile_goods,
- # io_path + upLoadFile_orderids)
- # beginTime_int = int ((datetime.today () + timedelta (days=-1)).strftime ('%Y%m%d')) # 20220623
- # endTime_int = int ((datetime.today () + timedelta (days=-1)).strftime ('%Y%m%d')) # 20220623
- # beginTime_temp = parse (str(beginTime_int)).timestamp ()
- # endTime_temp = parse (str(beginTime_int)).timestamp ()
- # endTime_temp = int(time.time()*1000)
- # print(endTime_temp)
- if 1 == 0:
- # 批量上下架产品
- df_in = pd.read_excel ( io_path + '/updatePublishStateBatch.xlsx', dtype = str )
- goods_id_list = list ( set ( df_in['商品id'] ) )
- for goods_id in goods_id_list:
- result = updatePublishState ( app_id, token, 0, goods_id )
- print ( goods_id, result )
- if 1==0:
- df_path = r'C:\Users\ClownHe\Desktop\店务通数据\2024-03-01至2024-03-31发货单(pay).xlsx'
- df_in = pd.read_excel(df_path)
- col = list(df_in.columns)
- print(col)
|