No Description

CustomerService.php 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?php
  2. namespace App\Services\Data;
  3. use App\Models\JxCostDailyData;
  4. use App\Models\JxQtaskLiveOrderList;
  5. use App\Models\JxQtaskVideoFlowOrderList;
  6. use App\Models\JxQtaskVideoOrderList;
  7. use App\Models\JxStarLiveFlowOrderList;
  8. use App\Models\JxStarLiveOrderList;
  9. use App\Models\JxStarVideoFlowOrderList;
  10. use App\Models\JxStarVideoOrderList;
  11. class CustomerService
  12. {
  13. public static function summaryTrend($advertiserIds, $stDate, $enDate)
  14. {
  15. if (empty($advertiserIds)) return [];
  16. $formatData = [
  17. 'cost' => 0,
  18. 'starVideoCost' => 0,
  19. 'starLiveCost' => 0,
  20. 'quickTaskCost' => 0,
  21. 'flowAssistCost' => 0
  22. ];
  23. $trend = getDayArr($stDate, $enDate, $formatData);
  24. $summary = [
  25. 'talCost' => 0,
  26. 'talStarVideoCost' => 0,
  27. 'talStarLiveCost' => 0,
  28. 'talQuickTaskCost' => 0,
  29. 'talFlowAssistCost' => 0
  30. ];
  31. $costDailyList = JxCostDailyData::query()
  32. ->selectRaw("day")
  33. ->selectRaw("SUM(star_video_cost) AS star_video_cost")
  34. ->selectRaw("SUM(star_live_cost) AS star_live_cost")
  35. ->selectRaw("SUM(qtask_video_cost) AS qtask_video_cost")
  36. ->selectRaw("SUM(qtask_live_cost) AS qtask_live_cost")
  37. ->selectRaw("SUM(flow_star_video_cost) AS flow_star_video_cost")
  38. ->selectRaw("SUM(flow_star_live_cost) AS flow_star_live_cost")
  39. ->selectRaw("SUM(flow_qtask_video_cost) AS flow_qtask_video_cost")
  40. ->whereIn('advertiser_id', $advertiserIds)
  41. ->where('enable', 1)
  42. ->groupBy('day')
  43. ->get();
  44. if ($costDailyList->isNotEmpty()) {
  45. $costDailyListMap = $costDailyList->keyBy('day');
  46. foreach ($trend as &$item) {
  47. $costDailyData = $costDailyListMap->get($item['day']) ?? [];
  48. if (empty($costDailyData)) continue;
  49. $item['starVideoCost'] += $costDailyData->star_video_cost;
  50. $item['starLiveCost'] += $costDailyData->star_live_cost;
  51. $item['quickTaskCost'] += ($costDailyData->qtask_video_cost + $costDailyData->qtask_live_cost);
  52. $item['flowAssistCost'] += ($costDailyData->flow_star_video_cost + $costDailyData->flow_star_live_cost + $costDailyData->flow_qtask_video_cost);
  53. $item['cost'] += ($item['starVideoCost'] + $item['starLiveCost'] + $item['quickTaskCost'] + $item['flowAssistCost']);
  54. $summary['talStarVideoCost'] += $item['starVideoCost'];
  55. $summary['talStarLiveCost'] += $item['starLiveCost'];
  56. $summary['talQuickTaskCost'] += $item['quickTaskCost'];
  57. $summary['talFlowAssistCost'] += $item['flowAssistCost'];
  58. $summary['talCost'] += $item['cost'];
  59. self::formatData($item);
  60. }
  61. self::formatData($summary);
  62. }
  63. return [
  64. 'trend' => $trend,
  65. 'summary' => $summary
  66. ];
  67. }
  68. public static function dataList($prType, $advertiserIds, $stDate, $enDate)
  69. {
  70. if (empty($advertiserIds)) return [];
  71. $fun = 'getCus'.ucwords($prType).'Data';
  72. $res = self::$fun($advertiserIds, $stDate, $enDate);
  73. return $res;
  74. }
  75. protected static function getCusStarVideoData($advertiserIds, $stDate, $enDate)
  76. {
  77. $summary = [
  78. 'tal_real_amount' => 0,
  79. 'tal_view' => 0,
  80. 'tal_play' => 0,
  81. 'tal_action' => 0,
  82. 'tal_admire' => 0,
  83. 'tal_comment' => 0,
  84. 'tal_click' => 0,
  85. 'tal_play_5s' => 0,
  86. 'tal_play_end' => 0,
  87. 'tal_item_impression_cnt' => 0,
  88. 'tal_item_click_cnt' => 0,
  89. 'tal_user_cnt' => 0,
  90. 'tal_ctr' => 0,
  91. 'tal_cpm' => 0,
  92. 'tal_cpc' => 0,
  93. 'tal_item_click_rate' => 0,
  94. 'tal_cpa' => 0,
  95. 'tal_play_5s_rate' => 0,
  96. 'tal_play_end_rate' => 0
  97. ];
  98. $orderList = JxStarVideoOrderList::query()
  99. ->selectRaw("DATE_FORMAT(star_release_time, '%Y-%m-%d') AS day")
  100. ->selectRaw("SUM(real_amount) AS real_amount")
  101. ->selectRaw("SUM(view) AS view")
  102. ->selectRaw("SUM(play) AS play")
  103. ->selectRaw("SUM(action) AS action")
  104. ->selectRaw("SUM(admire) AS admire")
  105. ->selectRaw("SUM(comment) AS comment")
  106. ->selectRaw("SUM(click) AS click")
  107. ->selectRaw("SUM(play_5s) AS play_5s")
  108. ->selectRaw("SUM(play_end) AS play_end")
  109. ->selectRaw("SUM(item_impression_cnt) AS item_impression_cnt")
  110. ->selectRaw("SUM(item_click_cnt) AS item_click_cnt")
  111. ->selectRaw("SUM(user_cnt) AS user_cnt")
  112. ->whereIn('advertiser_id', $advertiserIds)
  113. ->whereBetween('star_release_time', [$stDate.' 00:00:00', $enDate.' 23:59:59'])
  114. ->groupBy('day')
  115. ->orderByDesc('day')
  116. ->get();
  117. if ($orderList->isNotEmpty()) {
  118. foreach ($orderList as $item) {
  119. # 处理汇总
  120. $summary['tal_real_amount'] += $item->real_amount;
  121. $summary['tal_view'] += $item->view;
  122. $summary['tal_play'] += $item->play;
  123. $summary['tal_action'] += $item->action;
  124. $summary['tal_admire'] += $item->admire;
  125. $summary['tal_comment'] += $item->comment;
  126. $summary['tal_click'] += $item->click;
  127. $summary['tal_item_impression_cnt'] += $item->item_impression_cnt;
  128. $summary['tal_item_click_cnt'] += $item->item_click_cnt;
  129. $summary['tal_play_5s'] += $item->play_5s;
  130. $summary['tal_play_end'] += $item->play_end;
  131. # 处理列表
  132. $item->ctr = $item->view > 0
  133. ? round($item->click / $item->view * 100, 4) : 0;
  134. $item->cpm = $item->play > 0
  135. ? round($item->real_amount / $item->play, 4) : 0;
  136. $item->cpc = $item->click > 0
  137. ? round(($item->real_amount / $item->click) / 1000, 4) : 0;
  138. $item->item_click_rate = $item->item_impression_cnt > 0
  139. ? round($item->item_click_cnt / $item->item_impression_cnt * 100, 4) : 0;
  140. $item->cpa = $item->item_click_cnt > 0
  141. ? round(($item->real_amount / $item->item_click_cnt) / 1000, 4) : 0;
  142. $item->play_5s_rate = $item->view > 0
  143. ? round($item->play_5s / $item->view * 100, 4) : 0;
  144. $item->play_end_rate = $item->view > 0
  145. ? round($item->play_end / $item->view * 100, 4) : 0;
  146. $item->real_amount = round($item->real_amount / 1000, 4);
  147. }
  148. $summary['tal_ctr'] = $summary['tal_view'] > 0
  149. ? round($summary['tal_click'] / $summary['tal_view'] * 100, 4) : 0;
  150. $summary['tal_cpm'] = $summary['tal_play'] > 0
  151. ? round($summary['tal_real_amount'] / $summary['tal_play'], 4) : 0;
  152. $summary['tal_cpc'] = $summary['tal_click'] > 0
  153. ? round(($summary['tal_real_amount'] / $summary['tal_click']) / 1000, 4) : 0;
  154. $summary['tal_item_click_rate'] = $summary['tal_item_impression_cnt'] > 0
  155. ? round($summary['tal_item_click_cnt'] / $summary['tal_item_impression_cnt'] * 100, 4) : 0;
  156. $summary['tal_cpa'] = $summary['tal_item_click_cnt'] > 0
  157. ? round(($summary['tal_real_amount'] / $summary['tal_item_click_cnt']) / 1000, 4) : 0;
  158. $summary['tal_play_5s_rate'] = $summary['tal_view'] > 0
  159. ? round($summary['tal_play_5s'] / $summary['tal_view'] * 100, 4) : 0;
  160. $summary['tal_play_end_rate'] = $summary['tal_view'] > 0
  161. ? round($summary['tal_play_end'] / $summary['tal_view'] * 100, 4) : 0;
  162. $summary['tal_real_amount'] = round($summary['tal_real_amount'] / 1000, 4);
  163. }
  164. return [
  165. 'summary' => $summary,
  166. 'list' => $orderList
  167. ];
  168. }
  169. protected static function getCusStarLiveData($advertiserIds, $stDate, $enDate)
  170. {
  171. $summary = [
  172. 'tal_real_amount' => 0,
  173. 'tal_play_cnt' => 0,
  174. 'tal_play_uv' => 0,
  175. 'tal_like_cnt' => 0,
  176. 'tal_comment_cnt' => 0,
  177. 'tal_share_cnt' => 0,
  178. 'tal_live_duration' => 0,
  179. 'tal_item_show_cnt' => 0,
  180. 'tal_item_click_cnt' => 0,
  181. 'tal_sale_product_cnt' => 0,
  182. 'tal_sale_amount' => 0,
  183. 'tal_cpm' => 0,
  184. 'tal_item_click_rate' => 0,
  185. 'tal_cpa' => 0
  186. ];
  187. $orderList = JxStarLiveOrderList::query()
  188. ->selectRaw("DATE_FORMAT(live_start_time, '%Y-%m-%d') AS day")
  189. ->selectRaw("SUM(real_amount) AS real_amount")
  190. ->selectRaw("SUM(play_cnt) AS play_cnt")
  191. ->selectRaw("SUM(play_uv) AS play_uv")
  192. ->selectRaw("SUM(like_cnt) AS like_cnt")
  193. ->selectRaw("SUM(comment_cnt) AS comment_cnt")
  194. ->selectRaw("SUM(share_cnt) AS share_cnt")
  195. ->selectRaw("SUM(live_duration) AS live_duration")
  196. ->selectRaw("SUM(item_show_cnt) AS item_show_cnt")
  197. ->selectRaw("SUM(item_click_cnt) AS item_click_cnt")
  198. ->selectRaw("SUM(sale_product_cnt) AS sale_product_cnt")
  199. ->selectRaw("SUM(sale_amount) AS sale_amount")
  200. ->whereIn('advertiser_id', $advertiserIds)
  201. ->whereBetween('live_start_time', [$stDate.' 00:00:00', $enDate.' 23:59:59'])
  202. ->groupBy('day')
  203. ->orderByDesc('day')
  204. ->get();
  205. if ($orderList->isNotEmpty()) {
  206. foreach ($orderList as $item) {
  207. # 处理汇总
  208. $summary['tal_real_amount'] += $item->real_amount;
  209. $summary['tal_play_cnt'] += $item->play_cnt;
  210. $summary['tal_play_uv'] += $item->play_uv;
  211. $summary['tal_like_cnt'] += $item->like_cnt;
  212. $summary['tal_comment_cnt'] += $item->comment_cnt;
  213. $summary['tal_share_cnt'] += $item->share_cnt;
  214. $summary['tal_live_duration'] += $item->live_duration;
  215. $summary['tal_item_show_cnt'] += $item->item_show_cnt;
  216. $summary['tal_item_click_cnt'] += $item->item_click_cnt;
  217. $summary['tal_sale_product_cnt'] += $item->sale_product_cnt;
  218. $summary['tal_sale_amount'] += $item->sale_amount;
  219. $item->cpm = $item->play_cnt > 0
  220. ? round($item->real_amount / $item->play_cnt, 4) : 0;
  221. $item->item_click_rate = $item->item_show_cnt > 0
  222. ? round($item->item_click_cnt / $item->item_show_cnt * 100, 4) : 0;
  223. $item->cpa = $item->item_click_cnt > 0
  224. ? round(($item->real_amount / $item->item_click_cnt) / 1000, 4) : 0;
  225. $item->real_amount = round($item->real_amount / 1000, 4);
  226. }
  227. $summary['tal_cpm'] = $summary['tal_play_cnt'] > 0
  228. ? round($summary['tal_real_amount'] / $summary['tal_play_cnt'], 4) : 0;
  229. $summary['tal_item_click_rate'] = $summary['tal_item_show_cnt'] > 0
  230. ? round($summary['tal_item_click_cnt'] / $summary['tal_item_show_cnt'] * 100, 4) : 0;
  231. $summary['tal_cpa'] = $summary['tal_play_cnt'] > 0
  232. ? round(($summary['tal_real_amount'] / $summary['tal_item_click_cnt']) / 1000, 4) : 0;
  233. $summary['tal_real_amount'] = round($summary['tal_real_amount'] / 1000, 4);
  234. }
  235. return [
  236. 'summary' => $summary,
  237. 'list' => $orderList
  238. ];
  239. }
  240. protected static function getCusQtaskVideoData($advertiserIds, $stDate, $enDate)
  241. {
  242. $summary = [
  243. 'tal_amount' => 0,
  244. 'tal_view' => 0,
  245. 'tal_play' => 0,
  246. 'tal_action' => 0,
  247. 'tal_admire' => 0,
  248. 'tal_comment' => 0,
  249. 'tal_click' => 0,
  250. 'tal_play_3s' => 0,
  251. 'tal_play_5s' => 0,
  252. 'tal_play_end' => 0,
  253. 'tal_item_impression_cnt' => 0,
  254. 'tal_item_click_cnt' => 0,
  255. 'tal_ctr' => 0,
  256. 'tal_cpm' => 0,
  257. 'tal_cpc' => 0,
  258. 'tal_item_click_rate' => 0,
  259. 'tal_cpa' => 0,
  260. 'tal_play_3s_rate' => 0,
  261. 'tal_play_5s_rate' => 0,
  262. 'tal_play_end_rate' => 0,
  263. ];
  264. $orderList = JxQtaskVideoOrderList::query()
  265. ->selectRaw("DATE_FORMAT(star_release_time, '%Y-%m-%d') AS day")
  266. ->selectRaw("SUM(amount) AS amount")
  267. ->selectRaw("SUM(view) AS view")
  268. ->selectRaw("SUM(play) AS play")
  269. ->selectRaw("SUM(action) AS action")
  270. ->selectRaw("SUM(admire) AS admire")
  271. ->selectRaw("SUM(comment) AS comment")
  272. ->selectRaw("SUM(click) AS click")
  273. ->selectRaw("SUM(play_3s) AS play_3s")
  274. ->selectRaw("SUM(play_5s) AS play_5s")
  275. ->selectRaw("SUM(play_end) AS play_end")
  276. ->selectRaw("SUM(item_impression_cnt) AS item_impression_cnt")
  277. ->selectRaw("SUM(item_click_cnt) AS item_click_cnt")
  278. ->whereIn('advertiser_id', $advertiserIds)
  279. ->whereBetween('star_release_time', [$stDate.' 00:00:00', $enDate.' 23:59:59'])
  280. ->groupBy('day')
  281. ->orderByDesc('day')
  282. ->get();
  283. if ($orderList->isNotEmpty()) {
  284. foreach ($orderList as $item) {
  285. # 处理汇总
  286. $summary['tal_amount'] += $item->amount;
  287. $summary['tal_view'] += $item->view;
  288. $summary['tal_play'] += $item->play;
  289. $summary['tal_action'] += $item->action;
  290. $summary['tal_admire'] += $item->admire;
  291. $summary['tal_comment'] += $item->comment;
  292. $summary['tal_click'] += $item->click;
  293. $summary['tal_play_3s'] += $item->play_3s;
  294. $summary['tal_play_5s'] += $item->play_5s;
  295. $summary['tal_play_end'] += $item->play_end;
  296. $summary['tal_item_impression_cnt'] += $item->item_impression_cnt;
  297. $summary['tal_item_click_cnt'] += $item->item_click_cnt;
  298. # 处理列表
  299. $item->ctr = $item->view > 0
  300. ? round($item->click / $item->view * 100, 4) : 0;
  301. $item->cpm = $item->play > 0
  302. ? round($item->amount / $item->play, 4) : 0;
  303. $item->cpc = $item->click > 0
  304. ? round(($item->amount / $item->click) / 1000, 4) : 0;
  305. $item->item_click_rate = $item->item_impression_cnt > 0
  306. ? round($item->item_click_cnt / $item->item_impression_cnt * 100, 4) : 0;
  307. $item->cpa = $item->item_click_cnt > 0
  308. ? round(($item->amount / $item->item_click_cnt) / 1000, 4) : 0;
  309. $item->play_3s_rate = $item->play > 0
  310. ? round($item->play_3s / $item->play * 100, 4) : 0;
  311. $item->play_5s_rate = $item->play > 0
  312. ? round($item->play_5s / $item->play * 100, 4) : 0;
  313. $item->play_end_rate = $item->play > 0
  314. ? round($item->play_end / $item->play * 100, 4) : 0;
  315. $item->amount = round($item->amount / 1000, 4);
  316. }
  317. $summary['tal_ctr'] = $summary['tal_view'] > 0
  318. ? round($summary['tal_click'] / $summary['tal_view'] * 100, 4) : 0;
  319. $summary['tal_cpm'] = $summary['tal_play'] > 0
  320. ? round($summary['tal_amount'] / $summary['tal_play'], 4) : 0;
  321. $summary['tal_cpc'] = $summary['tal_click'] > 0
  322. ? round(($summary['tal_amount'] / $summary['tal_click']) / 1000, 4) : 0;
  323. $summary['tal_item_click_rate'] = $summary['tal_item_impression_cnt'] > 0
  324. ? round($summary['tal_item_click_cnt'] / $summary['tal_item_impression_cnt'] * 100, 4) : 0;
  325. $summary['tal_cpa'] = $summary['tal_item_click_cnt'] > 0
  326. ? round(($summary['tal_amount'] / $summary['tal_item_click_cnt']) / 1000, 4) : 0;
  327. $summary['tal_play_3s_rate'] = $summary['tal_play'] > 0
  328. ? round($summary['tal_play_3s'] / $summary['tal_play'] * 100, 4) : 0;
  329. $summary['tal_play_5s_rate'] = $summary['tal_play'] > 0
  330. ? round($summary['tal_play_5s'] / $summary['tal_play'] * 100, 4) : 0;
  331. $summary['tal_play_end_rate'] = $summary['tal_play'] > 0
  332. ? round($summary['tal_play_end'] / $summary['tal_play'] * 100, 4) : 0;
  333. $summary['tal_amount'] = round($summary['tal_amount'] / 1000, 4);
  334. }
  335. return [
  336. 'summary' => $summary,
  337. 'list' => $orderList
  338. ];
  339. }
  340. protected static function getCusQtaskLiveData($advertiserIds, $stDate, $enDate)
  341. {
  342. $summary = [
  343. 'tal_amount' => 0,
  344. 'tal_play_cnt' => 0,
  345. 'tal_play_uv' => 0,
  346. 'tal_like_cnt' => 0,
  347. 'tal_comment_cnt' => 0,
  348. 'tal_share_cnt' => 0,
  349. 'tal_live_duration' => 0,
  350. 'tal_item_show_cnt' => 0,
  351. 'tal_item_click_cnt' => 0,
  352. 'tal_cpm' => 0,
  353. 'tal_item_click_rate' => 0,
  354. 'tal_cpa' => 0
  355. ];
  356. $orderList = JxQtaskLiveOrderList::query()
  357. ->selectRaw("DATE_FORMAT(star_release_time, '%Y-%m-%d') AS day")
  358. ->selectRaw("SUM(amount) AS amount")
  359. ->selectRaw("SUM(play_cnt) AS play_cnt")
  360. ->selectRaw("SUM(play_uv) AS play_uv")
  361. ->selectRaw("SUM(like_cnt) AS like_cnt")
  362. ->selectRaw("SUM(comment_cnt) AS comment_cnt")
  363. ->selectRaw("SUM(share_cnt) AS share_cnt")
  364. ->selectRaw("SUM(live_duration) AS live_duration")
  365. ->selectRaw("SUM(item_show_cnt) AS item_show_cnt")
  366. ->selectRaw("SUM(item_click_cnt) AS item_click_cnt")
  367. ->whereIn('advertiser_id', $advertiserIds)
  368. ->whereBetween('star_release_time', [$stDate.' 00:00:00', $enDate.' 23:59:59'])
  369. ->groupBy('day')
  370. ->orderByDesc('day')
  371. ->get();
  372. if ($orderList->isNotEmpty()) {
  373. foreach ($orderList as $item) {
  374. # 处理汇总
  375. $summary['tal_amount'] += $item->amount;
  376. $summary['tal_play_cnt'] += $item->play_cnt;
  377. $summary['tal_play_uv'] += $item->play_uv;
  378. $summary['tal_like_cnt'] += $item->like_cnt;
  379. $summary['tal_comment_cnt'] += $item->comment_cnt;
  380. $summary['tal_share_cnt'] += $item->share_cnt;
  381. $summary['tal_live_duration'] += $item->live_duration;
  382. $summary['tal_item_show_cnt'] += $item->item_show_cnt;
  383. $summary['tal_item_click_cnt'] += $item->item_click_cnt;
  384. # 处理列表
  385. $item->cpm = $item->play_cnt > 0
  386. ? round($item->amount / $item->play_cnt, 4) : 0;
  387. $item->item_click_rate = $item->item_show_cnt > 0
  388. ? round($item->item_click_cnt / $item->item_show_cnt * 100, 4) : 0;
  389. $item->cpa = $item->item_click_cnt > 0
  390. ? round(($item->amount / $item->item_click_cnt) / 1000, 4) : 0;
  391. $item->amount = round($item->amount / 1000, 4);
  392. }
  393. $summary['tal_cpm'] = $summary['tal_play_cnt'] > 0
  394. ? round($summary['tal_amount'] / $summary['tal_play_cnt'], 4) : 0;
  395. $summary['tal_item_click_rate'] = $summary['tal_item_show_cnt'] > 0
  396. ? round($summary['tal_item_click_cnt'] / $summary['tal_item_show_cnt'] * 100, 4) : 0;
  397. $summary['tal_cpa'] = $summary['tal_item_click_cnt'] > 0
  398. ? round(($summary['tal_amount'] / $summary['tal_item_click_cnt']) / 1000, 4) : 0;
  399. $summary['tal_amount'] = round($summary['tal_amount'] / 1000, 4);
  400. }
  401. return [
  402. 'summary' => $summary,
  403. 'list' => $orderList
  404. ];
  405. }
  406. protected static function getCusFlowStarVideoData($advertiserIds, $stDate, $enDate)
  407. {
  408. $summary = [
  409. 'tal_consume_amount' => 0,
  410. 'tal_view' => 0,
  411. 'tal_play' => 0,
  412. 'tal_action' => 0,
  413. 'tal_conversion' => 0,
  414. 'tal_admire' => 0,
  415. 'tal_comment' => 0,
  416. 'tal_played3s_cnt' => 0,
  417. 'tal_cash_amount' => 0,
  418. 'tal_client_amount' => 0,
  419. 'tal_agency_amount' => 0,
  420. 'tal_credit_consume_amount' => 0,
  421. 'tal_cpm' => 0,
  422. 'tal_action_rate' => 0,
  423. 'tal_cpa' => 0,
  424. 'tal_play_3s_rate' => 0
  425. ];
  426. $orderList = JxStarVideoFlowOrderList::query()
  427. ->selectRaw("DATE_FORMAT(promotion_begin_time, '%Y-%m-%d') AS day")
  428. ->selectRaw("SUM(consume_amount) AS consume_amount")
  429. ->selectRaw("SUM(view) AS view")
  430. ->selectRaw("SUM(play) AS play")
  431. ->selectRaw("SUM(action) AS action")
  432. ->selectRaw("SUM(conversion) AS conversion")
  433. ->selectRaw("SUM(admire) AS admire")
  434. ->selectRaw("SUM(comment) AS comment")
  435. ->selectRaw("SUM(played3s_cnt) AS played3s_cnt")
  436. ->selectRaw("SUM(cash_amount) AS cash_amount")
  437. ->selectRaw("SUM(client_amount) AS client_amount")
  438. ->selectRaw("SUM(agency_amount) AS agency_amount")
  439. ->selectRaw("SUM(credit_consume_amount) AS credit_consume_amount")
  440. ->whereIn('advertiser_id', $advertiserIds)
  441. ->whereBetween('promotion_begin_time', [$stDate.' 00:00:00', $enDate.' 23:59:59'])
  442. ->groupBy('day')
  443. ->orderByDesc('day')
  444. ->get();
  445. if ($orderList->isNotEmpty()) {
  446. foreach ($orderList as $item) {
  447. # 处理汇总
  448. $summary['tal_consume_amount'] += $item->consume_amount;
  449. $summary['tal_view'] += $item->view;
  450. $summary['tal_play'] += $item->play;
  451. $summary['tal_action'] += $item->action;
  452. $summary['tal_conversion'] += $item->conversion;
  453. $summary['tal_admire'] += $item->admire;
  454. $summary['tal_comment'] += $item->comment;
  455. $summary['tal_played3s_cnt'] += $item->played3s_cnt;
  456. $summary['tal_cash_amount'] += $item->cash_amount;
  457. $summary['tal_client_amount'] += $item->client_amount;
  458. $summary['tal_agency_amount'] += $item->agency_amount;
  459. $summary['tal_credit_consume_amount'] += $item->credit_consume_amount;
  460. # 处理列表
  461. $item->cpm = $item->play > 0
  462. ? round($item->consume_amount / $item->play, 4) : 0;
  463. $item->action_rate = $item->play > 0
  464. ? round($item->action / $item->play * 100, 4) : 0;
  465. $item->cpa = $item->conversion > 0
  466. ? round(($item->consume_amount / $item->conversion) / 1000, 4) : 0;
  467. $item->cash_amount = round($item->cash_amount / 1000, 4);
  468. $item->client_amount = round($item->client_amount / 1000, 4);
  469. $item->agency_amount = round($item->agency_amount / 1000, 4);
  470. $item->credit_consume_amount = round($item->credit_consume_amount / 1000, 4);
  471. $item->play_3s_rate = $item->play > 0
  472. ? round($item->played3s_cnt / $item->play * 100, 4) : 0;
  473. $item->consume_amount = round($item->consume_amount / 1000, 4);
  474. }
  475. $summary['tal_cpm'] = $summary['tal_play'] > 0
  476. ? round($summary['tal_consume_amount'] / $summary['tal_play'], 4) : 0;
  477. $summary['tal_action_rate'] = $summary['tal_play'] > 0
  478. ? round($summary['tal_action'] / $summary['tal_play'] * 100, 4) : 0;
  479. $summary['tal_cpa'] = $summary['tal_conversion'] > 0
  480. ? round(($summary['tal_consume_amount'] / $summary['tal_conversion']) / 1000, 4) : 0;
  481. $summary['tal_consume_amount'] = round($summary['tal_consume_amount'] / 1000, 4);
  482. $summary['tal_cash_amount'] = round($summary['tal_cash_amount'] / 1000, 4);
  483. $summary['tal_client_amount'] = round($summary['tal_client_amount'] / 1000, 4);
  484. $summary['tal_agency_amount'] = round($summary['tal_agency_amount'] / 1000, 4);
  485. $summary['tal_credit_consume_amount'] = round($summary['tal_credit_consume_amount'] / 1000, 4);
  486. $summary['tal_play_3s_rate'] = $summary['tal_play'] > 0
  487. ? round($summary['tal_played3s_cnt'] / $summary['tal_play'] * 100, 4) : 0;
  488. }
  489. return [
  490. 'summary' => $summary,
  491. 'list' => $orderList
  492. ];
  493. }
  494. protected static function getCusFlowStarLiveData($advertiserIds, $stDate, $enDate)
  495. {
  496. $summary = [
  497. 'tal_consume_amount' => 0,
  498. 'tal_audience_num' => 0,
  499. 'tal_played3s_num' => 0,
  500. 'tal_fans_increase_num' => 0,
  501. 'tal_item_impression_num' => 0,
  502. 'tal_interactive_num' => 0,
  503. 'tal_conversion_impression_num' => 0,
  504. 'tal_conversion_action_num' => 0,
  505. 'tal_cash_amount' => 0,
  506. 'tal_client_amount' => 0,
  507. 'tal_agency_amount' => 0,
  508. 'tal_credit_consume_amount' => 0,
  509. 'tal_conversion_action_rate' => 0,
  510. 'tal_cpa' => 0,
  511. 'tal_conversion_action_cost' => 0
  512. ];
  513. $orderList = JxStarLiveFlowOrderList::query()
  514. ->selectRaw("DATE_FORMAT(promotion_begin_time, '%Y-%m-%d') AS day")
  515. ->selectRaw("SUM(consume_amount) AS consume_amount")
  516. ->selectRaw("SUM(audience_num) AS audience_num")
  517. ->selectRaw("SUM(played3s_num) AS played3s_num")
  518. ->selectRaw("SUM(fans_increase_num) AS fans_increase_num")
  519. ->selectRaw("SUM(item_impression_num) AS item_impression_num")
  520. ->selectRaw("SUM(interactive_num) AS interactive_num")
  521. ->selectRaw("SUM(conversion_impression_num) AS conversion_impression_num")
  522. ->selectRaw("SUM(conversion_action_num) AS conversion_action_num")
  523. ->selectRaw("SUM(cash_amount) AS cash_amount")
  524. ->selectRaw("SUM(client_amount) AS client_amount")
  525. ->selectRaw("SUM(agency_amount) AS agency_amount")
  526. ->selectRaw("SUM(credit_consume_amount) AS credit_consume_amount")
  527. ->whereIn('advertiser_id', $advertiserIds)
  528. ->whereBetween('promotion_begin_time', [$stDate.' 00:00:00', $enDate.' 23:59:59'])
  529. ->groupBy('day')
  530. ->orderByDesc('day')
  531. ->get();
  532. if ($orderList->isNotEmpty()) {
  533. foreach ($orderList as $item) {
  534. # 处理汇总
  535. $summary['tal_consume_amount'] += $item->consume_amount;
  536. $summary['tal_audience_num'] += $item->audience_num;
  537. $summary['tal_played3s_num'] += $item->played3s_num;
  538. $summary['tal_fans_increase_num'] += $item->fans_increase_num;
  539. $summary['tal_item_impression_num'] += $item->item_impression_num;
  540. $summary['tal_interactive_num'] += $item->interactive_num;
  541. $summary['tal_conversion_impression_num'] += $item->conversion_impression_num;
  542. $summary['tal_conversion_action_num'] += $item->conversion_action_num;
  543. $summary['tal_cash_amount'] += $item->cash_amount;
  544. $summary['tal_client_amount'] += $item->client_amount;
  545. $summary['tal_agency_amount'] += $item->agency_amount;
  546. $summary['tal_credit_consume_amount'] += $item->credit_consume_amount;
  547. # 处理列表
  548. $item->conversion_action_rate = $item->conversion_impression_num > 0
  549. ? round($item->conversion_action_num / $item->conversion_impression_num * 100, 4) : 0;
  550. $item->cpa = $item->consume_amount > 0
  551. ? round(($item->consume_amount / $item->conversion_action_num) / 1000, 4) : 0;
  552. $item->consume_amount = round($item->consume_amount / 1000, 4);
  553. $item->cash_amount = round($item->cash_amount / 1000, 4);
  554. $item->client_amount = round($item->client_amount / 1000, 4);
  555. $item->agency_amount = round($item->agency_amount / 1000, 4);
  556. $item->credit_consume_amount = round($item->credit_consume_amount / 1000, 4);
  557. $item->conversion_action_cost = $item->conversion_action_num > 0
  558. ? round(($item->consume_amount / $item->conversion_action_num) / 1000, 4) : 0;
  559. }
  560. $summary['tal_conversion_action_rate'] = $summary['tal_conversion_impression_num'] > 0
  561. ? round($summary['tal_conversion_action_num'] / $summary['tal_conversion_impression_num'] * 100, 4) : 0;
  562. $summary['tal_cpa'] = $summary['tal_conversion_action_num'] > 0
  563. ? round(($summary['tal_consume_amount'] / $summary['tal_conversion_action_num']) / 1000, 4) : 0;
  564. $summary['tal_consume_amount'] = round($summary['tal_consume_amount'] / 1000, 4);
  565. $summary['tal_cash_amount'] = round($summary['tal_cash_amount'] / 1000, 4);
  566. $summary['tal_client_amount'] = round($summary['tal_client_amount'] / 1000, 4);
  567. $summary['tal_agency_amount'] = round($summary['tal_agency_amount'] / 1000, 4);
  568. $summary['tal_credit_consume_amount'] = round($summary['tal_credit_consume_amount'] / 1000, 4);
  569. $summary['tal_conversion_action_cost'] = $summary['tal_conversion_action_num'] > 0
  570. ? round(($summary['tal_consume_amount'] / $summary['tal_conversion_action_num']) / 1000, 4) : 0;
  571. }
  572. return [
  573. 'summary' => $summary,
  574. 'list' => $orderList
  575. ];
  576. }
  577. protected static function getCusFlowQtaskVideoData($advertiserIds, $stDate, $enDate)
  578. {
  579. $summary = [
  580. 'tal_consume_amount' => 0,
  581. 'tal_view' => 0,
  582. 'tal_play' => 0,
  583. 'tal_action' => 0,
  584. 'tal_conversion' => 0,
  585. 'tal_admire' => 0,
  586. 'tal_comment' => 0,
  587. 'tal_played3s_cnt' => 0,
  588. 'tal_cash_amount' => 0,
  589. 'tal_client_amount' => 0,
  590. 'tal_agency_amount' => 0,
  591. 'tal_credit_consume_amount' => 0,
  592. 'tal_cpm' => 0,
  593. 'tal_action_rate' => 0,
  594. 'tal_cpa' => 0,
  595. 'tal_play_3s_rate' => 0
  596. ];
  597. $orderList = JxQtaskVideoFlowOrderList::query()
  598. ->selectRaw("DATE_FORMAT(promotion_begin_time, '%Y-%m-%d') AS day")
  599. ->selectRaw("SUM(consume_amount) AS consume_amount")
  600. ->selectRaw("SUM(view) AS view")
  601. ->selectRaw("SUM(play) AS play")
  602. ->selectRaw("SUM(action) AS action")
  603. ->selectRaw("SUM(conversion) AS conversion")
  604. ->selectRaw("SUM(admire) AS admire")
  605. ->selectRaw("SUM(comment) AS comment")
  606. ->selectRaw("SUM(played3s_cnt) AS played3s_cnt")
  607. ->selectRaw("SUM(cash_amount) AS cash_amount")
  608. ->selectRaw("SUM(client_amount) AS client_amount")
  609. ->selectRaw("SUM(agency_amount) AS agency_amount")
  610. ->selectRaw("SUM(credit_consume_amount) AS credit_consume_amount")
  611. ->whereIn('advertiser_id', $advertiserIds)
  612. ->whereBetween('promotion_begin_time', [$stDate.' 00:00:00', $enDate.' 23:59:59'])
  613. ->groupBy('day')
  614. ->orderByDesc('day')
  615. ->get();
  616. if ($orderList->isNotEmpty()) {
  617. foreach ($orderList as &$item) {
  618. # 处理汇总
  619. $summary['tal_consume_amount'] += $item->consume_amount;
  620. $summary['tal_view'] += $item->view;
  621. $summary['tal_play'] += $item->play;
  622. $summary['tal_action'] += $item->action;
  623. $summary['tal_conversion'] += $item->conversion;
  624. $summary['tal_admire'] += $item->admire;
  625. $summary['tal_comment'] += $item->comment;
  626. $summary['tal_played3s_cnt'] += $item->played3s_cnt;
  627. $summary['tal_cash_amount'] += $item->cash_amount;
  628. $summary['tal_client_amount'] += $item->client_amount;
  629. $summary['tal_agency_amount'] += $item->agency_amount;
  630. $summary['tal_credit_consume_amount'] += $item->credit_consume_amount;
  631. # 处理列表
  632. $item->cpm = $item->play > 0
  633. ? round($item->consume_amount / $item->play, 4) : 0;
  634. $item->action_rate = $item->play > 0
  635. ? round($item->action / $item->play * 100, 4) : 0;
  636. $item->cpa = $item->conversion > 0
  637. ? round(($item->consume_amount / $item->conversion) / 1000, 4) : 0;
  638. $item->consume_amount = round($item->consume_amount / 1000, 4);
  639. $item->cash_amount = round($item->cash_amount / 1000, 4);
  640. $item->client_amount = round($item->client_amount / 1000, 4);
  641. $item->agency_amount = round($item->agency_amount / 1000, 4);
  642. $item->credit_consume_amount = round($item->credit_consume_amount / 1000, 4);
  643. $item->play_3s_rate = $item->play > 0
  644. ? round($item->played3s_cnt / $item->play * 100, 4) : 0;
  645. }
  646. $summary['tal_cpm'] = $summary['tal_play'] > 0
  647. ? round($summary['tal_consume_amount'] / $summary['tal_play'], 4) : 0;
  648. $summary['tal_action_rate'] = $summary['tal_play'] > 0
  649. ? round($summary['tal_action'] / $summary['tal_play'] * 100, 4) : 0;
  650. $summary['tal_cpa'] = $summary['tal_conversion'] > 0
  651. ? round(($summary['tal_consume_amount'] / $summary['tal_conversion']) / 1000, 4) : 0;
  652. $summary['tal_consume_amount'] = round($summary['tal_consume_amount'] / 1000, 4);
  653. $summary['tal_cash_amount'] = round($summary['tal_cash_amount'] / 1000, 4);
  654. $summary['tal_client_amount'] = round($summary['tal_client_amount'] / 1000, 4);
  655. $summary['tal_agency_amount'] = round($summary['tal_agency_amount'] / 1000, 4);
  656. $summary['tal_credit_consume_amount'] = round($summary['tal_credit_consume_amount'] / 1000, 4);
  657. $summary['tal_play_3s_rate'] = $summary['tal_play'] > 0
  658. ? round($summary['tal_played3s_cnt'] / $summary['tal_play'] * 100, 4) : 0;
  659. }
  660. return [
  661. 'summary' => $summary,
  662. 'list' => $orderList
  663. ];
  664. }
  665. protected static function formatData(&$result)
  666. {
  667. # 格式化
  668. foreach ($result as &$item) {
  669. if (!is_numeric($item)) continue;
  670. $item = round($item / 1000, 4);
  671. }
  672. }
  673. }