report_push.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. from mysql_db import MysqlDB
  2. import datetime
  3. class ReportPush(object):
  4. """
  5. 报表推送功能实现类
  6. """
  7. pass
  8. # 1:总浏览量
  9. #
  10. # 集团部分+项目部分!!!
  11. # ----项目PV--权限项目范围内,求和
  12. # 参数:时间区间 和 项目列表
  13. sql_1_1 = """
  14. SELECT SUM(pv) AS pv1 FROM a_idfa_behavior_sum
  15. WHERE `report_d` >= %s and report_d < %s AND house_id IN %s
  16. """
  17. # ----集团PV--权限项目范围内,求和
  18. # 参数:数据区间和项目列表
  19. sql_1_2 = """
  20. SELECT SUM(pv) AS pav2 FROM a_behavior_brand_mini_day
  21. WHERE report_d >= %s and report_d < %s AND house_id IN %s
  22. """
  23. # 2:总浏览人数
  24. #
  25. # 参数,数据区间, 项目列表
  26. sql_1_3 = """
  27. SELECT
  28. count(
  29. DISTINCT IFNULL(mobile, user_id)
  30. ) as people
  31. FROM
  32. (
  33. SELECT
  34. A.user_id,
  35. B.mobile
  36. FROM
  37. a_idfa_behavior_sum A
  38. LEFT JOIN d_user B ON A.user_id = B.user_id
  39. WHERE
  40. A.report_d >= %s and A.report_d < %s
  41. AND A.house_id IN %s
  42. UNION
  43. SELECT
  44. A.brand_user_id AS user_id,
  45. B.mobile
  46. FROM
  47. a_behavior_brand_mini_day A
  48. LEFT JOIN `a_brand_app_customer` B ON A.brand_user_id = B.brand_customer_id
  49. WHERE
  50. A.report_d >= %s and A.report_d < %s
  51. AND A.house_id IN %s
  52. ) t1
  53. """
  54. # 3:新增获客
  55. sql_1_4 = """
  56. SELECT
  57. count(
  58. DISTINCT IFNULL(mobile, user_id)
  59. )
  60. FROM
  61. (
  62. SELECT
  63. user_id,
  64. mobile,
  65. created
  66. FROM
  67. `d_user`
  68. WHERE
  69. created >= %s
  70. AND created < %s
  71. AND house_id IN %s
  72. UNION
  73. SELECT
  74. brand_customer_id AS user_id,
  75. mobile,
  76. rlat_created
  77. FROM
  78. `a_brand_app_customer_house_rlat`
  79. WHERE
  80. rlat_created >= %s
  81. AND rlat_created < %s
  82. AND rlat_house_id IN %s
  83. ) t1
  84. """
  85. # 4:新增获电
  86. sql_1_5 = """
  87. SELECT
  88. COUNT(DISTINCT mobile)
  89. FROM
  90. (
  91. SELECT
  92. user_id,
  93. mobile,
  94. wx_phone_time AS created
  95. FROM
  96. `d_user`
  97. WHERE
  98. wx_phone_time >= %s
  99. AND wx_phone_time < %s
  100. AND house_id IN %s
  101. UNION
  102. SELECT
  103. brand_customer_id,
  104. mobile,
  105. houdian_time AS created
  106. FROM
  107. (
  108. SELECT
  109. *,
  110. CASE
  111. WHEN rlat_created > shouquan_time THEN
  112. rlat_created
  113. ELSE
  114. shouquan_time
  115. END AS houdian_time
  116. FROM
  117. a_brand_app_customer_house_rlat
  118. WHERE
  119. mobile IS NOT NULL
  120. AND rlat_house_id IN %s
  121. AND cust_house_flag = '1'
  122. ) t1
  123. WHERE
  124. houdian_time >= %s
  125. AND houdian_time < %s
  126. ) t1
  127. """
  128. # 5:集团小程序总浏览量(针对香港置地要命名为【CNC小程序总浏览量】)
  129. # 集团部分
  130. # 6:集团小程序总浏览人数(针对香港置地要命名为【CNC小程序总浏览人数】)
  131. #
  132. # 集团小程序整体UV(见SQL3)
  133. sql_1_6 = """
  134. SELECT
  135. COUNT(DISTINCT brand_user_id) AS UV4
  136. FROM
  137. a_behavior_brand_mini_day
  138. WHERE
  139. report_d > %s
  140. AND report_d < %s
  141. AND house_id IN %s
  142. """
  143. # 7: 集团小程序新增获客(针对香港置地要命名为【CNC小程序新增获客】)
  144. #
  145. # 权限项目范围内,集团维度的获客
  146. # 8: 集团小程序新增获电(针对香港置地要命名为【CNC小程序新增获电】)
  147. #
  148. # 权限项目范围内,集团维度的获电
  149. # 9.单项目小程序总浏览量
  150. #
  151. # 项目部分
  152. #
  153. # 10.单项目小程序总浏览人数
  154. #
  155. # 权限项目未授权部分求和+去重的授权部分(见SQL2)
  156. #
  157. # 11.单项目小程序新增获客
  158. #
  159. # 权限项目未授权部分求和+去重的授权部分(见SQL7)
  160. #
  161. # 12.单项目小程序新增获电
  162. #
  163. # 权限项目所有授权手机号去重(见SQL8)
  164. # 1.默认值/001_大麦/项目排行榜/小程序排行榜TOP_N
  165. sql_2_1 = """
  166. SELECT
  167. a.house_id,
  168. a.house_name,
  169. SUM(a.pv),
  170. SUM(a.uv),
  171. SUM(a.new_cust_num),
  172. SUM(a.wx_num)
  173. from
  174. (SELECT
  175. a.*,
  176. b.house_name,
  177. c.interested_num,
  178. d.wx_num,
  179. e.new_cust_num
  180. FROM
  181. (
  182. SELECT
  183. house_id,
  184. count(
  185. DISTINCT ifnull(user_id, idfa)
  186. ) uv,
  187. sum(session_times) session_times,
  188. sum(sum_session_time) sum_session_time,
  189. sum(pv) pv,
  190. sum(page_num) page_num
  191. FROM
  192. a_idfa_behavior_sum
  193. WHERE
  194. report_d >= %s
  195. AND report_d < %s
  196. GROUP BY
  197. house_id
  198. ) a
  199. JOIN d_house b ON a.house_id = b.house_id
  200. LEFT JOIN (
  201. SELECT
  202. house_id,
  203. count(*) interested_num
  204. FROM
  205. f_interested_custlist
  206. WHERE
  207. report_d >= %s
  208. AND report_d < %s
  209. GROUP BY
  210. house_id
  211. ) c ON a.house_id = c.house_id
  212. LEFT JOIN (
  213. SELECT
  214. house_id,
  215. count(*) wx_num
  216. FROM
  217. f_customer_dynamic
  218. WHERE
  219. dynamic = 1
  220. AND report_d >= %s
  221. AND report_d <= %s
  222. GROUP BY
  223. house_id
  224. ) d ON a.house_id = d.house_id
  225. LEFT JOIN (
  226. SELECT
  227. house_id,
  228. count(*) new_cust_num
  229. FROM
  230. d_user
  231. WHERE
  232. created >= %s
  233. AND created < %s # 时间需要加一天!!!!
  234. GROUP BY
  235. house_id
  236. ) e ON a.house_id = e.house_id
  237. ) a
  238. GROUP BY
  239. a.house_id,
  240. a.house_name
  241. order by a.pv desc
  242. """
  243. # 2.默认值/006_大麦(集团)/集团项目排行榜v1.3/集团排行榜
  244. sql_2_2 = """
  245. select
  246. a.brand_id,
  247. a.house_id,
  248. a.house_name,
  249. SUM(a.pv),
  250. SUM(a.uv),
  251. SUM(a.new_cust),
  252. SUM(a.shouquan_cust)
  253. from
  254. (SELECT
  255. c.pv,c.uv,a.brand_id,a.house_id, a.house_name,a.brand_name,
  256. ifnull(b.house_layout_num,0) house_layout_num,
  257. ifnull(d.launch_time,'--') launch_time,
  258. c.new_cust,
  259. c.shouquan_cust,
  260. c.revisit_cust
  261. FROM
  262. (
  263. SELECT
  264. brand_id,
  265. ifnull(house_id, '0') house_id,
  266. sum(pv) pv,
  267. count(DISTINCT brand_user_id) uv,
  268. count(DISTINCT case when is_new_user = 1 then
  269. brand_user_id end) new_cust,
  270. count(DISTINCT case when is_shouquan_user = 1 then
  271. brand_user_id end) shouquan_cust,
  272. count(DISTINCT case when is_new_user = 0 then
  273. brand_user_id end) revisit_cust
  274. from a_behavior_brand_mini_day
  275. where report_d>= %s
  276. and report_d < %s
  277. GROUP BY
  278. brand_id,
  279. ifnull(house_id, '0')
  280. ) c
  281. LEFT JOIN (
  282. SELECT
  283. house_id,
  284. count(1) house_layout_num
  285. FROM
  286. d_content_layout
  287. WHERE
  288. `status` = '1'
  289. and house_id <> 1
  290. group by house_id
  291. union all
  292. SELECT
  293. bb.brand_id house_id,
  294. count(1) house_layout_num
  295. FROM
  296. d_content_layout aa join d_house bb
  297. on aa.house_id = bb.house_id
  298. WHERE
  299. aa.`status` = '1'
  300. and bb.status = '1'
  301. and aa.house_id <> 1
  302. group by bb.brand_id
  303. ) b ON c.house_id = b.house_id
  304. JOIN d_house a ON a.house_id = c.house_id
  305. and a.brand_id = c.brand_id
  306. left join d_house_attr d
  307. on c.house_id = d.house_id
  308. and c.brand_id = d.brand_id ) a
  309. group by a.brand_id, a.house_id, a.house_name
  310. order by a.pv desc
  311. """
  312. # 默认值/001_大麦/场景_用户来源渠道/用户来源渠道—明细
  313. sql_3_1 = """
  314. SELECT
  315. house_id,
  316. house_name,
  317. label_wx,
  318. COUNT(a.id) as counts
  319. FROM
  320. d_user_attr a
  321. LEFT JOIN d_scene b ON a.scene = b. CODE
  322. WHERE
  323. a.source IN (1, 2, 3, 4, 10)
  324. AND a.report_d >= %s
  325. AND a.report_d < '%s
  326. GROUP BY
  327. house_id,
  328. house_name,
  329. label_wx
  330. """
  331. # 默认值/006_大麦(集团)/场景(集团)_用户来源渠道_v1.1/用户来源渠道—明细
  332. sql_3_2 = """
  333. select
  334. brand_id,
  335. x.brand_name,
  336. house_id,
  337. house_name,
  338. label_wx,
  339. COUNT(1)
  340. from
  341. (SELECT
  342. a.scene,
  343. a.brand_id,
  344. b.*, a.share_brand_customer_id,
  345. '2' adviser_agent,
  346. a.house_id house_id,
  347. c.house_name house_name,
  348. c.brand_name
  349. FROM
  350. (
  351. SELECT
  352. scene,
  353. brand_id,
  354. share_brand_customer_id,
  355. house_id
  356. FROM
  357. d_brand_app_customer
  358. WHERE
  359. created >= %s
  360. AND created < DATE_ADD(
  361. %s, INTERVAL 1 DAY
  362. )
  363. UNION ALL
  364. SELECT
  365. scene,
  366. brand_id,
  367. share_brand_customer_id,
  368. brand_id house_id
  369. FROM
  370. d_brand_app_customer
  371. WHERE
  372. created >= %s
  373. AND created < DATE_ADD(
  374. %s, INTERVAL 1 DAY
  375. )
  376. ) a
  377. LEFT JOIN d_scene b ON a.scene = b. CODE
  378. JOIN d_house c ON a.house_id = c.house_id
  379. AND a.brand_id = c.brand_id) x
  380. group by x.brand_id, x.brand_name, x.house_id, x.house_name, x.label_wx
  381. """
  382. # 根据任务id获取推送客户信息
  383. sql_4 = """
  384. select a.task_key, a.customer_id, b.customer_type, b.`name`, b.mail, GROUP_CONCAT(c.house_or_brand_id) as ids
  385. from report_task_info a left join report_push_customer_info b on b.id = a.customer_id
  386. left join report_customer_authority_info c on b.id = c.customer_id
  387. where a.task_key = %s and a.status = b.status = c.status = 1
  388. group by a.task_key, a.customer_id, b.customer_type, b.`name`, b.mail
  389. """
  390. # 根据集团id获取项目id
  391. sql_5 = """
  392. select house_id, house_name from d_house where brand_id = %s
  393. """
  394. sql_6 = """insert into report_push_log(name, mail, report_name, push_time, send_status, status) values(%s, %s,
  395. %s, now(), %s, 1) """
  396. # 根据项目id获取集团id和名称
  397. sql_7 = """
  398. select a.brand_id, a.brand_name from d_house a where a.house_id = %s;
  399. """
  400. def __init__(self, db_name):
  401. self.db = MysqlDB(db_name)
  402. def report_data_query(self, task_key):
  403. """
  404. 定时任务推送数据准备
  405. :param task_key:
  406. :return:
  407. """
  408. # 根据任务key获取需要推送的客户以及可以的权限
  409. result = {}
  410. customers = self.db.select(self.sql_4, [task_key])
  411. # a.task_key, a.customer_id, b.customer_type, b.`name`, b.mail, GROUP_CONCAT(c.house_or_brand_id)
  412. time_range = self.get_time_range(task_key)
  413. all_time_rang = self.get_time_range(4)
  414. # 有限时间范围内的数据
  415. xcx_top_data = self.xcx_top(time_range)
  416. brand_top_data = self.brand_top(time_range)
  417. customer_channel_details_data = self.customer_channel_details(time_range)
  418. brand_customer_channel_details = self.brand_customer_channel_details(time_range)
  419. # 所有历史数据
  420. xcx_top_data_all = self.xcx_top(all_time_rang)
  421. brand_top_data_all = self.brand_top(all_time_rang)
  422. for customer in customers:
  423. customer_type = customer[2]
  424. house_ids = []
  425. brand_id_list = []
  426. if customer_type == 1:
  427. # 项目
  428. ids = customer[5]
  429. if str(house_ids).find(',') != -1:
  430. house_ids = [x for x in str(ids).split(',')]
  431. else:
  432. house_ids = [ids]
  433. pass
  434. elif customer_type == 2:
  435. # 集团
  436. brands = []
  437. brand_ids = customer[5]
  438. if str(brand_ids).find(',') != -1:
  439. brands = [x for x in str(brand_ids).split(',')]
  440. else:
  441. brands = [brand_ids]
  442. for id in brands:
  443. house_ids.extend(self.get_house_ids_by_brand_id(id))
  444. brand_id_list = brands
  445. result_data_1 = []
  446. result_data_2 = []
  447. result_data_3 = []
  448. result_data_4 = []
  449. result_data_5 = []
  450. result_data_6 = []
  451. result_data_7 = []
  452. result_data_8 = []
  453. # 1 数据总览 12个统计指标
  454. data_overview = self.data_overview(time_range, house_ids, xcx_top_data, brand_top_data)
  455. result_data_1.extend(data_overview)
  456. # 4:单个项目小程序数据排行榜
  457. for index, x in enumerate(xcx_top_data):
  458. if x[0] in house_ids:
  459. result_data_4.append([index, x[1], x[2], x[3], x[4], x[5]])
  460. # 5: 集团项目数据排行榜
  461. if customer_type == 2:
  462. for index, x2 in enumerate(brand_top_data):
  463. if x2[1] in house_ids or x2[0] in brand_id_list:
  464. result_data_5.append([index, x2[2], x2[3], x2[4], x2[5], x2[5], x2[6]])
  465. pass
  466. pass
  467. else:
  468. for index, x1 in enumerate(brand_top_data):
  469. if x1[1] in house_ids:
  470. result_data_5.append([index, x1[2], x1[3], x1[4], x1[5], x1[5], x1[6]])
  471. # 2: 项目数据排行榜
  472. house_with_brand_data = self.house_with_brand(xcx_top_data, brand_top_data)
  473. for index, x in enumerate(house_with_brand_data):
  474. if x[1] in house_ids or x[0] in brand_id_list:
  475. obj = [index]
  476. obj.extend(x)
  477. result_data_2.append(obj)
  478. # 3: 项目历史累计总数
  479. if customer_type == 2:
  480. all_data_history = self.house_with_brand(xcx_top_data_all, brand_top_data_all, brand_id_list)
  481. for index, x in enumerate(all_data_history):
  482. if x[1] in house_ids or x[0] in brand_id_list:
  483. obj = [index]
  484. obj.extend(x)
  485. result_data_3.append(obj)
  486. else:
  487. all_data_history = self.house_with_brand(xcx_top_data_all, brand_top_data_all)
  488. for index, x in enumerate(all_data_history):
  489. if x[0] in house_ids:
  490. obj = [index]
  491. obj.extend(x)
  492. result_data_3.append(obj)
  493. result[1] = result_data_1
  494. result[2] = result_data_2
  495. result[3] = result_data_3
  496. result[4] = result_data_4
  497. result[5] = result_data_5
  498. result[6] = result_data_6
  499. break
  500. # 7: 单个项目小程序获客来源场景分析
  501. # 8: 集团项目获客来源场景分析
  502. # 6: 项目获客来源场景分析
  503. return result
  504. def data_overview(self, time_range, house_ids, xcx_top_data, brand_top_data):
  505. """
  506. 统计数据总览
  507. :param time_range:
  508. :param house_ids:
  509. :return:
  510. """
  511. result = []
  512. # 1:总浏览量
  513. data_1_1 = self.db.select(self.sql_1_1, [time_range[0], time_range[1], house_ids])
  514. number_1_1 = data_1_1[0][0]
  515. data_1_2 = self.db.select(self.sql_1_2, [time_range[0], time_range[1], house_ids])
  516. number_1_2 = data_1_2[0][0]
  517. number_1 = number_1_1 + number_1_2
  518. result.append(number_1)
  519. # 2: 总浏览人数
  520. data_2 = self.db.select(self.sql_1_3, [time_range[0], time_range[1], house_ids, time_range[0], time_range[1]])
  521. number_2 = data_2[0][0]
  522. result.append(number_2)
  523. # 3:新增获客
  524. data_3 = self.db.select(self.sql_1_4, [time_range[0], time_range[1], house_ids, time_range[0], time_range[1]])
  525. number_3 = data_3[0][0]
  526. result.append(number_3)
  527. # 4:新增获电
  528. data_4 = self.db.select(self.sql_1_5, [time_range[0], time_range[1], house_ids, house_ids, time_range[0], time_range[1]])
  529. number_4 = data_4[0][0]
  530. result.append(number_4)
  531. xcx_top_data_part = [x for x in xcx_top_data if x[0] in house_ids]
  532. brand_top_data_part = [x for x in brand_top_data if x[0] in house_ids]
  533. # 5 6 7 8
  534. number_5 = 0
  535. number_6 = 0
  536. number_7 = 0
  537. number_8 = 0
  538. for x in brand_top_data_part:
  539. number_5 += x[3]
  540. number_6 += x[4]
  541. number_7 += x[5]
  542. number_8 += x[6]
  543. result.append(number_5)
  544. result.append(number_6)
  545. result.append(number_7)
  546. result.append(number_8)
  547. # 9 10 11 12
  548. number_9 = 0
  549. number_10 = 0
  550. number_11 = 0
  551. number_12 = 0
  552. for x in xcx_top_data_part:
  553. number_9 += x[2]
  554. number_10 += x[3]
  555. number_11 += x[4]
  556. number_12 += x[5]
  557. result.append(number_9)
  558. result.append(number_10)
  559. result.append(number_11)
  560. result.append(number_12)
  561. return result
  562. def house_with_brand(self, xcx_top_data, brand_top_data, brands=None):
  563. """
  564. 项目数据和集团数据的求和
  565. :param brands:
  566. :param xcx_top_data:
  567. :param brand_top_data:
  568. :return:
  569. """
  570. result = []
  571. house_ids = []
  572. if brands:
  573. house_ids.extend(house_ids)
  574. for x in xcx_top_data:
  575. house_ids.append(x[0])
  576. for x in brand_top_data:
  577. if x[1] not in house_ids:
  578. house_ids.append(x[1])
  579. for house_id in house_ids:
  580. a = []
  581. for index, x in enumerate(xcx_top_data):
  582. if house_id == x[0]:
  583. a.extend(x)
  584. b = []
  585. for index, y in enumerate(brand_top_data):
  586. if house_id == y[1] or house_id == y[0]:
  587. b.extend(y)
  588. if len(a) == 1 and len(b) == 1:
  589. result.append([b[0], a[0], a[1], a[2] + b[3], a[3] + b[4], a[4] + b[5], a[5] + b[6]])
  590. elif len(a) == 1 and len(b) == 0:
  591. _a = [1]
  592. for x in a:
  593. _a.append(x)
  594. result.append(_a)
  595. elif len(a) == 0 and len(b) == 1:
  596. result.append(b)
  597. else:
  598. pass
  599. result.sort(key=lambda obj: obj[1])
  600. result.reverse()
  601. return result
  602. def xcx_top(self, time_range):
  603. """
  604. 获取 1.默认值/001_大麦/项目排行榜/小程序排行榜TOP_N
  605. :return:
  606. """
  607. params = []
  608. params.extend(time_range)
  609. params.extend(time_range)
  610. params.extend(time_range)
  611. params.extend(time_range)
  612. xcx_top_data = self.db.select(self.sql_2_1, params)
  613. result = []
  614. for x in xcx_top_data:
  615. result.append([n for n in x])
  616. # xcx_top_data的结果结构
  617. # 0 a.house_id, 项目id
  618. # 1 a.house_name, 项目名称
  619. # 2 SUM(a.pv), 浏览总量
  620. # 3 SUM(a.uv), 浏览人数
  621. # 4 SUM(a.new_cust_num), 新增获客
  622. # 5 SUM(a.wx_num) 授权手机号
  623. result.sort(key=lambda obj: obj[2])
  624. result.reverse()
  625. return result
  626. def brand_top(self, time_range):
  627. """
  628. 2.默认值/006_大麦(集团)/集团项目排行榜v1.3/集团排行榜
  629. :param task_key:
  630. :return:
  631. """
  632. params = [time_range]
  633. brand_top_data = self.db.select(self.sql_2_2, params)
  634. result = []
  635. for x in brand_top_data:
  636. result.append([n for n in x])
  637. # brand_top_data结果的结构
  638. # 0 a.brand_id, 集团id
  639. # 1 a.house1_id, 项目id
  640. # 2 a.house_name, 项目名称
  641. # 3 SUM(a.pv), 浏览总量
  642. # 4 SUM(a.uv), 浏览人数
  643. # 5 SUM(a.new_cust), 新增获客
  644. # 6 SUM(a.shouquan_cust) 授权手机号
  645. result.sort(key=lambda obj: obj[3])
  646. result.reverse()
  647. return result
  648. """
  649. 数据分享类别
  650. 1:长按识别二维码 2:会话 3:公众号菜单 4:公众号文章 5:小程序历史列表 6:扫一扫二维码
  651. 7:搜索 8:相册选取二维码 9:其他小程序 10:其他
  652. """
  653. share_way = {
  654. "长按识别二维码": 1,
  655. "会话": 2,
  656. "公众号菜单": 3,
  657. '公众号文章': 4,
  658. '小程序历史列表': 5,
  659. '扫一扫二维码': 6,
  660. '搜索': 7,
  661. '相册选取二维码': 8,
  662. '其他小程序': 9,
  663. '': 10
  664. }
  665. def customer_channel_details(self, time_range):
  666. """
  667. 1.默认值/001_大麦/场景_用户来源渠道/用户来源渠道—明细
  668. :param task_key:
  669. :return:
  670. """
  671. params = []
  672. params.extend(time_range)
  673. params.extend(time_range)
  674. customer_channel_details_data = self.db.select(self.sql_3_1, params)
  675. # customer_channel_details_data数据结构
  676. # house_id, 项目id
  677. # house_name, 项目名称
  678. # label_wx, 分享类别
  679. # COUNT(a.id) as counts, 数量
  680. return customer_channel_details_data
  681. def brand_customer_channel_details(self, time_range):
  682. """
  683. 2.默认值/006_大麦(集团)/场景(集团)_用户来源渠道_v1.1/用户来源渠道—明细
  684. :param frequency:
  685. :return:
  686. """
  687. params = [time_range[0], time_range[1]]
  688. brand_customer_channel_details_data = self.db.select(self.sql_3_2, params)
  689. # brand_customer_channel_details_data数据结构
  690. # brand_id, 集团id
  691. # x.brand_name, 集团名称
  692. # house_id, 项目id
  693. # house_name, 项目名称
  694. # label_wx, 分享类别
  695. # COUNT(1) 数量
  696. return brand_customer_channel_details_data
  697. def push_log_recording(self, push_message):
  698. """
  699. 报表推送日志记录
  700. :param push_message:
  701. :return:
  702. """
  703. self.db.add_some(self.sql_6, push_message)
  704. def get_house_ids_by_brand_id(self, brand_id):
  705. return self.db.select(self.sql_5, [brand_id])
  706. def get_brand_info_by_house_id(self, house_id):
  707. """
  708. 根据项目id或者相应的集团信息
  709. :param house_id:
  710. :return:
  711. """
  712. brand_info = self.db.select(self.sql_7, [house_id])
  713. if len(brand_info) == 1:
  714. return brand_info[0][0]
  715. return
  716. def get_time_range(self, task_key):
  717. """
  718. 根据定时任务id获取时间区间
  719. 时间格式 yyyy-mm-dd
  720. :param task_key:1: 日报,2:周报, 3:all
  721. :return:
  722. """
  723. now_time = datetime.datetime.now()
  724. pre_time = None
  725. if task_key in (2, 3):
  726. # 上周,上周一到上周天
  727. pre_time = now_time + datetime.timedelta(days=-7)
  728. pass
  729. elif task_key in (1):
  730. # 昨天
  731. pre_time = now_time + datetime.timedelta(days=-1)
  732. pass
  733. elif task_key in (4):
  734. # 不限时间
  735. pre_time = now_time + datetime.timedelta(days=-2999)
  736. return [pre_time.strftime('%Y-%m-%d'), now_time.strftime('%Y-%m-%d')]
  737. if __name__ == '__main__':
  738. rp = ReportPush('linshi')
  739. print(rp.get_time_range(3))
  740. sql = "select COUNT(1) from t_house_image where id in %s and status = %s"
  741. print(rp.db.select(sql, [[46, 47, 48], -1]))
  742. list_data = [2, 1, 4]
  743. for x in list_data:
  744. print(x)