ShopOrderCriteria.php 4.7 KB

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