get_order.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. from app.api_data.order_util import *
  2. from model.DataBaseUtils import MysqlUtils
  3. from concurrent.futures import ThreadPoolExecutor
  4. from model.DingTalkUtils import DingTalkUtils
  5. db=MysqlUtils()
  6. def get_account(plactform,id=None):
  7. op = f" and id={id} " if id else ''
  8. data = db.quchen_text.getData(f"select text from order_account_text where platform='{plactform}' {op}")
  9. new_data = []
  10. for i in data:
  11. new_data.append(i[0].replace('\n', '').split(","))
  12. return new_data
  13. def get_new_account(plactform):
  14. data = db.quchen_text.getData(f"select text from order_account_text where platform='{plactform}' and create_time>='{du.get_n_days(-1)}'")
  15. new_data = []
  16. for i in data:
  17. new_data.append(i[0].replace('\n', '').split(","))
  18. return new_data
  19. def yangguang(start=None, end=None,new=None):
  20. if start:
  21. start = start+' 00:00:00'
  22. end = end+' 23:59:59'
  23. else:
  24. start = du.getTodayOrYestoday() + ' 00:00:00'
  25. end = du.get_n_hours_ago(0)
  26. client_id = 10008097
  27. token = '2xa1d55tTPBjeEA8Ho'
  28. accounts=get_account("阳光") if new is None else get_new_account('阳光')
  29. if accounts.__len__()==0:
  30. return
  31. else:
  32. print(f"阳光账号数:{accounts.__len__()}")
  33. for i in accounts:
  34. stage = i[0]
  35. vip_id = i[1]
  36. print(vip_id)
  37. get_yg_vip_channel(stage, vip_id, client_id, token)
  38. get_yg_data(stage, vip_id, client_id, token, start, end)
  39. x=1
  40. while True:
  41. a = db.quchen_text.getOne("select count(1) from yangguang_path where update_time is null")
  42. print(f" vip 待处理数量 {a} 正在等待数据回调")
  43. if a == 0:
  44. break
  45. time.sleep(60)
  46. x+=1
  47. if x>20:
  48. DingTalkUtils.send('阳光订单回调延时20min','18860455786')
  49. break
  50. for i in accounts:
  51. vip_id = i[1]
  52. stage=i[0]
  53. parse_yg_data(vip_id,stage)
  54. def huasheng(start=None,end=None,new=None):
  55. if start is None:
  56. start = end = du.getTodayOrYestoday()
  57. executor = ThreadPoolExecutor(max_workers=5)
  58. accounts = get_account("花生") if new is None else get_new_account('花生')
  59. if len(accounts)==0:
  60. return
  61. else:
  62. print(f'花生有账号{len(accounts)}个')
  63. li = []
  64. for account in accounts:
  65. channel_data = get_hs_channel(account)
  66. if not channel_data:
  67. continue
  68. else:
  69. print(f"账号:{account[2]} 有channel{len(channel_data)}个")
  70. for merchant in channel_data:
  71. executor.submit(get_huasheng_order_task, start, end, account, merchant,li)
  72. executor.shutdown(True)
  73. save_hs_data(li)
  74. def qiyue(start=None,end=None,new=None):
  75. if start is None:
  76. start = end = du.getNow()
  77. accounts = get_account("七悦") if new is None else get_new_account('七悦')
  78. if len(accounts) == 0:
  79. return
  80. else:
  81. print(f'七悦有账号{len(accounts)}个')
  82. for account in accounts:
  83. get_qiyue_order_task(start, end, account)
  84. def wending(start=None,end=None,new=None):
  85. if start is None:
  86. start = end = du.getNow()
  87. accounts = get_account("文鼎") if new is None else get_new_account('文鼎')
  88. if len(accounts) == 0:
  89. return
  90. else:
  91. print(f'文鼎有账号{len(accounts)}个')
  92. for account in accounts:
  93. get_wd_order_task(start, end, account)
  94. def zhangdu(start=None,end=None,new=None):
  95. if start is None:
  96. start = end = du.getNow()
  97. accounts = get_account("掌读") if new is None else get_new_account('掌读')
  98. if len(accounts) == 0:
  99. return
  100. else:
  101. print(f'掌读有账号{len(accounts)}个')
  102. for account in accounts:
  103. get_zd_order_task(start, end, account)
  104. def zhangzhongyun(start=None,end=None,new=None):
  105. if start is None:
  106. start = end = du.getNow()
  107. executor = ThreadPoolExecutor(max_workers=5)
  108. accounts = get_account("掌中云") if new is None else get_new_account('掌中云')
  109. if len(accounts) == 0:
  110. return
  111. else:
  112. print(f'掌中云有账号{len(accounts)}个')
  113. for account in accounts:
  114. executor.submit(get_zzy_order_task,start, end, account)
  115. executor.shutdown()
  116. def yueweng(start=None,end=None,new=None):
  117. if start is None:
  118. start = end = du.getNow()
  119. executor = ThreadPoolExecutor(max_workers=5)
  120. accounts = get_account("阅文") if new is None else get_new_account('阅文')
  121. if len(accounts) == 0:
  122. return
  123. else:
  124. print(f'阅文有账号{len(accounts)}个')
  125. for account in accounts:
  126. executor.submit(get_yueweng_order_task,start, end, account)
  127. executor.shutdown()
  128. def hourly():
  129. # try:
  130. # yangguang()
  131. # except:
  132. # pass
  133. st = du.get_n_days(0)
  134. et = du.get_n_days(1)
  135. huasheng()
  136. qiyue()
  137. wending()
  138. zhangdu()
  139. zhangzhongyun(st,et)
  140. def daily():
  141. st = du.get_n_days(-10)
  142. st2=du.get_n_days(-3)
  143. et = du.get_n_days(-1)
  144. # try:
  145. # yangguang(st, et)
  146. # except:
  147. # pass
  148. huasheng(st, et)
  149. qiyue(st2, et) # 有毛病
  150. wending(st, et)
  151. zhangdu(st, et)
  152. zhangzhongyun(st, et)
  153. def daily_yg():
  154. st = du.get_n_days(-10)
  155. et = du.get_n_days(-1)
  156. try:
  157. yangguang(st, et)
  158. except:
  159. pass
  160. if __name__ == '__main__':
  161. # a=time.time()
  162. # yangguang()
  163. # print(time.time()-a)
  164. # huasheng('2021-02-24','2021-02-24')
  165. # qiyue()
  166. # wending()
  167. # zhangdu('2020-11-01', '2020-12-20')
  168. zhangzhongyun('2021-04-01', '2021-04-21')