UserJifenCriteria.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\Repositories\Criteria\Dwbs;
  3. use App\Repositories\Models\Base\Menu;
  4. use App\Repositories\Models\Base\User;
  5. use Illuminate\Http\Request;
  6. use Prettus\Repository\Contracts\CriteriaInterface;
  7. use Prettus\Repository\Contracts\RepositoryInterface;
  8. class UserJifenCriteria implements CriteriaInterface
  9. {
  10. /**
  11. * @var \Illuminate\Http\Request
  12. */
  13. protected $request;
  14. public function __construct(Request $request)
  15. {
  16. $this->request = $request;
  17. }
  18. /**
  19. * @param $model
  20. * @param RepositoryInterface $repository
  21. *
  22. * @return mixed
  23. */
  24. public function apply($model, RepositoryInterface $repository)
  25. {
  26. if ($this->request->filled('type')) {
  27. $val = $this->request->get('type');
  28. $model = $model->where('type', '=', $val);
  29. }
  30. if ($this->request->filled('day')) {
  31. $val = $this->request->get('day');
  32. if (is_string($val)) $model = $model->where('day', '=', $val);
  33. if (is_array($val)) {
  34. $model = $model->where('day', '>=', $val[0])->where('day', '<=', $val[1]);
  35. }
  36. }
  37. if ($this->request->filled('reward_type')) {
  38. $val = $this->request->get('reward_type');
  39. $model = $model->where('reward_type', '=', $val);
  40. }
  41. if ($this->request->filled('is_reward')) {
  42. $val = $this->request->get('is_reward');
  43. $model = $model->where('is_reward', '=', $val);
  44. }
  45. if ($this->request->filled('user_id')) {
  46. $val = $this->request->get('user_id');
  47. $model = $model->where('user_id', '=', $val);
  48. }
  49. if ($this->request->filled('user_mobile')) {
  50. $val = $this->request->get('user_mobile');
  51. $ids = User::byMobileGetIds($val);
  52. $model = $model->whereIn('user_id', $ids);
  53. }
  54. if ($this->request->filled('user_nickname')) {
  55. $val = $this->request->get('user_nickname');
  56. $model = $model->whereHas('user', function ($query) use ($val) {
  57. return $query->where('nickname', 'like', "%{$val}%");
  58. });
  59. }
  60. if ($this->request->filled('reward_explain')) {
  61. $val = $this->request->get('reward_explain');
  62. $model = $model->where('reward_explain', 'like', "%{$val}%");
  63. }
  64. if ($this->request->filled('source_type')) {
  65. $val = $this->request->get('source_type');
  66. $model = $model->where('source_type', $val);
  67. }
  68. if ($this->request->filled('status')) {
  69. $status = $this->request->get('status');
  70. $model = $model->where('status', '=', $status);
  71. }
  72. if ($this->request->filled('created_at')) {
  73. $val = $this->request->get('created_at');
  74. if (is_string($val)) $model = $model->where('created_at', '=', $val);
  75. if (is_array($val)) {
  76. $model = $model->where('created_at', '>=', $val[0])->where('created_at', '<=', $val[1]);
  77. }
  78. }
  79. if ($this->request->filled('ids')) {
  80. $ids = $this->request->get('ids');
  81. $model = $model->whereIn('id', $ids);
  82. }
  83. if (!$this->request->filled('orderBy')) {
  84. $model = $model->orderByDesc('id');
  85. }
  86. if (!isAdminModule()) {
  87. $model = $model->where('user_id', login_user_id());
  88. } else {
  89. if (Menu::checkUserIsBtn(151)) {
  90. //全部数据
  91. } elseif (Menu::checkUserIsBtn(150)) {
  92. $admin = login_admin();
  93. $model = $model->whereHas('user', function ($q) use ($admin) {
  94. return $q->where('kefu_tag', $admin['user_tag']);
  95. });
  96. } else {
  97. $model = $model->where('id', 0);
  98. }
  99. }
  100. return $model;
  101. }
  102. }