ScaleCategoryFacadeRepository.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Repositories\Eloquent;
  3. use App\Models\ScaleCategory;
  4. use App\Repositories\Contracts\ScaleCategoryInterface;
  5. /**
  6. * 量表分类
  7. * @author lilin
  8. *
  9. */
  10. class ScaleCategoryFacadeRepository extends BaseRepository implements ScaleCategoryInterface
  11. {
  12. public function getList(array $conditions, array $fields, string $sort, int $page, int $limit)
  13. {
  14. $result = ScaleCategory::where(function($query) use($conditions){
  15. if (isset($conditions['uid'])){
  16. $query->where('uid', $conditions['uid']);
  17. }
  18. })->orderByRaw($sort)->paginate($limit, $fields);
  19. return $this->response($result);
  20. }
  21. public function findBy(array $conditions, array $fields){
  22. $result = ScaleCategory::where(function($query) use($conditions){
  23. if (isset($conditions['id'])){
  24. $query->where('id', $conditions['id']);
  25. }
  26. if (isset($conditions['uid'])){
  27. $query->where('uid', $conditions['uid']);
  28. }
  29. })->first($fields);
  30. return $result ? $this->response($result) : $this->error()->dataDoesNotExist();
  31. }
  32. public function create(array $data)
  33. {
  34. $result = ScaleCategory::create($data);
  35. return $result ? $this->response($result) : $this->error()->fail();
  36. }
  37. public function updateBy(array $conditions, array $data)
  38. {
  39. $result = ScaleCategory::where(function($query) use($conditions){
  40. if (isset($conditions['id'])){
  41. $query->where('id', $conditions['id']);
  42. }
  43. if (isset($conditions['uid'])){
  44. $query->where('uid', $conditions['uid']);
  45. }
  46. })->update($data);
  47. return $result ? $this->response($result) : $this->error()->fail();
  48. }
  49. public function deleteBy(array $conditions)
  50. {
  51. $result = ScaleCategory::where(function($query) use($conditions){
  52. if (isset($conditions['id'])){
  53. $query->where('id', $conditions['id']);
  54. }
  55. if (isset($conditions['uid'])){
  56. $query->where('uid', $conditions['uid']);
  57. }
  58. })->delete();
  59. return $result ? $this->response($result) : $this->error()->fail();
  60. }
  61. }