LaborCompanyDispatchFilters.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Filters;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Carbon;
  5. class LaborCompanyDispatchFilters
  6. {
  7. protected $request;
  8. protected $queryBuilder;
  9. protected $filters = [
  10. 'dispatch_date_start',//起始时间
  11. 'dispatch_date_end',//截止时间
  12. 'labor_company',//劳务公司
  13. 'warehouse',//仓库
  14. 'status',//状态
  15. ];
  16. protected $orderIssueQuery;
  17. public function __construct(Request $request)
  18. {
  19. $this->request = $request;
  20. }
  21. public function apply($builder)
  22. {
  23. $this->queryBuilder = $builder;
  24. $filters = array_filter($this->request->only($this->filters), function ($item) {
  25. return $item !== null;
  26. });
  27. foreach ($filters as $filter => $value) {
  28. if (method_exists($this, $filter)) {
  29. $this->$filter($value, $this->queryBuilder);
  30. }
  31. }
  32. return $this->queryBuilder;
  33. }
  34. public function dispatch_date_start($dispatch_date_start)
  35. {
  36. $this->queryBuilder->whereDate('dispatch_date', '>=', $dispatch_date_start);
  37. }
  38. public function dispatch_date_end($dispatch_date_end)
  39. {
  40. $this->queryBuilder->whereDate('dispatch_date', '<=', $dispatch_date_end);
  41. }
  42. public function warehouse($warehouse)
  43. {
  44. $warehouse = array_filter(preg_split('/[,, ]+/is', $warehouse), function ($item) {
  45. return $item !== null;
  46. });
  47. $this->queryBuilder->whereIn('warehouse_id', $warehouse);
  48. }
  49. public function labor_company($labor_company)
  50. {
  51. $labor_company = array_filter(preg_split('/[,, ]+/is', $labor_company), function ($item) {
  52. return $item !== null;
  53. });
  54. $this->queryBuilder->whereIn('labor_company_id', $labor_company);
  55. }
  56. public function status($status)
  57. {
  58. $status = array_filter(preg_split('/[,, ]+/is', $status), function ($item) {
  59. return $item !== null;
  60. });
  61. $this->queryBuilder->whereIn('status', $status);
  62. }
  63. }