demo_20221026.py 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080
  1. # -*- codeing = utf-8 -*-
  2. # @Time : 2022/10/26 12:26
  3. # @Author : Clown
  4. # @File : demo_20221026.py
  5. # @Software : PyCharm
  6. import re
  7. import pandas as pd
  8. import hashlib
  9. import requests
  10. import json
  11. import math
  12. from dateutil.parser import parse
  13. import time
  14. import random
  15. from datetime import datetime, timedelta
  16. # 登录
  17. def getToken():
  18. url = 'https://cloud.xc-fintech.com/api/v1/login'
  19. headers = {
  20. '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'}
  21. json_params = {"employee_relation_id": "7008629262119084032"}
  22. resp = requests.post ( url, headers = headers, json = json_params ).json ()
  23. print ( json.dumps ( resp, ensure_ascii = False ) )
  24. return resp['app_id'], resp['token']
  25. # 下载或查询【订货商品】页面商品信息 mode:download下载 select查询
  26. # 信息包含【商品系统id,商品编码,商品名称,所属分类,是否有图,定价模式】
  27. def selectAllGoodsInfo(app_id, token, mode):
  28. # mode:download下载 select查询
  29. df_out = []
  30. url = 'https://cloud.xc-fintech.com/api/v1/good_centre/goods'
  31. headers = {
  32. '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',
  33. 'Authorization': token}
  34. page_size = 10
  35. total_count = 100
  36. current_page = 1
  37. while page_size * current_page - total_count < 0:
  38. # time.sleep(random.uniform(1,2))
  39. try:
  40. json_params = {"app_id": app_id,
  41. "sell_type": "2",
  42. "create_time_order": "desc",
  43. "current_page": current_page,
  44. "page_size": page_size}
  45. proxies = {'http': None, 'https': None}
  46. resp1 = requests.post ( url, headers = headers, json = json_params, proxies = proxies )
  47. resp = resp1.json ()
  48. current_page += 1
  49. for good_info in resp['detail']:
  50. good_info_dict = {}
  51. good_info_dict['商品系统id'] = good_info['goods_id']
  52. good_info_dict['商品编码'] = good_info['goods_no']
  53. good_info_dict['商品名称'] = good_info['goods_name']
  54. good_info_dict['所属分类'] = good_info['classify_name']
  55. good_info_dict['是否有图'] = f"有{len ( good_info['pic_show_url'] )}张图"
  56. if good_info['price_mode'] == 2:
  57. good_info_dict['定价模式'] = '分区定价'
  58. elif good_info['price_mode'] == 1:
  59. good_info_dict['定价模式'] = '统一定价'
  60. publish_state = {'1': '上架', '0': '下架'}
  61. good_info_dict['上下架状态'] = publish_state[str ( good_info['publish_state'] )]
  62. df_out.append ( good_info_dict )
  63. total_count = resp['total_count']
  64. if current_page % 5 == 0:
  65. time.sleep ( random.uniform ( 1, 4 ) )
  66. print ( f'\r当前已下载第{current_page}页', end = '' )
  67. except:
  68. resp1.close ()
  69. time.sleep ( 2 )
  70. if mode == 'download':
  71. excel_out = pd.DataFrame ( df_out )
  72. excel_out.to_excel ( 'selectAllGoodsInfo.xlsx', index = False )
  73. elif mode == 'select':
  74. return df_out
  75. # 下载【订货商品】【定价】页面售价,采购价,限购量信息
  76. def selectAllGoodsInfoInDetailPrice(app_id, token, downloadPath):
  77. df_in = selectAllGoodsInfo ( app_id, token, 'select' )
  78. time.sleep ( random.uniform ( 1, 3 ) )
  79. cnt_all = len ( df_in )
  80. print ( f'已完成df_in执行,共计商品{cnt_all}个' )
  81. df_out = []
  82. cnt = 1
  83. for goods_info in df_in:
  84. goods_id = goods_info['商品系统id']
  85. a = 0
  86. while a == 0:
  87. try:
  88. goods_units_info = selectGoodsInfoDetail ( app_id, token, 'select', '', '', goods_id )
  89. goods_info.update ( goods_units_info )
  90. # print('goods_info.update')
  91. # 获取商品区域售价
  92. url_goods_price = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/query'
  93. headers = {
  94. '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',
  95. 'Authorization': token,
  96. 'Content-Type': 'application/json; charset=UTF-8'}
  97. json_goods_price = {"subscribe_type": "1",
  98. "goods_id": goods_id,
  99. "app_id": app_id}
  100. proxies = {'http': None, 'https': None}
  101. resp_goods_price_0 = requests.post ( url_goods_price, headers = headers, json = json_goods_price,
  102. proxies = proxies, timeout = 3 )
  103. resp_goods_price = resp_goods_price_0.json ()
  104. if goods_info['定价模式'] == '分区定价':
  105. for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
  106. dict_l1 = {}
  107. store_area_id = area_price_1['store_area_id']
  108. store_area_name = area_price_1['store_area_name']
  109. dict_l1['区域id'] = store_area_id
  110. dict_l1['区域名称(1级)'] = store_area_name
  111. try:
  112. # 供应商你信息
  113. dict_l1['供应商id'] = area_price_1['sup_id']
  114. dict_l1['供应商名称'] = area_price_1['sup_name']
  115. # 起订限订量
  116. dict_l1['起订量'] = area_price_1['spu_order_price']['buy_limit_min']
  117. try:
  118. dict_l1['限订量'] = area_price_1['spu_order_price']['buy_limit_max']
  119. except:
  120. dict_l1['限订量'] = ''
  121. # 单位对应采购价
  122. supply_price_list1 = area_price_1['supply_price_list']
  123. m = 1
  124. min_unit = ''
  125. for supply_price in supply_price_list1:
  126. if supply_price['is_min_unit']:
  127. dict_l1['最小单位采购价'] = int ( supply_price['supply_price_desc']['min'] ) / 100
  128. min_unit = supply_price['unit']
  129. else:
  130. dict_l1[f'副单位{m}采购价'] = int ( supply_price['supply_price_desc']['min'] ) / 100
  131. m += 1
  132. # 单位对应售价
  133. unit_price_list1 = area_price_1['spu_order_price']['unit_price_list']
  134. n = 1
  135. for unit_price in unit_price_list1:
  136. if unit_price['is_min_unit'] and unit_price['unit'] == min_unit:
  137. dict_l1['最小单位售价'] = int ( unit_price['actual_amount'] ) / 100
  138. else:
  139. dict_l1[f'副单位{n}售价'] = int ( unit_price['actual_amount'] ) / 100
  140. n += 1
  141. except:
  142. ...
  143. dict_l1.update ( goods_info )
  144. df_out.append ( dict_l1 )
  145. else:
  146. df_out.append ( goods_info )
  147. a = 1
  148. except:
  149. resp_goods_price_0.close ()
  150. a = 0
  151. time.sleep ( 2 )
  152. print ( 'mark' )
  153. print ( f'\r已完成{cnt}个产品下载,完成进度{int ( cnt / cnt_all * 100 )}%', end = '' )
  154. cnt += 1
  155. if cnt % 5 == 0:
  156. time.sleep ( random.uniform ( 0.5, 2.5 ) )
  157. if cnt % 100 == 0:
  158. time.sleep ( random.uniform ( 10, 15 ) )
  159. # columns = ['商品系统id','商品编码','商品名称','所属分类','是否有图','定价模式',]
  160. df_out = pd.DataFrame ( df_out )
  161. df_out.to_excel ( downloadPath, index = False )
  162. # 查询商品goods_no:为商品编码,返回上下架状态publish_state,及goods_id系统内商品id
  163. def selectGoodsInfoPubAndId(app_id, token, goods_no):
  164. # goods_no = "P9265021186"
  165. url = 'https://cloud.xc-fintech.com/api/v1/good_centre/goods'
  166. headers = {
  167. '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',
  168. 'Authorization': token}
  169. json_params = {"app_id": app_id,
  170. "sell_type": "2",
  171. "goods_no": goods_no,
  172. "create_time_order": "desc",
  173. "current_page": 1,
  174. "page_size": 10}
  175. resp = requests.post ( url, headers = headers, json = json_params ).json ()
  176. # print (json.dumps (resp, ensure_ascii=False))
  177. publish_state = resp['detail'][0]['publish_state']
  178. publish_state_dict = {'1': '上架', '0': '下架'}
  179. publish_state_info = publish_state_dict[str ( publish_state )]
  180. # print(publish_state_info)
  181. return publish_state, resp['detail'][0]['goods_id']
  182. # 【单品上下架】操作,【publish_state:0上架,1下架】
  183. def updatePublishState(app_id, token, publish_state, goods_id):
  184. on_off_dict = {'1': 'off_shelf',
  185. '0': 'on_shelf'}
  186. turn_on_off = on_off_dict[str ( publish_state )]
  187. url = f'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/{turn_on_off}'
  188. headers = {
  189. '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',
  190. 'Authorization': token}
  191. json_params = {"app_id": app_id,
  192. "goods_id": goods_id}
  193. resp = requests.post ( url, headers = headers, json = json_params ).json ()
  194. return_result = resp['goods_id'] = goods_id
  195. return return_result
  196. # 【批量上下架】操作,【publish_state:0上架,1下架】goods_id_list:是列表
  197. def updatePublishStateBatch(app_id, token, publish_state, goods_id_list):
  198. on_off_dict = {'1': 'batch_off_shelf',
  199. '0': 'batch_on_shelf'}
  200. turn_on_off = on_off_dict[str ( publish_state )]
  201. url = f'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/{turn_on_off}'
  202. headers = {
  203. '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',
  204. 'Authorization': token}
  205. json_params = {"app_id": app_id,
  206. "goods_id_list": goods_id_list}
  207. resp = requests.post ( url, headers = headers, json = json_params ).json ()
  208. print ( resp )
  209. return_result = resp['message'] = '操作成功'
  210. return return_result
  211. # 下载或查询供应商列表 mode:download下载 select查询 查询返回列表格式[{'供应商id':'xxxx', '供应商全名':'xxxxx', '简称':'xxxx'}]
  212. def selectSupplierlist(app_id, token, mode):
  213. url = 'https://cloud.xc-fintech.com/api/v1/supplier/query'
  214. headers = {
  215. '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',
  216. 'Authorization': token}
  217. page_size = 10
  218. total_count = 10
  219. current_page = 0
  220. df_out = []
  221. while page_size * current_page - total_count < 0:
  222. current_page += 1
  223. json_params = {"type": 1,
  224. "app_id": app_id,
  225. "current_page": current_page,
  226. "page_size": page_size}
  227. resp = requests.post ( url, headers = headers, json = json_params ).json ()
  228. total_count = resp['total_count']
  229. for sup_info in resp['detail']:
  230. sup_info_dict = {}
  231. sup_info_dict['供应商id'] = sup_info['supplier_id']
  232. sup_info_dict['供应商全名'] = sup_info['sup_name']
  233. sup_info_dict['供应商编号'] = sup_info['sup_no']
  234. try:
  235. sup_info_dict['简称'] = sup_info['remark']
  236. except:
  237. sup_info_dict['简称'] = ''
  238. df_out.append ( sup_info_dict )
  239. # print(json.dumps(resp,ensure_ascii=False))
  240. if mode == 'download':
  241. excel_out = pd.DataFrame ( df_out )
  242. excel_out.to_excel ( 'SupplierInfoList.xlsx', sheet_name = 'sheet1' )
  243. elif mode == 'select':
  244. return df_out
  245. # 获取【区域管理】层级树返回selectAreaTree1.xlsx文件
  246. def selectAreaTree(app_id, token):
  247. url = 'https://cloud.xc-fintech.com/split/store/area/tree'
  248. headers = {
  249. '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',
  250. 'Authorization': token}
  251. json_params = {"parent_id": "0",
  252. "app_id": app_id}
  253. resp = requests.post ( url, headers = headers, json = json_params ).json ()['tree'][0]
  254. df_out = []
  255. for children1 in resp['children']:
  256. # 省
  257. level1 = {}
  258. level1['父级id'] = children1['id']
  259. level1['父级名称'] = children1['name']
  260. # 市
  261. childrens2 = children1['children']
  262. level0 = {'子级id': children1['id'],
  263. '子级名称': children1['name'],
  264. '父级id2': children1['id']}
  265. level0.update ( level1 )
  266. df_out.append ( level0 )
  267. if len ( childrens2 ) > 0:
  268. for children2 in childrens2:
  269. level2 = {}
  270. level2['子级id'] = children2['id']
  271. level2['子级名称'] = children2['name']
  272. level2['父级id2'] = children2['parentId']
  273. parentId = children2['parentId']
  274. level2.update ( level1 )
  275. df_out.append ( level2 )
  276. childrens3 = children2['children']
  277. if len ( childrens3 ) > 0:
  278. for children3 in childrens3:
  279. level3 = {}
  280. level3['子级id'] = children3['id']
  281. level3['子级名称'] = children3['name']
  282. level3['父级id2'] = parentId
  283. level3.update ( level1 )
  284. df_out.append ( level3 )
  285. excel_out = pd.DataFrame ( df_out )
  286. excel_out.to_excel ( 'selectAreaTree1.xlsx', sheet_name = 'sheet1' )
  287. # 【单个更新】供应商供货区域
  288. def updateSupplierAreaInfo(app_id, token, supUploadInfoDict):
  289. sup_id = supUploadInfoDict['sup_id'] # 供应商id
  290. store_area_id_list = supUploadInfoDict['store_area_id_list'] # 供应商服务区域对应id(全域)
  291. url = 'https://cloud.xc-fintech.com/api/v1/supplier/area/save'
  292. headers = {
  293. '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',
  294. 'Authorization': token}
  295. json_params = {'app_id': app_id,
  296. 'sup_id': sup_id,
  297. 'store_area_id_list': store_area_id_list}
  298. resp = requests.post ( url, headers = headers, json = json_params ).json ()
  299. return_result = resp['sup_id'] = sup_id
  300. return return_result
  301. # 读取供应商供货区域导入表
  302. def readUploadFile(uploadFile):
  303. df_in = pd.read_excel ( uploadFile, dtype = str )
  304. sup_ids = list ( df_in['供应商id'] )
  305. sup_ids = list ( set ( sup_ids ) )
  306. waite_list = []
  307. for sup_id in sup_ids:
  308. sup_info_dict = {}
  309. sup_info_dict['sup_id'] = sup_id
  310. store_area_id_list = list ( df_in[df_in['供应商id'] == sup_id]['供货区域'] )
  311. sup_info_dict['store_area_id_list'] = store_area_id_list
  312. waite_list.append ( sup_info_dict )
  313. # for i in waite_list:
  314. # print(i)
  315. return waite_list
  316. # 【批量更新】供应商供货区域
  317. def updateSuppliersAreaInfo(app_id, token, uploadFile):
  318. waite_list = readUploadFile ( uploadFile )
  319. error_cnt = 0
  320. error_list = []
  321. for supUploadInfoDict in waite_list:
  322. return_result = updateSupplierAreaInfo ( app_id, token, supUploadInfoDict )
  323. if return_result:
  324. ...
  325. else:
  326. error_list.append ( supUploadInfoDict['sup_id'] )
  327. error_cnt += 1
  328. if error_cnt == 0:
  329. print ( 'all Down' )
  330. else:
  331. print ( 'error_list:', error_list )
  332. # 供应商供货清单
  333. def goodsInSupplierList(app_id, token, selectSupplierlist, mode):
  334. url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/supply_goods/freight/template/query'
  335. headers = {
  336. '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',
  337. 'Authorization': token}
  338. df_out = []
  339. for supplierInfo in selectSupplierlist:
  340. supplierId = supplierInfo['供应商id']
  341. try:
  342. supplierName = supplierInfo['供应商全名']
  343. except:
  344. supplierName = ''
  345. page_size = 40
  346. total_count = 40
  347. current_page = 0
  348. while page_size * current_page - total_count < 0:
  349. current_page += 1
  350. json_params = {"sup_id": supplierId,
  351. "app_id": app_id,
  352. "current_page": current_page,
  353. "page_size": page_size}
  354. resp = requests.post ( url, headers = headers, json = json_params ).json ()
  355. total_count = resp['total_count']
  356. if total_count == 0:
  357. good_info_dict = {}
  358. good_info_dict['供应商id'] = supplierId
  359. good_info_dict['供应商全名'] = supplierName
  360. good_info_dict['商品系统id'] = ''
  361. good_info_dict['商品编码'] = ''
  362. good_info_dict['商品名称'] = ''
  363. good_info_dict['最小单位'] = ''
  364. df_out.append ( good_info_dict )
  365. else:
  366. for good_info in resp['goods_list']:
  367. good_info_dict = {}
  368. good_info_dict['供应商id'] = supplierId
  369. good_info_dict['供应商全名'] = supplierName
  370. good_info_dict['商品系统id'] = good_info['goods_id']
  371. good_info_dict['商品编码'] = good_info['goods_no']
  372. good_info_dict['商品名称'] = good_info['goods_name']
  373. spu_unit_list = good_info['spu_unit_list']
  374. try:
  375. for unit_info in spu_unit_list:
  376. if unit_info['is_min_unit']:
  377. good_info_dict['最小单位'] = unit_info['unit']
  378. else:
  379. good_info_dict['副单位'] = unit_info['unit']
  380. except:
  381. good_info_dict['最小单位'] = '无最小单位'
  382. df_out.append ( good_info_dict )
  383. excel_out = pd.DataFrame ( df_out )
  384. if mode == 'download':
  385. excel_out.to_excel ( 'goodsInSupplierList.xlsx', sheet_name = 'sheet1' )
  386. print ( 'all Down' )
  387. elif mode == 'select':
  388. goods_in_suped = list ( excel_out['商品系统id'] )
  389. print ( goods_in_suped )
  390. return goods_in_suped
  391. # 【批量更新】供应商供货管理中供货列表
  392. def addGoodsToSupplierSupList(app_id, token, uploadFile):
  393. url = 'https://cloud.xc-fintech.com/api/v1/supplier/sup_goods/batch_establish'
  394. headers = {
  395. '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',
  396. 'Authorization': token}
  397. df_in = pd.read_excel ( uploadFile, dtype = str )
  398. sup_ids = list ( df_in['供应商id'] )
  399. sup_ids = list ( set ( sup_ids ) )
  400. # waite_list = []
  401. for sup_id in sup_ids:
  402. goods_in_suped = goodsInSupplierList ( app_id, token, [{'供应商id': sup_id}], 'select' )
  403. sup_info_dict = {}
  404. sup_info_dict['supplier_id'] = sup_id
  405. goods_in_sup = list ( df_in[df_in['供应商id'] == sup_id]['供货商品'] )
  406. goods_in_sup = list ( set ( goods_in_sup ).difference ( set ( goods_in_suped ) ) )
  407. sup_info_dict['goods_list'] = goods_in_sup
  408. sup_info_dict['app_id'] = app_id
  409. if 1 == 1:
  410. if len ( goods_in_sup ) > 0:
  411. resp = requests.post ( url, headers = headers, json = sup_info_dict ).json ()['message']
  412. if resp == '操作成功':
  413. print ( sup_id, '\033[1;32m 新增商品成功 \033[0m' )
  414. else:
  415. print ( resp )
  416. print ( sup_id, '\033[1;31m 新增商品失败 \033[0m' )
  417. else:
  418. print ( sup_id, '\033[1;33m 无有效商品需更新 \033[0m' )
  419. # print(goods_in_sup)
  420. # 【批量更新】供应商供货管理中商品供货【1】或缺货【2】
  421. def updateGoodsSupStatus(app_id, token, uploadFile):
  422. df_in = pd.read_excel ( uploadFile, dtype = str )
  423. n = 0
  424. for supplier_id in df_in['供应商id']:
  425. info = df_in.loc[n]
  426. goods_id = info['商品id']
  427. status = info['供缺货操作']
  428. n += 1
  429. url = 'https://cloud.xc-fintech.com/api/v1/supplier/sup_goods/status/set'
  430. json_params = {"supplier_id": str ( supplier_id ),
  431. "goods_id": str ( goods_id ),
  432. "status": int ( status ),
  433. "app_id": app_id}
  434. headers = {
  435. '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',
  436. 'Authorization': token,
  437. 'Content-Type': 'application/json; charset=UTF-8'}
  438. resp = requests.post ( url, headers = headers, json = json_params ).text
  439. print ( resp )
  440. # 【批量更新】供应商供货管理中 区域商品建议售价及采购价 (仅需要输入需要更新的区域,如需清除区域定价,直接输入0,并在【订货商品】页面进行不供货设置
  441. def updateGoodsAreaSupplierPrice(app_id, token, uploadFile):
  442. updateSingleGoodsPriceInGoodsInfoCentre ( app_id, token, uploadFile, 0 )
  443. df_in = pd.read_excel ( uploadFile )
  444. sup_ids = list ( set ( df_in['供应商id'] ) )
  445. # print(sup_ids)
  446. for sup_id in sup_ids:
  447. goods_ids_l = df_in[df_in['供应商id'] == sup_id]
  448. goods_ids = list ( set ( goods_ids_l['商品id'] ) )
  449. # print(goods_ids)
  450. for goods_id in goods_ids:
  451. area_prices = goods_ids_l[goods_ids_l['商品id'] == goods_id]
  452. area_prices = area_prices.to_dict ( 'records' )
  453. area_prices_dict = {}
  454. for area_price in area_prices:
  455. supply_price_list = []
  456. if area_price['副单位'] is not None:
  457. b = {'is_min_unit': False,
  458. 'unit': area_price['副单位'],
  459. 'suggested_order_price': area_price['副单位售价'] * 100,
  460. 'supply_price': area_price['副单位采购价'] * 100}
  461. supply_price_list.append ( b )
  462. if area_price['副单位1'] is not None:
  463. c = {'is_min_unit': False,
  464. 'unit': area_price['副单位1'],
  465. 'suggested_order_price': area_price['副单位1售价'] * 100,
  466. 'supply_price': area_price['副单位1采购价'] * 100}
  467. supply_price_list.append(c)
  468. a = {'is_min_unit': True,
  469. 'unit': area_price['最小单位'],
  470. 'suggested_order_price': area_price['最小单位售价'] * 100,
  471. 'supply_price': area_price['最小单位采购价'] * 100}
  472. supply_price_list.append ( a )
  473. area_prices_dict[str ( area_price['供货区域'] )] = supply_price_list
  474. # print(area_prices_dict)
  475. headers = {
  476. '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',
  477. 'Authorization': token}
  478. # 获取当前供应商供应商品的明细信息
  479. # sup_id = '6976780582995234816'
  480. # goods_id = '6952558678100807680'
  481. url_get = 'https://cloud.xc-fintech.com/api/v1/goods_centre/supply_goods/detail'
  482. json_params_get = {"app_id": app_id, "sup_id": sup_id, "goods_id": goods_id}
  483. resp = requests.post ( url_get, headers = headers, json = json_params_get ).json ()
  484. # print(resp)
  485. publish_state = resp['publish_state'] # 上下架状态
  486. price_mode = resp['price_mode']
  487. unit_list = resp['unit_list']
  488. supply_price_list_false = []
  489. for unit in unit_list:
  490. unit.pop ( 'is_use' )
  491. supply_price_list_false.append ( unit )
  492. area_price_list = []
  493. for areas_price_1 in resp['area_price_list']:
  494. area_price_1 = {}
  495. area_price_1['store_area_name'] = areas_price_1['store_area_name']
  496. area_price_1['store_area_id'] = areas_price_1['store_area_id']
  497. # print(area_price_1['store_area_id'])
  498. try:
  499. supply_price_list = area_prices_dict[area_price_1['store_area_id']]
  500. # print ('1', supply_price_list)
  501. except:
  502. try:
  503. supply_price_list = areas_price_1['sku_price_list'][0]['supply_price_list']
  504. except:
  505. supply_price_list = supply_price_list_false
  506. area_price_1['sku_price_list'] = [{'sku_id': 0,
  507. 'supply_price_list': supply_price_list
  508. }]
  509. area_price_list.append ( area_price_1 )
  510. if len ( areas_price_1['area_price_list'] ) > 0:
  511. for areas_price_2 in areas_price_1['area_price_list']:
  512. area_price_2 = {}
  513. area_price_2['store_area_name'] = areas_price_2['store_area_name']
  514. area_price_2['store_area_id'] = areas_price_2['store_area_id']
  515. try:
  516. supply_price_list = area_prices_dict[areas_price_2['store_area_id']]
  517. # print ('2', supply_price_list)
  518. except:
  519. supply_price_list = supply_price_list_false
  520. # supply_price_list = areas_price_2['sku_price_list'][0]['supply_price_list']
  521. area_price_2['sku_price_list'] = [{'sku_id': 0,
  522. 'supply_price_list': supply_price_list
  523. }]
  524. area_price_list.append ( area_price_2 )
  525. if len ( areas_price_2['area_price_list'] ) > 0:
  526. for areas_price_3 in areas_price_2['area_price_list']:
  527. area_price_3 = {}
  528. area_price_3['store_area_name'] = areas_price_3['store_area_name']
  529. area_price_3['store_area_id'] = areas_price_3['store_area_id']
  530. try:
  531. supply_price_list = area_prices_dict[area_price_1['store_area_id']]
  532. # print ('3', supply_price_list)
  533. except:
  534. supply_price_list = supply_price_list_false
  535. # supply_price_list = areas_price_3['sku_price_list'][0]['supply_price_list']
  536. area_price_3['sku_price_list'] = [{'sku_id': 0,
  537. 'supply_price_list': supply_price_list
  538. }]
  539. area_price_list.append ( area_price_3 )
  540. # print(area_price_list)
  541. # 构建json_params_up
  542. # price_mode = '2'
  543. supply_rela_list = [{'sku_id': 0, 'm_supply_count': '', 'init_stock': ''}] # 默认
  544. # area_price = {'store_area_name':'上海',
  545. # 'store_area_id':'5843112869169733638',
  546. # 'sku_price_list':[{'sku_id':0,
  547. # 'supply_price_list':[{'is_min_unit':True,
  548. # 'unit':'箱',
  549. # 'suggested_order_price':99900,
  550. # 'supply_price':34000
  551. # }]
  552. # }]}
  553. # area_price_list = []
  554. json_params_up = {'app_id': app_id,
  555. 'goods_id': goods_id,
  556. 'price_mode': 2,
  557. 'sup_id': sup_id,
  558. 'supply_rela_list': supply_rela_list,
  559. 'area_price_list': area_price_list}
  560. # print(json_params_up)
  561. if publish_state == 1:
  562. # 下架
  563. if updatePublishState ( app_id, token, 1, goods_id ):
  564. url_up = 'https://cloud.xc-fintech.com/api/v1/supplier/sup_goods/establish'
  565. resp_up = requests.post ( url_up, headers = headers, json = json_params_up ).json ()
  566. print ( resp_up )
  567. print ( sup_id, goods_id, resp_up['sup_id'] == sup_id )
  568. # 上架
  569. updatePublishState ( app_id, token, 0, goods_id )
  570. else:
  571. print ( sup_id, goods_id, '无法操作下架' )
  572. else:
  573. url_up = 'https://cloud.xc-fintech.com/api/v1/supplier/sup_goods/establish'
  574. resp_up = requests.post ( url_up, headers = headers, json = json_params_up ).json ()
  575. print ( sup_id, goods_id, resp_up )
  576. print ( sup_id, goods_id, resp_up['sup_id'] == sup_id )
  577. updateSingleGoodsPriceInGoodsInfoCentre ( app_id, token, uploadFile, 1 )
  578. # 【单独更新】订货商品中改价界面的参数,配合updateGoodsAreaSupplierPrice执行,主要在调整供应商端采购价和建议售价时,完成订货商品【供货方】调整
  579. # mode = 0时为【供货方】调整为【不供货】,mode = 1时为【供货方】调整为表中指定供应商
  580. def updateSingleGoodsPriceInGoodsInfoCentre(app_id, token, uploadFile, mode):
  581. df_in = pd.read_excel ( uploadFile )
  582. goods_ids = list ( set ( df_in['商品id'] ) )
  583. df_in_dict = {}
  584. for goods_id in goods_ids:
  585. df_in_dict[str ( goods_id )] = {}
  586. area_ids_l = df_in[df_in['商品id'] == goods_id]
  587. area_ids = list ( set ( area_ids_l['供货区域'] ) )
  588. for area_id in area_ids:
  589. df_in_dict[str ( goods_id )][str ( area_id )] = {}
  590. sup_ids_l = area_ids_l[area_ids_l['供货区域'] == area_id]
  591. sup_ids_l = sup_ids_l.to_dict ( 'records' )
  592. try:
  593. if len ( sup_ids_l ) > 1:
  594. print ( f'商品【{goods_id}】在【{area_id}】存在多个供应商,请检查此字段【订货商品【供货方】是否立即调整】是否有调整' )
  595. except:
  596. print ( '一品一地多供点检出错' )
  597. sup_info = sup_ids_l[0]
  598. unit_price_list = []
  599. if str ( sup_info['副单位'] ) != 'nan':
  600. b = {'is_min_unit': False,
  601. 'unit': sup_info['副单位'],
  602. 'actual_amount': int ( sup_info['副单位售价'] * 100 )}
  603. unit_price_list.append ( b )
  604. if str ( sup_info['副单位1'] ) != 'nan':
  605. c = {'is_min_unit': False,
  606. 'unit': sup_info['副单位1'],
  607. 'actual_amount': int ( sup_info['副单位1售价'] * 100 )}
  608. unit_price_list.append ( c )
  609. a = {'is_min_unit': True,
  610. 'unit': sup_info['最小单位'],
  611. 'actual_amount': int ( sup_info['最小单位售价'] * 100 )}
  612. unit_price_list.append ( a )
  613. if str ( sup_info['限订量'] ) != 'nan':
  614. buy_limit_max = sup_info['限订量']
  615. else:
  616. buy_limit_max = ''
  617. if sup_info['订货商品【供货方】是否立即调整'] != 'nan':
  618. isAddToListRightNow = sup_info['订货商品【供货方】是否立即调整']
  619. else:
  620. isAddToListRightNow = 0
  621. df_in_dict[str ( goods_id )][str ( area_id )] = {'sup_id': str ( sup_info['供应商id'] ),
  622. 'buy_limit_min': sup_info['起订量'],
  623. 'buy_limit_max': buy_limit_max,
  624. 'unit_price_list': unit_price_list,
  625. 'isAddToListRightNow': isAddToListRightNow}
  626. df_in_dict[str ( goods_id )][str ( area_id )][str ( sup_info['供应商id'] )] = {
  627. 'sup_id': str ( sup_info['供应商id'] ),
  628. 'buy_limit_min': sup_info['起订量'],
  629. 'buy_limit_max': buy_limit_max,
  630. 'unit_price_list': unit_price_list,
  631. 'isAddToListRightNow': isAddToListRightNow}
  632. # 以上对导入表进行字典化整理df_in_dict
  633. print ( len ( goods_ids ) )
  634. headers = {
  635. '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',
  636. 'Authorization': token,
  637. 'Content-Type': 'application/json; charset=UTF-8'}
  638. for goods_id in goods_ids:
  639. # 查询商品相关规格信息
  640. url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/' + str ( goods_id )
  641. json = {"app_id": app_id}
  642. resp_goodsInfo = requests.post ( url, headers = headers, json = json ).json ()
  643. unit_list = []
  644. publish_state = resp_goodsInfo['publish_state']
  645. for unit_info in resp_goodsInfo['spu_unit_list']:
  646. unit_info_dict = {}
  647. unit_info_dict['is_min_unit'] = unit_info['is_min_unit']
  648. unit_info_dict['unit'] = unit_info['unit']
  649. unit_list.append ( unit_info_dict )
  650. if publish_state == 1:
  651. # 下架
  652. updatePublishState ( app_id, token, 1, goods_id )
  653. # 返回规格数据unit_list
  654. # 按goods_id搜索当前商品定价界面相关信息
  655. url_goods_price = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/query'
  656. json_goods_price = {"subscribe_type": "1",
  657. "goods_id": goods_id,
  658. "app_id": app_id}
  659. resp_goods_price = requests.post ( url_goods_price, headers = headers, json = json_goods_price ).json ()
  660. if mode == 0:
  661. # area_price_list为构建的请求参数中的列表参数
  662. area_price_list = []
  663. for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
  664. dict_l1 = {}
  665. store_area_id = area_price_1['store_area_id']
  666. store_area_name = area_price_1['store_area_name']
  667. is_extend = area_price_1['is_extend']
  668. dict_l1['is_extend'] = is_extend
  669. dict_l1['store_area_id'] = store_area_id
  670. dict_l1['store_area_name'] = store_area_name
  671. # dict_l1['is_supply'] = True
  672. # dict_l1['spu_order_price'] = {}
  673. try:
  674. sup_id = area_price_1['sup_id']
  675. # print(sup_id)
  676. except:
  677. ...
  678. # 判断是否在上载的表里
  679. try:
  680. # 如果'在'则进行【不供货】调整
  681. sup_id_in = df_in_dict[str ( goods_id )][str ( store_area_id )][str ( sup_id )]['sup_id']
  682. dict_l1['is_supply'] = False
  683. print ( goods_id, '|区域', store_area_id, '已设置值不供货' )
  684. # dict_l1['spu_order_price']['buy_limit_min'] = df_in_dict[str (goods_id)][store_area_id][sup_id]['buy_limit_min']
  685. # dict_l1['spu_order_price']['buy_limit_max'] = df_in_dict[str (goods_id)][store_area_id][sup_id]['buy_limit_max']
  686. # dict_l1['spu_order_price']['unit_price_list'] = df_in_dict[str (goods_id)][store_area_id][sup_id][
  687. # 'unit_price_list']
  688. except:
  689. # 判断是否已分配供应商
  690. dict_l1['is_supply'] = True
  691. dict_l1['spu_order_price'] = {}
  692. try:
  693. dict_l1['sup_id'] = sup_id
  694. dict_l1['spu_order_price']['buy_limit_min'] = area_price_1['spu_order_price']['buy_limit_min']
  695. try:
  696. dict_l1['spu_order_price']['buy_limit_max'] = area_price_1['spu_order_price'][
  697. 'buy_limit_max']
  698. except:
  699. dict_l1['spu_order_price']['buy_limit_max'] = ''
  700. dict_l1['spu_order_price']['unit_price_list'] = area_price_1['spu_order_price'][
  701. 'unit_price_list']
  702. except:
  703. dict_l1['spu_order_price']['unit_price_list'] = unit_list
  704. dict_l1['spu_order_price']['buy_limit_min'] = ''
  705. dict_l1['spu_order_price']['buy_limit_max'] = ''
  706. area_price_list.append ( dict_l1 )
  707. store_area_list2 = area_price_1['store_area_list']
  708. if len ( store_area_list2 ) > 0:
  709. for area_price_2 in store_area_list2:
  710. dict_l2 = {}
  711. store_area_id = area_price_2['store_area_id']
  712. store_area_name = area_price_2['store_area_name']
  713. is_extend = area_price_2['is_extend']
  714. dict_l2['is_extend'] = is_extend
  715. dict_l2['store_area_id'] = store_area_id
  716. dict_l2['store_area_name'] = store_area_name
  717. # dict_l2['spu_order_price'] = {}
  718. # dict_l2['is_supply'] = True
  719. # try:
  720. # dict_l2['sup_id'] = df_in_dict[str (goods_id)][store_area_id][sup_id]['sup_id']
  721. # dict_l2['is_supply'] = False
  722. # # dict_l2['spu_order_price']['buy_limit_min'] = df_in_dict[str (goods_id)][store_area_id][
  723. # # 'buy_limit_min']
  724. # # dict_l2['spu_order_price']['buy_limit_max'] = df_in_dict[str (goods_id)][store_area_id][
  725. # # 'buy_limit_max']
  726. # # dict_l2['spu_order_price']['unit_price_list'] = df_in_dict[str (goods_id)][store_area_id][
  727. # # 'unit_price_list']
  728. # except:
  729. dict_l2['spu_order_price'] = {}
  730. dict_l2['is_supply'] = True
  731. dict_l2['spu_order_price']['unit_price_list'] = unit_list
  732. dict_l2['spu_order_price']['buy_limit_min'] = ''
  733. dict_l2['spu_order_price']['buy_limit_max'] = ''
  734. area_price_list.append ( dict_l2 )
  735. store_area_list3 = area_price_2['store_area_list']
  736. if len ( store_area_list3 ) > 0:
  737. for area_price_3 in store_area_list3:
  738. dict_l3 = {}
  739. store_area_id = area_price_3['store_area_id']
  740. store_area_name = area_price_3['store_area_name']
  741. is_extend = area_price_3['is_extend']
  742. dict_l3['is_extend'] = is_extend
  743. dict_l3['is_supply'] = True
  744. dict_l3['store_area_id'] = store_area_id
  745. dict_l3['store_area_name'] = store_area_name
  746. dict_l3['spu_order_price'] = {}
  747. # try:
  748. # dict_l3['sup_id'] = df_in_dict[str (goods_id)][store_area_id]['sup_id']
  749. # dict_l3['spu_order_price']['buy_limit_min'] = df_in_dict[str (goods_id)][store_area_id][
  750. # 'buy_limit_min']
  751. # dict_l3['spu_order_price']['buy_limit_max'] = df_in_dict[str (goods_id)][store_area_id][
  752. # 'buy_limit_max']
  753. # dict_l3['spu_order_price']['unit_price_list'] = \
  754. # df_in_dict[str (goods_id)][store_area_id][
  755. # 'unit_price_list']
  756. # except:
  757. dict_l3['spu_order_price']['unit_price_list'] = unit_list
  758. dict_l3['spu_order_price']['buy_limit_min'] = ''
  759. dict_l3['spu_order_price']['buy_limit_max'] = ''
  760. area_price_list.append ( dict_l3 )
  761. brand_list = [{'brand_id': '0',
  762. 'area_price_list': area_price_list}]
  763. json_params_full_update = {'app_id': app_id,
  764. 'goods_id': goods_id,
  765. 'subscribe_type': '1',
  766. 'brand_list': brand_list}
  767. url_full_update = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/full_update'
  768. headers = {
  769. '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',
  770. 'Authorization': token,
  771. 'Content-Type': 'application/json; charset=UTF-8'}
  772. resp_full_update = requests.post ( url_full_update, headers = headers, json = json_params_full_update ).text
  773. print ( resp_full_update )
  774. if mode == 1:
  775. area_price_list = []
  776. for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
  777. dict_l1 = {}
  778. store_area_id = area_price_1['store_area_id']
  779. store_area_name = area_price_1['store_area_name']
  780. is_extend = area_price_1['is_extend']
  781. dict_l1['is_extend'] = is_extend
  782. dict_l1['is_supply'] = True
  783. dict_l1['store_area_id'] = store_area_id
  784. dict_l1['store_area_name'] = store_area_name
  785. dict_l1['spu_order_price'] = {}
  786. try:
  787. dict_l1['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
  788. dict_l1['spu_order_price']['buy_limit_min'] = df_in_dict[str ( goods_id )][store_area_id][
  789. 'buy_limit_min']
  790. dict_l1['spu_order_price']['buy_limit_max'] = df_in_dict[str ( goods_id )][store_area_id][
  791. 'buy_limit_max']
  792. dict_l1['spu_order_price']['unit_price_list'] = df_in_dict[str ( goods_id )][store_area_id][
  793. 'unit_price_list']
  794. except:
  795. # 判断是否已分配供应商
  796. try:
  797. dict_l1['sup_id'] = area_price_1['sup_id']
  798. dict_l1['spu_order_price']['buy_limit_min'] = area_price_1['spu_order_price']['buy_limit_min']
  799. try:
  800. dict_l1['spu_order_price']['buy_limit_max'] = area_price_1['spu_order_price'][
  801. 'buy_limit_max']
  802. except:
  803. dict_l1['spu_order_price']['buy_limit_max'] = ''
  804. dict_l1['spu_order_price']['unit_price_list'] = area_price_1['spu_order_price'][
  805. 'unit_price_list']
  806. except:
  807. dict_l1['spu_order_price']['unit_price_list'] = unit_list
  808. dict_l1['spu_order_price']['buy_limit_min'] = ''
  809. dict_l1['spu_order_price']['buy_limit_max'] = ''
  810. area_price_list.append ( dict_l1 )
  811. store_area_list2 = area_price_1['store_area_list']
  812. if len ( store_area_list2 ) > 0:
  813. for area_price_2 in store_area_list2:
  814. dict_l2 = {}
  815. store_area_id = area_price_2['store_area_id']
  816. store_area_name = area_price_2['store_area_name']
  817. is_extend = area_price_2['is_extend']
  818. dict_l2['is_extend'] = is_extend
  819. dict_l2['is_supply'] = True
  820. dict_l2['store_area_id'] = store_area_id
  821. dict_l2['store_area_name'] = store_area_name
  822. dict_l2['spu_order_price'] = {}
  823. try:
  824. dict_l2['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
  825. dict_l2['spu_order_price']['buy_limit_min'] = df_in_dict[str ( goods_id )][store_area_id][
  826. 'buy_limit_min']
  827. dict_l2['spu_order_price']['buy_limit_max'] = df_in_dict[str ( goods_id )][store_area_id][
  828. 'buy_limit_max']
  829. dict_l2['spu_order_price']['unit_price_list'] = df_in_dict[str ( goods_id )][store_area_id][
  830. 'unit_price_list']
  831. except:
  832. dict_l2['spu_order_price']['unit_price_list'] = unit_list
  833. dict_l2['spu_order_price']['buy_limit_min'] = ''
  834. dict_l2['spu_order_price']['buy_limit_max'] = ''
  835. area_price_list.append ( dict_l2 )
  836. store_area_list3 = area_price_2['store_area_list']
  837. if len ( store_area_list3 ) > 0:
  838. for area_price_3 in store_area_list3:
  839. dict_l3 = {}
  840. store_area_id = area_price_3['store_area_id']
  841. store_area_name = area_price_3['store_area_name']
  842. is_extend = area_price_3['is_extend']
  843. dict_l3['is_extend'] = is_extend
  844. dict_l3['is_supply'] = True
  845. dict_l3['store_area_id'] = store_area_id
  846. dict_l3['store_area_name'] = store_area_name
  847. dict_l3['spu_order_price'] = {}
  848. try:
  849. dict_l3['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
  850. dict_l3['spu_order_price']['buy_limit_min'] = \
  851. df_in_dict[str ( goods_id )][store_area_id][
  852. 'buy_limit_min']
  853. dict_l3['spu_order_price']['buy_limit_max'] = \
  854. df_in_dict[str ( goods_id )][store_area_id][
  855. 'buy_limit_max']
  856. dict_l3['spu_order_price']['unit_price_list'] = \
  857. df_in_dict[str ( goods_id )][store_area_id][
  858. 'unit_price_list']
  859. except:
  860. dict_l3['spu_order_price']['unit_price_list'] = unit_list
  861. dict_l3['spu_order_price']['buy_limit_min'] = ''
  862. dict_l3['spu_order_price']['buy_limit_max'] = ''
  863. area_price_list.append ( dict_l3 )
  864. brand_list = [{'brand_id': '0',
  865. 'area_price_list': area_price_list}]
  866. json_params_full_update = {'app_id': app_id,
  867. 'goods_id': goods_id,
  868. 'subscribe_type': '1',
  869. 'brand_list': brand_list}
  870. url_full_update = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/full_update'
  871. headers = {
  872. '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',
  873. 'Authorization': token,
  874. 'Content-Type': 'application/json; charset=UTF-8'}
  875. resp_full_update = requests.post ( url_full_update, headers = headers, json = json_params_full_update ).text
  876. print ( resp_full_update )
  877. if publish_state == 1:
  878. # 上架
  879. updatePublishState ( app_id, token, 0, goods_id )
  880. print ( '----------【不供货】操作----------' )
  881. # 【批量更新】订货商品中改价界面的参数
  882. def updateGoodsPriceInGoodsInfoCentre(app_id, token, uploadFile):
  883. df_in = pd.read_excel ( uploadFile )
  884. goods_ids = list ( set ( df_in['商品id'] ) )
  885. df_in_dict = {}
  886. for goods_id in goods_ids:
  887. df_in_dict[str ( goods_id )] = {}
  888. area_ids_l = df_in[df_in['商品id'] == goods_id]
  889. area_ids = list ( set ( area_ids_l['区域id'] ) )
  890. for area_id in area_ids:
  891. df_in_dict[str ( goods_id )][str ( area_id )] = {}
  892. sup_ids_l = area_ids_l[area_ids_l['区域id'] == area_id]
  893. sup_ids_l = sup_ids_l.to_dict ( 'records' )
  894. try:
  895. if len ( sup_ids_l ) > 1:
  896. print ( f'商品【{goods_id}】在【{area_id}】存在多个供应商,请检查此字段【订货商品【供货方】是否立即调整】是否有调整' )
  897. except:
  898. print ( '一品一地多供点检出错' )
  899. sup_info = sup_ids_l[0]
  900. unit_price_list = []
  901. if str ( sup_info['副单位'] ) != 'nan':
  902. b = {'is_min_unit': False,
  903. 'unit': sup_info['副单位'],
  904. 'actual_amount': int ( sup_info['副单位售价'] * 100 )}
  905. unit_price_list.append ( b )
  906. if str ( sup_info['副单位1'] ) != 'nan':
  907. c = {'is_min_unit': False,
  908. 'unit': sup_info['副单位1'],
  909. 'actual_amount': int ( sup_info['副单位1售价'] * 100 )}
  910. unit_price_list.append ( c )
  911. a = {'is_min_unit': True,
  912. 'unit': sup_info['最小单位'],
  913. 'actual_amount': int ( sup_info['最小单位售价'] * 100 )}
  914. unit_price_list.append ( a )
  915. if str ( sup_info['限订量'] ) != 'nan':
  916. buy_limit_max = sup_info['限订量']
  917. else:
  918. buy_limit_max = ''
  919. df_in_dict[str ( goods_id )][str ( area_id )] = {'sup_id': str ( sup_info['供应商id'] ),
  920. 'buy_limit_min': sup_info['起订量'],
  921. 'buy_limit_max': buy_limit_max,
  922. 'unit_price_list': unit_price_list}
  923. # 以上对导入表进行字典化整理df_in_dict
  924. print ( len ( goods_ids ) )
  925. headers = {
  926. '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',
  927. 'Authorization': token,
  928. 'Content-Type': 'application/json; charset=UTF-8'}
  929. for goods_id in goods_ids:
  930. # 查询商品相关规格信息
  931. url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/' + str ( goods_id )
  932. json = {"app_id": app_id}
  933. resp_goodsInfo = requests.post ( url, headers = headers, json = json ).json ()
  934. unit_list = []
  935. publish_state = resp_goodsInfo['publish_state']
  936. for unit_info in resp_goodsInfo['spu_unit_list']:
  937. unit_info_dict = {}
  938. unit_info_dict['is_min_unit'] = unit_info['is_min_unit']
  939. unit_info_dict['unit'] = unit_info['unit']
  940. unit_list.append ( unit_info_dict )
  941. if publish_state == 1:
  942. # 下架
  943. updatePublishState ( app_id, token, 1, goods_id )
  944. # 返回规格数据unit_list
  945. # 按goods_id搜索当前商品定价界面相关信息
  946. url_goods_price = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/query'
  947. json_goods_price = {"subscribe_type": "1",
  948. "goods_id": goods_id,
  949. "app_id": app_id}
  950. resp_goods_price = requests.post ( url_goods_price, headers = headers, json = json_goods_price ).json ()
  951. area_price_list = []
  952. for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
  953. dict_l1 = {}
  954. store_area_id = area_price_1['store_area_id']
  955. store_area_name = area_price_1['store_area_name']
  956. is_extend = area_price_1['is_extend']
  957. dict_l1['is_extend'] = is_extend
  958. dict_l1['is_supply'] = True
  959. dict_l1['store_area_id'] = store_area_id
  960. dict_l1['store_area_name'] = store_area_name
  961. dict_l1['spu_order_price'] = {}
  962. # in_put_area_dict_l1 = {'is_extend': is_extend,
  963. # 'is_supply': True,
  964. # 'spu_order_price': {'buy_limit_min': buy_limit_min,
  965. # 'buy_limit_max': buy_limit_max,
  966. # 'unit_price_list': unit_price_list},
  967. # 'store_area_id': store_area_id,
  968. # 'store_area_name': store_area_name,
  969. # 'sup_id': sup_id}
  970. # in_put_area_dict_l1 = {'is_extend': is_extend,
  971. # 'is_supply': True,
  972. # 'spu_order_price': {'buy_limit_min': '',
  973. # 'buy_limit_max': '',
  974. # 'unit_price_list': unit_price_list},
  975. # 'store_area_id': store_area_id,
  976. # 'store_area_name': store_area_name,
  977. # }
  978. # 判断是否在上载的表里
  979. try:
  980. dict_l1['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
  981. dict_l1['spu_order_price']['buy_limit_min'] = df_in_dict[str ( goods_id )][store_area_id][
  982. 'buy_limit_min']
  983. dict_l1['spu_order_price']['buy_limit_max'] = df_in_dict[str ( goods_id )][store_area_id][
  984. 'buy_limit_max']
  985. dict_l1['spu_order_price']['unit_price_list'] = df_in_dict[str ( goods_id )][store_area_id][
  986. 'unit_price_list']
  987. except:
  988. # 判断是否已分配供应商
  989. try:
  990. dict_l1['sup_id'] = area_price_1['sup_id']
  991. dict_l1['spu_order_price']['buy_limit_min'] = area_price_1['spu_order_price']['buy_limit_min']
  992. try:
  993. dict_l1['spu_order_price']['buy_limit_max'] = area_price_1['spu_order_price']['buy_limit_max']
  994. except:
  995. dict_l1['spu_order_price']['buy_limit_max'] = ''
  996. dict_l1['spu_order_price']['unit_price_list'] = area_price_1['spu_order_price']['unit_price_list']
  997. except:
  998. dict_l1['spu_order_price']['unit_price_list'] = unit_list
  999. dict_l1['spu_order_price']['buy_limit_min'] = ''
  1000. dict_l1['spu_order_price']['buy_limit_max'] = ''
  1001. area_price_list.append ( dict_l1 )
  1002. store_area_list2 = area_price_1['store_area_list']
  1003. if len ( store_area_list2 ) > 0:
  1004. for area_price_2 in store_area_list2:
  1005. dict_l2 = {}
  1006. store_area_id = area_price_2['store_area_id']
  1007. store_area_name = area_price_2['store_area_name']
  1008. is_extend = area_price_2['is_extend']
  1009. dict_l2['is_extend'] = is_extend
  1010. dict_l2['is_supply'] = True
  1011. dict_l2['store_area_id'] = store_area_id
  1012. dict_l2['store_area_name'] = store_area_name
  1013. dict_l2['spu_order_price'] = {}
  1014. try:
  1015. dict_l2['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
  1016. dict_l2['spu_order_price']['buy_limit_min'] = df_in_dict[str ( goods_id )][store_area_id][
  1017. 'buy_limit_min']
  1018. dict_l2['spu_order_price']['buy_limit_max'] = df_in_dict[str ( goods_id )][store_area_id][
  1019. 'buy_limit_max']
  1020. dict_l2['spu_order_price']['unit_price_list'] = df_in_dict[str ( goods_id )][store_area_id][
  1021. 'unit_price_list']
  1022. except:
  1023. dict_l2['spu_order_price']['unit_price_list'] = unit_list
  1024. dict_l2['spu_order_price']['buy_limit_min'] = ''
  1025. dict_l2['spu_order_price']['buy_limit_max'] = ''
  1026. area_price_list.append ( dict_l2 )
  1027. store_area_list3 = area_price_2['store_area_list']
  1028. if len ( store_area_list3 ) > 0:
  1029. for area_price_3 in store_area_list3:
  1030. dict_l3 = {}
  1031. store_area_id = area_price_3['store_area_id']
  1032. store_area_name = area_price_3['store_area_name']
  1033. is_extend = area_price_3['is_extend']
  1034. dict_l3['is_extend'] = is_extend
  1035. dict_l3['is_supply'] = True
  1036. dict_l3['store_area_id'] = store_area_id
  1037. dict_l3['store_area_name'] = store_area_name
  1038. dict_l3['spu_order_price'] = {}
  1039. try:
  1040. dict_l3['sup_id'] = df_in_dict[str ( goods_id )][store_area_id]['sup_id']
  1041. dict_l3['spu_order_price']['buy_limit_min'] = \
  1042. df_in_dict[str ( goods_id )][store_area_id][
  1043. 'buy_limit_min']
  1044. dict_l3['spu_order_price']['buy_limit_max'] = \
  1045. df_in_dict[str ( goods_id )][store_area_id][
  1046. 'buy_limit_max']
  1047. dict_l3['spu_order_price']['unit_price_list'] = \
  1048. df_in_dict[str ( goods_id )][store_area_id][
  1049. 'unit_price_list']
  1050. except:
  1051. dict_l3['spu_order_price']['unit_price_list'] = unit_list
  1052. dict_l3['spu_order_price']['buy_limit_min'] = ''
  1053. dict_l3['spu_order_price']['buy_limit_max'] = ''
  1054. area_price_list.append ( dict_l3 )
  1055. brand_list = [{'brand_id': '0',
  1056. 'area_price_list': area_price_list}]
  1057. json_params_full_update = {'app_id': app_id,
  1058. 'goods_id': goods_id,
  1059. 'subscribe_type': '1',
  1060. 'brand_list': brand_list}
  1061. url_full_update = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/full_update'
  1062. headers = {
  1063. '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',
  1064. 'Authorization': token,
  1065. 'Content-Type': 'application/json; charset=UTF-8'}
  1066. resp_full_update = requests.post ( url_full_update, headers = headers, json = json_params_full_update ).text
  1067. print ( resp_full_update )
  1068. if publish_state == 1:
  1069. # 上架
  1070. updatePublishState ( app_id, token, 0, goods_id )
  1071. '''
  1072. goods_id = "6997811305520701440"
  1073. url_full_update = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/full_update'
  1074. 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',
  1075. 'Authorization': token,
  1076. 'Content-Type': 'application/json; charset=UTF-8'}
  1077. area_price_list=[]
  1078. #按goods_id搜索当前商品定价界面相关信息
  1079. url_goods_price = 'https://cloud.xc-fintech.com/api/v2/goods_centre/goods/goods_price/query'
  1080. json_goods_price = {"subscribe_type":"1",
  1081. "goods_id":goods_id,
  1082. "app_id":app_id}
  1083. resp_goods_price = requests.post(url_goods_price,headers=headers,json=json_goods_price).json()
  1084. for area_price_1 in resp_goods_price['data']['brand_list'][0]['store_area_list']:
  1085. store_area_list2 = area_price_1['store_area_list']
  1086. if len(store_area_list2)>0:
  1087. for area_price_2 in store_area_list2:
  1088. store_area_list3 = area_price_2['store_area_list']
  1089. if len(store_area_list3)>0:
  1090. for area_price_3 in store_area_list3:
  1091. ...
  1092. in_put_area_F_dict = {'is_extend': False,
  1093. 'is_supply': True,
  1094. 'spu_order_price': {'buy_limit_min': 1,
  1095. 'buy_limit_max': '',
  1096. 'unit_price_list': [{'actual_amount': 37280,
  1097. 'is_min_unit': True,
  1098. 'unit': '桶'}]},
  1099. 'store_area_id': '5843111700124934144',
  1100. 'store_area_name': '河北省',
  1101. 'sup_id': '6976010005263032320'}
  1102. in_put_area_S_dict = {'is_extend': True,
  1103. 'is_supply': True,
  1104. 'spu_order_price': {'buy_limit_min': 1,
  1105. 'buy_limit_max': '',
  1106. 'unit_price_list': [{'actual_amount': '',
  1107. 'is_min_unit': True,
  1108. 'unit': '桶'}]},
  1109. 'store_area_id': '6990852309777522688',
  1110. 'store_area_name': '河北省a顶灿'}
  1111. brand_list= [{'brand_id':'0',
  1112. 'area_price_list':area_price_list}]
  1113. json_params_full_update = {'app_id':app_id,
  1114. 'goods_id':goods_id,
  1115. 'subscribe_type':'1',
  1116. 'brand_list':brand_list}
  1117. '''
  1118. # 获取【订货橱窗】中的商品信息
  1119. def goodsInGoodsCentre(app_id, token, downloadPath):
  1120. # 第一步构造 目录列表包含信息['品牌id','品牌名称','L1橱窗id','L1橱窗名称','L2橱窗id','L2橱窗名称','publish_goods_count']
  1121. headers = {
  1122. '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',
  1123. 'Authorization': token}
  1124. # 获取所有品牌名称及id
  1125. brand_url = 'https://cloud.xc-fintech.com/api/v1/brand/list'
  1126. brand_json_params = {"current_page": 1,
  1127. "page_size": 999,
  1128. "app_id": app_id}
  1129. brand_list = requests.post ( brand_url, headers = headers, json = brand_json_params ).json ()['detail']
  1130. # print(brand_list)
  1131. df_out = []
  1132. i = 0
  1133. for brand_info in brand_list:
  1134. brand_id = brand_info['brand_id']
  1135. brand_name = brand_info['brand_name']
  1136. # 创建表信息
  1137. brand_info_dict = {'品牌id': brand_id, '品牌名称': brand_name}
  1138. # 获取当前品牌下各分类名称及id
  1139. shop_window_url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/shop_window/tree/query'
  1140. shop_window_json_params = {"app_id": app_id,
  1141. "sell_type": 2,
  1142. "brand_id": brand_id}
  1143. try:
  1144. shop_window_list = \
  1145. requests.post ( shop_window_url, headers = headers, json = shop_window_json_params ).json ()[
  1146. 'shop_window_detail']
  1147. shop_window_list_out = []
  1148. for shop_window_info in shop_window_list:
  1149. try:
  1150. childs = shop_window_info['child']
  1151. for child in childs:
  1152. shop_window_id = child['shop_window_id']
  1153. shop_window_name = child['shop_window_name']
  1154. publish_goods_count = child['publish_goods_count']
  1155. shop_window_info_dict = {'橱窗id': shop_window_id, '橱窗名称': shop_window_name,
  1156. 'publish_goods_count': publish_goods_count}
  1157. shop_window_info_dict.update ( brand_info_dict )
  1158. shop_window_list_out.append ( shop_window_info_dict )
  1159. except:
  1160. shop_window_name = shop_window_info['shop_window_name']
  1161. shop_window_id = shop_window_info['shop_window_id']
  1162. # 创建表信息
  1163. publish_goods_count = shop_window_info['publish_goods_count']
  1164. shop_window_info_dict = {'橱窗id': shop_window_id, '橱窗名称': shop_window_name,
  1165. 'publish_goods_count': publish_goods_count}
  1166. shop_window_info_dict.update ( brand_info_dict )
  1167. shop_window_list_out.append ( shop_window_info_dict )
  1168. for shop_window_info_dict in shop_window_list_out:
  1169. page_size = 40
  1170. page_count = math.ceil ( shop_window_info_dict['publish_goods_count'] / page_size )
  1171. for current_page in range ( 1, page_count + 1 ):
  1172. goodsInGoodsCentre_url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/shop_window/goods'
  1173. goodsInGoodsCentre_json_params = {"sell_type": 2,
  1174. "shop_window_id": shop_window_info_dict['橱窗id'],
  1175. "current_page": current_page,
  1176. "page_size": page_size,
  1177. "app_id": app_id}
  1178. goodsInGoodsCentre = requests.post ( goodsInGoodsCentre_url, headers = headers,
  1179. json = goodsInGoodsCentre_json_params ).json ()['detail']
  1180. for goodsInfo in goodsInGoodsCentre:
  1181. goods_id = goodsInfo['goods_id']
  1182. goods_name = goodsInfo['goods_name']
  1183. goods_no = goodsInfo['goods_no']
  1184. publish_state_judge = {'1': '上架', '0': '下架'}
  1185. publish_state = publish_state_judge[str ( goodsInfo['publish_state'] )]
  1186. i += 1
  1187. # 查看商品适用于哪些门店
  1188. apply_store_url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods_shop_window/apply_store/query'
  1189. apply_store_json_params = {"goods_id": goods_id,
  1190. "shop_window_id": shop_window_info_dict['橱窗id'],
  1191. "app_id": app_id}
  1192. apply_store_info = requests.post ( apply_store_url, headers = headers,
  1193. json = apply_store_json_params ).json ()
  1194. apply_type_mark = apply_store_info['data']['apply_type']
  1195. if apply_type_mark == 1:
  1196. apply_type = '全部门店适用'
  1197. elif apply_type_mark == 2:
  1198. apply_type = '部分门店适用'
  1199. elif apply_type_mark == 3:
  1200. apply_type = '部分门店不适用'
  1201. else:
  1202. apply_type = '未知'
  1203. # 创建表信息
  1204. goodsInfo_dict = {'商品id': goods_id,
  1205. '商品编号': goods_no,
  1206. '商品名称': goods_name,
  1207. '商品状态': publish_state,
  1208. '适用门店类型': apply_type}
  1209. goodsInfo_dict.update ( shop_window_info_dict )
  1210. try:
  1211. for apply_store_id in apply_store_info['data']['apply_store_id_list']:
  1212. apply_store_dict = selectStoreNoByStoreId ( app_id, token, apply_store_id )
  1213. # store_info_dict = {'门店编号':store_no,'门店名称':store_name,'所属品牌':brand_name}
  1214. apply_store_dict['相关门店id'] = apply_store_id
  1215. apply_store_dict.update ( goodsInfo_dict )
  1216. df_out.append ( apply_store_dict )
  1217. except:
  1218. df_out.append ( goodsInfo_dict )
  1219. print ( brand_info_dict, '完成' )
  1220. except:
  1221. print ( brand_info_dict, '出错' )
  1222. df_headers = ['品牌id', '品牌名称', '橱窗id', '橱窗名称', '商品id', '商品编号', '商品名称', '商品状态', '适用门店类型', '相关门店id', '门店编号', '门店名称',
  1223. '所属品牌']
  1224. df_out = pd.DataFrame ( df_out, columns = df_headers )
  1225. df_out.to_excel ( downloadPath + '/goodsInGoodsCentre.xlsx' )
  1226. # 获取【订货橱窗】中商品对应的【适用门店】
  1227. def selectGoodInGoodsCentreSUPshops(app_id, token, goods_id, shop_window_id):
  1228. url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods_shop_window/apply_store/query'
  1229. headers = {
  1230. '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',
  1231. 'Authorization': token}
  1232. json_params = {"goods_id": goods_id,
  1233. "shop_window_id": shop_window_id,
  1234. "app_id": app_id}
  1235. resp = requests.post ( url, headers = headers, json = json_params ).json ()
  1236. print(resp)
  1237. return resp
  1238. # 更新【订货橱窗】中的商品对应的【适用门店】
  1239. def updateGoodsInGoodsCentreSUPshops(app_id, token, uploadFile):
  1240. headers = {
  1241. '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',
  1242. 'Authorization': token}
  1243. df_in = pd.read_excel ( uploadFile )
  1244. goods_ids = list ( set ( df_in['商品id'] ) )
  1245. for goods_id in goods_ids:
  1246. shop_window_ids_df = df_in[df_in['商品id'] == goods_id]
  1247. shop_window_ids = list ( set ( shop_window_ids_df['橱窗id'] ) )
  1248. for shop_window_id in shop_window_ids:
  1249. # brand_id = list (set (shop_window_ids_df[shop_window_ids_df['橱窗id'] == shop_window_id]['品牌id']))[0]
  1250. # apply_store_ids = list(set(shop_window_ids_df[shop_window_ids_df['橱窗id']==shop_window_id]['门店编号']))
  1251. # apply_store_ids1 = selectStoreIdByStoreNo (app_id, token, apply_store_ids,brand_id) #门店编码转门店id
  1252. # apply_type = list(set(shop_window_ids_df[shop_window_ids_df['橱窗id']==shop_window_id]['适用类型']))[0] #适用类型
  1253. apply_store_ids_df = shop_window_ids_df[shop_window_ids_df['橱窗id'] == shop_window_id]
  1254. apply_types = list (
  1255. set ( shop_window_ids_df[shop_window_ids_df['橱窗id'] == shop_window_id]['适用类型'] ) ) # 适用类型
  1256. for apply_type in apply_types:
  1257. time.sleep(random.uniform(2,4))
  1258. brand_id = list ( set ( shop_window_ids_df[shop_window_ids_df['橱窗id'] == shop_window_id]['品牌id'] ) )[0]
  1259. apply_store_ids = list ( set ( apply_store_ids_df[apply_store_ids_df['适用类型'] == apply_type]['门店编号'] ) )
  1260. apply_store_ids1 = selectStoreIdByStoreNo ( app_id, token, apply_store_ids, brand_id ) # 门店编码转门店id
  1261. goods_info = selectGoodInGoodsCentreSUPshops ( app_id, token, goods_id, shop_window_id )
  1262. goods_info_apply_type = goods_info['data']['apply_type']
  1263. url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods_shop_window/apply_store/set'
  1264. # 在当前适用类型下追加
  1265. if int ( goods_info_apply_type ) == int ( apply_type ):
  1266. apply_store_id_list = goods_info['data']['apply_store_id_list']
  1267. apply_store_ids2 = list ( set ( apply_store_ids1 ) | set ( apply_store_id_list ) )
  1268. json_params = {"apply_type": apply_type,
  1269. "shop_window_id": shop_window_id,
  1270. "goods_id": goods_id,
  1271. "apply_store_id_list": apply_store_ids2,
  1272. "app_id": app_id}
  1273. no = 1
  1274. # 在当前适用类型下移除门店
  1275. elif int ( goods_info_apply_type ) != int ( apply_type ) and int (
  1276. goods_info_apply_type ) != 1 and int (
  1277. apply_type ) != 1:
  1278. apply_store_id_list = goods_info['data']['apply_store_id_list']
  1279. for apply_store_id in apply_store_ids1:
  1280. try:
  1281. apply_store_id_list.remove ( apply_store_id )
  1282. except:
  1283. ...
  1284. json_params = {"apply_type": goods_info_apply_type,
  1285. "shop_window_id": shop_window_id,
  1286. "goods_id": goods_id,
  1287. "apply_store_id_list": apply_store_id_list,
  1288. "app_id": app_id}
  1289. no = 2
  1290. # 初始进行适用类型划分
  1291. elif int ( goods_info_apply_type ) == 1:
  1292. json_params = {"apply_type": apply_type,
  1293. "shop_window_id": shop_window_id,
  1294. "goods_id": goods_id,
  1295. "apply_store_id_list": apply_store_ids1,
  1296. "app_id": app_id}
  1297. no = 3
  1298. # 恢复全部门店可见
  1299. elif int ( apply_type ) == 1:
  1300. json_params = {"apply_type": apply_type,
  1301. "shop_window_id": shop_window_id,
  1302. "goods_id": goods_id,
  1303. "app_id": app_id}
  1304. no = 4
  1305. try:
  1306. resp = requests.post ( url, json = json_params, headers = headers ).json ()['message']
  1307. print ( goods_id, shop_window_id, apply_type, resp, no )
  1308. except:
  1309. print ( '参数有误!' )
  1310. # 按门店编号查门店id
  1311. def selectStoreIdByStoreNo(app_id, token, store_no, brand_id):
  1312. if str ( type ( store_no ) ) != "<class 'list'>":
  1313. url = 'https://cloud.xc-fintech.com/split/get_store_list'
  1314. headers = {
  1315. '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',
  1316. 'Authorization': token}
  1317. json_params = {"app_id": app_id,
  1318. "store_no": store_no,
  1319. "page": 0, "page_size": 10,
  1320. "open_align": True,
  1321. "business_scene_list": []}
  1322. store_id = requests.post ( url, headers = headers, json = json_params ).json ()['store_list'][0]['store_id']
  1323. else:
  1324. url = 'https://cloud.xc-fintech.com/split/get_store_list'
  1325. headers = {
  1326. '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',
  1327. 'Authorization': token}
  1328. json_params = {"app_id": app_id,
  1329. "page": 0, "page_size": 9999,
  1330. "brand_id": brand_id}
  1331. store_list = requests.post ( url, headers = headers, json = json_params ).json ()['store_list']
  1332. df_in0 = pd.DataFrame ( store_list ).set_index ( 'store_no' )
  1333. df_in1 = pd.DataFrame ( store_no, columns = ['store_no'] )
  1334. df_in1['store_no'] = df_in1['store_no'].astype ( str )
  1335. df_out = df_in1.join ( df_in0, on = 'store_no', how = 'inner' )
  1336. store_id = list ( set ( df_out['store_id'] ) )
  1337. return store_id
  1338. # 按门店id查门店信息
  1339. def selectStoreNoByStoreId(app_id, token, store_id):
  1340. url = 'https://cloud.xc-fintech.com/split/get_store_list'
  1341. headers = {
  1342. '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',
  1343. 'Authorization': token}
  1344. json_params = {"app_id": app_id,
  1345. "store_id": store_id,
  1346. "page": 0, "page_size": 10,
  1347. "open_align": False,
  1348. "business_scene_list": []}
  1349. store_info = requests.post ( url, headers = headers, json = json_params ).json ()['store_list'][0]
  1350. store_no = store_info['store_no']
  1351. brand_name = store_info['brand_name']
  1352. store_name = store_info['store_name']
  1353. store_info_dict = {'门店编号': store_no,
  1354. '门店名称': store_name,
  1355. '所属品牌': brand_name}
  1356. # print(json.dumps(store_info,ensure_ascii=False))
  1357. return store_info_dict
  1358. # 查询所有门店信息
  1359. def selectAllStoreInfo(app_id, token, downloadPath):
  1360. template_dict = selectServiceRate ( app_id, token )
  1361. df_out = []
  1362. url = 'https://cloud.xc-fintech.com/split/get_store_list'
  1363. headers = {
  1364. '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',
  1365. 'Authorization': token}
  1366. json_0 = {"app_id": app_id, "page": 0, "page_size": 40, "open_align": True, "align_status": 2,
  1367. "business_scene_list": ["meituan", "eleme", "meituan_group_purchase", "dou_yin_life"]}
  1368. n = 0
  1369. x = requests.post ( url, headers = headers, json = json_0 ).json ()['total_count'] / 40
  1370. while n <= x:
  1371. print ( n )
  1372. json_1 = {"app_id": app_id, "page": n, "page_size": 40, "open_align": True, "align_status": 2,
  1373. "business_scene_list": ["meituan", "eleme", "meituan_group_purchase", "dou_yin_life"]}
  1374. n += 1
  1375. resp = requests.post ( url, headers = headers, json = json_1 ).json ()
  1376. print ( json.dumps ( resp, ensure_ascii = False ) )
  1377. store_list = resp['store_list']
  1378. for store_info in store_list:
  1379. try:
  1380. store_info_dic = {
  1381. 'store_no': store_info['store_no'],
  1382. 'store_name': store_info['store_name'],
  1383. 'brand_name': store_info['brand_name'],
  1384. 'store_id': store_info['store_id'],
  1385. 'store_area_name': store_info['store_area_name'],
  1386. 'store_area_no': store_info['store_area_no'],
  1387. 'brand_id': store_info['brand_id']}
  1388. except:
  1389. store_info_dic = {
  1390. 'store_no': store_info['store_no'],
  1391. 'store_name': store_info['store_name'],
  1392. 'store_id': store_info['store_id']
  1393. }
  1394. try:
  1395. store_info_dic['order_template_name'] = template_dict[store_info['order_template_id']]
  1396. except:
  1397. ...
  1398. try:
  1399. trade_mch_list = store_info['trade_mch_list']
  1400. trade_mch_dict = {}
  1401. for trade_mch_info in trade_mch_list:
  1402. scene = trade_mch_info['scene']
  1403. trade_mch_dict[scene] = trade_mch_info['mch_no']
  1404. store_info_dic.update ( trade_mch_dict )
  1405. except:
  1406. ...
  1407. df_out.append ( store_info_dic )
  1408. df_out = pd.DataFrame ( df_out )
  1409. df_out.to_excel ( downloadPath )
  1410. # 查询费率模板
  1411. def selectServiceRate(app_id, token):
  1412. url = 'https://cloud.xc-fintech.com/split/store/area/template'
  1413. headers = {
  1414. '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',
  1415. 'Authorization': token}
  1416. params = {"template_type": 1,
  1417. "app_id": app_id}
  1418. template_dict = {}
  1419. try:
  1420. resp = requests.post ( url, headers = headers, json = params ).json ()['template_list']
  1421. for i in resp:
  1422. name = i['template_name']
  1423. rate = name.split ( '取' )[1].split ( '服' )[0]
  1424. template_dict[i['template_id']] = rate
  1425. except:
  1426. ...
  1427. return template_dict
  1428. # 查询供应商供货管理中的采购价及建议售价,需上传文件(可参考文件uploadGoods.xlsx)
  1429. def selectGoodsPriceInSup(app_id, token, uploadFile, downloadPath):
  1430. # uploadFile = io_path + '/uploadGoods.xlsx'
  1431. df_in = pd.read_excel ( uploadFile, dtype = str )
  1432. n = 0
  1433. df_out = []
  1434. for sup_id in df_in['供应商id']:
  1435. goods_id = df_in.loc[n]['商品id']
  1436. n += 1
  1437. url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/supply_goods/detail'
  1438. json = {"app_id": app_id,
  1439. "sup_id": sup_id,
  1440. "goods_id": goods_id}
  1441. headers = {
  1442. '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',
  1443. 'Authorization': token}
  1444. resp = requests.post ( url, headers = headers, json = json ).json ()['area_price_list']
  1445. for a in resp:
  1446. store_area_id = a['store_area_id']
  1447. try:
  1448. unit = a['sku_price_list'][0]['supply_price_list'][0]['unit']
  1449. supply_price = a['sku_price_list'][0]['supply_price_list'][0]['supply_price']
  1450. except:
  1451. unit = ''
  1452. supply_price = ''
  1453. l = [sup_id, goods_id, store_area_id, unit, supply_price]
  1454. df_out.append ( l )
  1455. df_out = pd.DataFrame ( df_out, columns = ['sup_id', 'goods_id', 'store_area_id', 'unit', 'supply_price'] )
  1456. df_out.to_excel ( downloadPath )
  1457. # 查询下载商品具体信息mode(select【需传入goods_id】,download【需传入uploadFile,downloadPath】)
  1458. def selectGoodsInfoDetail(app_id, token, mode, uploadFile, downloadPath, goods_id):
  1459. if mode == 'download':
  1460. df_in = pd.read_excel ( uploadFile, dtype = str )
  1461. goods_ids = list ( set ( df_in['商品id'] ) )
  1462. df_out = []
  1463. for goods_id in goods_ids:
  1464. df_dict = {}
  1465. url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/' + goods_id
  1466. headers = {
  1467. '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',
  1468. 'Authorization': token}
  1469. json = {"app_id": app_id}
  1470. resp = requests.post ( url, headers = headers, json = json ).json ()
  1471. df_dict['商品id'] = goods_id
  1472. df_dict['商品编码'] = resp['goods_no']
  1473. df_dict['商品名称'] = resp['name']
  1474. df_dict['上下架状态'] = resp['publish_state']
  1475. units_info = resp['spu_unit_list']
  1476. n = 1
  1477. for unit_info in units_info:
  1478. if unit_info['is_min_unit']:
  1479. df_dict['最小单位'] = unit_info['unit']
  1480. # df_dict['最小单位换算值'] = unit_info['rela_num']
  1481. else:
  1482. df_dict[f'副单位{n}'] = unit_info['unit']
  1483. df_dict[f'副单位{n}换算值'] = unit_info['rela_num']
  1484. n += 1
  1485. df_out.append ( df_dict )
  1486. df_out = pd.DataFrame ( df_out,
  1487. columns = ['商品id', '商品编码', '商品名称', '上下架状态', '最小单位', '副单位1', '副单位1换算值', '副单位2',
  1488. '副单位2换算值'] )
  1489. df_out.to_excel ( downloadPath )
  1490. elif mode == 'select':
  1491. df_dict = {}
  1492. url = 'https://cloud.xc-fintech.com/api/v1/goods_centre/goods/' + goods_id
  1493. headers = {
  1494. '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',
  1495. 'Authorization': token}
  1496. json = {"app_id": app_id}
  1497. resp = requests.post ( url, headers = headers, json = json ).json ()
  1498. df_dict['上下架状态'] = resp['publish_state']
  1499. units_info = resp['spu_unit_list']
  1500. n = 1
  1501. for unit_info in units_info:
  1502. if unit_info['is_min_unit']:
  1503. df_dict['最小单位'] = unit_info['unit']
  1504. df_dict['最小单位开关'] = str ( unit_info['orderable'] )
  1505. else:
  1506. df_dict[f'副单位{n}'] = unit_info['unit']
  1507. df_dict[f'副单位{n}开关'] = str ( unit_info['orderable'] )
  1508. df_dict[f'副单位{n}换算值'] = unit_info['rela_num']
  1509. n += 1
  1510. return df_dict
  1511. def selectGoodsOrderByGoodsOrderId(app_id, token, orderId, goodsInfoDf):
  1512. order_list = []
  1513. sup_list = []
  1514. url = f'https://cloud.xc-fintech.com/api/v1/goods_order/{int ( orderId )}/query'
  1515. headers = {
  1516. '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',
  1517. 'Authorization': token}
  1518. json_p = {"app_id": app_id}
  1519. resp = requests.post ( url, headers = headers, json = json_p ).json ()
  1520. try:
  1521. goods_order = resp['goods_order']
  1522. goods_order_id = str ( orderId )
  1523. store_id = goods_order['store_id']
  1524. store_info = selectStoreNoByStoreId ( app_id, token, store_id )
  1525. store_no = str ( store_info['门店编号'] )
  1526. store_name = store_info['门店名称']
  1527. store_brand = store_info['所属品牌']
  1528. store_area_name = goods_order['store_area_name']
  1529. # print(store_area_name)
  1530. receiver = goods_order['receiver']
  1531. receiver_mobile = goods_order['receiver_mobile']
  1532. receiver_address = goods_order['receiver_address']
  1533. try:
  1534. receiver_province_name = goods_order['receiver_province_name']
  1535. receiver_city_name = goods_order['receiver_city_name']
  1536. receiver_district_name = goods_order['receiver_district_name']
  1537. except:
  1538. try:
  1539. area_dict = {'无锡市':'江苏省',
  1540. '盐城市':'江苏省',
  1541. '苏州市':'江苏省',
  1542. '南京市':'江苏省',
  1543. '泰州市':'江苏省',
  1544. '华江':'上海',
  1545. '浦东新区':'上海',
  1546. '青浦区':'上海',
  1547. '奉贤区':'上海',
  1548. '嘉定区':'上海',
  1549. '拉萨市':'西藏自治区',
  1550. '岳阳市':'湖南省'}
  1551. receiver_province_name = area_dict[store_area_name]
  1552. receiver_city_name = ''
  1553. receiver_district_name = ''
  1554. except Exception as e:
  1555. print(e)
  1556. receiver_province_name = receiver_address[:2]
  1557. receiver_city_name = ''
  1558. receiver_district_name = ''
  1559. print ( orderId, receiver_province_name, receiver_address )
  1560. create_time = goods_order['create_time']
  1561. temp_time = str ( int ( parse ( create_time ).timestamp () ) )
  1562. amount = goods_order['amount'] / 100
  1563. goods_order_detail_list = goods_order['goods_order_detail_list']
  1564. for goods_order_detail in goods_order_detail_list:
  1565. goods_id = goods_order_detail['goods_id']
  1566. goods_name = goods_order_detail['goods_name']
  1567. goods_count = goods_order_detail['goods_count']
  1568. unit = goods_order_detail['unit']
  1569. store_unit_amount = goods_order_detail['store_unit_amount'] / 100
  1570. store_total_amount = goods_order_detail['store_total_amount'] / 100
  1571. df_out = goodsInfoDf[goodsInfoDf['商品系统id'] == str ( goods_id )]
  1572. df_out = df_out[df_out['区域名称(1级)'] == str ( receiver_province_name )]
  1573. df_out = pd.DataFrame ( df_out ).to_dict ( 'records' )
  1574. if len ( df_out ) == 1:
  1575. dict_out = df_out[0]
  1576. min_unit = dict_out['最小单位']
  1577. classify_name = dict_out['所属分类']
  1578. goods_no = dict_out['商品编码']
  1579. sup_id = dict_out['供应商id']
  1580. sup_name = dict_out['供应商名称']
  1581. min_sup_sale = dict_out['最小单位采购价']
  1582. sup_sale = dict_out['副单位1采购价']
  1583. send_id = str ( sup_id[:9] ) + temp_time
  1584. if min_unit == unit:
  1585. goods_count_min = goods_count
  1586. sup_sale_out = float ( min_sup_sale )
  1587. sup_unit = unit
  1588. else:
  1589. rela_num = int ( dict_out['副单位1换算值'] )
  1590. sup_sale_out = float ( sup_sale )
  1591. sup_unit = f'{unit}({rela_num}{min_unit})'
  1592. goods_count_min = rela_num * goods_count
  1593. sup_sale_total = float ( sup_sale_out ) * goods_count
  1594. else:
  1595. if goods_name == '运费补差价':
  1596. min_unit = '单'
  1597. classify_name = '运费'
  1598. goods_no = 'P12345'
  1599. sup_id = '4976010005263032320'
  1600. sup_name = '上海餐小白贸易有限公司'
  1601. send_id = str ( sup_id[:9] ) + temp_time
  1602. goods_count_min = goods_count
  1603. sup_sale_out = 0
  1604. sup_sale_total = 0
  1605. sup_unit = '单'
  1606. else:
  1607. min_unit = 'error'
  1608. classify_name = 'error'
  1609. goods_no = 'error'
  1610. sup_id = 'error'
  1611. sup_name = 'error'
  1612. send_id = 'error'
  1613. goods_count_min = 'error'
  1614. sup_sale_out = 'error'
  1615. sup_sale_total = 'error'
  1616. sup_unit = 'error'
  1617. print ( goods_order_id, goods_id, '异常' )
  1618. dict_out_order = {'订货单号': goods_order_id,
  1619. '订货门店编号': store_no,
  1620. '订货门店': store_name,
  1621. '所属区域': store_area_name,
  1622. '加盟商级别': '-',
  1623. '品牌': store_brand,
  1624. '收货人': receiver,
  1625. '收货人电话': receiver_mobile,
  1626. '收货地址': f'{receiver_province_name}/{receiver_city_name}/{receiver_district_name}/{receiver_address}',
  1627. '下单时间': create_time,
  1628. '订货单状态': '-',
  1629. '关闭/完成时间': '-',
  1630. '订货单总金额(包含运费)': amount,
  1631. '商品分类': classify_name,
  1632. '商品编号': goods_no,
  1633. '商品名称': goods_name,
  1634. '商品厂商': '-',
  1635. '规格货号': '-',
  1636. '规格内容': '-',
  1637. '商品单位': unit,
  1638. '商品数量': goods_count,
  1639. '最小单位': min_unit,
  1640. '最小单位数量': goods_count_min,
  1641. '销售单价': store_unit_amount,
  1642. '小计': store_total_amount,
  1643. '退款金额': 0,
  1644. '发货单号': send_id,
  1645. '发货方编号': sup_id,
  1646. '发货方名称': sup_name,
  1647. '发货单状态': '-',
  1648. '运单号': '-',
  1649. '发货时间': '-',
  1650. '签收时间': '-'}
  1651. dict_out_sup = {'订货门店编号': store_no,
  1652. '订货门店名称': store_name,
  1653. '品牌': store_brand,
  1654. '所属省市区': f'{receiver_province_name}{receiver_city_name}{receiver_district_name}',
  1655. '发货单号': send_id,
  1656. '订货单号': goods_order_id,
  1657. '发货方': sup_name,
  1658. '发货单金额': '-',
  1659. '结算金额': '-',
  1660. '服务费': '-',
  1661. '交易手续费': '-',
  1662. '通道手续费': '-',
  1663. '发货单状态': '-',
  1664. '创建时间': create_time,
  1665. '下单时间': create_time,
  1666. '发货时间': '-',
  1667. '签收时间': '-',
  1668. '商品分类': classify_name,
  1669. '商品编号': goods_no,
  1670. '商品名称': goods_name,
  1671. '商品厂商': '-',
  1672. '货号': '-',
  1673. '规格': '-',
  1674. '数量': goods_count,
  1675. '订货单价': store_unit_amount,
  1676. '订货小计': store_total_amount,
  1677. '采购单价': sup_sale_out,
  1678. '采购小计': sup_sale_total,
  1679. '单位': sup_unit,
  1680. '收货人': receiver,
  1681. '收货人电话': receiver_mobile,
  1682. '收货地址': f'{receiver_province_name}/{receiver_city_name}/{receiver_district_name}/{receiver_address}',
  1683. }
  1684. order_list.append ( dict_out_order )
  1685. sup_list.append ( dict_out_sup )
  1686. except:
  1687. print ( orderId, json.dumps ( resp, ensure_ascii = False ) )
  1688. return order_list, sup_list
  1689. def readExcelByPd(upLoadFilePath):
  1690. df_in = pd.read_excel ( upLoadFilePath, dtype = str )
  1691. # receiver_province_name = '江苏省'
  1692. # goods_id = '4993092771502759936'
  1693. # df_out = df_in[df_in['商品系统id']==str(goods_id)]
  1694. # df_out = df_out[df_out['区域名称(1级)']==str(receiver_province_name)]
  1695. # df_out = pd.DataFrame(df_out).to_dict('records')
  1696. # if len(df_out) == 1:
  1697. # dict_out = df_out[0]
  1698. # print(dict_out)
  1699. return df_in
  1700. def selectGoodsOrderByGoodsOrderIds(app_id, token, outDfPath, upLoadFile_goods, upLoadFile_orderids):
  1701. goodsInfoDf = readExcelByPd ( upLoadFile_goods )
  1702. orderidsDF = readExcelByPd ( upLoadFile_orderids )
  1703. orderIds = list ( set ( orderidsDF['订货单号'] ) )
  1704. order_df_out = []
  1705. sup_df_out = []
  1706. for orderId in orderIds:
  1707. order_list, sup_list = selectGoodsOrderByGoodsOrderId ( app_id, token, orderId, goodsInfoDf )
  1708. order_df_out = order_df_out + order_list
  1709. sup_df_out = sup_df_out + sup_list
  1710. order_df_out = pd.DataFrame ( order_df_out )
  1711. sup_df_out = pd.DataFrame ( sup_df_out )
  1712. writer = pd.ExcelWriter ( outDfPath )
  1713. orderidsDF.to_excel ( writer, sheet_name = '查询订货单号', columns = ['订货单号'], index = False )
  1714. order_df_out.to_excel ( writer, sheet_name = '订货单', index = False )
  1715. sup_df_out.to_excel ( writer, sheet_name = '发货单', index = False )
  1716. writer.save ()
  1717. # 创建发货单下载请求 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1718. def createInvoiceDownload(app_id, token, start_date, end_date, mode='pay'):
  1719. '''
  1720. mode参数
  1721. 'pay'指定为下单时间
  1722. 'supplier_split'指定为供应商预结算时间
  1723. '''
  1724. url = 'https://cloud.xc-fintech.com/api/v1/file/create'
  1725. headers = {
  1726. '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',
  1727. 'Authorization': token}
  1728. params = {"download_file_type": 40,
  1729. "sale_type_list": [1, 2, 3, 5, 6],
  1730. f"start_{mode}_time": f"{start_date} 00:00:00",
  1731. f"end_{mode}_time": f"{end_date} 23:59:59",
  1732. "app_id": app_id}
  1733. resp = requests.post ( url, json = params, headers = headers ).text
  1734. log_time = datetime.now ().strftime ( '%Y-%m-%d %H:%M:%S' )
  1735. print ( log_time, len ( resp ) )
  1736. # 查询发货单下载列表,循环检查 发货单是否可以进行下载
  1737. def selectInvoiceDownloadList(app_id, token) -> str:
  1738. '''
  1739. 【返回值】为 task_id -> str
  1740. '''
  1741. url = 'https://cloud.xc-fintech.com/api/v1/file/buffer_area/list'
  1742. headers = {
  1743. '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',
  1744. 'Authorization': token}
  1745. params = {"file_type": 40,
  1746. "current_page": 1,
  1747. "page_size": 5,
  1748. "app_id": app_id}
  1749. a = 2
  1750. n = 0
  1751. task_ids = []
  1752. while a == 2 and n <= 10:
  1753. try:
  1754. resp = requests.post(url, json = params, headers = headers, timeout = 2)
  1755. resp_json = resp.json ()
  1756. task_list = resp_json['task_list']
  1757. handle_status = task_list[0]['handle_status']
  1758. task_id = task_list[0]['task_id']
  1759. task_ids.append ( task_id )
  1760. a = handle_status
  1761. time.sleep(10)
  1762. except:
  1763. resp.close ()
  1764. time.sleep (10)
  1765. a = 2
  1766. n += 1
  1767. print(n,end ='-')
  1768. return task_ids[0]
  1769. # 下载发货单
  1770. def invoiceDownload(app_id, token, task_id, save_path, start_date, end_date, mode = 'pay') -> str:
  1771. '''
  1772. 【save_path参数】例:'C:/Users/ClownHe/Desktop/店务通数据'
  1773. 【mode参数】'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1774. 【返回值】为 df_path -> str格式
  1775. '''
  1776. url = 'https://cloud.xc-fintech.com/api/v1/file/download'
  1777. headers = {
  1778. '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',
  1779. 'Authorization': token,
  1780. 'Accept':'application/json, text/plain, */*',
  1781. 'Accept-Encoding':'gzip, deflate, br'}
  1782. params = {"task_id":task_id,
  1783. "app_id":app_id,
  1784. "token":token}
  1785. df_data = requests.post(url,headers=headers,json=params).content
  1786. with open(save_path + f'/{start_date}至{end_date}发货单({mode}).xlsx', mode = 'wb') as f:
  1787. f.write(df_data)
  1788. print(f'【已下载】{start_date}至{end_date}发货单({mode}).xlsx')
  1789. df_path = save_path + f'/{start_date}至{end_date}发货单({mode}).xlsx'
  1790. return df_path
  1791. # 运行发货单下载 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1792. def runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode = 'pay') -> str:
  1793. '''
  1794. 【save_path参数】例:'C:/Users/ClownHe/Desktop/店务通数据'
  1795. 【mode参数】'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1796. 【返回值】为 df_path -> str格式
  1797. '''
  1798. createInvoiceDownload(app_id, token, start_date, end_date, mode)
  1799. time.sleep(0.5)
  1800. task_id = selectInvoiceDownloadList(app_id, token)
  1801. print(task_id)
  1802. df_path = invoiceDownload(app_id, token, task_id, save_path, start_date, end_date, mode)
  1803. print(df_path)
  1804. if 1==1:
  1805. dfFormatting(df_path)
  1806. return df_path
  1807. def dfFormatting(df_in_path):
  1808. df_in = pd.read_excel(df_in_path)
  1809. df_in['一级区域'] = df_in['一级区域'].fillna('')
  1810. df_in['二级区域'] = df_in['二级区域'].fillna('')
  1811. df_in['三级区域'] = df_in['三级区域'].fillna('')
  1812. df_in['所属省市区'] = df_in['一级区域'] + df_in['二级区域'] + df_in['三级区域']
  1813. df_in['商品分类'] = df_in['二级分类'].fillna(df_in['一级分类'])
  1814. df_in['发货单号'] = df_in['发货单号'].astype(str)
  1815. df_in['订货单号'] = df_in['订货单号'].astype(str)
  1816. # print(df_in.info())
  1817. df_out = df_in[
  1818. ['订货门店编号', '订货门店名称', '品牌', '所属省市区', '发货单号', '订货单号', '发货方', '发货单金额', '结算金额', '服务费', '交易手续费', '通道手续费', '发货单状态',
  1819. '创建时间', '下单时间', '发货时间', '签收时间', '商品分类', '商品编号', '商品名称', '商品厂商', '货号', '规格', '数量', '订货单价', '订货小计', '采购单价',
  1820. '采购小计', '单位', '收货人', '收货人电话', '收货地址']]
  1821. df_out.to_excel(df_in_path,index = False)
  1822. if __name__ == '__main__':
  1823. if 1==1:
  1824. app_id, token = getToken ()
  1825. print ( app_id, token )
  1826. # app_id = '7005337094168150016'
  1827. # token ='20230207-bff9c872aa2842d2b03f75e25bfb37a0'
  1828. goods_no = 'P4464051565'
  1829. io_path = 'C:/Users/ClownHe/Desktop/店务通数据'
  1830. if 1 == 0:
  1831. # 获取商品上下架状态及商品id
  1832. publish_state, goods_id = selectGoodsInfoPubAndId ( app_id, token, goods_no )
  1833. # 操作商品上下架,并返回操作结果
  1834. return_result = updatePublishState ( app_id, token, publish_state, goods_id )
  1835. if return_result:
  1836. print ( '已完成操作' )
  1837. readUploadFile ( 'uploadfileForSupArea.xlsx' )
  1838. selectSupplierlist ( app_id, token, 'download' )
  1839. selectAllGoodsInfo ( app_id, token, 'download' )
  1840. selectAreaTree ( app_id, token )
  1841. updateSuppliersAreaInfo ( app_id, token, 'uploadfileForSupArea.xlsx' )
  1842. # 以下两步操作,导出供应商在供商品
  1843. selectSupplierlist = selectSupplierlist ( app_id, token, 'select' )
  1844. goodsInSupplierList ( app_id, token, selectSupplierlist, 'download' )
  1845. publish_state, goods_id = selectGoodsInfoPubAndId ( app_id, token, goods_no )
  1846. print ( publish_state, goods_id )
  1847. addGoodsToSupplierSupList ( app_id, token, io_path + '/addGoodsToSupplierSupList.xlsx' )
  1848. selectSupplierlist = selectSupplierlist ( app_id, token, 'select' )
  1849. goodsInSupplierList ( app_id, token, selectSupplierlist, 'download' )
  1850. updateGoodsAreaSupplierPrice ( app_id, token, io_path + '/updateGoodsAreaSupplierPrice.xlsx' )
  1851. goodsInGoodsCentre ( app_id, token, io_path )
  1852. selectGoodsInfoDetail ( app_id, token, io_path + '/selectGoodsInfoDetailUP.xlsx',
  1853. io_path + '/selectGoodsInfoDetail.xlsx' )
  1854. updateGoodsSupStatus ( app_id, token, io_path + '/updateGoodsSupStatus-模板.xlsx' )
  1855. updateGoodsPriceInGoodsInfoCentre ( app_id, token, io_path + '/updateGoodsPriceInGoodsInfoCentre.xlsx' )
  1856. selectAllGoodsInfoInDetailPrice ( app_id, token, io_path + '/selectAllGoodsInfoInDetailPrice.xlsx' )
  1857. updateGoodsAreaSupplierPrice ( app_id, token, io_path + '/updateGoodsAreaSupplierPrice.xlsx' )
  1858. selectAllStoreInfo ( app_id, token, io_path + '/selectAllStoreInfo.xlsx' )
  1859. selectAllGoodsInfoInDetailPrice ( app_id, token,
  1860. io_path + '/selectAllGoodsInfoInDetailPrice(20230524.9.57).xlsx' )
  1861. goodsInGoodsCentre ( app_id, token, io_path )
  1862. # 以下三步完成单品绑定供应商,变更供货,实现价格更新
  1863. addGoodsToSupplierSupList ( app_id, token, io_path + '/addGoodsToSupplierSupList.xlsx' )
  1864. updateGoodsSupStatus ( app_id, token, io_path + '/updateGoodsSupStatus.xlsx' )
  1865. updateGoodsAreaSupplierPrice ( app_id, token, io_path + '/updateGoodsAreaSupplierPrice.xlsx' )
  1866. readExcelByPd ( io_path + '/selectAllGoodsInfoInDetailPrice(20230524.9.57).xlsx' )
  1867. # 按 订货单号 查询订单信息 及发货信息
  1868. upLoadFile_goods = '/selectAllGoodsInfoInDetailPrice(20230524.13.00).xlsx'
  1869. upLoadFile_orderids = '/订货单号查询(截至2023-05-24 12-10-02).xlsx'
  1870. selectGoodsOrderByGoodsOrderIds ( app_id, token,
  1871. io_path + '/selectGoodsOrderByGoodsOrderIds.xlsx',
  1872. io_path + upLoadFile_goods,
  1873. io_path + upLoadFile_orderids )
  1874. selectSupplierlist = [{'供应商id': '7036927150058246144', '供应商全名': '上海炳优实业有限公司', '简称': ''}]
  1875. goodsInSupplierList ( app_id, token, selectSupplierlist, 'download' )
  1876. for i in [0, 1, 2, 3]:
  1877. updateGoodsAreaSupplierPrice ( app_id, token, io_path + f'/updateGoodsAreaSupplierPrice{i}.xlsx' )
  1878. time.sleep ( 4 )
  1879. # 运行发货单下载 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1880. start_date = '2023-10-01'
  1881. end_date = '2023-10-27'
  1882. mode = 'supplier_split' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1883. save_path = io_path
  1884. runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
  1885. if 1==0:
  1886. goodsInGoodsCentre(app_id, token, io_path)
  1887. if 1==0:
  1888. updateGoodsInGoodsCentreSUPshops(app_id, token, io_path + '/updateGoodsInGoodsCentreSUPshops.xlsx')
  1889. if 1==1:
  1890. # 操作区
  1891. # 运行发货单下载 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1892. start_date = '2024-03-01'
  1893. end_date = '2024-03-31'
  1894. mode = 'supplier_split' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1895. save_path = io_path
  1896. runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
  1897. start_date = '2024-04-01'
  1898. end_date = '2024-04-05'
  1899. mode = 'supplier_split' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间 11
  1900. save_path = io_path
  1901. runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
  1902. start_date = '2024-03-30'
  1903. end_date = '2024-04-05'
  1904. mode = 'supplier_split' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1905. save_path = io_path
  1906. runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
  1907. start_date = '2024-03-01'
  1908. end_date = '2024-03-31'
  1909. mode = 'pay' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1910. save_path = io_path
  1911. runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
  1912. start_date = '2024-04-01'
  1913. end_date = '2024-04-05'
  1914. mode = 'pay' # 'pay'指定为下单时间 'supplier_split'指定为供应商预结算时间
  1915. save_path = io_path
  1916. runInvoiceDownload(app_id, token, save_path, start_date, end_date, mode)
  1917. # upLoadFile_goods = '/selectAllGoodsInfoInDetailPrice(20231012.16.50).xlsx'
  1918. # upLoadFile_orderids = '/活动赠送产品订单查询10.12v1.xlsx'
  1919. # selectGoodsOrderByGoodsOrderIds(app_id, token,
  1920. # io_path + '/selectGoodsOrderByGoodsOrderIds(赠品)1.xlsx',
  1921. # io_path + upLoadFile_goods,
  1922. # io_path + upLoadFile_orderids)
  1923. # beginTime_int = int ((datetime.today () + timedelta (days=-1)).strftime ('%Y%m%d')) # 20220623
  1924. # endTime_int = int ((datetime.today () + timedelta (days=-1)).strftime ('%Y%m%d')) # 20220623
  1925. # beginTime_temp = parse (str(beginTime_int)).timestamp ()
  1926. # endTime_temp = parse (str(beginTime_int)).timestamp ()
  1927. # endTime_temp = int(time.time()*1000)
  1928. # print(endTime_temp)
  1929. if 1 == 0:
  1930. # 批量上下架产品
  1931. df_in = pd.read_excel ( io_path + '/updatePublishStateBatch.xlsx', dtype = str )
  1932. goods_id_list = list ( set ( df_in['商品id'] ) )
  1933. for goods_id in goods_id_list:
  1934. result = updatePublishState ( app_id, token, 0, goods_id )
  1935. print ( goods_id, result )
  1936. if 1==0:
  1937. df_path = r'C:\Users\ClownHe\Desktop\店务通数据\2024-03-01至2024-03-31发货单(pay).xlsx'
  1938. df_in = pd.read_excel(df_path)
  1939. col = list(df_in.columns)
  1940. print(col)