MentalityDrillCategoryFacadeRepository.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\Repositories\Eloquent;
  3. use App\Repositories\Eloquent\BaseRepository;
  4. use App\Repositories\Contracts\MentalityDrillCategoryInterface;
  5. use App\Models\MentalityDrillCategory;
  6. use Illuminate\Database\Query\Builder;
  7. /**
  8. *
  9. * @author lilin
  10. *
  11. */
  12. class MentalityDrillCategoryFacadeRepository extends BaseRepository implements MentalityDrillCategoryInterface
  13. {
  14. public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
  15. {
  16. $result = MentalityDrillCategory::where(function( $query) use($conditions){
  17. if (isset($conditions['id'])){
  18. $query->where('id', $conditions['id']);
  19. }
  20. if (isset($conditions['name'])){
  21. $query->where('name', 'like' , '%'.$conditions['name'].'%');
  22. }
  23. if (isset($conditions["isSubject"])){
  24. $query->where('is_subject', "=",0);
  25. }
  26. if (isset($conditions["is_enable"])){
  27. $query->where('is_enable', $conditions["is_enable"]);
  28. }
  29. })->orderByRaw($sort)->paginate($limit, $fields);
  30. return $this->response($result);
  31. }
  32. public function findBy(array $conditions, array $fields){
  33. $result = MentalityDrillCategory::with(['mentalityDrill'=>function($with){
  34. $with->select(['id','pic','name']);
  35. }])->where(function($query) use($conditions){
  36. if (isset($conditions['id'])){
  37. $query->where('id', $conditions['id']);
  38. }
  39. })->first($fields);
  40. return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
  41. }
  42. public function create(array $data)
  43. {
  44. $result = MentalityDrillCategory::create($data);
  45. return $result ? $this->response($result) : $this->error()->fail();
  46. }
  47. public function updateBy(array $conditions, array $data)
  48. {
  49. $result = MentalityDrillCategory::where(function($query) use($conditions){
  50. if (isset($conditions['id'])){
  51. $query->where('id', $conditions['id']);
  52. }
  53. })->update($data);
  54. return $result ? $this->response($result) : $this->error()->fail();
  55. }
  56. public function deleteBy(array $conditions)
  57. {
  58. $result = MentalityDrillCategory::where(function($query) use($conditions){
  59. if (isset($conditions['id'])){
  60. $query->where('id', $conditions['id']);
  61. }
  62. })->delete();
  63. return $result ? $this->response($result) : $this->error()->fail();
  64. }
  65. }