RegionController.php
1.23 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
<?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
);
}
}