ChengjiuCriteria.php 2.8 KB

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