UserXuefenCriteria.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 UserXuefenCriteria 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('reward_explain')) {
  27. $val = $this->request->get('reward_explain');
  28. $model = $model->where('reward_explain', 'like', "%{$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('created_at')) {
  38. $val = $this->request->get('created_at');
  39. if (is_string($val)) $model = $model->where('created_at', '=', $val);
  40. if (is_array($val)) {
  41. $model = $model->where('created_at', '>=', $val[0])->where('created_at', '<=', $val[1]);
  42. }
  43. }
  44. if ($this->request->filled('user_id')) {
  45. $val = $this->request->get('user_id');
  46. $model = $model->where('user_id', '=', $val);
  47. }
  48. if ($this->request->filled('user_mobile')) {
  49. $val = $this->request->get('user_mobile');
  50. $ids = User::byMobileGetIds($val);
  51. $model = $model->whereIn('user_id', $ids);
  52. }
  53. if ($this->request->filled('user_nickname')) {
  54. $val = $this->request->get('user_nickname');
  55. $model = $model->whereHas('user', function ($query) use ($val) {
  56. return $query->where('nickname', 'like', "%{$val}%");
  57. });
  58. }
  59. if ($this->request->filled('reward_type')) {
  60. $val = $this->request->get('reward_type');
  61. $model = $model->where('reward_type', '=', $val);
  62. }
  63. if ($this->request->filled('is_reward')) {
  64. $val = $this->request->get('is_reward');
  65. $model = $model->where('is_reward', '=', $val);
  66. }
  67. if ($this->request->filled('status')) {
  68. $status = $this->request->get('status');
  69. $model = $model->where('status', '=', $status);
  70. }
  71. if ($this->request->filled('source_type')) {
  72. $val = $this->request->get('source_type');
  73. $model = $model->where('source_type', $val);
  74. }
  75. if ($this->request->filled('ids')) {
  76. $ids = $this->request->get('ids');
  77. $model = $model->whereIn('id', $ids);
  78. }
  79. if (!$this->request->filled('orderBy')) {
  80. $model = $model->orderByDesc('id');
  81. }
  82. if (!isAdminModule()) {
  83. $model = $model->where('user_id', login_user_id());
  84. } else {
  85. if (Menu::checkUserIsBtn(151)) {
  86. //全部数据
  87. } elseif (Menu::checkUserIsBtn(150)) {
  88. $admin = login_admin();
  89. $model = $model->whereHas('user', function ($q) use ($admin) {
  90. return $q->where('kefu_tag', $admin['user_tag']);
  91. });
  92. } else {
  93. $model = $model->where('id', 0);
  94. }
  95. }
  96. return $model;
  97. }
  98. }