12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045 |
- # -*- 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:
- a = {'is_min_unit': True,
- 'unit': area_price['最小单位'],
- 'suggested_order_price': area_price['最小单位售价'] * 100,
- 'supply_price': area_price['最小单位采购价'] * 100}
- b = {'is_min_unit': False,
- 'unit': area_price['副单位'],
- 'suggested_order_price': area_price['副单位售价'] * 100,
- 'supply_price': area_price['副单位采购价'] * 100}
- supply_price_list.append ( a )
- supply_price_list.append ( b )
- else:
- 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':
- a = {'is_min_unit': True,
- 'unit': sup_info['最小单位'],
- 'actual_amount': int ( sup_info['最小单位售价'] * 100 )}
- b = {'is_min_unit': False,
- 'unit': sup_info['副单位'],
- 'actual_amount': int ( sup_info['副单位售价'] * 100 )}
- unit_price_list.append ( a )
- unit_price_list.append ( b )
- else:
- 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':
- a = {'is_min_unit': True,
- 'unit': sup_info['最小单位'],
- 'actual_amount': int ( sup_info['最小单位售价'] * 100 )}
- b = {'is_min_unit': False,
- 'unit': sup_info['副单位'],
- 'actual_amount': int ( sup_info['副单位售价'] * 100 )}
- unit_price_list.append ( a )
- unit_price_list.append ( b )
- else:
- 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 ()
- 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:
- 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],
- 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)
- return df_path
- if __name__ == '__main__':
- 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==1:
- # 操作区
- # 运行发货单下载 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- start_date = '2024-02-01'
- end_date = '2024-02-29'
- 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-01'
- 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-02-24'
- end_date = '2024-03-01'
- 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-01'
- mode = 'pay' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
- save_path = io_path
- runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
- # start_date = '2023-12-01'
- # end_date = '2023-12-01'
- # 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 )
|