AdminLineController.php 3.4 KB
<?php
/**
 * 商旅服务
 * Author : xiaojie
 * DateTime: 2018/11/29 17:26
 */
namespace app\portal\controller;


use app\portal\model\LineModel;
use cmf\controller\AdminBaseController;

class AdminLineController extends AdminBaseController
{

    //网上展厅显示
    public function lines()
    {
        $lineModel = new LineModel();
        $cate_list = $this->category();
        if($this->request->isPost()){
            $param = $this->request->param();
            if($param['cate_id'] == 0){
                $list = $lineModel
                    ->paginate(30);
            }else{
                $list = $lineModel
                    ->where($param)
                    ->paginate(30);
            }
            $cate_id = $param['cate_id'];
        }else{
            $list = $lineModel
                ->paginate(30);
            $cate_id = 0;
        }
        $this->assign('cate_id',$cate_id);
        $this->assign('cate_list',$cate_list);
        $this->assign('list',$list);
        $this->assign('page',$list->render());
        return $this->fetch();
    }

    //添加网上展厅
    public function lines_add()
    {
        if($this->request->isPost()){
            $lineModel = new LineModel();
            $param = $this->request->param();
            if($param['cate_id']==0){
                $this->error('请选择分类');
            }
            if(empty($param['thumb'])){
                $this->error('请上传缩略图');
            }
//            for ($i=0;$i<10;$i++){
            $param['create_time'] = time();
            $param['update_time'] = time();
            $res = $lineModel::create($param);
            //}
//            $res = $showModel->save($param);
            if($res){
                $this->success('添加成功');
            }
        }else{
            $cate_list = $this->category();
            $this->assign('cate_list',$cate_list);
            return $this->fetch();
        }
    }

    //网上展厅分类
    private function category(){
        $cate_list = [
            ['id'=>1,'name'=>'第一天'],
            ['id'=>2,'name'=>'第二天'],
            ['id'=>3,'name'=>'第三天'],
            ['id'=>4,'name'=>'第四天'],
        ];
        return $cate_list;
    }

    //编辑网上展厅
    public function lines_detail()
    {
        $lineModel = new LineModel();
        $id = $this->request->param('id','','intval');
        if($this->request->isPost()){
            $param = $this->request->param();
            if($param['cate_id']==0){
                $this->error('请选择分类');
            }
            if(empty($param['thumb'])){
                $this->error('请上传缩略图');
            }
            $param['update_time'] = time();
            $res = $lineModel::update($param);
            if($res){
                $this->success('更新成功');
            }
        }else{
            $info = $lineModel->where('id',$id)->find();
            $cate_list = $this->category();
            $this->assign('cate_list',$cate_list);
            $this->assign('info',$info);
            return $this->fetch();
        }
    }

    //删除网上展厅
    public function delete(){
        $lineModel = new LineModel();
        $id = $this->request->param('id');
        $res = $lineModel->where(['id'=>$id])->delete();
        if($res){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }
}