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

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

/**
 * Class BingoController
 * @package app\portal\controller
 * @adminMenuRoot(
 *     'name'   =>'定制咨询',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'定制咨询'
 * )
 */
class BingoController extends AdminBaseController
{
    public function adminIndex($data){
        $arr = array();
        $find = array();
        if($data){
            $startTime = empty($data['start_time']) ? 0 : strtotime($data['start_time']);
            $endTime   = empty($data['end_time']) ? 0 : strtotime($data['end_time']);
            if ($startTime && $endTime) {
                $arr['start_time'] = $data['start_time'];
                $arr['end_time'] = $data['end_time'];
                $find['create_time'] = array('between',"$startTime,$endTime");
                $this->assign('start_time', $data['start_time']);
                $this->assign('end_time', $data['end_time']);
            }else{
                if($startTime){
                    $arr['start_time'] = $data['start_time'];
                    $find['create_time'] = array('egt',$startTime);
                    $this->assign('start_time', $data['start_time']);
                }
                if($endTime){
                    $arr['end_time'] = $data['end_time'];
                    $find['create_time'] = array('elt',$endTime);
                    $this->assign('end_time', $data['end_time']);
                }
            }
        }
        $return['page_arr'] = $arr;
        $return['where_arr'] = $find;
        return $return;
    }



    /**
     * 定制咨询列表
     * @adminMenu(
     *     'name'   => '定制咨询列表',
     *     'parent' => 'portal/Bingo/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '定制咨询列表',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $data = $this->request->param();
        $final = $this->adminIndex($data);
        $where_ask = $final['where_arr'];
        if(!empty($data['name'])){
            $final['page_arr']['name'] = $data['name'];
            $where_ask['name'] = array('like', '%'.$data['name'].'%');
            $this->assign('name', $data['name']);
        }
        if(!empty($data['tel'])){
            $final['page_arr']['tel'] = $data['tel'];
            $where_ask['tel'] = array('like', '%'.$data['tel'].'%');
            $this->assign('tel', $data['tel']);
        }
        if(!empty($data['start'])){
            $final['page_arr']['start'] = $data['start'];
            $where_ask['start'] = array('like', '%'.$data['start'].'%');
            $this->assign('start', $data['start']);
        }
        if(!empty($data['end'])){
            $final['page_arr']['end'] = $data['end'];
            $where_ask['end'] = array('like', '%'.$data['end'].'%');
            $this->assign('end', $data['end']);
        }
        $where_ask['status'] = array('neq', 9);
        $ask = Db::name('Ask')->where($where_ask)->order('create_time desc')->paginate(10,false,['query'=>$final['page_arr']]);;
        $page = $ask->render();
        $this->assign('page',$page);
        $this->assign('list', $ask);
        return $this->fetch();
    }

    /**
     * 定制咨询详情
     * @adminMenu(
     *     'name'   => '定制咨询详情',
     *     'parent' => 'portal/Bingo/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '定制咨询详情',
     *     'param'  => ''
     * )
     */
    public function view()
    {
        $data = $this->request->param();
        $where_ask['status'] = array('neq', 9);
        $where_ask['id'] = $data['id'];
        $ask = Db::name('Ask')->where($where_ask)->find();
        $ask['create_time'] = date('Y-m-d H:i:s', $ask['create_time']);
        $ask['update_time'] = date('Y-m-d H:i:s', $ask['update_time']);
        $this->assign('list', $ask);
        return $this->fetch();
    }

    /**
     * 定制咨询修改
     * @adminMenu(
     *     'name'   => '定制咨询修改',
     *     'parent' => 'portal/Bingo/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '定制咨询修改',
     *     'param'  => ''
     * )
     */
    public function change()
    {
        $data = $this->request->param();
        unset($data['create_time']);
        unset($data['update_time']);
        $validate = Loader::validate('Ask');
        if (!$validate->scene('edit')->check($data)) {
            $mes = $validate->getError();
            $this->error($mes);
        }
        $model = new AskModel();
        $res = $model->isUpdate(true)->save($data);
        if ($res) {
            $this->success('修改成功', url('Bingo/index'));
        } else {
            $this->error('修改失败');
        }
    }

    /**
     * 删除轮播图
     * @adminMenu(
     *     'name'   => '删除轮播图',
     *     'parent' => 'banner',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除轮播图',
     *     'param'  => ''
     * )
     */
    public function del()
    {
        $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 AskModel();
        $del = $model->isUpdate(true)->allowField(true)->save($add_del);
        if ($del) {
            $this->success('删除成功', url('index'));
        } else {
            $this->error('删除失败');


        }
    }
}