platform_order_api_util.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. __title__ = '各个平台的订单API接口'
  5. @Time : 2020/9/30 12:33
  6. @Author : Kenny-PC
  7. @Software: PyCharm
  8. # code is far away from bugs with the god animal protecting
  9. I love animals. They taste delicious.
  10. ┏┓ ┏┓
  11. ┏┛┻━━━┛┻┓
  12. ┃ ☃ ┃
  13. ┃ ┳┛ ┗┳ ┃
  14. ┃ ┻ ┃
  15. ┗━┓ ┏━┛
  16. ┃ ┗━━━┓
  17. ┃ 神兽保佑 ┣┓
  18. ┃ 永无BUG! ┏┛
  19. ┗┓┓┏━┳┓┏┛
  20. ┃┫┫ ┃┫┫
  21. ┗┻┛ ┗┻┛
  22. """
  23. import datetime
  24. import hashlib
  25. import math
  26. import time
  27. from concurrent.futures import ProcessPoolExecutor
  28. from urllib import parse
  29. import requests
  30. import account_list_zwg as al
  31. from util import date_util
  32. from util import platform_config_util
  33. from util import robust_util
  34. # md5加密,使用utf-8编码
  35. def md5(s):
  36. md5 = hashlib.md5()
  37. md5.update(s.encode("utf-8"))
  38. return md5.hexdigest()
  39. # 阅文
  40. @robust_util.catch_exception
  41. def get_yuewen_order(st, et):
  42. start_exec_seconds = date_util.getCurrentSecondTime()
  43. total_order_list = ()
  44. account_list = platform_config_util.get_yuewen_account_list()
  45. executor = ProcessPoolExecutor(max_workers=5)
  46. futures = []
  47. for account in account_list:
  48. future = executor.submit(get_yuewen_order_task, st, et, account)
  49. futures.append(future)
  50. executor.shutdown(True)
  51. for future in futures:
  52. order_list = future.result()
  53. if len(order_list) > 0:
  54. total_order_list = order_list + total_order_list
  55. print('阅文订单数量:', len(total_order_list), '执行时长(秒):', date_util.getCurrentSecondTime() - start_exec_seconds)
  56. return total_order_list
  57. def get_yuewen_order_task(st, et, account):
  58. order_list = ()
  59. email = account[0]
  60. appsecert = account[1]
  61. url = 'https://open.yuewen.com/cpapi/wxRecharge/querychargelog'
  62. version = 1
  63. order_status = 2 # 已支付
  64. page_count = 100 # 每页100条数据
  65. start_time = st
  66. for i in range((et - st) // 86400 + 1):
  67. page = 1
  68. last_min_id = ''
  69. last_max_id = ''
  70. total_count = ''
  71. last_page = ''
  72. while True:
  73. if start_time == et:
  74. break
  75. end_time = min(start_time + 86400, et)
  76. timestamp = int(time.time())
  77. params = {
  78. 'email': email,
  79. 'version': version,
  80. 'timestamp': timestamp,
  81. 'start_time': start_time,
  82. 'end_time': end_time,
  83. 'page': page,
  84. 'order_status': order_status
  85. }
  86. if page > 1:
  87. params['last_min_id'] = last_min_id
  88. params['last_max_id'] = last_max_id
  89. params['total_count'] = total_count
  90. params['last_page'] = last_page
  91. sorted_data = sorted(params.items())
  92. str_params = ''
  93. for k, v in sorted_data:
  94. str_params = str_params + str(k) + str(v)
  95. sign = md5(appsecert + str_params).upper()
  96. # 放入签名
  97. params['sign'] = sign
  98. response_result_json = requests.get(url=url, params=params).json()
  99. code = response_result_json['code']
  100. ## 此接口有调用频率限制,相同查询条件每分钟仅能请求一次
  101. if code != 0:
  102. print('阅文查询充值接口异常:', response_result_json, '参数', params)
  103. break
  104. # if code == 10408:
  105. # if fail_count > 0:
  106. # break
  107. #
  108. # sleep_seconds = random.randint(60, 70)
  109. # print('阅文获取订单数据线程休眠【{sleep_seconds}】秒,因为该接口有一分钟的限制'.format(sleep_seconds=sleep_seconds))
  110. # time.sleep(sleep_seconds)
  111. #
  112. # print('重试一次')
  113. # fail_count = fail_count + 1
  114. # get_yuewen_order_task(st, et, account, fail_count)
  115. response_data = response_result_json['data']
  116. total_count = response_data['total_count']
  117. if total_count == 0:
  118. continue
  119. last_min_id = response_data['min_id']
  120. last_max_id = response_data['max_id']
  121. last_page = response_data['page']
  122. order_item_list = response_data['list']
  123. for order_item in order_item_list:
  124. order_time = order_item['order_time']
  125. dtime = datetime.datetime.strptime(order_time, "%Y-%m-%d %H:%M:%S")
  126. order_time_unix = int(time.mktime(dtime.timetuple()))
  127. order_id = order_item['order_id']
  128. if date_util.checkInterval(start_time, end_time, order_time_unix) == False:
  129. print('阅文账号【{key}】,查询时间【{start_time} - {end_time}】,有不符合该时间范围的订单,订单Id【{order_id}】的时间为【{order_time}】'
  130. .format(key=email, start_time=date_util.getSecondsToDatetime(start_time),
  131. end_time=date_util.getSecondsToDatetime(end_time), order_id=order_id,
  132. order_time=order_time))
  133. continue
  134. order = {}
  135. order['date'] = ((order_time_unix + 8 * 3600) // 86400) * 86400 - 8 * 3600
  136. order['platform'] = '阅文'
  137. order['channel'] = order_item['app_name']
  138. order['from_novel'] = order_item['book_name']
  139. order['user_id'] = order_item['openid']
  140. order['stage'] = ''
  141. order['channel_id'] = 0
  142. order['order_time'] = order_time
  143. order['amount'] = order_item['amount']
  144. order['reg_time'] = order_item['reg_time']
  145. order['order_id'] = order_id
  146. order = sorted(order.items(), key=lambda item: item[0])
  147. order = dict(order)
  148. order = tuple(order.values())
  149. order_list = order_list + ((order),)
  150. # print('阅文账号【{key}】, 查询时间【{start_time} - {end_time}】,当前页【{page}】,本次查询订单数量【{total_count}】'
  151. # .format(key=email, start_time=date_util.getSecondsToDatetime(start_time),
  152. # end_time=date_util.getSecondsToDatetime(end_time),page=page, total_count=total_count))
  153. if int(page) >= math.ceil(total_count / int(page_count)):
  154. break
  155. page = page + 1
  156. start_time = start_time + 86400 # 天数加1
  157. # sleep_seconds = random.randint(60, 70)
  158. # print('阅文获取订单数据线程休眠【{sleep_seconds}】秒,因为该接口有一分钟的限制'.format(sleep_seconds=sleep_seconds))
  159. # time.sleep(sleep_seconds)
  160. return order_list
  161. # 掌读
  162. @robust_util.catch_exception
  163. def get_zhangdu_order(st, et):
  164. start_exec_seconds = date_util.getCurrentSecondTime()
  165. total_order_list = ()
  166. account_list = platform_config_util.get_zhangdu_account_list()
  167. executor = ProcessPoolExecutor(max_workers=5)
  168. futures = []
  169. for account in account_list:
  170. future = executor.submit(get_zhangdu_order_task, st, et, account)
  171. futures.append(future)
  172. executor.shutdown(True)
  173. for future in futures:
  174. order_list = future.result()
  175. if len(order_list) > 0:
  176. total_order_list = order_list + total_order_list
  177. print('掌读订单数量:', len(total_order_list), '执行时长(秒):', date_util.getCurrentSecondTime() - start_exec_seconds)
  178. return total_order_list
  179. def get_zhangdu_order_task(st, et, account):
  180. order_list = ()
  181. url = 'https://api.zhangdu520.com/channel/getorder'
  182. uid = account[0]
  183. appsecert = account[1]
  184. channel = account[2]
  185. timestamp = int(time.time())
  186. sign = md5(str(uid) + '&' + appsecert + '&' + str(timestamp))
  187. starttime = st
  188. timespace = 90 * 3600 * 24
  189. endtime = min(et, st + timespace)
  190. for x in range((et - st) // timespace + 1): # 分时段
  191. if x > 0:
  192. print('掌读跨天数查询:', x)
  193. page = 1
  194. while True:
  195. params = {
  196. 'uid': uid,
  197. 'timestamp': timestamp,
  198. 'sign': sign,
  199. 'starttime': starttime,
  200. 'endtime': endtime,
  201. 'page': page
  202. }
  203. response_result_json = requests.get(url=url, params=params).json()
  204. if 'data' not in response_result_json.keys():
  205. print('掌读账号【{key}】, 查询时间【{start_time} - {end_time}】,本次请求数据异常,响应报文【{result}】'
  206. .format(key=uid, start_time=date_util.getSecondsToDatetime(starttime),
  207. end_time=date_util.getSecondsToDatetime(endtime), result=response_result_json))
  208. break
  209. result_data = response_result_json['data']
  210. page_count = result_data['pageCount']
  211. if page_count == 0:
  212. break
  213. order_item_list = result_data['list']
  214. for order_item in order_item_list:
  215. if order_item['status'] != '1':#1为已支付
  216. continue
  217. order = {}
  218. order['amount'] = order_item['amount']
  219. order['channel_id'] = uid
  220. order['order_id'] = str(order_item['orderno'])
  221. order['order_time'] = order_item['ctime']
  222. order['user_id'] = order_item['openid']
  223. order['platform'] = '掌读'
  224. order['channel'] = channel
  225. order['reg_time'] = order_item['regtime']
  226. order['from_novel'] = ''
  227. order['stage'] = ''
  228. order['date'] = ((int(order_item['ctime']) + 8 * 3600) // 86400) * 86400 - 8 * 3600
  229. x = sorted(order.items(), key=lambda item: item[0])
  230. x = dict(x)
  231. x = tuple(x.values())
  232. order_list = order_list + ((x),)
  233. if page == page_count: #是最后一页
  234. break
  235. page = page + 1
  236. starttime = starttime + timespace
  237. endtime = min(et, starttime + timespace)
  238. return order_list
  239. # 花生
  240. @robust_util.catch_exception
  241. def get_huasheng_order(st, et):
  242. start_exec_seconds = date_util.getCurrentSecondTime()
  243. total_order_list = ()
  244. account_list = platform_config_util.get_huasheng_account_list()
  245. executor = ProcessPoolExecutor(max_workers=5)
  246. futures = []
  247. for account in account_list:
  248. url = 'https://vip.rlcps.cn/api/getMerchants'
  249. apiKey = str(account[0])
  250. apiSecurity = account[1]
  251. timestamp = str(int(time.time()))
  252. sign = md5(apiKey + timestamp + apiSecurity).upper()
  253. params = {
  254. 'apiKey': apiKey,
  255. 'apiSecurity': apiSecurity,
  256. 'timestamp': timestamp,
  257. 'sign': sign
  258. }
  259. response_result_json = requests.post(url, params).json()
  260. if 'data' not in response_result_json.keys():
  261. print('花生账号【{apiKey}】本次请求数据异常,响应报文【{result}】'.format(apiKey=apiKey, result=response_result_json))
  262. continue
  263. for merchant in response_result_json['data']:
  264. future = executor.submit(get_huasheng_order_task, st, et, account, merchant)
  265. futures.append(future)
  266. executor.shutdown(True)
  267. for future in futures:
  268. order_list = future.result()
  269. if len(order_list) > 0:
  270. total_order_list = order_list + total_order_list
  271. print('花生订单数量:', len(total_order_list), '执行时长(秒):', date_util.getCurrentSecondTime() - start_exec_seconds)
  272. return total_order_list
  273. def get_huasheng_order_task(st, et, account, merchant):
  274. order_list = ()
  275. apiKey = str(account[0])
  276. apiSecurity = account[1]
  277. stage = account[2]
  278. timestamp = str(int(time.time()))
  279. order_url = 'https://vip.rlcps.cn/api/orderList'
  280. merchant_id = merchant['merchant_id']
  281. merchant_name = merchant['merchant_name']
  282. start_time = st
  283. limit = 500
  284. for i in range((et - st) // 86400 + 1):
  285. page = 1
  286. while True:
  287. date = time.strftime("%Y-%m-%d", time.localtime(start_time))
  288. sign = md5(apiKey + date + str(merchant_id) + timestamp + apiSecurity).upper()
  289. order_params = {
  290. 'apiKey': apiKey,
  291. 'apiSecurity': apiSecurity,
  292. 'timestamp': timestamp,
  293. 'date': date,
  294. 'merchant_id': merchant_id,
  295. 'sign': sign,
  296. 'page': page,
  297. 'limit': limit
  298. }
  299. response_result_json = requests.post(order_url, order_params).json()
  300. if 'data' not in response_result_json.keys():
  301. print('花生账号【{key}】, 查询时间【{date}】, 渠道【{merchant_id}:{merchant_name}】本次请求数据异常,响应报文【{result}】'
  302. .format(key=apiKey, date=date, merchant_id=merchant_id, merchant_name=merchant_name,
  303. result=response_result_json))
  304. break
  305. if len(response_result_json['data']) == 0:
  306. break
  307. total_count = response_result_json['count']
  308. order_item_list = response_result_json['data']
  309. for order_item in order_item_list:
  310. if order_item['order_status'] == 1: # 1为已支付
  311. order = {}
  312. ##dtime = datetime.datetime.strptime(order_item['pay_at'],"%Y-%m-%d")
  313. ##order['date']= ((int(time.mktime(dtime.timetuple()))+8*3600)//86400)*86400-8*3600
  314. order['user_id'] = order_item['openid']
  315. order['order_id'] = order_item['trans_id']
  316. order['order_time'] = order_item['pay_at']
  317. order['reg_time'] = order_item['join_at']
  318. # TODO 花生的时间需要统一
  319. order['date'] = (start_time + 8 * 3600) // 86400 * 86400 - 8 * 3600
  320. order['channel'] = merchant_name
  321. order['channel_id'] = merchant_id
  322. order['platform'] = '花生'
  323. order['stage'] = stage
  324. order['from_novel'] = order_item['book_name']
  325. order['amount'] = order_item['amount']
  326. order = sorted(order.items(), key=lambda item: item[0])
  327. order = dict(order)
  328. order = tuple(order.values())
  329. order_list = order_list + ((order),)
  330. if int(page) >= math.ceil(total_count / int(limit)):
  331. break
  332. # print('花生账号【{key}】, 渠道【{merchant_id}:{merchant_name}】当前页【{page}】,本次查询订单数【{total_count}】,即将查询下一页'
  333. # .format(key=apiKey, merchant_id=merchant_id, merchant_name=merchant_name, page=page, total_count=total_count))
  334. page = page + 1
  335. start_time = start_time + 86400 # 天数加1
  336. return order_list
  337. # 掌中云
  338. @robust_util.catch_exception
  339. def get_zhangzhongyun_order(st, et):
  340. start_exec_seconds = date_util.getCurrentSecondTime()
  341. total_order_list = ()
  342. account_list = al.zzy_account_list
  343. # account_list = platform_util.get_zhangzhongyun_account_list()
  344. # account_list = [['1108701f1d6','0f9c0f8429d1a16a8a78c2306e7a4db3','清勇7月']]
  345. # account_list = [['1109295d56c','9bb955186597882ac473e86ba4576158','趣程20期']]
  346. executor = ProcessPoolExecutor(max_workers=5)
  347. futures = []
  348. for account in account_list:
  349. #url = 'https://openapi.818tu.com/partners/channel/channels/list?'
  350. url = 'https://inovel.818tu.com/partners/channel/channels/list?'
  351. key = account[0]
  352. secert = account[1]
  353. sign = md5(secert + 'key=' + key)
  354. params = 'key=' + key + '&sign=' + sign
  355. response_result_json = requests.get(url + params).json() # 获取子渠道列表
  356. if 'data' not in response_result_json.keys():
  357. print('掌中云账号【{key}】本次请求数据异常,响应报文【{result}】'.format(key=key, result=response_result_json))
  358. continue
  359. items = response_result_json['data']['items']
  360. for channel in items:
  361. # 获取channel_id 后逐个拉取历史orders
  362. future = executor.submit(get_zhangzhongyun_order_task, st, et, account, channel)
  363. futures.append(future)
  364. executor.shutdown(True)
  365. for future in futures:
  366. order_list = future.result()
  367. if len(order_list) > 0:
  368. total_order_list = order_list + total_order_list
  369. print('掌中云订单数量:', len(total_order_list), '执行时长(秒):', date_util.getCurrentSecondTime() - start_exec_seconds)
  370. return total_order_list
  371. def get_zhangzhongyun_order_task(st, et, account, channel):
  372. # 掌中云的时间格式比较特殊,转换下
  373. st = platform_config_util.get_zhangzhongyun_format_time(st)
  374. et = platform_config_util.get_zhangzhongyun_format_time(et)
  375. order_list = ()
  376. key = account[0]
  377. secert = account[1]
  378. stage = account[2]
  379. order_url = 'https://openapi.818tu.com/partners/channel/orders/list?'
  380. channel_id = channel['id']
  381. channel_name = channel['nickname']
  382. status = str(1)
  383. page = str(1)
  384. per_page = str(1000)
  385. get_time = st
  386. limit_time = et
  387. gte = parse.urlencode({'created_at[gte]': get_time}) # gte就是ge 大于等于开始时间
  388. lt = parse.urlencode({'created_at[lt]': limit_time}) # 小于 结束时间
  389. while True:
  390. sign = md5(secert + 'channel_id=' + str(
  391. channel_id) + '&created_at[gte]=' + get_time + '&created_at[lt]=' + limit_time + '&key=' + key + '&page=' + str(
  392. page) + '&per_page=' + per_page + '&status=' + status)
  393. params = 'channel_id=' + str(channel_id) + '&' + gte + '&' + lt + '&page=' + str(
  394. page) + '&per_page=' + per_page + '&status=' + status + '&key=' + key + '&sign=' + sign
  395. response_result_json = requests.get(order_url + params).json()
  396. if 'data' not in response_result_json.keys():
  397. print('掌中云账号【{key}】,查询时间【{start_time} - {end_time}】,渠道【{channel_id}:{channel_name}】本次请求数据异常,响应报文【{result}】'
  398. .format(key=key, start_time=date_util.getSecondsToDatetime(get_time),
  399. end_time=date_util.getSecondsToDatetime(limit_time),channel_id=channel_id, channel_name=channel_name, result=response_result_json))
  400. break
  401. total_count = response_result_json['data']['count'] # 总数量
  402. order_item_list = response_result_json['data']['items'] # 订单列表
  403. for order_item in order_item_list:
  404. order = {}
  405. order['user_id'] = str(order_item['member']['openid'])
  406. order['channel'] = channel_name
  407. order['reg_time'] = order_item['member']['created_at']
  408. order['channel_id'] = channel_id
  409. order['amount'] = round(order_item['price'] / 100, 2)
  410. order['order_id'] = str(order_item['id'])
  411. order['order_time'] = order_item['created_at']
  412. order['platform'] = '掌中云'
  413. order['stage'] = stage
  414. dtime = datetime.datetime.strptime(order_item['created_at'][0:10], "%Y-%m-%d")
  415. order['date'] = ((int(time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
  416. if str(order_item['from_novel_id']) != 'None':
  417. order['from_novel'] = order_item['from_novel']['title']
  418. else:
  419. order['from_novel'] = 'None'
  420. x = sorted(order.items(), key=lambda item: item[0])
  421. x = dict(x)
  422. x = tuple(x.values())
  423. order_list = order_list + ((x),)
  424. if int(page) >= math.ceil(total_count / int(per_page)):
  425. break
  426. # print('掌中云账号【{key}】, 渠道【{channel_id}:{channel_name}】当前页【{page}】,本次查询订单数【{total_count}】,即将查询下一页'
  427. # .format(key=key, channel_id=channel_id, channel_name=channel_name, page=page, total_count=total_count))
  428. page = int(page) + 1
  429. return order_list
  430. # 悠书阁
  431. @robust_util.catch_exception
  432. def get_youshuge_order(st, et):
  433. start_exec_seconds = date_util.getCurrentSecondTime()
  434. total_order_list = ()
  435. account_list = platform_config_util.get_youshuge_account_list()
  436. executor = ProcessPoolExecutor(max_workers=5)
  437. futures = []
  438. for account in account_list:
  439. future = executor.submit(get_youshuge_order_task, st, et, account)
  440. futures.append(future)
  441. executor.shutdown(True)
  442. for future in futures:
  443. order_list = future.result()
  444. if len(order_list) > 0:
  445. total_order_list = order_list + total_order_list
  446. print('悠书阁订单数量:', len(total_order_list), '执行时长(秒):', date_util.getCurrentSecondTime() - start_exec_seconds)
  447. return total_order_list
  448. def get_youshuge_order_task(st, et, account):
  449. order_list = ()
  450. host_name = account[0]
  451. channel_id = int(account[1])
  452. secert_key = account[2]
  453. channel = account[3]
  454. stage = account[4]
  455. url = 'https://novel.youshuge.com/v2/open/orders'
  456. page = 1
  457. timestamp = int(time.time())
  458. start_date = time.strftime("%Y-%m-%d", time.localtime(st))
  459. end_date = time.strftime("%Y-%m-%d", time.localtime(et))
  460. while True:
  461. sign = md5('channel_id=' + str(channel_id) + '&end_date=' + end_date + '&host_name=' + host_name + '&page='
  462. + str(page) + '&pay_status=1' + '&start_date=' + start_date + '&time=' + str(timestamp) + '&key=' + secert_key).upper()
  463. params = {
  464. 'sign': sign,
  465. 'host_name': host_name,
  466. 'time': timestamp,
  467. 'channel_id': channel_id,
  468. 'page': page,
  469. 'pay_status': 1,
  470. 'start_date': start_date,
  471. 'end_date': end_date
  472. }
  473. respone = requests.post(url, params)
  474. if respone.status_code == 400:
  475. print('respone', respone)
  476. response_result_json = respone.json()
  477. if 'data' not in response_result_json.keys():
  478. print('悠书阁账号【{key}】,查询时间【{start_time} - {end_time}】,渠道【{channel_id}:{channel_name}】本次请求数据异常,响应报文【{result}】'
  479. .format(key=host_name, start_time=start_date, end_time=end_date, channel_id=channel_id, result=response_result_json))
  480. break
  481. order_item_list = response_result_json['data']
  482. if len(order_item_list) == 0:
  483. break
  484. for order_item in order_item_list:
  485. order = {}
  486. dtime = datetime.datetime.strptime(order_item['create_time'][0:10], "%Y-%m-%d")
  487. order['date'] = ((int(
  488. time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
  489. order['order_id'] = order_item['order_num']
  490. order['amount'] = round(int(order_item['price']) / 100, 2)
  491. order['order_time'] = order_item['create_time']
  492. order['channel'] = channel
  493. order['from_novel'] = order_item['book_name']
  494. order['stage'] = stage
  495. order['user_id'] = order_item['openid']
  496. order['channel_id'] = channel_id
  497. order['platform'] = '悠书阁'
  498. order['reg_time'] = order_item['reg_time']
  499. order = sorted(order.items(), key=lambda item: item[0])
  500. order = dict(order)
  501. order = tuple(order.values())
  502. order_list = order_list + ((order),)
  503. total_count = order_item_list[0]['count']
  504. if page == total_count:
  505. break
  506. page = page + 1
  507. return order_list
  508. def build_ysg_order_data(channel, channel_id, result_json, stage):
  509. order_list = ()
  510. if 'data' in result_json.keys():
  511. data = result_json['data']
  512. if len(data) > 0:
  513. for x in data:
  514. y = {}
  515. dtime = datetime.datetime.strptime(x['create_time'][0:10], "%Y-%m-%d")
  516. y['date'] = ((int(
  517. time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
  518. y['order_id'] = x['order_num']
  519. y['amount'] = round(int(x['price']) / 100, 2)
  520. y['order_time'] = x['create_time']
  521. y['channel'] = channel
  522. y['from_novel'] = x['book_name']
  523. y['stage'] = stage
  524. y['user_id'] = x['openid']
  525. y['channel_id'] = channel_id
  526. y['platform'] = '悠书阁'
  527. y['reg_time'] = x['reg_time']
  528. y = sorted(y.items(), key=lambda item: item[0])
  529. y = dict(y)
  530. y = tuple(y.values())
  531. order_list = order_list + ((y),)
  532. return order_list
  533. @robust_util.catch_exception
  534. def nor():
  535. return 1
  536. @robust_util.catch_exception
  537. def throw_exception():
  538. return 5 / 0