コード例 #1
0
 public function match()
 {
     $options = ContractSearchCriteria::where('user_id', Auth::user()->id)->first();
     if (!$options) {
         flash()->error('Настройте критерии поиска.');
         return redirect()->route('admin.contracts.index');
     }
     $contract_ids = Contract::elasticSearch($options);
     $list = Contract::whereIn('id', $contract_ids)->whereRaw('(finished_at > NOW() OR finished_at IS NULL)')->with('organization')->get();
     return view('admin.contracts.view', compact('list'));
 }
コード例 #2
0
ファイル: SendMail.php プロジェクト: 6akcuk/infotendermail
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $elastic = ClientBuilder::create()->build();
     $searches = ContractSearchCriteria::with('user')->get();
     foreach ($searches as $search) {
         $criteria = json_decode($search->criterias, true);
         $this->info('Обработка критерия для пользователя ' . $search->user_id);
         if (is_array($criteria) && sizeof($criteria) > 0) {
             $max_id = (int) UserSendedContract::where('user_id', $search->user_id)->max('contract_id');
             $this->info('Поиск контрактов');
             $contract_ids = Contract::elasticSearch($search, $max_id);
             foreach ($contract_ids as $contract) {
                 UserSendedContract::create(['user_id' => $search->user_id, 'contract_id' => $contract]);
             }
             $list = Contract::whereIn('id', $contract_ids)->with('organization')->get();
             Mail::send('emails.contracts', ['list' => $list], function ($m) use($list, $search, $contract_ids) {
                 $m->from('*****@*****.**', 'infotendermail');
                 $m->to($search->user->email, $search->user->name)->subject('Контракты с infotendermail.ru #' . sizeof($contract_ids));
             });
         }
     }
 }