SpecialistCloumnFacadeRepository.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\Repositories\Eloquent;
  3. use App\Repositories\Eloquent\BaseRepository;
  4. use App\Models\SpecialistCloumn;
  5. use App\Repositories\Contracts\SpecialistCloumnInterface;
  6. use Illuminate\Support\Facades\DB;
  7. /**
  8. *
  9. * @author lilin
  10. *
  11. */
  12. class SpecialistCloumnFacadeRepository extends BaseRepository implements SpecialistCloumnInterface
  13. {
  14. public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
  15. {
  16. $result = SpecialistCloumn::with(['tags'])->where(function($query) use($conditions){
  17. if (isset($conditions['pid'])){
  18. $query->where('pid', $conditions['pid']);
  19. }
  20. if (isset($conditions['is_show'])){
  21. $query->where('is_show', $conditions['is_show']);
  22. }
  23. })->orderByRaw($sort)->paginate($limit, $fields);
  24. return $this->response($result);
  25. }
  26. public function findBy(array $conditions, array $fields){
  27. $result = SpecialistCloumn::where(function($query) use($conditions){
  28. if (isset($conditions['id'])){
  29. $query->where('id', $conditions['id']);
  30. }
  31. })->first($fields);
  32. if ($result->banner){
  33. $newBanner = [];
  34. foreach ($result->banner as $banner){
  35. $newBanner[] = [
  36. 'pic' => config('console.pic_path').$banner['src'],
  37. 'url' => $banner['url']
  38. ];
  39. }
  40. $result->banner = $newBanner;
  41. }
  42. return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
  43. }
  44. public function create(array $data)
  45. {
  46. $result = SpecialistCloumn::create($data);
  47. return $result ? $this->response($result) : $this->error()->fail();
  48. }
  49. public function updateBy(array $conditions, array $data)
  50. {
  51. $result = SpecialistCloumn::where(function($query) use($conditions){
  52. if (isset($conditions['id'])){
  53. $query->where('id', $conditions['id']);
  54. }
  55. })->update($data);
  56. return $result ? $this->response($result) : $this->error()->fail();
  57. }
  58. public function deleteBy(array $conditions)
  59. {
  60. $result = SpecialistCloumn::where(function($query) use($conditions){
  61. if (isset($conditions['id'])){
  62. $query->where('id', $conditions['id']);
  63. }
  64. })->delete();
  65. return $result ? $this->response($result) : $this->error()->fail();
  66. }
  67. public function getChapterList(array $conditions, array $fields, string $sort, int $page, int $limit)
  68. {
  69. $result = SpecialistCloumn::with(['tags'])->where(function($query) use($conditions){
  70. if (isset($conditions['pid'])){
  71. // $query->where('pid', $conditions['pid']);
  72. }
  73. if (isset($conditions['is_show'])){
  74. $query->where('is_show', $conditions['is_show']);
  75. }
  76. $query->where('pid', 0);
  77. })->orderByRaw($sort)->paginate($limit, $fields,"",$page);
  78. // $result->each(function($item) use ($conditions){
  79. // $sort = 's.rank desc, s.id asc';
  80. // $item->infoList = DB::table("specialist_infos as s")->selectRaw("s.*,!ISNULL(b.id) as isStudy")
  81. // ->leftJoin("browse_records as b",function($join) use ($conditions){
  82. // $join->on('s.id','=','b.object_id')
  83. // ->where('b.column','=',3);
  84. // })->where("s.deleted_at","=",null)
  85. // // ->where("s.release","=",1)
  86. // ->where("s.second_id","=",$item->id)
  87. // ->orderByRaw($sort)
  88. // ->get();
  89. // $item->infoListcount = count($item->infoList);
  90. // });
  91. return $this->response($result);
  92. }
  93. }