12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Repositories\Criteria;
- use App\Models\Role;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class OrderCriteria extends RequestCriteria implements CriteriaInterface
- {
- /**
- * @var \Illuminate\Http\Request
- */
- protected $request;
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
- /**
- * @inheritDoc
- */
- public function apply($model, RepositoryInterface $repository)
- {
- if ($no = $this->request->get('no', false)) {
- $model = $model->where('no', $no);
- }
- if ($this->request->filled('status')) {
- $model = $model->where('status', $this->request->get('status'));
- }
- if ($this->request->filled('device_id')) {
- $model = $model->where('device_id', $this->request->get('device_id'));
- }
- if ($this->request->filled('shop_id')) {
- $model = $model->where('shop_id', $this->request->get('shop_id'));
- }
- if ($this->request->filled('mobile')) {
- $mobile = $this->request->get('mobile');
- $model = $model->whereHas('user', function ($query) use ($mobile) {
- return $query->where('mobile', 'like', "%{$mobile}%");
- });
- }
- $model = $model->orderBy("id", 'desc');
- //用户
- if (is_user_login()) {
- // if ($this->request->filled('user_id')) {
- // $model = $model->where('user_id', $this->request->get('user_id'));
- // } else {
- $model = $model->where('user_id', login_user_id());
- // }
- }
- //管理员
- if (is_admin_login()) {
- $admin = login_admin();
- switch ($admin->type) {
- case Role::Merchants:
- $model = $model->where('merchant_id', $admin->id);
- break;
- case Role::Admin:
- break;
- case Role::Agency:
- $model = $model->where('agency_id', $admin->id);
- break;
- case Role::Invest:
- $model = $model->where('invest_id', $admin->id);
- break;
- }
- }
- return parent::apply($model, $repository);
- }
- }
|