示例#1
0
 public function createConversation($sender_id, $data)
 {
     try {
         $receiver_id = $data['receiver_id'];
         $content = $data['message'];
         $conversation = new Conversation();
         $conversation->sender_id = $sender_id;
         $conversation->receiver_id = $receiver_id;
         $conversation->parent_conversation_id = $data['parent_conversation_id'] > 0 ? $data['parent_conversation_id'] : 0;
         $conversation->message = $content;
         if ($conversation->save()) {
             $sender = $this->user_service->getUserById($sender_id);
             $receiver = $this->user_service->getUserById($receiver_id);
             $send_from = $this->user_service->userHasCompany($sender_id) ? $sender['company']['name'] : $sender['first_name'] . ' ' . $sender['last_name'];
             $send_to = $this->user_service->userHasCompany($receiver_id) ? $receiver['company']['name'] : $receiver['first_name'] . ' ' . $receiver['last_name'];
             $email = $receiver['email'];
             $data = ['name' => $send_to, 'from' => $send_from, 'content' => $content, 'account_type' => $this->user_service->userHasCompany($sender_id) ? 'user' : 'company'];
             Mail::queue('worklemon.email.messages', $data, function ($message) use($email, $send_from, $send_to) {
                 $message->to($email, $send_to);
                 $message->subject('Message from ' . $send_from);
                 $message->priority(1);
             });
             return $conversation->toArray();
         }
         return [];
     } catch (Exception $e) {
         return Response::json(['error' => $e->getMessage()]);
     }
 }
示例#2
0
 public function applyCompanyJob($user_id, $data)
 {
     try {
         $job_id = $data['job_id'];
         $apply = new CompanyApplyJob();
         $apply->job_id = $job_id;
         $apply->user_id = $user_id;
         $apply->status = 0;
         if ($apply->save()) {
             $receiver_id = $data['receiver_id'];
             $content = $data['message'];
             $conversation = new Conversation();
             $conversation->sender_id = $user_id;
             $conversation->receiver_id = $receiver_id;
             $conversation->message = $content;
             $conversation->parent_conversation_id = 0;
             $conversation->application_id = $apply->id;
             if ($conversation->save()) {
                 $sender = $this->user_service->getUserById($user_id);
                 $receiver = $this->user_service->getUserById($receiver_id);
                 $user_name = $sender['first_name'] . ' ' . $sender['last_name'];
                 $company_name = $receiver['company']['name'];
                 $job_post = $this->getJobPostById($job_id)['title'];
                 $email = $receiver['email'];
                 $data = ['company' => $company_name, 'applicant' => $user_name, 'job_post' => $job_post, 'content' => $content];
                 Mail::queue('worklemon.email.company.applicant', $data, function ($message) use($email, $company_name, $user_name, $job_post) {
                     $message->to($email, $company_name);
                     $message->subject('Job Application from ' . $user_name . ' for job post ' . $job_post);
                     $message->priority(1);
                 });
                 return true;
             }
         }
         return false;
     } catch (Exception $e) {
         return Response::json(['error' => $e->getMessage()]);
     }
 }