123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\Repositories\Eloquent;
- use App\Repositories\Eloquent\BaseRepository;
- use App\Models\SpecialistCloumn;
- use App\Repositories\Contracts\SpecialistCloumnInterface;
- use Illuminate\Support\Facades\DB;
- /**
- *
- * @author lilin
- *
- */
- class SpecialistCloumnFacadeRepository extends BaseRepository implements SpecialistCloumnInterface
- {
- public function getList(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']);
- }
- })->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);
- }
- }
|