Commit c96e0a61 authored by hujun's avatar hujun

商圈获取省市区封装

parent d5913d9c
......@@ -116,20 +116,9 @@ class BusinessDistrict extends Basic
* @throws \think\exception\DbException
*/
public function regions() {
$code = $this->request->get('code');
$parent_code = $this->request->get('parent_code');
$params = $this->request->param();
$regions = new Regions();
if ($code) {
$where = 'code = '.$code;
} elseif ($parent_code) {
$where = 'parentCode = '.$parent_code;
} else {
$type = $this->request->get('type') ? $this->request->get('type') : 1;
$where = 'type = '.$type;
}
$fields = 'code,parentCode,name';
$data = $regions->field($fields)->where($where)->select();
$data = $regions->getRegions($params['code'], $params['parent_code'], $params['type']);
return $this->response(200, '', $data);
}
}
\ No newline at end of file
......@@ -6,5 +6,27 @@ use think\Model;
class Regions extends Model
{
//
/**
* 根据code或parent_code获取省市区
*
* @param $code
* @param string $parent_code
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getRegions($code, $parent_code = '', $type = 1){
if ($code) {
$where = 'code = '.$code;
} elseif ($parent_code) {
$where = 'parentCode = '.$parent_code;
} else {
$type = $type ? $type:1;
$where = 'type = '.$type;
}
$fields = 'code,parentCode,name';
$data = $this->field($fields)->where($where)->select();
return $data;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment