暫無描述

AccountActionReport.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Support\RedisModel;
  4. use App\Support\Log;
  5. use App\Support\EmailQueue;
  6. use App\Services\UserActionsReportService;
  7. use Illuminate\Console\Command;
  8. class AccountActionReport extends Command
  9. {
  10. protected $signature = 'account:action-report';
  11. protected $description = '处理账户行为报告';
  12. public function handle()
  13. {
  14. $startTime = time();
  15. $endTime = $startTime + 600; // 10分钟后结束
  16. while (time() < $endTime) {
  17. try {
  18. // 从Redis队列获取数据
  19. $data = RedisModel::rPop(UserActionsReportService::ACCOUNT_ACTION_REPORT_LIST);
  20. if (empty($data)) {
  21. sleep(1); // 如果没有数据,休眠1秒
  22. continue;
  23. }
  24. // 解析数据
  25. $dataArray = json_decode($data, true);
  26. $orderId = $dataArray['order_id'] ?? null;
  27. $type = $dataArray['type'] ?? null;
  28. // 调用actionReport函数
  29. UserActionsReportService::actionReport($orderId, $type);
  30. } catch (\Exception $e) {
  31. // 记录错误日志
  32. $errorContext = [
  33. 'request_params' => $dataArray ?? [],
  34. 'file' => $e->getFile(),
  35. 'line' => $e->getLine(),
  36. 'message' => $e->getMessage(),
  37. 'trace' => $e->getTraceAsString()
  38. ];
  39. Log::error('Account Action Report Error', $errorContext, 'AccountActionReport');
  40. // 发送错误通知邮件
  41. EmailQueue::rPush(
  42. 'Account Action Report Error',
  43. json_encode($errorContext),
  44. ['song.shen@ekuxuan-inc.com'],
  45. '聚星'
  46. );
  47. }
  48. }
  49. }
  50. }