| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Filters;
- use Illuminate\Http\Request;
- use Illuminate\Support\Carbon;
- class LaborCompanyDispatchFilters
- {
- protected $request;
- protected $queryBuilder;
- protected $filters = [
- 'dispatch_date_start',//起始时间
- 'dispatch_date_end',//截止时间
- 'labor_company',//劳务公司
- 'warehouse',//仓库
- 'status',//状态
- ];
- 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 dispatch_date_start($dispatch_date_start)
- {
- $this->queryBuilder->whereDate('dispatch_date', '>=', $dispatch_date_start);
- }
- public function dispatch_date_end($dispatch_date_end)
- {
- $this->queryBuilder->whereDate('dispatch_date', '<=', $dispatch_date_end);
- }
- public function warehouse($warehouse)
- {
- $warehouse = array_filter(preg_split('/[,, ]+/is', $warehouse), function ($item) {
- return $item !== null;
- });
- $this->queryBuilder->whereIn('warehouse_id', $warehouse);
- }
- public function labor_company($labor_company)
- {
- $labor_company = array_filter(preg_split('/[,, ]+/is', $labor_company), function ($item) {
- return $item !== null;
- });
- $this->queryBuilder->whereIn('labor_company_id', $labor_company);
- }
- public function status($status)
- {
- $status = array_filter(preg_split('/[,, ]+/is', $status), function ($item) {
- return $item !== null;
- });
- $this->queryBuilder->whereIn('status', $status);
- }
- }
|