| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Filters;
- use App\OrderIssue;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Http\Request;
- use Illuminate\Support\Carbon;
- class LaborApplyFilters
- {
- protected $request;
- /** @var $queryBuilder Builder */
- protected $queryBuilder;
- protected $filters = [
- 'created_at_start',//创建起始时间
- 'created_at_end',//创建截止时间
- 'apply_user',//申请人
- 'warehouse',//仓库
- 'status',//状态
- 'remark',//用工要求
- 'user_work_group',//仓库小组
- ];
- protected $orderIssueQuery;
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
- public function apply($builder)
- {
- $this->queryBuilder = $builder;
- $filters = array_filter($this->request->only($this->filters), function ($item) {
- return $item !== null;
- });
- foreach ($filters as $filter => $value) {
- if (method_exists($this, $filter)) {
- $this->$filter($value, $this->queryBuilder);
- }
- }
- return $this->queryBuilder;
- }
- public function created_at_start($created_at_start)
- {
- $this->queryBuilder->whereDate('created_at', '>=', $created_at_start);
- }
- public function created_at_end($created_at_end)
- {
- $this->queryBuilder->whereDate('created_at', '<=', $created_at_end);
- }
- //user_work_group
- public function apply_user($apply_user)
- {
- $user_ids = \App\User::query()
- ->select('id')
- ->where('name', 'like', $apply_user . '%')
- ->pluck('id');
- $this->queryBuilder->whereIn('apply_user_id', $user_ids);
- }
- public function warehouse($warehouse)
- {
- $warehouse = array_filter(preg_split('/[,, ]+/is', $warehouse), function ($item) {
- return $item !== null;
- });
- $this->queryBuilder->whereIn('warehouse_id', $warehouse);
- }
- public function status($status)
- {
- $status = array_filter(preg_split('/[,, ]+/is', $status), function ($item) {
- return $item !== null;
- });
- $this->queryBuilder->whereIn('status', $status);
- }
- public function remark($remark)
- {
- $this->queryBuilder->where('remark', 'like', $remark . '%');
- }
- public function user_work_group($user_work_group)
- {
- $user_work_group = array_filter(preg_split('/[,, ]+/is', $user_work_group), function ($item) {
- return $item !== null;
- });
- $this->queryBuilder->whereIn('user_workgroup_id', $user_work_group);
- }
- }
|