noticeRule = $noticeRule; $this->rabbitMqUtil = $rabbitMqUtil; } /** * Execute the console command. * * @return mixed */ public function handle() { $this->line("开始添加发送通知"); $this->noticeRule ->where('notice_type', 0) ->where('notice_status', 0) ->where('send_time', '<', Carbon::now()->toDateTimeString()) ->whereNotNUll('send_time') ->chunk(100, function($notices){ foreach($notices as $notice){ DB::beginTransaction(); try{ $notice->notice_status = 1; $noticeUsers = json_decode($notice->notice_users, true); if(isset($noticeUsers['category']) && $noticeUsers['category']){ $uids = $this->getCategoryUids(json_encode($noticeUsers['category'])); Log::debug('uids'.json_encode($uids)); if(!$uids){ DB::rollBack(); Log::error('获取关注分类用户失败:'); } $noticeUsers['category_uids'] = $uids; $notice->notice_users = json_encode($noticeUsers); } $notice->save(); DB::commit(); $this->rabbitMqUtil->push('add_notice_rule', $notice); Log::info('添加发送通知成功:'.$notice->id); }catch (QueryException $exception){ DB::rollBack(); Log::error('添加发送通知失败:'.$exception->getMessage()); } } }); $this->line("添加发送消息结束"); } }