Online.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\NewUserSummaryService;
  6. use App\Services\OnlineUserService;
  7. use Exception;
  8. use Illuminate\Validation\ValidationException;
  9. class Online extends Controller
  10. {
  11. /**
  12. * 在线用户列表
  13. */
  14. public function users()
  15. {
  16. try {
  17. $params = request()->validate([
  18. 'page' => ['nullable', 'integer', 'min:1'],
  19. 'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
  20. 'member_id' => ['nullable', 'string'],
  21. 'account' => ['nullable', 'string', 'max:64'],
  22. 'first_name' => ['nullable', 'string'],
  23. 'login_ip' => ['nullable', 'string'],
  24. 'platform' => ['nullable', 'string'],
  25. ]);
  26. $result = OnlineUserService::list($params);
  27. } catch (ValidationException $e) {
  28. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  29. } catch (Exception $e) {
  30. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  31. }
  32. return $this->success($result);
  33. }
  34. /**
  35. * 新用户汇总(按天)
  36. */
  37. public function newUserSummary()
  38. {
  39. try {
  40. $params = request()->validate([
  41. 'start_time' => ['nullable', 'date', 'date_format:Y-m-d'],
  42. 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'after_or_equal:start_time'],
  43. ]);
  44. $endDate = $params['end_time'] ?? date('Y-m-d');
  45. $startDate = $params['start_time'] ?? date('Y-m-d', strtotime($endDate . ' -6 days'));
  46. $result = NewUserSummaryService::summarize($startDate, $endDate);
  47. } catch (ValidationException $e) {
  48. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  49. } catch (Exception $e) {
  50. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  51. }
  52. return $this->success($result);
  53. }
  54. /**
  55. * 在线用户按端计数:苹果 APP / 安卓 APP / PC / 手机 H5
  56. * 唯一在线人数接口(勿挂到 paymentOrder/unProcessed)
  57. */
  58. public function platformCount()
  59. {
  60. try {
  61. $result = OnlineUserService::platformCounts();
  62. } catch (Exception $e) {
  63. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  64. }
  65. return $this->success($result);
  66. }
  67. }