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

use cmf\controller\AdminBaseController;
use think\Db;

class AdminTempleAreaController extends AdminBaseController
{
    /**
     * 寺庙区域
     * @adminMenu(
     *     'name'   => '寺庙区域',
     *     'parent' => 'portal/AdminTemple/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '寺庙区域',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        //接收搜索参数
        $param = $this->request->param();
        //添加搜索条件
        $where=[];
        if (cmf_get_current_admin_id()!=1){
            $where['t.user_id']=cmf_get_current_admin_id();
        };
        $keyword = empty($param['keyword']) ? '' : $param['keyword'];
        if (!empty($keyword)) {
            $where['ta.name'] = ['like', "%$keyword%"];
        }
        $temple=empty($param['temple']) ? '' : $param['temple'];
        if (!empty($temple)) {
            $where['ta.temple_id'] = $temple;
        }
        $data = Db::name('temple_area')
            ->alias('ta')
            ->join('temple t','ta.temple_id=t.id')
            ->where($where)
            ->field('ta.*,t.name as tname')
            ->order('ta.create_time','desc')
            ->paginate('10');

        $data->appends($param);

        $temple_choose=Db::name('temple')->select();
        $this->assign('page',$data->render());
        $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
        $this->assign('temple', isset($param['temple']) ? $param['temple'] : '');
        $this->assign('temple_choose',$temple_choose);
        $this->assign('list', $data);
        return $this->fetch();
    }

    /**
     * 添加地区
     * @adminMenu(
     *     'name'   => '添加地区',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '添加地区',
     *     'param'  => ''
     * )
     */
    public function add()
    {
        $where=[];
        if (cmf_get_current_admin_id()!=1){
            $where['user_id']=cmf_get_current_admin_id();
        };
        $temple=Db::name('temple')->where($where)->select();
        $this->assign('temple',$temple);
        return $this->fetch();
    }

    /**
     * 添加地区提交
     * @adminMenu(
     *     'name'   => '添加地区提交',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '添加地区提交',
     *     'param'  => ''
     * )
     */
    public function addPost()
    {
        $param = $this->request->param();
        $param['create_time'] = time();
        $re = Db::name('temple_area')->insert($param);
        if ($re) {
            $this->success('添加成功', 'AdminTempleArea/index');
        } else {
            $this->error('添加失败', 'AdminTempleArea/index');
        }
    }

    /**
     * 编辑地区
     * @adminMenu(
     *     'name'   => '编辑地区',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '编辑地区',
     *     'param'  => ''
     * )
     */
    public function edit()
    {
        $id = $this->request->param('id');
        $data = Db::name('temple_area')
//            ->alias('t')
//            ->join('user u','t.user_id=u.id')
            ->where('id', $id)
//            ->field('t.*,u.user_login')
            ->find();
        $where=[];
        if (cmf_get_current_admin_id()!=1){
            $where['user_id']=cmf_get_current_admin_id();
        };
        $temple=Db::name('temple')->where($where)->select();
        $this->assign('temple',$temple);
        $this->assign('list', $data);
        return $this->fetch();
    }
    /**
     * 编辑地区提交
     * @adminMenu(
     *     'name'   => '编辑地区提交',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '编辑地区提交',
     *     'param'  => ''
     * )
     */
    public function editPost()
    {
        $param = $this->request->param();
        $param['create_time'] = time();
        Db::name('temple_area')->where('id', $param['id'])->update($param);
        $this->success('编辑成功');
    }

    /**
     * 删除地区
     * @adminMenu(
     *     'name'   => '删除地区',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除地区',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $id = $this->request->param('id');
        $re=Db::name('light_order')
            ->alias('lo')
            ->join('light l','lo.light_id=l.id')
            ->where(['l.area_id'=>$id,'lo.end_time'=>['>',time()]])
            ->find();
        if ($re){
            $this->error('该区域下有进行中的订单,不允许删除');
        }
        Db::name('temple_area')->where('id', $id)->delete();
        $this->success('删除成功');
    }

}