示例#1
0
 public function index($userId = null)
 {
     $auth = auth();
     if (!$userId) {
         $userId = $auth->id();
         $isAuthUser = true;
     } else {
         $isAuthUser = $userId == $auth->id();
     }
     if ($isAuthUser) {
         $user = $auth->user();
     } else {
         $user = User::findOrFail($userId);
     }
     $count['create'] = Project::where('user_id', $userId)->count();
     $count['join'] = Project::join('project_members', function ($join) use($userId) {
         $join->on('projects.id', '=', 'project_members.project_id')->where('project_members.user_id', '=', $userId);
     })->where('projects.user_id', '<>', $userId)->count();
     $count['comment'] = 0;
     $count['collect'] = ProjectFavorite::where('user_id', $userId)->count();
     $showList = 'create';
     foreach ($count as $key => $value) {
         if ($value > 0) {
             $showList = $key;
             break;
         }
     }
     return view('user.home.index', ['userData' => $user, 'isAuthUser' => $isAuthUser, 'projectCount' => $count, 'showList' => $showList]);
 }
示例#2
0
 protected function getCreate($startId, $userId)
 {
     $startId = intval($startId);
     $builder = Project::where('user_id', $userId);
     if ($startId > 0) {
         $builder->where('id', '<', $startId);
     }
     return $builder->orderBy('id', 'desc')->take($this->listTake)->get();
 }
示例#3
0
 protected function getUserProjectCount($userId)
 {
     $count = [];
     $count['create'] = Project::where('user_id', $userId)->count();
     $count['join'] = Project::join('project_members', function ($join) use($userId) {
         $join->on('projects.id', '=', 'project_members.project_id')->where('project_members.user_id', '=', $userId);
     })->where('projects.user_id', '<>', $userId)->count();
     $count['comment'] = 0;
     $count['collect'] = 0;
     return $count;
 }
示例#4
0
 public function postApplyJoin($id)
 {
     $this->projectId = $id = (int) $id;
     if (Project::where('id', $id)->exists()) {
         if ($this->authUserIsProjectMember()) {
             return response()->json(['status' => false, 'message' => '你已经是项目成员,无需重复加入']);
         }
         $userId = auth()->id();
         $join = ProjectMemberJoin::where('user_id', $userId)->where('project_id', $id)->where('status', '0')->first();
         if (!$join) {
             $join = new ProjectMemberJoin();
             $join->user_id = $userId;
             $join->project_id = $id;
             $join->status = 0;
         }
         $join->join_remark = trim(request()->input('join_remark'));
         $join->save();
         return response()->json(['status' => true, 'message' => '你的申请已经提交审核']);
     }
     return response()->json(['status' => false, 'message' => '你要加入的项目不存在']);
 }