/** * Execute the console command. * 该任务具体的执行代码, 这边实现定时发邮件 * * @return mixed */ public function handle() { $issue = Issue::published()->latest('issue')->pluck('issue'); $issueArticles = Issue::published()->latest()->first()->articles->groupBy('category_id'); $recommendId = Category::recommend()->pluck('id'); $otherId = Category::other()->pluck('id'); $recommArticles = []; $normalArticles = collect(); // 创建一个新集合 $otherArticles = []; foreach ($issueArticles as $key => $value) { if ($key == $recommendId) { // 推荐分类文章 $recommArticles = $value; } elseif ($key == $otherId) { // 其他分类文章 $otherArticles = $value; } else { $normalArticles = $normalArticles->merge($value); } } // 把推荐分类文章放在集合第一个 其他分类文章放在集合最后一个 $articles = collect(); $articles = $articles->merge($recommArticles)->merge($normalArticles)->merge($otherArticles)->groupBy('category_id'); $users = Subscribe::where('is_confirmed', 1)->get(); foreach ($users as $user) { $this->dispatch(new SendIssueEmail($user, $issue, $articles)); // 推送到队列 } }
/** * @param Event $event * @param array $data * @return bool|static */ public function subscribe(Event $event, array $data) { $requesterCount = $this->countRequesters($data); $subscribers = $event->subscribers; $count = 0; foreach ($subscribers as $subscriber) { $count += $this->verifyDad($subscriber); $count += $this->verifyMom($subscriber); $count += $this->verifyChildren($subscriber); } if ($count + $requesterCount <= $event->vagas) { try { $subscribe = Subscribe::create(array_merge(['evento_id' => $event->id], $data)); } catch (\Exception $e) { header('HTTP/1.1 500 Internal Server Error'); return 'Ocorreu um erro ao salvar os dados'; } $event = $subscribe->event; $successResponse = 'Não se esqueça de anotar o endereço, sua data e a hora escolhida. Até lá!<br/><br/>' . "Cadastrado em: {$event->dia} - {$event->horario}"; return $successResponse; } header('HTTP/1.1 500 Internal Server Error'); return 'Limite de vagas atingido. Por favor, escolha um outro horário'; }
/** * Run the database seeds. * * @return void */ public function run() { $subscribes = factory(Subscribe::class)->times(30)->make(); Subscribe::insert($subscribes->toArray()); }
public function getSubscribe($id){ $subscribe = new Subscribe([//помен¤ть на функцию create 'question_id'=>$id, 'user_id'=>$this->user->id ]); $subscribe->save(); return redirect()->back()->with('message','Вы успешно подписаны, когда будет ответ на данный вопрос, вам на почту придет уведомление.'); }
/** * @param $id * @return mixed */ public function delete($id) { return $this->model->find($id)->delete(); }