123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\api\controller;
- /**
- * 地区控制器
- */
- class Area extends MobileMall
- {
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- }
- /**
- * @api {POST} api/Area/area_app 地区列表
- * @apiVersion 1.0.0
- * @apiGroup Area
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- * @apiSuccess {Object[]} result.area_list 地区列表
- * @apiSuccess {String} result.area_list.area_name 地区名称
- * @apiSuccess {Int} result.area_list.area_id 地区ID
- * @apiSuccess {Object[]} result.area_list.child 子地区列表
- */
- public function area_app()
- {
- $cache_key = "api-area";
- $area_list = rcache($cache_key);
- if (empty($area_list)) {
- $area_model = model('area');
- $lev1 = $area_model->getTopLevelAreas();
- foreach ($lev1 as $k => $v) {
- $lev3 = $lev2[$k]['area_id'] = $area_model->GetChildName($k);
- foreach ($lev3 as $val) {
- $lev4[$k]['area_name'] = $v;
- $lev4[$k]['area_id'] = $k;
- $lev4[$k]['child'][$val['area_id']]['area_name'] = $val['area_name'];
- $lev4[$k]['child'][$val['area_id']]['area_id'] = $val['area_id'];
- $lev4[$k]['child'][$val['area_id']]['child'] = $area_model->GetChildName($val['area_id']);
- }
- }
- $area_list = array();
- foreach ($lev4 as $key => $val) {
- $val['child'] = array_values($val['child']);
- $area_list[] = $val;
- }
- wcache($cache_key, $area_list);
- }
- ds_json_encode(10000, '', array('area_list' => $area_list));
- }
- public function area_list()
- {
- $areas = model('area')->getAreas();
- ds_json_encode(10000, '', array('area_list' => $areas));
- }
- }
|