Area.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\api\controller;
  3. /**
  4. * 地区控制器
  5. */
  6. class Area extends MobileMall
  7. {
  8. public function initialize()
  9. {
  10. parent::initialize(); // TODO: Change the autogenerated stub
  11. }
  12. /**
  13. * @api {POST} api/Area/area_app 地区列表
  14. * @apiVersion 1.0.0
  15. * @apiGroup Area
  16. *
  17. * @apiSuccess {String} code 返回码,10000为成功
  18. * @apiSuccess {String} message 返回消息
  19. * @apiSuccess {Object} result 返回数据
  20. * @apiSuccess {Object[]} result.area_list 地区列表
  21. * @apiSuccess {String} result.area_list.area_name 地区名称
  22. * @apiSuccess {Int} result.area_list.area_id 地区ID
  23. * @apiSuccess {Object[]} result.area_list.child 子地区列表
  24. */
  25. public function area_app()
  26. {
  27. $cache_key = "api-area";
  28. $area_list = rcache($cache_key);
  29. if (empty($area_list)) {
  30. $area_model = model('area');
  31. $lev1 = $area_model->getTopLevelAreas();
  32. foreach ($lev1 as $k => $v) {
  33. $lev3 = $lev2[$k]['area_id'] = $area_model->GetChildName($k);
  34. foreach ($lev3 as $val) {
  35. $lev4[$k]['area_name'] = $v;
  36. $lev4[$k]['area_id'] = $k;
  37. $lev4[$k]['child'][$val['area_id']]['area_name'] = $val['area_name'];
  38. $lev4[$k]['child'][$val['area_id']]['area_id'] = $val['area_id'];
  39. $lev4[$k]['child'][$val['area_id']]['child'] = $area_model->GetChildName($val['area_id']);
  40. }
  41. }
  42. $area_list = array();
  43. foreach ($lev4 as $key => $val) {
  44. $val['child'] = array_values($val['child']);
  45. $area_list[] = $val;
  46. }
  47. wcache($cache_key, $area_list);
  48. }
  49. ds_json_encode(10000, '', array('area_list' => $area_list));
  50. }
  51. public function area_list()
  52. {
  53. $areas = model('area')->getAreas();
  54. ds_json_encode(10000, '', array('area_list' => $areas));
  55. }
  56. }