SpecialistCloumnFacadeRepository.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /**
  7. *
  8. * @author lilin
  9. *
  10. */
  11. class SpecialistCloumnFacadeRepository extends BaseRepository implements SpecialistCloumnInterface
  12. {
  13. public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
  14. {
  15. $result = SpecialistCloumn::with(['tags'])->where(function($query) use($conditions){
  16. if (isset($conditions['pid'])){
  17. $query->where('pid', $conditions['pid']);
  18. }
  19. if (isset($conditions['is_show'])){
  20. $query->where('is_show', $conditions['is_show']);
  21. }
  22. })->orderByRaw($sort)->paginate($limit, $fields);
  23. return $this->response($result);
  24. }
  25. public function findBy(array $conditions, array $fields){
  26. $result = SpecialistCloumn::where(function($query) use($conditions){
  27. if (isset($conditions['id'])){
  28. $query->where('id', $conditions['id']);
  29. }
  30. })->first($fields);
  31. if ($result->banner){
  32. $newBanner = [];
  33. foreach ($result->banner as $banner){
  34. $newBanner[] = [
  35. 'pic' => config('console.pic_path').$banner['src'],
  36. 'url' => $banner['url']
  37. ];
  38. }
  39. $result->banner = $newBanner;
  40. }
  41. return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
  42. }
  43. public function create(array $data)
  44. {
  45. $result = SpecialistCloumn::create($data);
  46. return $result ? $this->response($result) : $this->error()->fail();
  47. }
  48. public function updateBy(array $conditions, array $data)
  49. {
  50. $result = SpecialistCloumn::where(function($query) use($conditions){
  51. if (isset($conditions['id'])){
  52. $query->where('id', $conditions['id']);
  53. }
  54. })->update($data);
  55. return $result ? $this->response($result) : $this->error()->fail();
  56. }
  57. public function deleteBy(array $conditions)
  58. {
  59. $result = SpecialistCloumn::where(function($query) use($conditions){
  60. if (isset($conditions['id'])){
  61. $query->where('id', $conditions['id']);
  62. }
  63. })->delete();
  64. return $result ? $this->response($result) : $this->error()->fail();
  65. }
  66. }