小说推广数据系统

PlayletPromoteService.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Services;
  3. use App\Models\PlayletConfig;
  4. use App\Models\VpAccount;
  5. use App\Models\VpPlayletCampaign;
  6. class PlayletPromoteService
  7. {
  8. /**
  9. * 获取账号已设置的推广计划
  10. * @param $appId string 公众账号AppId
  11. * @param $startDate string 计划创建开始时间
  12. * @param $endDate string 计划创建结束时间
  13. * @param $page integer 当前页码数
  14. * @param $pageSize integer 每页显示条数
  15. * */
  16. public static function promoteList($appId, $startDate, $endDate, $page, $pageSize)
  17. {
  18. list($list, $count) = VpPlayletCampaign::getPromoteList($appId, $startDate, $endDate, $page, $pageSize);
  19. return [$list, $count];
  20. }
  21. /**
  22. * 短剧作品朋友圈推广数据趋势
  23. * @param $playletId string 短剧ID
  24. * @param $startDate string 计划创建开始时间
  25. * @param $endDate string 计划创建结束时间
  26. * @param $page integer 当前页码数
  27. * @param $pageSize integer 每页显示条数
  28. * */
  29. public static function promoteData($playletId, $startDate, $endDate, $page, $pageSize)
  30. {
  31. list($list, $count) = VpPlayletCampaign::getPromoteData($playletId, $startDate, $endDate, $page, $pageSize);
  32. # 获取公众账号消息
  33. $accountList = VpAccount::select(['app_id', 'nickname'])->where('enable', 1)->get();
  34. foreach ($list as $item) {
  35. # 访问uv
  36. $viewUv = isset($item->view_uv_total) ? $item->view_uv_total : 0;
  37. # 付费率
  38. $item->charge_rate = $viewUv ? round($item->pay_uv_total / $viewUv, 5) * 100 . '%' : '0%';
  39. # 总充值
  40. $item->charge_total = $item->charge_total / 10000;
  41. # 今日充值
  42. $item->charge_today = $item->charge_today / 10000;
  43. # 公众账号
  44. $accountInfo = $accountList->where('app_id', $item->app_id)->first();
  45. $item->nickname = isset($accountInfo->nickname) ? $accountInfo->nickname : '';
  46. }
  47. return [$list, $count];
  48. }
  49. }