您好,欢迎访问一九零五行业门户网

地区管理功能

thinkphp 地区管理功能,因为最近有些系统有这方面的需求行业不一样用到区域也不一样,完成70%, ajax 双击修改地区部分没实现,有时间弄下。本来打算移植ecshop 的不过有点麻烦。还是自己写把。数据库部分来自ecshop region表。至于前端部分,参考任何一个城市级联即可实现,高端上档次!
实现效果:
前台代码:
{if $region_type=3}{$regionts}:
{/if}
                $region_typeyuanshi,'parentid'=>$fuid))}>返回上一级
{$region_type}
{$vo['region_name']}|
                    {if $region_type=3}
                        $region_type,'parentid'=>$vo['id']))}>管理
                    {/if}
                    $vo['id'],'parentid'=>$vo['id']))} >删除
暂无地区
注视:1级地区:国家 2级地区:省份 3级地区:市级 4级地区:县/区
public function region(){
$parent_id = intval(trim($_get['parentid']));//父id
        $region = d(region);
        $regionarr = $region->where( parent_id=.$parent_id)->select();
        if( $_get['regiontype']==  ){
            $region_type = '0';
            $regionts = 新增1级地区;
        }else{
            if($regionarr[0]['id'] == ){
                //取出上一级的region_type
                $regiontypearr = $region->where('id='.$parent_id)->field('region_type')->find();
$region_type = $regiontypearr['region_type']+1;
            }else{
                $region_type = $regionarr[0]['region_type'];
            }
            $regionts = $region_type+1;
            $regionts = 新增.$regionts.级地区;
        }
$this->assign(region_type,$region_type);//属于省份还是市
        $region_typeyuanshi=$region_type-1;
        $this->assign(region_typeyuanshi,$region_typeyuanshi);
        $this->assign(regionts,$regionts);//文字提示
if(  $regionarr[0]['parent_id'] != 0){
            $fuidarr = $region->where(id=.$regionarr[0]['parent_id'])->find();//用fuid去取fuid的parent_id;
            $this->assign(fuid,  $fuidarr['parent_id']  );//返回上一级的时候,取的fuid
        }
if( $region_type == 0 ){
            $this->assign('id',  '0' );
        }else{
            $this->assign('id', $parent_id );
        }
        $this->assign('list',$regionarr);
$this->display();
    }
function delregion(){
$region = d(region);
        //删除
        if( $_get['regionid'] !=  ){
            //先判断是否有子分类
            $regionid= intval( $_get['regionid'] );
            $ziarr = $region->where(parent_id=.$regionid)->select();
            if( $ziarr[0]['id'] !=  ){
                $this->error(请先删除子分类!);
            }else{
                $region->id=$regionid;
                if($region->delete()){
                    $this->success();
                }else{
                    $this->error(删除失败);
                }
            }
        }
    }
public function add(){
        $region = d('region');
        $region_name=trim($_post['region_name']);
        if(!$region_name) $this->error(新增地区不能为空!);
        $region->region_name = $region_name;
        $region->region_type = trim($_post['region_type']);
        $region->parent_id   = trim($_post['parent_id']);
        if($region->add()){
            $this->success('添加成功!');
        }else{
            $this->error($region->geterror());
        }
    }数据库结构:create table `sp_region` (
  `id` int(11) not null auto_increment,
  `parent_id` int(11) default null,
  `region_name` varchar(120) character set gbk default null,
  `region_type` smallint(5) default null,
  `agency_id` smallint(5) unsigned not null default '0',
  `is_show` smallint(5) not null default '0',
  primary key (`id`)
) engine=myisam auto_increment=3417 default charset=utf8 collate=utf8_bin数据的话,ecshop 里面region 表和其一样。
ad:真正免费,域名+虚机+企业邮箱=0元
其它类似信息

推荐信息