Area.php 2.5 KB

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