RecuperateApplyRepository.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\RecuperateApply;
  4. use Prettus\Repository\Eloquent\BaseRepository;
  5. class RecuperateApplyRepository extends BaseRepository
  6. {
  7. /**
  8. * Specify Model class name
  9. *
  10. * @return string
  11. */
  12. public function model()
  13. {
  14. return RecuperateApply::class;
  15. }
  16. /**
  17. * @param $where array
  18. * @param $page mixed
  19. * @param $with array
  20. * @return null|\Illuminate\Database\Eloquent\Model
  21. */
  22. public function getRecuperate($where, $page, $with)
  23. {
  24. $res = $this->model->with($with)->where($where)->orderByRaw('created_at desc');
  25. if ($page) {
  26. return $res->paginate($page);
  27. } else {
  28. return $res->get();
  29. }
  30. }
  31. /**
  32. * @param $where array
  33. * @return null|\Illuminate\Database\Eloquent\Model
  34. */
  35. public function getAllRecuperate($where, $orWhere, $page, $with)
  36. {
  37. $res = $this->model->with($with)->where(function ($query) use ($where, $orWhere) {
  38. $query->where($where)->orwhere($orWhere);
  39. })->orderByRaw('created_at desc');
  40. if ($page) {
  41. return $res->paginate($page);
  42. } else {
  43. return $res->get();
  44. }
  45. }
  46. public function firstWhere($where)
  47. {
  48. return $this->model->where($where)->first();
  49. }
  50. public function incrementData($where, $num, $filed)
  51. {
  52. return $this->model->where($where)->increment($filed, $num);
  53. }
  54. public function filterRecuperate($where = [], $whereIn = [], $order = [])
  55. {
  56. $rst = $this->model->where($where);
  57. if ($whereIn) {
  58. foreach ($whereIn as $k => $v) {
  59. $rst->whereIn($k, $v);
  60. }
  61. }
  62. if ($order) {
  63. if (is_array($order)) {
  64. foreach ($order as $k => $v) {
  65. $rst->orderBy($k, $v);
  66. }
  67. } else {
  68. $rst->orderbyRaw($order);
  69. }
  70. }
  71. return $rst->get();
  72. }
  73. public function createApply($attr)
  74. {
  75. $this->model->user_name = $attr['user_name'] ?? '';
  76. $this->model->user_idcard = $attr['user_idcard'] ?? '';
  77. $this->model->mobile = $attr['mobile'] ?? '';
  78. $this->model->wechat = $attr['wechat'] ?? '';
  79. $this->model->level = $attr['level'] ?? 0;
  80. $this->model->company_name = $attr['company_name'] ?? '';
  81. $this->model->validate_time = $attr['validate_time'] ?? '';
  82. $this->model->salary = $attr['salary'] ?? 2;
  83. $this->model->tax = $attr['tax'] ?? 2;
  84. $this->model->condition = $attr['condition'] ?? 0;
  85. $this->model->uid = $attr['uid'] ?? 0;
  86. $this->model->recuperate_id = $attr['recuperate_id'] ?? 0;
  87. $this->model->price = $attr['price'] ?? 0;
  88. $this->model->recuperate_time_id = $attr['recuperate_time_id'] ?? 0;
  89. $res = $this->model->save();
  90. if ($res) {
  91. return true;
  92. } else {
  93. return false;
  94. }
  95. }
  96. }