AreaModel.class.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Model;
  15. class AreaModel{
  16. public function get_area_id_by_name($name='',$pid=0)
  17. {
  18. $area_info = M('lionfish_comshop_area')->where( array('name' => $name) )->find();
  19. if( empty($area_info) )
  20. {
  21. $max_code_info = M('lionfish_comshop_area')->field('code')->order('code desc')->find();
  22. $max_code = $max_code_info['code'];
  23. $max_code = $max_code +1;
  24. $data = array();
  25. $data['name'] = $name;
  26. $data['pid'] = $pid;
  27. $data['code'] = $max_code;
  28. $id = M('lionfish_comshop_area')->add($data);
  29. return $id;
  30. }else{
  31. return $area_info['id'];
  32. }
  33. }
  34. public function get_area_info($id=0)
  35. {
  36. $area_info = M('lionfish_comshop_area')->where( array('id' => $id ) )->find();
  37. return $area_info['name'];
  38. }
  39. public function getAreas( $is_parse = false)
  40. {
  41. global $_W;
  42. global $_GPC;
  43. //$result = load_class('cache')->getArray('areas', $uniacid);
  44. $result = S('areas_list');
  45. if (empty($result)) {
  46. $result = array();
  47. //@attributes
  48. $provinces = M('lionfish_comshop_area')->field('id,name,code')->where( array('pid' => 0) )->order('code asc')->select();
  49. $result['province'][] = array(
  50. '@attributes' => array(
  51. 'name'=>'请选择省份',
  52. 'city'=>array(
  53. '@attributes'=>array('name' =>'请选择城市','county' => array(
  54. '@attributes' => array('name' => '请选择区域')
  55. )) ) )
  56. );
  57. foreach($provinces as $key => $val)
  58. {
  59. $province_tmp = array();
  60. $province_tmp['@attributes']['name'] = $val['name'];
  61. $province_tmp['@attributes']['code'] = $val['code'];
  62. $province_tmp['city'] = array();
  63. $city_list = M('lionfish_comshop_area')->field('id,name,code')->where( array('pid' => $val['id']) )->order('code asc')->select();
  64. $city_tmp_list = array();
  65. foreach($city_list as $vv)
  66. {
  67. $city_tmp = array();
  68. $city_tmp['@attributes']['name'] = $vv['name'];
  69. $city_tmp['@attributes']['code'] = $vv['code'];
  70. $city_tmp['country'] = array();
  71. $country_list = M('lionfish_comshop_area')->field('id,name,code')->where( array('pid' => $vv['id']) )->order('code asc')->select();
  72. $country_tmp_list = array();
  73. if( !empty($country_list) )
  74. {
  75. foreach($country_list as $vvv)
  76. {
  77. $country_tmp = array();
  78. $country_tmp['@attributes']['name'] = $vvv['name'];
  79. $country_tmp['@attributes']['code'] = $vvv['code'];
  80. $country_tmp_list[] = $country_tmp;
  81. }
  82. }
  83. $city_tmp['country'] = $country_tmp_list;
  84. $city_tmp_list[] = $city_tmp;
  85. }
  86. $province_tmp['city'] = $city_tmp_list;
  87. $result['province'][] = $province_tmp;
  88. }
  89. //load_class('cache')->set('areas', $result, $uniacid);
  90. S('areas_list', $result);
  91. }
  92. return $result;
  93. }
  94. }
  95. ?>