RecuperateRepository.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Recuperate;
  4. use Prettus\Repository\Eloquent\BaseRepository;
  5. class RecuperateRepository extends BaseRepository
  6. {
  7. /**
  8. * Specify Model class name
  9. *
  10. * @return string
  11. */
  12. public function model()
  13. {
  14. return Recuperate::class;
  15. }
  16. /**
  17. * @param $where array
  18. * @return null|\Illuminate\Database\Eloquent\Model
  19. */
  20. public function getRecuperate($where, $page)
  21. {
  22. $res = $this->model->where($where)->orderByRaw('list_order desc,created_at desc');
  23. if ($page) {
  24. return $res->paginate($page);
  25. } else {
  26. return $res->get();
  27. }
  28. }
  29. /**
  30. * @param $where array
  31. * @return null|\Illuminate\Database\Eloquent\Model
  32. */
  33. public function getAllRecuperate($where, $orWhere, $page)
  34. {
  35. $res = $this->model->where(function ($query) use ($where, $orWhere) {
  36. $query->where($where)->orwhere($orWhere);
  37. })->orderByRaw('list_order desc,created_at desc');
  38. if ($page) {
  39. return $res->paginate($page);
  40. } else {
  41. return $res->get();
  42. }
  43. }
  44. public function firstWhere($where)
  45. {
  46. return $this->model->where($where)->first();
  47. }
  48. public function incrementData($where, $num, $filed)
  49. {
  50. return $this->model->where($where)->increment($filed, $num);
  51. }
  52. public function filterRecuperate($where = array(), $whereIn = array(), $order = array())
  53. {
  54. $rst = $this->model->where($where);
  55. if ($whereIn) {
  56. foreach ($whereIn as $k => $v) {
  57. $rst->whereIn($k, $v);
  58. }
  59. }
  60. if ($order) {
  61. if (is_array($order)) {
  62. foreach ($order as $k => $v) {
  63. $rst->orderBy($k, $v);
  64. }
  65. } else {
  66. $rst->orderbyRaw($order);
  67. }
  68. }
  69. return $rst->get();
  70. }
  71. }