企微短剧业务系统

DataStatisticsController.php 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/4/20
  6. * Time: 11:48
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Http\Controllers\Controller;
  10. use App\Service\DataStatisticsService;
  11. use App\Service\NewStatisticsService;
  12. use App\Service\Report\ServiceDataService;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Validation\Rule;
  15. use Validator;
  16. class DataStatisticsController extends Controller
  17. {
  18. // 公众号数据(旧版,不用)
  19. // public function wechatAccountData(Request $request)
  20. // {
  21. // $validator = \Validator::make($request->all(),[
  22. // 'start_date' => 'nullable|date',
  23. // 'end_date' => 'nullable|date'
  24. // ]);
  25. //
  26. // if ($validator->fails()) {
  27. // return self::returnValue($validator->getMessageBag(), 1102);
  28. // }
  29. //
  30. // $startDate = $request->input('start_date');
  31. // $endDate = $request->input('end_date');
  32. // $accountId = $request->input('account_id');
  33. // $corpid = $request->input('corpid');
  34. // $sortField = $request->input('sort_field', 'charge_total');
  35. // $sysGroupId = $request->input('sys_group_id');
  36. //
  37. // $page = $request->input('page', 1);
  38. // $pageSize = $request->input('page_size', 10);
  39. //
  40. // list($data, $count) = DataStatisticsService::wechatAccountData($startDate, $endDate, $accountId, $corpid,
  41. // $sortField, $page, $pageSize, $sysGroupId);
  42. //
  43. // return self::returnPageValue($data, $count, $pageSize, $page);
  44. // }
  45. // 短剧投放趋势数据
  46. public function playletTrendData(Request $request)
  47. {
  48. $validator = Validator::make($request->all(),[
  49. 'start_date' => 'nullable|date',
  50. 'end_date' => 'nullable|date'
  51. ]);
  52. if ($validator->fails()) {
  53. return self::returnValue($validator->getMessageBag(), 1102);
  54. }
  55. $startDate = $request->input('start_date');
  56. $endDate = $request->input('end_date');
  57. $accountId = $request->input('account_id');
  58. $corpid = $request->input('corpid');
  59. $playletId = $request->input('playlet_id');
  60. $page = $request->input('page', 1);
  61. $pageSize = $request->input('page_size', 10);
  62. list($data, $count) = DataStatisticsService::playletTrendData($startDate, $endDate, $accountId, $corpid, $playletId,
  63. $page, $pageSize);
  64. return self::returnPageValue($data, $count, $pageSize, $page);
  65. }
  66. // 短剧数据(老)
  67. public function playletData(Request $request)
  68. {
  69. $validator = Validator::make($request->all(),[
  70. 'start_date' => 'nullable|date',
  71. 'end_date' => 'nullable|date'
  72. ]);
  73. if ($validator->fails()) {
  74. return self::returnValue($validator->getMessageBag(), 1102);
  75. }
  76. $startDate = $request->input('start_date');
  77. $endDate = $request->input('end_date');
  78. $accountId = $request->input('account_id');
  79. $corpid = $request->input('corpid');
  80. $playletId = $request->input('playlet_id');
  81. $sortField = $request->input('sort_field', 'charge_total');
  82. $page = $request->input('page', 1);
  83. $pageSize = $request->input('page_size', 10);
  84. list($data, $count) = DataStatisticsService::playletData($startDate, $endDate, $accountId, $corpid, $playletId,
  85. $sortField, $page, $pageSize);
  86. return self::returnPageValue($data, $count, $pageSize, $page);
  87. }
  88. # 短剧数据(新)
  89. public function playletDataTrend(Request $request)
  90. {
  91. $validator = Validator::make($request->all(),[
  92. 'start_date' => 'nullable|date',
  93. 'end_date' => 'nullable|date'
  94. ]);
  95. if ($validator->fails()) {
  96. return self::returnValue($validator->getMessageBag(), 1102);
  97. }
  98. $startDate = $request->input('start_date');
  99. $endDate = $request->input('end_date');
  100. $playletId = $request->input('playlet_id');
  101. $sysGroupId = $request->input('sys_group_id');
  102. $page = $request->input('page', 1);
  103. $pageSize = $request->input('page_size', 10);
  104. list($data, $count) = DataStatisticsService::playletDataTrend($startDate, $endDate, $playletId,
  105. $page, $pageSize, $sysGroupId);
  106. return self::returnPageValue($data, $count, $pageSize, $page);
  107. }
  108. /**
  109. * 短剧粉丝激活趋势
  110. * */
  111. public function activeFansData(Request $request)
  112. {
  113. $validator = Validator::make($request->all(),[
  114. 'start_date' => 'nullable|date',
  115. 'end_date' => 'nullable|date'
  116. ]);
  117. if ($validator->fails()) {
  118. return self::returnValue($validator->getMessageBag(), 1102);
  119. }
  120. $startDate = $request->input('start_date');
  121. $endDate = $request->input('end_date');
  122. $closingDate = $request->input('closing_date');
  123. $accountId = $request->input('app_id');
  124. $minPaid = $request->input('min_paid');
  125. $maxPaid = $request->input('max_paid');
  126. $page = $request->input('page', 1);
  127. $pageSize = $request->input('page_size', 10);
  128. $sysGroupId = $request->input('sys_group_id');
  129. list($data, $count) = DataStatisticsService::activeFansData(
  130. $startDate, $endDate, $closingDate, $accountId, $minPaid, $maxPaid, $page, $pageSize, $sysGroupId
  131. );
  132. return self::returnPageValue($data, $count, $pageSize, $page);
  133. }
  134. // 公众号数据(2022-07-21改版)
  135. public function OfficialAccountData(Request $request)
  136. {
  137. $validator = Validator::make($request->all(),[
  138. 'start_date' => 'nullable|date',
  139. 'end_date' => 'nullable|date'
  140. ]);
  141. if ($validator->fails()) {
  142. return self::returnValue($validator->getMessageBag(), 1102);
  143. }
  144. $startDate = $request->input('start_date');
  145. $endDate = $request->input('end_date');
  146. $accountId = $request->input('account_id');
  147. $sortField = $request->input('sort_field', 'charge_total');
  148. $sysGroupId = $request->input('sys_group_id');
  149. $page = $request->input('page', 1);
  150. $pageSize = $request->input('page_size', 10);
  151. list($data, $count) = DataStatisticsService::OfficialAccountData($startDate, $endDate, $accountId,
  152. $sortField, $page, $pageSize, $sysGroupId);
  153. return self::returnPageValue($data, $count, $pageSize, $page);
  154. }
  155. public function playletDataUniqueUser (Request $request)
  156. {
  157. $validator = Validator::make($request->all(),[
  158. 'start_date' => 'required|date',
  159. 'end_date' => 'required|date'
  160. ]);
  161. if ($validator->fails()) {
  162. return self::returnValue($validator->getMessageBag(), 1102);
  163. }
  164. $startDate = $request->input('start_date');
  165. $endDate = $request->input('end_date');
  166. $playletId = $request->input('playlet_id');
  167. $sysGroupId = $request->input('sys_group_id');
  168. $adminId = $request->input('admin_id');
  169. $isSystemAdmin = $request->input('is_system_admin');
  170. $appId = $request->input('app_id'); // 公众号
  171. $launchAccountId = $request->input('launch_account_id');
  172. $data = DataStatisticsService::statisticsDataUniqueUser($startDate, $endDate, $playletId, null, $sysGroupId
  173. , 3, $adminId, $isSystemAdmin, $appId, $launchAccountId);
  174. return self::returnValue($data);
  175. }
  176. public function pitcherDataUniqueUser (Request $request)
  177. {
  178. $validator = Validator::make($request->all(),[
  179. 'start_date' => 'required|date',
  180. 'end_date' => 'required|date'
  181. ]);
  182. if ($validator->fails()) {
  183. return self::returnValue($validator->getMessageBag(), 1102);
  184. }
  185. $startDate = $request->input('start_date');
  186. $endDate = $request->input('end_date');
  187. $pitcherId = $request->input('pitcher_id');
  188. $sysGroupId = $request->input('sys_group_id');
  189. $playletId = $request->input('playlet_id', null);
  190. $adminId = $request->input('admin_id');
  191. $isSystemAdmin = $request->input('is_system_admin');
  192. $appId = $request->input('app_id'); // 公众号
  193. $launchAccountId = $request->input('launch_account_id');
  194. $data = DataStatisticsService::statisticsDataUniqueUser($startDate, $endDate, $playletId, $pitcherId, $sysGroupId
  195. , 1, $adminId, $isSystemAdmin, $appId, $launchAccountId);
  196. return self::returnValue($data);
  197. }
  198. /*
  199. * 数据循环统计
  200. * */
  201. public function dataCycleList(Request $request)
  202. {
  203. $validator = \Validator::make($request->all(),[
  204. 'begin_date' => 'required',
  205. 'end_date' => 'required',
  206. 'first_order_cost_min' => 'nullable|numeric',
  207. 'first_order_cost_max' => 'nullable|numeric',
  208. 'first_order_cost_unique_min' => 'nullable|numeric',
  209. 'first_order_cost_unique_max' => 'nullable|numeric',
  210. 'per_follow_cost_min' => 'nullable|numeric',
  211. 'per_follow_cost_max' => 'nullable|numeric',
  212. 'total_roi_min' => 'nullable|numeric',
  213. 'total_roi_max' => 'nullable|numeric',
  214. 'first_day_roi_min' => 'nullable|numeric',
  215. 'first_day_roi_max' => 'nullable|numeric',
  216. 'order_type' => 'required|in:1,2',// 1Mp 2Adq
  217. 'plat_order_type' => 'nullable|numeric',
  218. 'paid_min' => 'nullable|numeric',
  219. 'paid_max' => 'nullable|numeric',
  220. ]);
  221. if ($validator->fails()) {
  222. return self::returnValue($validator->getMessageBag(), 1102);
  223. }
  224. $page = $request->input("page",1);
  225. $pageSize = $request->input("page_size",20);
  226. $beginDate = $request->input("begin_date", null);
  227. $endDate = $request->input("end_date", null);
  228. $sysGroupId = $request->input('sys_group_id');
  229. $firstOrderCostMin = $request->input('first_order_cost_min', null);
  230. $firstOrderCostMax = $request->input('first_order_cost_max', null);
  231. $firstOrderCostUniqueMin= $request->input('first_order_cost_unique_min', null);
  232. $firstOrderCostUniqueMax= $request->input('first_order_cost_unique_max', null);
  233. $perFollowCostMin = $request->input('per_follow_cost_min', null);
  234. $perFollowCostMax = $request->input('per_follow_cost_max', null);
  235. $totalRoiMin = $request->input('total_roi_min', null);
  236. $totalRoiMax = $request->input('total_roi_max', null);
  237. $firstDayRoiMin = $request->input('first_day_roi_min', null);
  238. $firstDayRoiMax = $request->input('first_day_roi_max', null);
  239. $orderType = $request->input('order_type', 1);
  240. $platOrderType = $request->input('plat_order_type', null);
  241. $closingDate = $request->input('closing_date', null);
  242. $paidMin = $request->input('paid_min', null);
  243. $paidMax = $request->input('paid_max', null);
  244. $sortField = $request->input('sort_field', 'date');
  245. $sortType = $request->input('sort_type', 'desc');
  246. list($total, $list, $overview) = DataStatisticsService::dataCycleList(
  247. $beginDate,$endDate,$page,$pageSize, $sysGroupId, $firstOrderCostMin, $firstOrderCostMax,
  248. $firstOrderCostUniqueMin, $firstOrderCostUniqueMax, $perFollowCostMin, $perFollowCostMax,
  249. $totalRoiMin, $totalRoiMax, $firstDayRoiMin, $firstDayRoiMax, $orderType, $platOrderType, $closingDate,
  250. $paidMin, $paidMax, $sortField, $sortType);
  251. return self::returnPageValue(['list'=>$list, 'overview' => $overview],$total,$pageSize,$page);
  252. }
  253. /**
  254. * 获取数据看板数据更新时间
  255. * */
  256. public function uptime(Request $request)
  257. {
  258. $validator = \Validator::make($request->all(),[
  259. 'type' => ['required', Rule::in([
  260. 'account_data_trend_mp', 'account_data_trend_adq', 'playlet_data_trend_adq', 'data_cycle_nur',
  261. 'playlet_data_trend_mp', 'data_cycle_adq', 'data_cycle_mp', 'account_data_trend', 'playlet_data_trend',
  262. 'operate_data_trend', 'cumulative_recovery_data', 'account_funds'
  263. ])],
  264. ]);
  265. if ($validator->fails()) {
  266. return self::returnValue($validator->getMessageBag(), 1102);
  267. }
  268. $type = $request->input('type');
  269. # 获取数据更新时间
  270. $dateTime = DataStatisticsService::getDataUptime($type);
  271. return self::returnValue(['uptime' => $dateTime]);
  272. }
  273. public function HuaShengDataCycleList(Request $request)
  274. {
  275. $validator = \Validator::make($request->all(),[
  276. 'begin_date' => 'required',
  277. 'end_date' => 'required',
  278. 'first_order_cost_min' => 'nullable|numeric',
  279. 'first_order_cost_max' => 'nullable|numeric',
  280. 'per_follow_cost_min' => 'nullable|numeric',
  281. 'per_follow_cost_max' => 'nullable|numeric',
  282. 'total_roi_min' => 'nullable|numeric',
  283. 'total_roi_max' => 'nullable|numeric',
  284. 'first_day_roi_min' => 'nullable|numeric',
  285. 'first_day_roi_max' => 'nullable|numeric',
  286. 'paid_min' => 'nullable|numeric',
  287. 'paid_max' => 'nullable|numeric',
  288. 'plat_order_type' => 'nullable|numeric',
  289. 'order_source' => 'nullable|numeric',
  290. ]);
  291. if ($validator->fails()) {
  292. return self::returnValue($validator->getMessageBag(), 1102);
  293. }
  294. $page = $request->input("page",1);
  295. $pageSize = $request->input("page_size",20);
  296. $beginDate = $request->input("begin_date", null);
  297. $endDate = $request->input("end_date", null);
  298. $sysGroupId = $request->input('sys_group_id');
  299. $firstOrderCostMin = $request->input('first_order_cost_min', null);
  300. $firstOrderCostMax = $request->input('first_order_cost_max', null);
  301. $perFollowCostMin = $request->input('per_follow_cost_min', null);
  302. $perFollowCostMax = $request->input('per_follow_cost_max', null);
  303. $totalRoiMin = $request->input('total_roi_min', null);
  304. $totalRoiMax = $request->input('total_roi_max', null);
  305. $firstDayRoiMin = $request->input('first_day_roi_min', null);
  306. $firstDayRoiMax = $request->input('first_day_roi_max', null);
  307. $closingDate = $request->input('closing_date', null);
  308. $paidMin = $request->input('paid_min', null);
  309. $paidMax = $request->input('paid_max', null);
  310. $sortField = $request->input('sort_field', 'date');
  311. $sortType = $request->input('sort_type', 'desc');
  312. $appId = $request->input('app_id');
  313. $platOrderType = $request->input('plat_order_type', null);
  314. $adminId = $request->input('admin_id');
  315. $isSystemAdmin = $request->input('is_system_admin');
  316. $orderSource = $request->input('order_source', 5);
  317. list($total, $list, $overview) = DataStatisticsService::huaShengDataCycleList($adminId, $isSystemAdmin,
  318. $beginDate,$endDate,$page,$pageSize, $sysGroupId, $firstOrderCostMin, $firstOrderCostMax,
  319. $perFollowCostMin, $perFollowCostMax, $totalRoiMin, $totalRoiMax, $firstDayRoiMin, $firstDayRoiMax,
  320. $closingDate, $paidMin, $paidMax, $sortField, $sortType, $appId, $platOrderType, $orderSource);
  321. return self::returnPageValue(['list'=>$list, 'overview' => $overview],$total,$pageSize,$page);
  322. }
  323. public function dataCycleListByAccount(Request $request)
  324. {
  325. $validator = \Validator::make($request->all(),[
  326. 'begin_date' => 'required',
  327. 'end_date' => 'required',
  328. 'first_order_cost_min' => 'nullable|numeric',
  329. 'first_order_cost_max' => 'nullable|numeric',
  330. 'per_follow_cost_min' => 'nullable|numeric',
  331. 'per_follow_cost_max' => 'nullable|numeric',
  332. 'total_roi_min' => 'nullable|numeric',
  333. 'total_roi_max' => 'nullable|numeric',
  334. 'first_day_roi_min' => 'nullable|numeric',
  335. 'first_day_roi_max' => 'nullable|numeric',
  336. 'order_type' => 'required|in:1,2',// 1Adq 2Mp
  337. 'plat_order_type' => 'nullable|numeric',
  338. 'paid_min' => 'nullable|numeric',
  339. 'paid_max' => 'nullable|numeric',
  340. ]);
  341. if ($validator->fails()) {
  342. return self::returnValue($validator->getMessageBag(), 1102);
  343. }
  344. $params['begin_date'] = $request->input("begin_date", null);
  345. $params['end_date'] = $request->input("end_date", null);
  346. $params['sys_group_id'] = $request->input('sys_group_id');
  347. $params['is_system_admin'] = $request->input('is_system_admin');
  348. $params['admin_id'] = $request->input('admin_id');
  349. $params['first_order_cost_min'] = $request->input('first_order_cost_min', null);
  350. $params['first_order_cost_max'] = $request->input('first_order_cost_max', null);
  351. $params['per_follow_cost_min'] = $request->input('per_follow_cost_min', null);
  352. $params['per_follow_cost_max'] = $request->input('per_follow_cost_max', null);
  353. $params['total_roi_min'] = $request->input('total_roi_min', null);
  354. $params['total_roi_max'] = $request->input('total_roi_max', null);
  355. $params['first_day_roi_min'] = $request->input('first_day_roi_min', null);
  356. $params['first_day_roi_max'] = $request->input('first_day_roi_max', null);
  357. $params['plat_order_type'] = $request->input('plat_order_type', null);
  358. $params['closing_date'] = $request->input('closing_date', null);
  359. $params['paid_min'] = $request->input('paid_min', null);
  360. $params['paid_max'] = $request->input('paid_max', null);
  361. $orderType = $request->input('order_type', 1);
  362. $sortField = $request->input('sort_field', 'date');
  363. $sortType = $request->input('sort_type', 'desc');
  364. $page = $request->input("page",1);
  365. $pageSize = $request->input("page_size",20);
  366. list($total, $list, $overview) = NewStatisticsService::dataCycleListByAccount($params, $orderType, $page, $pageSize
  367. , $sortField, $sortType);
  368. return self::returnPageValue(['list'=>$list, 'overview' => $overview],$total,$pageSize,$page);
  369. }
  370. public function HuaShengDataPlatformList(Request $request)
  371. {
  372. $data = [
  373. ['order_source' => 99, 'desc' => '全部'],
  374. ['order_source' => 5, 'desc' => '花生'],
  375. ['order_source' => 7, 'desc' => '九州'],
  376. ];
  377. return self::returnValue($data);
  378. }
  379. # 投手ADQ数据汇总(账户数以及投放天数只统计有消耗的数据)
  380. public function pitcherAdqAccountData(Request $request) {
  381. $validator = \Validator::make($request->all(),[
  382. 'start_date' => 'required',
  383. 'end_date' => 'required',
  384. ]);
  385. if ($validator->fails()) {
  386. return self::returnValue($validator->getMessageBag(), 1102);
  387. }
  388. $params['start_date'] = $request->input("start_date", null);
  389. $params['end_date'] = $request->input("end_date", null);
  390. $params['sys_group_id'] = $request->input('sys_group_id');
  391. $params['is_system_admin'] = $request->input('is_system_admin');
  392. $params['admin_id'] = $request->input('admin_id');
  393. $sortField = $request->input('sort_field', 'total_paid');
  394. $sortType = $request->input('sort_type', 'desc');
  395. $res = DataStatisticsService::pitcherAdqAccountData($params, $sortField, $sortType);
  396. return self::returnValue($res);
  397. }
  398. # 送达数据 - 客户群发消息
  399. public function massMsgServiceData(Request $request) {
  400. $validator = \Validator::make($request->all(),[
  401. 'send_time_start' => 'nullable|date_format:Y-m-d',
  402. 'send_time_end' => 'nullable|date_format:Y-m-d',
  403. ]);
  404. if ($validator->fails()) {
  405. return self::returnValue($validator->getMessageBag(), 1102);
  406. }
  407. $creatorId = $request->input('creator_id');
  408. $sendTimeStart = $request->input('send_time_start');
  409. $sendTimeEnd = $request->input('send_time_end');
  410. $keyword = $request->input('keyword');
  411. $sysGroupId = $request->input('sys_group_id');
  412. $page = $request->input('page', 1);
  413. $pageSize = $request->input('page_size', 20);
  414. list($data, $count) = ServiceDataService::massMsgServiceData($creatorId, $sendTimeStart, $sendTimeEnd, $keyword
  415. , $sysGroupId, $page, $pageSize);
  416. return self::returnPageValue($data, $count, $pageSize, $page);
  417. }
  418. # 送达数据 - 客户群群发消息
  419. public function chatGroupMassMsgServiceData(Request $request) {
  420. $validator = \Validator::make($request->all(),[
  421. 'send_time_start' => 'nullable|date_format:Y-m-d',
  422. 'send_time_end' => 'nullable|date_format:Y-m-d',
  423. ]);
  424. if ($validator->fails()) {
  425. return self::returnValue($validator->getMessageBag(), 1102);
  426. }
  427. $creatorId = $request->input('creator_id');
  428. $sendTimeStart = $request->input('send_time_start');
  429. $sendTimeEnd = $request->input('send_time_end');
  430. $keyword = $request->input('keyword');
  431. $sysGroupId = $request->input('sys_group_id');
  432. $page = $request->input('page', 1);
  433. $pageSize = $request->input('page_size', 20);
  434. list($data, $count) = ServiceDataService::chatGroupMassMsgServiceData($creatorId, $sendTimeStart, $sendTimeEnd
  435. , $keyword, $sysGroupId, $page, $pageSize);
  436. return self::returnPageValue($data, $count, $pageSize, $page);
  437. }
  438. # 送达数据 - 智能群发消息
  439. public function periodMassMsgServiceData(Request $request) {
  440. $validator = \Validator::make($request->all(),[
  441. 'send_time_start' => 'nullable|date_format:Y-m-d',
  442. 'send_time_end' => 'nullable|date_format:Y-m-d',
  443. ]);
  444. if ($validator->fails()) {
  445. return self::returnValue($validator->getMessageBag(), 1102);
  446. }
  447. $creatorId = $request->input('creator_id');
  448. $sendTimeStart = $request->input('send_time_start');
  449. $sendTimeEnd = $request->input('send_time_end');
  450. $keyword = $request->input('keyword');
  451. $sysGroupId = $request->input('sys_group_id');
  452. $page = $request->input('page', 1);
  453. $pageSize = $request->input('page_size', 20);
  454. list($data, $count) = ServiceDataService::periodMassMsgServiceData($creatorId, $sendTimeStart, $sendTimeEnd, $keyword
  455. , $sysGroupId, $page, $pageSize);
  456. return self::returnPageValue($data, $count, $pageSize, $page);
  457. }
  458. }