12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Console\Commands;
- use App\Support\RedisModel;
- use App\Support\Log;
- use App\Support\EmailQueue;
- use App\Services\UserActionsReportService;
- use Illuminate\Console\Command;
- class AccountActionReport extends Command
- {
- protected $signature = 'account:action-report';
- protected $description = '处理账户行为报告';
- public function handle()
- {
- $startTime = time();
- $endTime = $startTime + 600; // 10分钟后结束
- while (time() < $endTime) {
- try {
- // 从Redis队列获取数据
- $data = RedisModel::rPop(UserActionsReportService::ACCOUNT_ACTION_REPORT_LIST);
- if (empty($data)) {
- sleep(1); // 如果没有数据,休眠1秒
- continue;
- }
- // 解析数据
- $dataArray = json_decode($data, true);
- $orderId = $dataArray['order_id'] ?? null;
- $type = $dataArray['type'] ?? null;
- // 调用actionReport函数
- UserActionsReportService::actionReport($orderId, $type);
- } catch (\Exception $e) {
- // 记录错误日志
- $errorContext = [
- 'request_params' => $dataArray ?? [],
- 'file' => $e->getFile(),
- 'line' => $e->getLine(),
- 'message' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ];
- Log::error('Account Action Report Error', $errorContext, 'AccountActionReport');
- // 发送错误通知邮件
- EmailQueue::rPush(
- 'Account Action Report Error',
- json_encode($errorContext),
- ['song.shen@ekuxuan-inc.com'],
- '聚星'
- );
- }
- }
- }
- }
|