| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace addons\Community\api\modules\v1\controllers;
- use addons\Community\common\service\SettingService;
- use api\controllers\OnAuthController;
- use common\models\common\Region;
- use yii\helpers\Json;
- class RegionController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- public function actionIndex()
- {
- $ids = (new SettingService())->getFieldSetting($this->mall_id, 'area', true);
- // 需要先找出pid
- $cIds = Region::find()->where(['level' => 3])->andWhere(['id' => Json::decode($ids)])->select('parent_id')->column();
- $rows = Region::find()->where(['id' => $cIds])->andWhere(['level' => 2])
- ->orderBy('initial asc')->select('id, name, initial, lng, lat')->asArray()->all();
- if (!empty($rows)) {
- $rows = array_reduce($rows, function (&$rows, $item) {
- $rows[!empty($item['initial']) ? $item['initial'] : '#'][] = $item;
- return $rows;
- });
- }
- return $this->success('获取成功', $rows);
- }
- }
|