Online.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. 'first_name' => ['nullable', 'string'],
  22. 'login_ip' => ['nullable', 'string'],
  23. 'platform' => ['nullable', 'string'],
  24. ]);
  25. $result = OnlineUserService::list($params);
  26. } catch (ValidationException $e) {
  27. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  28. } catch (Exception $e) {
  29. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  30. }
  31. return $this->success($result);
  32. }
  33. /**
  34. * 新用户汇总(按天)
  35. */
  36. public function newUserSummary()
  37. {
  38. try {
  39. $params = request()->validate([
  40. 'start_time' => ['nullable', 'date', 'date_format:Y-m-d'],
  41. 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'after_or_equal:start_time'],
  42. ]);
  43. $endDate = $params['end_time'] ?? date('Y-m-d');
  44. $startDate = $params['start_time'] ?? date('Y-m-d', strtotime($endDate . ' -6 days'));
  45. $result = NewUserSummaryService::summarize($startDate, $endDate);
  46. } catch (ValidationException $e) {
  47. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  48. } catch (Exception $e) {
  49. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  50. }
  51. return $this->success($result);
  52. }
  53. /**
  54. * 在线用户按端计数:苹果 APP / 安卓 APP / PC / 手机 H5
  55. * 唯一在线人数接口(勿挂到 paymentOrder/unProcessed)
  56. */
  57. public function platformCount()
  58. {
  59. try {
  60. $result = OnlineUserService::platformCounts();
  61. } catch (Exception $e) {
  62. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  63. }
  64. return $this->success($result);
  65. }
  66. }