AdminVehicleBannerController.php 5.1 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <bronet@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\model\BannerModel;
use cmf\controller\AdminBaseController;
use think\Db;
use think\Loader;

class AdminVehicleBannerController extends AdminBaseController
{
    /**
     * 商品列表图片
     * @adminMenu(
     *     'name'   => '商品列表图片',
     *     'parent' => 'portal/AdminCommodityCate/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '商品列表图片',
     *     'param'  => ''
     * )
     */
    public function banner()
    {
        $data = $this->request->param();
        $final = $this->adminIndex($data);
        $where_else = $final['where_arr'];
        $where_else['status'] = 1;
        $where_else['type'] = array('in','2,3');
        $coo_list = Db::name('Banner')->where($where_else)->order('score desc , create_time desc')
            ->paginate(10,false,['query'=>$final['page_arr']]);
        $page = $coo_list->render();
        $this->assign('page',$page);
        $this->assign('list',$coo_list);
        return $this->fetch('index');
    }



    /**
     * 添加轮播图
     * @adminMenu(
     *     'name'   => '添加轮播图',
     *     'parent' => 'banner',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '添加轮播图',
     *     'param'  => ''
     * )
     */
    public function addBanner()
    {
        if($data = $this->request->param()){
//            添加数据
            $validate = Loader::validate('Banner');
            if(!$validate->scene('add')->check($data)){
                $mes = $validate->getError();
                $this->error("$mes");
            }
            $model = new BannerModel();
            $final = $model->save($data);
            if($final){
                $this->success('成功',url('banner'));
            }else{
                $this->error('失败');
            }
        }else{
            return $this->fetch('add');
        }
    }


    /**
     * 查看轮播图
     * @adminMenu(
     *     'name'   => '查看轮播图',
     *     'parent' => 'banner',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '查看轮播图',
     *     'param'  => ''
     * )
     */
    public function viewBanner()
    {
        $where_find['id'] = $this->request->param('id');
        $list = Db::name('Banner')->where($where_find)->find();
        $this->assign('list',$list);
        return $this->fetch('view');
    }


    /**
     * 编辑轮播图
     * @adminMenu(
     *     'name'   => '编辑轮播图',
     *     'parent' => 'banner',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '编辑轮播图',
     *     'param'  => ''
     * )
     */
    public function editBanner()
    {
//            添加数据
        $data = $this->request->post();
//                修改
        $add['pic'] = $data['pic'];
        $add['score'] = $data['score'];
        $add['type'] = $data['type'];
        $validate = Loader::validate('Banner');
        if(!$validate->scene('edit')->check($add)){
            $mes = $validate->getError();
            $this->error("$mes");
        }
        $add['id'] = $data['id'];
        $model = new BannerModel();
        $final = $model->isUpdate(true)->save($add);
        if($final){
            $this->success('成功',url('banner'));
        }else{
            $this->error('失败');
        }
    }


    /**
     * 删除轮播图
     * @adminMenu(
     *     'name'   => '删除轮播图',
     *     'parent' => 'banner',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除轮播图',
     *     'param'  => ''
     * )
     */
    public function delBanner(){
        $ids = $this->request->post();
        $id = $this->request->param('id');
        if($ids){
            $add_del['id'] = array('in',$ids['ids']);
        }else if($id){
            $add_del['id'] = $id;
        }else{
            $this->error('删除失败');
        }
        $add_del['status'] = 9;
        $model = new BannerModel();
        $del = $model->isUpdate(true)->allowField(true)->save($add_del);
        if($del){
            $this->success('删除成功',url('banner'));
        }else{
            $this->error('删除失败');
        }
    }
}