Commit 9e3742ab authored by hujun's avatar hujun

根据省市区名字,查找对应的code

parent 6b674963
......@@ -36,4 +36,31 @@ class Regions extends Model
return $data;
}
/**
* 根据省市区名字,查找对应的code
*
* @param $province
* @param string $city
* @param string $disc
* @return mixed
*/
public function getRegionsCodeByName($province, $city = '', $disc = '') {
if ($province) {
$result['province_code'] = $this->where('parentCode',100000)
->where('name','LIKE',$province.'%')->value('code');
if ($result['province_code'] && $city) {
$result['city_code'] = $this->where('parentCode',$result['province_code'])
->where('name','LIKE',$city.'%')->value('code');
if ($disc) {
$result['disc_code'] = $this->where('parentCode',$result['city_code'])
->where('name','LIKE',$disc.'%')->value('code');
}
}
}
return $result;
}
}
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