Exemplo n.º 1
0
 public function toFocus(Request $request)
 {
     if (Auth::check()) {
         $from_id = $request->user()->id;
         //关注者
         $all = $request->all();
         $to_id = $this->project->getUserId($all['item_id'])->user_id;
         $user = new User();
         $userInfo = $user->getEmail($to_id);
         switch ($all['type']) {
             case 1:
                 if ($from_id == $to_id) {
                     return $this->_returnMessage('不能关注自己的项目', 102);
                 }
                 $focus = new User_relation();
                 $focus_result = $focus->getFocus($from_id, $all['item_id'], 1);
                 if (empty($focus_result)) {
                     $insert = $focus->insertFocus($from_id, $to_id, $all['item_id'], 1);
                     if ($insert != 1) {
                         return $this->_returnMessage('插入失败', 101);
                     } else {
                         $update = $this->project->updateFocus($all['item_id']);
                         if ($update != 1) {
                             return $this->_returnMessage('更新失败', 101);
                         }
                         $mes = new Message();
                         $mes->insertMes($from_id, $to_id, $all['item_id'], 1, 1);
                         $data = ['email' => $userInfo->email, 'name' => $userInfo->name];
                         Mail::send('activemail', $data, function ($message) use($data) {
                             $message->to($data['email'], $data['name'])->subject('【拾】有人关注你的项目~,请登录网站进行查看哦!~');
                         });
                         return $this->_returnMessage('关注成功', 200);
                     }
                 } else {
                     return $this->_returnMessage('已关注过', 102);
                 }
                 break;
             case 2:
                 $like = new Like_relations();
                 $like_result = $like->getLike($from_id, $all['item_id'], 1);
                 if (empty($like_result)) {
                     //插入关注记录
                     $insert = $like->insertLike($from_id, $to_id, $all['item_id'], 1);
                     if ($insert != 1) {
                         return $this->_returnMessage('插入失败', 101);
                     } else {
                         $update = $this->project->updateLike($all['item_id']);
                         if ($update != 1) {
                             return $this->_returnMessage('更新失败', 101);
                         }
                         //                            $mes = new Message();
                         //                            $mes->insertMes($from_id,$to_id,$all['item_id'],2,1);
                         return $this->_returnMessage('点赞成功', 201);
                     }
                 } else {
                     return $this->_returnMessage('已赞', 102);
                 }
                 break;
             case 3:
                 if ($from_id == $to_id) {
                     return $this->_returnMessage('不能向自己的项目发送感兴趣', 102);
                 }
                 $interest = new Interest_relations();
                 $interest_result = $interest->getInterest($from_id, $all['item_id'], 1);
                 if (empty($interest_result)) {
                     $insert = $interest->insertInterest($from_id, $to_id, $all['item_id'], 1);
                     if ($insert != 1) {
                         return $this->_returnMessage('插入失败', 101);
                     } else {
                         $update = $this->project->updateInterest($all['item_id']);
                         if ($update != 1) {
                             return $this->_returnMessage('更新失败', 101);
                         }
                         $mes = new Message();
                         $mes->insertMes($from_id, $to_id, $all['item_id'], 3, 1);
                         $data = ['email' => $userInfo->email, 'name' => $userInfo->name];
                         Mail::send('activemail', $data, function ($message) use($data) {
                             $message->to($data['email'], $data['name'])->subject('【拾】有人对你的项目感兴趣~,请登录网站进行查看哦!~');
                         });
                         return $this->_returnMessage('感兴趣成功', 202);
                     }
                 } else {
                     return $this->_returnMessage('已感兴趣', 102);
                 }
             default:
                 return $this->_returnMessage('参数错误', 101);
                 break;
         }
     } else {
         return redirect()->guest('login');
     }
 }