123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace App\Http\Controllers\Banner;
- use App\Http\Controllers\AdminBaseController;
- use App\Http\Requests\BannerCreateRequest;
- use App\Http\Requests\BannerUpdateRequest;
- use App\Models\Goods;
- use App\Models\GoodsClass;
- use App\Models\Menu;
- use App\Repositories\Eloquent\BannerRepositoryEloquent;
- use App\Validators\BannerValidator;
- /**
- * Class BannersController.
- *
- * @package namespace App\Http\Controllers;
- */
- class BannersController extends AdminBaseController
- {
- /**
- * @var BannerRepositoryEloquent
- */
- protected $repository;
- /**
- * @var BannerValidator
- */
- protected $validator;
- /**
- * BannersController constructor.
- *
- * @param BannerRepositoryEloquent $repository
- * @param BannerValidator $validator
- */
- public function __construct(BannerRepositoryEloquent $repository, BannerValidator $validator)
- {
- parent::__construct($repository, $validator);
- }
- /**
- * 数据检索
- */
- public function _indexScopeQuery()
- {
- $where = [];
- $search = explode(";", request()->input('search', ""));
- $start = $end = null;
- $fieldSearchable = $this->repository->getFieldsSearchable();
- foreach ($search as $value) {
- if (!empty($value)) {
- list($one, $tow) = explode(":", $value);
- if (!empty($fieldSearchable[$one])) {
- if ($fieldSearchable[$one] == 'like') $tow = "%{$tow}%";
- $where[] = [$one, $fieldSearchable[$one], $tow];
- } elseif ($one == 'start') {
- $start = $tow . " 00:00:00";
- } elseif ($one == 'end') {
- $end = $tow . " 23:59:59";
- } else {
- continue;
- }
- }
- }
- return function ($query) use ($where, $start, $end) {
- if ($start) $where[] = ['created_at', '>=', $start];
- if ($end) $where[] = ['created_at', '<=', $end];
- if ($where) {
- $query->where($where);
- }
- };
- }
- /**
- * 数据更新
- */
- protected function _indexPost($datum)
- {
- foreach ($datum as $value){
- $value->{'image'}=env('APP_URL').$value->{'image'};
- }
- return $datum;
- }
- /**
- * 创建数据组建
- * @return array
- */
- function _storeGet()
- {
- return [];
- }
- /**
- * 修改数据组建
- * @param $id
- * @return array
- */
- function _editGet($id)
- {
- $model = $this->repository->find($id);
- return ['model' => $model];
- }
- }
|