73 lines
1.7 KiB
PHP
Executable File
73 lines
1.7 KiB
PHP
Executable File
<?php
|
|
namespace wstmart\common\model;
|
|
use think\Db;
|
|
/**
|
|
* ============================================================================
|
|
* 地区类
|
|
*/
|
|
class Position extends Base{
|
|
|
|
private $level = 1;
|
|
private $tagName = 'province';
|
|
private $pName = '';
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->initData((int)input('post.level/d'));
|
|
}
|
|
function initData($level){
|
|
switch ($level) {
|
|
case 1:
|
|
$this->level = 1;
|
|
$this->tagName = 'province';
|
|
$this->pName = '';
|
|
break;
|
|
case 2:
|
|
$this->level = 2;
|
|
$this->tagName = 'city';
|
|
$this->pName = 'province';
|
|
break;
|
|
case 3:
|
|
$this->level = 3;
|
|
$this->tagName = 'county';
|
|
$this->pName = 'city';
|
|
break;
|
|
case 4:
|
|
$this->level = 4;
|
|
$this->tagName = 'town';
|
|
$this->pName = 'county';
|
|
break;
|
|
case 5:
|
|
$this->level = 5;
|
|
$this->tagName = 'village';
|
|
$this->pName = 'town';
|
|
break;
|
|
|
|
default:
|
|
$this->level = 1;
|
|
$this->tagName = 'province';
|
|
$this->pName = '';
|
|
break;
|
|
}
|
|
}
|
|
/**
|
|
* 获取区域名称
|
|
* @return [type] [description]
|
|
*/
|
|
public function getAreaName($areaId=0){
|
|
$where[$this->tagName.'_id']=empty($areaId) ? (int)input('post.id/d') : $areaId;
|
|
$field=$this->tagName.'_id areaId'.','.$this->tagName.'_name areaName';;
|
|
return Db::name('position_'.$this->tagName)->where($where)->cache(true)->field($field)->find();
|
|
}
|
|
/**
|
|
* 获取地区列表
|
|
*/
|
|
public function listQuery(){
|
|
$where=[];
|
|
if($this->level > 1){
|
|
$where[$this->pName.'_id']=(int)input('post.pid/d');
|
|
}
|
|
$field=$this->tagName.'_id areaId'.','.$this->tagName.'_name areaName';
|
|
return Db::name('position_'.$this->tagName)->where($where)->cache(true)->field($field)->select();
|
|
}
|
|
}
|