UserAddressCriteria.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 UserAddressCriteria 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('user_id')) {
  27. $val = $this->request->get('user_id');
  28. $model = $model->where('user_id', '=', $val);
  29. }
  30. if ($this->request->filled('user_mobile')) {
  31. $val = $this->request->get('user_mobile');
  32. $ids = User::byMobileGetIds($val);
  33. $model = $model->whereIn('user_id', $ids);
  34. }
  35. if ($this->request->filled('user_nickname')) {
  36. $val = $this->request->get('user_nickname');
  37. $model = $model->whereHas('user', function ($query) use ($val) {
  38. return $query->where('nickname', 'like', "%{$val}%");
  39. });
  40. }
  41. if ($this->request->filled('name')) {
  42. $val = $this->request->get('name');
  43. $model = $model->where('name', 'like', "%{$val}%");
  44. }
  45. if ($this->request->filled('name')) {
  46. $val = $this->request->get('name');
  47. $model = $model->where('name', 'like', "%{$val}%");
  48. }
  49. if ($this->request->filled('province')) {
  50. $val = $this->request->get('province');
  51. $model = $model->where('province', 'like', "%{$val}%");
  52. }
  53. if ($this->request->filled('city')) {
  54. $val = $this->request->get('city');
  55. $model = $model->where('city', 'like', "%{$val}%");
  56. }
  57. if ($this->request->filled('area')) {
  58. $val = $this->request->get('area');
  59. $model = $model->where('area', 'like', "%{$val}%");
  60. }
  61. if ($this->request->filled('address')) {
  62. $val = $this->request->get('address');
  63. $model = $model->where('address', 'like', "%{$val}%");
  64. }
  65. if ($this->request->filled('status')) {
  66. $status = $this->request->get('status');
  67. $model = $model->where('status', '=', $status);
  68. }
  69. if ($this->request->filled('ids')) {
  70. $ids = $this->request->get('ids');
  71. $model = $model->whereIn('id', $ids);
  72. }
  73. if (!$this->request->filled('orderBy')) {
  74. $model = $model->orderByDesc('id');
  75. }
  76. if (!isAdminModule()) {
  77. $model = $model->where('user_id', login_user_id());
  78. } else {
  79. if (Menu::checkUserIsBtn(151)) {
  80. //全部数据
  81. } elseif (Menu::checkUserIsBtn(150)) {
  82. $admin = login_admin();
  83. $model = $model->whereHas('user', function ($q) use ($admin) {
  84. return $q->where('kefu_tag', $admin['user_tag']);
  85. });
  86. } else {
  87. $model = $model->where('id', 0);
  88. }
  89. }
  90. return $model;
  91. }
  92. }