BannersController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace App\Http\Controllers\Banner;
  3. use App\Http\Controllers\AdminBaseController;
  4. use App\Http\Requests\BannerCreateRequest;
  5. use App\Http\Requests\BannerUpdateRequest;
  6. use App\Models\Goods;
  7. use App\Models\GoodsClass;
  8. use App\Models\Menu;
  9. use App\Repositories\Eloquent\BannerRepositoryEloquent;
  10. use App\Validators\BannerValidator;
  11. /**
  12. * Class BannersController.
  13. *
  14. * @package namespace App\Http\Controllers;
  15. */
  16. class BannersController extends AdminBaseController
  17. {
  18. /**
  19. * @var BannerRepositoryEloquent
  20. */
  21. protected $repository;
  22. /**
  23. * @var BannerValidator
  24. */
  25. protected $validator;
  26. /**
  27. * BannersController constructor.
  28. *
  29. * @param BannerRepositoryEloquent $repository
  30. * @param BannerValidator $validator
  31. */
  32. public function __construct(BannerRepositoryEloquent $repository, BannerValidator $validator)
  33. {
  34. parent::__construct($repository, $validator);
  35. }
  36. /**
  37. * 数据检索
  38. */
  39. public function _indexScopeQuery()
  40. {
  41. $where = [];
  42. $search = explode(";", request()->input('search', ""));
  43. $start = $end = null;
  44. $fieldSearchable = $this->repository->getFieldsSearchable();
  45. foreach ($search as $value) {
  46. if (!empty($value)) {
  47. list($one, $tow) = explode(":", $value);
  48. if (!empty($fieldSearchable[$one])) {
  49. if ($fieldSearchable[$one] == 'like') $tow = "%{$tow}%";
  50. $where[] = [$one, $fieldSearchable[$one], $tow];
  51. } elseif ($one == 'start') {
  52. $start = $tow . " 00:00:00";
  53. } elseif ($one == 'end') {
  54. $end = $tow . " 23:59:59";
  55. } else {
  56. continue;
  57. }
  58. }
  59. }
  60. return function ($query) use ($where, $start, $end) {
  61. if ($start) $where[] = ['created_at', '>=', $start];
  62. if ($end) $where[] = ['created_at', '<=', $end];
  63. if ($where) {
  64. $query->where($where);
  65. }
  66. };
  67. }
  68. /**
  69. * 数据更新
  70. */
  71. protected function _indexPost($datum)
  72. {
  73. foreach ($datum as $value){
  74. $value->{'image'}=env('APP_URL').$value->{'image'};
  75. }
  76. return $datum;
  77. }
  78. /**
  79. * 创建数据组建
  80. * @return array
  81. */
  82. function _storeGet()
  83. {
  84. return [];
  85. }
  86. /**
  87. * 修改数据组建
  88. * @param $id
  89. * @return array
  90. */
  91. function _editGet($id)
  92. {
  93. $model = $this->repository->find($id);
  94. return ['model' => $model];
  95. }
  96. }