EmailBatch = $EmailBatch; } /** * Execute the job. * * @return void */ public function handle() { $status = $this->getRuleStatus($this->EmailBatch->template->alias); if ($status) { if ($this->EmailBatch->emails) { $emails=explode(",", $this->EmailBatch->emails); foreach ($emails as $emails) { if (validator_check($emails, ['email'])) { $this->dispatchSms($emails); $this->EmailBatch->target_num++; } $this->EmailBatch->save(); } } else { $emails=$this->getEmails($this->EmailBatch->accept_member, $this->EmailBatch->accept_type); if (!empty($emails)) { foreach ($emails as $emails) { if (validator_check($emails, ['email'])) { $this->dispatchSms($emails); $this->EmailBatch->target_num++; } $this->EmailBatch->save(); } } } } if ($this->EmailBatch->target_num == 0) { $this->EmailBatch->status=1; $this->EmailBatch->save(); } } protected function getEmails($accept_member, $accept_type) { $where=[]; if ($accept_type) { $where[]=["last_login_time",'<',time()-($accept_type==1?7:30)*24*60*60]; } $memberEmail=Member::where($where)->pluck('email'); $companyEmail=Company::where($where)->pluck('email'); if ($accept_member == 0) { return $memberEmail->concat($companyEmail); } else { return $accept_member==1?$companyEmail:$memberEmail; } } protected function dispatchSms($emails) { $emailJob=new EmailJob($emails, $this->EmailBatch->template->alias, [], []); $emailJob->setBatchId($this->EmailBatch->id); dispatch($emailJob); } protected function getRuleStatus($alias) { $result = Email::where(['alias'=>$alias])->first(); if ($result) { if ($result->status) { return true; } return false; } else { return false; } } }