VersionFacadeRepository.php 2.3 KB

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