RegionController.php
1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use DB;
class RegionController extends Controller
{
public function getAll()
{
$provinces = array(); $citys = array(); $towns = array();
$list = DB::connection('order')->table('lie_region')->orderBy('region_id', 'asc')->get();
foreach (@$list as $val) {
if (!$val->parent_id) continue;
switch ($val->region_type) {
case 1:
$provinces[$val->parent_id]['parent_id'] = $val->parent_id;
$provinces[$val->parent_id]['children'][] = $val;
break;
case 2:
$citys[$val->parent_id]['parent_id'] = $val->parent_id;
$citys[$val->parent_id]['children'][] = $val;
break;
case 3:
$towns[$val->parent_id]['parent_id'] = $val->parent_id;
$towns[$val->parent_id]['children'][] = $val;
break;
}
}
return array(
'errcode'=>0,
'errmsg'=>'success',
'provinces'=> $provinces,
'citys'=> $citys,
'towns'=> $towns
);
}
//获取省市县名称
public function getRegionName($region_id){
if (empty($region_id)){
return "";
}
$list = DB::connection('order')->table('lie_region')->select("region_name")->where("region_id",$region_id)->get();
return !$list ? "" : current(objectToArray($list))['region_name'];
}
}