member_data = $member_data; } public function getCorpId() { return $this->member_data['authCorpId'] ?? null; } /** * Execute the job. * * @return void */ public function handle() { // $corpId = $this->member_data['authCorpId']; (new DbService())->getConnectionNameByCorpId($corpId); // 创建任务记录 $this->Records = Records::create([ 'job_id' => $this->member_data['authCorpId'] . '_GroupMemberJobs', 'name' => static::class, 'payload' => json_encode($this->member_data), 'status' => 'processing', 'started_at' => now() ]); $Chat_model = new chatModel(); $corpid = $this->member_data['authCorpId']; $chat_id = $this->member_data['chat_id']; $status = $this->member_data['status']; //获取redis缓存 $chat_list_redis = Cache::get('openwork_chat_list_' . $corpid); try { if (!empty($chat_list_redis)) { $corpid_chat_id = $corpid . '_' . $chat_id; if (in_array($corpid_chat_id, $chat_list_redis)) { $Chat_model->edit($corpid, $chat_id, $status); } else { $Chat_model->add($corpid, $chat_id, $status); } } else { $chat_data_log = $Chat_model->where([['corpid', '=', $corpid], ['chat_id', '=', $chat_id]])->first(); if (!$chat_data_log) { $Chat_model->add($corpid, $chat_id, $status); } else { $Chat_model->edit($corpid, $chat_id, $status); } } //删除任务记录 $this->Records->delete(); } catch (\Exception $e) { // 失败处理... if ($this->Records) { $this->Records->delete(); } Log::info('job_error', '群成员队列失败-异常原因', ['data'=>$this->member_data,'error' => $e->getMessage()]); } } public function failed(\Throwable $exception) { Log::info('job_error', 'GroupMemberJobs彻底失败', ['data'=>$this->member_data,'error' => $exception]); // 失败处理... if ($this->Records) { $this->Records->delete(); } } }