| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?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) {
- $this->getValue($value);
- }
- return $datum;
- }
- private function getValue(&$value)
- {
- $to_name='无';
- if($value->{'type'}==0){
- $value->{'type'}='无';
- }elseif ($value->{'type'}==1){
- $value->{'type'}='链接商品';
- $to_name=Goods::where('id', $value->{'to_id'})->value('good_name');
- }elseif ($value->{'type'}==2){
- $value->{'type'}='链接分类';
- $to_name=GoodsClass::where('id', $value->{'to_id'})->value('class_name');
- }elseif ($value->{'type'}==3){
- $to_name='秒杀';
- $value->{'type'}='链接秒杀';
- }else{
- $value->{'type'}='外部链接';
- }
- $value->{'to_name'}=$to_name;
- }
- /**
- * 创建数据组建
- * @return array
- */
- function _storeGet()
- {
- $type_list = $this->getTypeList('0');
- return ['type_list' => json_encode($type_list, JSON_UNESCAPED_SLASHES)];
- }
- /**
- * 修改数据组建
- * @param $id
- * @return array
- */
- function _editGet($id)
- {
- $model = $this->repository->find($id);
- $type_list = $this->getTypeList($model->{'type'});
- $this->getBannerInfo($model);
- return ['model' => $model, 'type_list' => json_encode($type_list, JSON_UNESCAPED_SLASHES)];
- }
- private function getBannerInfo(&$model)
- {
- $goods_name = '';
- $class_id = 0;
- if ($model->{'type'} == 1) {
- $goods_name = Goods::where('id', $model->{'to_id'})->value('good_name');
- } elseif ($model->{'type'} == 2) {
- $class_id = GoodsClass::where('id', $model->{'to_id'})->value('p_id');
- }
- $model->{'to_name'} = $goods_name;
- $model->{'class_id'} = $class_id;
- }
- /**
- * 轮播链接类型
- * @param $type
- * @return array
- */
- private function getTypeList($type)
- {
- $option = [
- 'checked' => $type . '',
- 'attr' => [
- [
- 'value' => '0',
- 'label' => "无链接",
- 'disabled' => false,
- 'notice' => '*'
- ],
- [
- 'value' => '1',
- 'label' => "链接商品",
- 'disabled' => false,
- 'notice' => '*'
- ],
- [
- 'value' => '2',
- 'label' => "链接分类",
- 'disabled' => false,
- 'notice' => '*'
- ],
- [
- 'value' => '3',
- 'label' => "链接秒杀",
- 'disabled' => false,
- 'notice' => '*'
- ],
- [
- 'value' => '4',
- 'label' => "外部链接",
- 'disabled' => false,
- 'notice' => '*'
- ],
- ]
- ];
- return $option;
- }
- }
|