where(function($query) use($conditions){ if (isset($conditions['pid'])){ $query->where('pid', $conditions['pid']); } if (isset($conditions['is_show'])){ $query->where('is_show', $conditions['is_show']); } })->orderByRaw($sort)->paginate($limit, $fields); return $this->response($result); } public function findBy(array $conditions, array $fields){ $result = SpecialistCloumn::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } })->first($fields); if ($result->banner){ $newBanner = []; foreach ($result->banner as $banner){ $newBanner[] = [ 'pic' => config('console.pic_path').$banner['src'], 'url' => $banner['url'] ]; } $result->banner = $newBanner; } return $result ? $this->response($result) : $this->error()->dataDoesNotExist(); } public function create(array $data) { $result = SpecialistCloumn::create($data); return $result ? $this->response($result) : $this->error()->fail(); } public function updateBy(array $conditions, array $data) { $result = SpecialistCloumn::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } })->update($data); return $result ? $this->response($result) : $this->error()->fail(); } public function deleteBy(array $conditions) { $result = SpecialistCloumn::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } })->delete(); return $result ? $this->response($result) : $this->error()->fail(); } public function getChapterList(array $conditions, array $fields, string $sort, int $page, int $limit) { $result = SpecialistCloumn::with(['tags'])->where(function($query) use($conditions){ if (isset($conditions['pid'])){ // $query->where('pid', $conditions['pid']); } if (isset($conditions['is_show'])){ $query->where('is_show', $conditions['is_show']); } $query->where('pid', 0); })->orderByRaw($sort)->paginate($limit, $fields,"",$page); // $result->each(function($item) use ($conditions){ // $sort = 's.rank desc, s.id asc'; // $item->infoList = DB::table("specialist_infos as s")->selectRaw("s.*,!ISNULL(b.id) as isStudy") // ->leftJoin("browse_records as b",function($join) use ($conditions){ // $join->on('s.id','=','b.object_id') // ->where('b.column','=',3); // })->where("s.deleted_at","=",null) // // ->where("s.release","=",1) // ->where("s.second_id","=",$item->id) // ->orderByRaw($sort) // ->get(); // $item->infoListcount = count($item->infoList); // }); return $this->response($result); } }