You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
6.2 KiB
162 lines
6.2 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | YFCMF [ WE CAN DO IT MORE SIMPLE ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: rainfer <81818832@qq.com>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\admin\controller;
|
|
use think\Db;
|
|
class Region extends Base
|
|
{
|
|
public function region_list(){
|
|
$key=input('key');
|
|
$where['pid']=0;
|
|
$province=input('province','');
|
|
$this->assign('province',$province);
|
|
if($province !== ''){
|
|
$where['pid']=$province;
|
|
}
|
|
$city=input('city','');
|
|
$this->assign('city',$city);
|
|
if($city !== ''){
|
|
$cityfind=DB::name('region')->where(array('type'=>2,'pid'=>$province,'id'=>$city))->find();
|
|
if($cityfind){
|
|
$where['pid']=$city;
|
|
}else{
|
|
$this->assign('city','');
|
|
}
|
|
}
|
|
if($where['pid']==0){
|
|
$where['pid']=array(array('eq',0),array('eq',1),'or');;
|
|
}
|
|
|
|
$province_list=DB::name('region')->where(array('type'=>1))->order('id,pid')->select();
|
|
$this->assign('province_list',$province_list);
|
|
$city_list=DB::name('region')->where(array('type'=>2,'pid'=>$province))->order('id,pid')->select();
|
|
$this->assign('city_list',$city_list);
|
|
$region_list=DB::name('region')->where($where)->where('name','like',"%".$key."%")->order('id,pid')->paginate(config('paginate.list_rows'),false,['query'=>get_query()]);
|
|
|
|
$show=$region_list->render();
|
|
$show=preg_replace("(<a[^>]*page[=|/](\d+).+?>(.+?)<\/a>)","<a href='javascript:ajax_page($1);'>$2</a>",$show);
|
|
$this->assign('region_list',$region_list);
|
|
$this->assign('page',$show);
|
|
$this->assign('val',$key);
|
|
if(request()->isAjax()){
|
|
return $this->fetch('ajax_region_list');
|
|
}else{
|
|
return $this->fetch();
|
|
}
|
|
}
|
|
|
|
public function region_add(){
|
|
$province = Db::name('Region')->where ( array('pid'=>1) )->select ();
|
|
$this->assign('province',$province);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function region_runadd(){
|
|
if (!request()->isAjax()){
|
|
$this->error('提交方式不正确',url('admin/Region/region_add'));
|
|
}else{
|
|
$input_type=input('input_type',0);
|
|
$province=input('region_list_province');
|
|
$city=input('region_list_city');
|
|
if($input_type==2){
|
|
if(!$province){
|
|
$this->error('请选择省份',url('admin/Region/region_add'));
|
|
}
|
|
$pid=$province;
|
|
}elseif($input_type==3){
|
|
if(!$city){
|
|
$this->error('请选择城市',url('admin/Region/region_add'));
|
|
}
|
|
$pid=$city;
|
|
}else{
|
|
$pid=1;
|
|
}
|
|
|
|
$sl_data=array(
|
|
'pid'=>$pid,
|
|
'name'=>input('areaname'),
|
|
'type' => $input_type,
|
|
);
|
|
|
|
$rst=DB::name('region')->insert($sl_data);
|
|
if($rst!==false){
|
|
$this->success('添加成功',url('admin/Region/region_list',array('province'=>$province,'city'=>$city)));
|
|
}else{
|
|
$this->error('添加失败',url('admin/Region/region_add'));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function region_edit(){
|
|
$editdata = Db::name('Region')->where ( array('id'=>input('id')) )->find();
|
|
$this->assign('editdata',$editdata);
|
|
$province = Db::name('Region')->where ( array('pid'=>1) )->select ();
|
|
$this->assign('province',$province);
|
|
if($editdata['type']==2){//市
|
|
$provincedata = Db::name('Region')->where ( array('id'=>$editdata['pid']) )->find();
|
|
$this->assign('provinceid',$provincedata['id']);
|
|
$this->assign('cityid',0);
|
|
}elseif($editdata['type']==3){//县
|
|
$citydata = Db::name('Region')->where ( array('id'=>$editdata['pid']) )->find();
|
|
$provincedata = Db::name('Region')->where ( array('id'=>$citydata['pid']) )->find();
|
|
$this->assign('cityid',$citydata['id']);
|
|
$this->assign('provinceid',$provincedata['id']);
|
|
$city = Db::name('Region')->where ( array('pid'=>$citydata['pid']) )->select();
|
|
$this->assign('city',$city);
|
|
}else{//省
|
|
$this->assign('provinceid',0);
|
|
$this->assign('cityid',0);
|
|
}
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function region_runedit(){
|
|
if (!request()->isAjax()){
|
|
$this->error('提交方式不正确',url('admin/Region/region_add'));
|
|
}else{
|
|
$input_type=input('input_type',0);
|
|
$province=input('region_list_province');
|
|
$city=input('region_list_city');
|
|
if($input_type==2){
|
|
if(!$province){
|
|
$this->error('请选择省份',url('admin/Region/region_edit'));
|
|
}
|
|
$pid=$province;
|
|
}elseif($input_type==3){
|
|
if(!$city){
|
|
$this->error('请选择城市',url('admin/Region/region_edit'));
|
|
}
|
|
$pid=$city;
|
|
}else{
|
|
$pid=1;
|
|
}
|
|
|
|
$sl_data['pid']=$pid;
|
|
$sl_data['name']=input('areaname');
|
|
$sl_data['type']=$input_type;
|
|
|
|
$rst=DB::name('region')->where(array('id'=>input('regionid')))->update($sl_data);
|
|
if($rst!==false){
|
|
$this->success('修改成功',url('admin/Region/region_list',array('province'=>$province,'city'=>$city)));
|
|
}else{
|
|
$this->error('修改失败',url('admin/Region/region_edit'));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function region_del()
|
|
{
|
|
$id=input('id');
|
|
$rst=Db::name('region')->where('id',$id)->delete();
|
|
if($rst!==false){
|
|
$this->success('删除成功',url('admin/Region/region_list'));
|
|
}else{
|
|
$this->error('删除失败',url('admin/Region/region_list'));
|
|
}
|
|
}
|
|
}
|