error('auth.failed',401,401); } //判断我的角色 $my = CourseMember::where('user_id',$user["user_uid"]) ->where('is_current',true) ->where('course_id',$request->get('course_id')) ->first(); if(!$my){ return $this->error('auth.failed',403,403); } //获取全部成员列表 $allMembers = CourseMember::where('is_current',true) ->where('course_id',$request->get('course_id')) ->select('user_id') ->get(); //获取答案channel $answerChannel = Course::where('id',$request->get('course_id')) ->value('channel_id'); $exerciseChannels = CourseMember::where('is_current',true) ->where('course_id',$request->get('course_id')) ->select('channel_id') ->get(); $channels = array(); if($answerChannel){ array_push($channels,$answerChannel); } $users = array(); if($my->role === 'student'){ //自己的channel + 答案 if($my->channel_id){ array_push($channels,$my->channel_id); } }else{ //找到全部学员channel + 答案 foreach ($exerciseChannels as $key => $value) { array_push($channels,$value->channel_id); } } //获取全部学员对应的资源列表 $querySentId = $request->get('sentences'); $resId = array(); //译文 $sentUid = Sentence::whereIns(['book_id','paragraph','word_start','word_end'],$querySentId) ->whereIn('channel_uid',$channels) ->select('uid')->get(); foreach ($sentUid as $key => $value) { $resId[] = $value->uid; } //wbw $wbwBlockParagraphs = []; foreach ($querySentId as $key => $value) { $wbwBlockParagraphs[] = [$value[0],$value[1]]; } $wbwBlock = WbwBlock::whereIn('channel_uid',$channels) ->whereIns(['book_id','paragraph'],$wbwBlockParagraphs) ->select('uid') ->get(); if($wbwBlock){ //找到逐词解析数据 foreach ($querySentId as $key => $value) { $wbwData = Wbw::whereIn('block_uid',$wbwBlock) ->whereBetween('wid',[$value[2],$value[3]]) ->select('uid') ->get(); foreach ($wbwData as $key => $value) { $resId[] = $value->uid; } } } Log::debug('res id',['res'=>$resId,'members'=>$allMembers]); //全部资源id获取完毕 $allDiscussions = Discussion::where('status','active') ->whereNull('parent') ->whereIn('res_id',$resId) ->whereIn('editor_uid',$allMembers) ->select(['id','res_id','type','editor_uid']) ->get(); $result = DiscussionCountResource::collection($allDiscussions); Log::debug('response',['data'=>$result]); return $this->ok($result); } /** * Display the specified resource. * * @param \App\Models\Discussion $discussion * @return \Illuminate\Http\Response */ public function show(Discussion $discussion) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Discussion $discussion * @return \Illuminate\Http\Response */ public function update(Request $request, Discussion $discussion) { // } /** * Remove the specified resource from storage. * * @param \App\Models\Discussion $discussion * @return \Illuminate\Http\Response */ public function destroy(Discussion $discussion) { // } }