error('auth.failed', 401, 401); } $studioIdForTag = $user["user_uid"]; if ($request->has('course_id')) { //判断我的角色 $my = CourseMember::where('user_id', $user["user_uid"]) ->where('is_current', true) ->where('course_id', $request->input('course_id')) ->first(); if (!$my) { return $this->error('auth.failed', 403, 403); } //获取全部成员列表 $allMembers = CourseMember::where('is_current', true) ->where('course_id', $request->input('course_id')) ->select('user_id') ->get(); Log::debug('allMembers', ['members' => $allMembers]); //找到全部相关channel $channels = array(); //获取答案 channel $answerChannel = Course::where('id', $request->input('course_id')) ->value('channel_id'); $exerciseChannels = CourseMember::where('is_current', true) ->where('course_id', $request->input('course_id')) ->select('channel_id') ->get(); 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); } //找到 $courseStudioId = Course::where('id', $request->input('course_id')) ->value('studio_id'); if ($courseStudioId) { $studioIdForTag = $courseStudioId; } } } //获取全部资源列表 $resId = array(); $querySentId = $request->input('sentences'); //译文 $table = Sentence::select('uid') ->whereIns(['book_id', 'paragraph', 'word_start', 'word_end'], $querySentId); if (isset($channels)) { $table = $table->whereIn('channel_uid', $channels); } $sentUid = $table->get(); foreach ($sentUid as $key => $value) { $resId[] = $value->uid; } //wbw $wbwBlockParagraphs = []; foreach ($querySentId as $key => $value) { $wbwBlockParagraphs[] = [$value[0], $value[1]]; } $table = WbwBlock::select('uid') ->whereIns(['book_id', 'paragraph'], $wbwBlockParagraphs); if (isset($channels)) { $table = $table->whereIn('channel_uid', $channels); } $wbwBlock = $table->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]); //全部资源id获取完毕 //获取discussion $table = Discussion::select(['id', 'res_id', 'res_type', 'type', 'editor_uid']) ->where('status', 'active') ->whereNull('parent') ->whereIn('res_id', $resId); if (isset($allMembers)) { $table = $table->whereIn('editor_uid', $allMembers); } $allDiscussions = $table->get(); $discussions = DiscussionCountResource::collection($allDiscussions); //获取 tag $tags = TagMap::select(['tag_maps.id', 'anchor_id', 'table_name', 'tag_id', 'editor_uid', 'tags.name', 'tags.color']) ->whereIn('anchor_id', $resId) ->where('owner_uid', $studioIdForTag) ->leftJoin('tags', 'tags.id', '=', 'tag_maps.tag_id') ->get(); Log::debug('response', ['data' => $discussions]); return $this->ok([ 'discussions' => $discussions, 'tags' => $tags, ]); } /** * Display the specified resource. * * @param string $resId * @return \Illuminate\Http\Response */ public function show(string $resId) { // $allDiscussions = Discussion::where('status', 'active') ->whereNull('parent') ->where('res_id', $resId) ->select(['id', 'res_id', 'res_type', 'type', 'editor_uid']) ->get(); $discussions = DiscussionCountResource::collection($allDiscussions); //获取 tag $table = TagMap::select(['id', 'anchor_id', 'table_name', 'tag_id', 'editor_uid']) ->where('anchor_id', $resId); $allTags = $table->get(); $tags = TagMapResource::collection($allTags); Log::debug('response', ['discussions' => $discussions]); return $this->ok([ 'discussions' => $discussions, 'tags' => $tags, ]); } /** * 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) { // } }