DistributionItemsController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Http\Controllers\DistributionItem;
  3. use App\Http\Controllers\AdminBaseController;
  4. use App\Http\Requests\DistributionItemCreateRequest;
  5. use App\Http\Requests\DistributionItemUpdateRequest;
  6. use App\Repositories\Eloquent\DistributionItemRepositoryEloquent;
  7. use App\Validators\DistributionItemValidator;
  8. /**
  9. * Class DistributionItemsController.
  10. *
  11. * @package namespace App\Http\Controllers;
  12. */
  13. class DistributionItemsController extends AdminBaseController
  14. {
  15. /**
  16. * @var DistributionItemRepositoryEloquent
  17. */
  18. protected $repository;
  19. /**
  20. * @var DistributionItemValidator
  21. */
  22. protected $validator;
  23. /**
  24. * DistributionItemsController constructor.
  25. *
  26. * @param DistributionItemRepositoryEloquent $repository
  27. * @param DistributionItemValidator $validator
  28. */
  29. public function __construct(DistributionItemRepositoryEloquent $repository, DistributionItemValidator $validator)
  30. {
  31. parent::__construct($repository, $validator);
  32. }
  33. /**
  34. * 数据检索
  35. */
  36. public function _indexScopeQuery()
  37. {
  38. $where = [];
  39. $search = explode(";", request()->input('search', ""));
  40. $start = $end = null;
  41. $fieldSearchable=$this->repository->getFieldsSearchable();
  42. foreach ($search as $value) {
  43. if (!empty($value)) {
  44. list($one, $tow) = explode(":", $value);
  45. if (!empty($fieldSearchable[$one])) {
  46. if($fieldSearchable[$one]=='like')$tow="%{$tow}%";
  47. $where[]=[$one,$fieldSearchable[$one],$tow];
  48. } elseif ($one == 'start') {
  49. $start = $tow . " 00:00:00";
  50. } elseif ($one == 'end') {
  51. $end = $tow . " 23:59:59";
  52. } else {
  53. continue;
  54. }
  55. }
  56. }
  57. return function ($query) use ($where, $start, $end) {
  58. if ($start) $where[] = ['created_at', '>=', $start];
  59. if ($end) $where[] = ['created_at', '<=', $end];
  60. if ($where) {
  61. $query->where($where);
  62. }
  63. };
  64. }
  65. /**
  66. * 数据更新
  67. */
  68. protected function _indexPost($datum)
  69. {
  70. return $datum;
  71. }
  72. }