data = $data ?? []; $this->user = $user ?? []; } /** * * file_put_contents('charge.txt',"标记位置退出".PHP_EOL,8); * Execute the job. * * @return void */ public function handle() { $service = new BoxService(); $currentAttempt = $this->attempts(); try { Log::info("任务开始执行", [ 'job_id' => $this->job->getJobId(), 'attempt' => $currentAttempt, 'data' => $this->data ]); list($status,$msg) = $service->boxInSettle($this->data, $this->user); if(! $status) { Log::info("业务逻辑执行失败", [ 'job_id' => $this->job->getJobId(), 'attempt' => $currentAttempt, 'error' => $msg ]); $service->dellimitingSendRequestBackgNeed($service->lock_key); //删除锁 $this->recordErrorTable($msg); }else { Log::info("任务执行成功", [ 'job_id' => $this->job->getJobId(), 'attempt' => $currentAttempt ]); } } catch (\Throwable $e) { Log::error("任务执行异常", [ 'job_id' => $this->job->getJobId(), 'attempt' => $currentAttempt, 'exception' => $e->getMessage(), ]); $service->dellimitingSendRequestBackgNeed($service->lock_key);//删除锁 $this->delete(); $this->recordErrorTable($e->getFile() . $e->getMessage() . $e->getLine()); } //输出信息 $this->echoMessage(new ConsoleOutput()); } protected function echoMessage(OutputInterface $output) { //输出消息 $output->writeln(json_encode($this->data)); } private function recordErrorTable($msg){ // 连接到指定数据库连接 ErrorTable::insert([ 'msg' => $msg, 'data' => json_encode($this->data), 'user_id' => $this->user['id'] ?? 0, 'user_operation_time' => time(), 'type' => 1, 'order_no' => $data['order_no'] ?? "" ]); } }