最新服务器上的版本,以后用这个
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
49
50
51
52
53
54
55
56
57
<?php
/**
 * @link:http://www.zjhejiang.com/
 * @copyright: Copyright (c) 2018 浙江禾匠信息科技有限公司
 *
 * Created by PhpStorm.
 * User: 风哀伤
 * Date: 2018/12/4
 * Time: 13:42
 */
 
namespace app\controllers;
 
 
use app\models\DistrictArr;
 
class DistrictController extends Controller
{
    public function actionIndex()
    {
        if (\Yii::$app->request->isAjax) {
            if (\Yii::$app->request->isPost) {
                $level = \Yii::$app->request->post('level');
            } elseif (\Yii::$app->request->isGet) {
                $level = \Yii::$app->request->get('level');
            } else {
                $level = 3;
            }
            switch ($level) {
                case 3:
                    $level = null;
                    break;
                case 2:
                    $level = 'district';
                    break;
                case 1:
                    $level = 'city';
                    break;
                default:
                    $level = null;
            }
            $list = DistrictArr::getArr();
            $district = DistrictArr::getList($list, $level);
            return $this->asJson([
                'code' => 0,
                'msg' => '',
                'data' => [
                    'district' => $district
                ]
            ]);
        }
        return $this->asJson([
            'code' => 1,
            'msg' => '返回错误'
        ]);
    }
}