Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\common\model;
  14. use think\Db;
  15. use think\Model;
  16. /**
  17. * 区域分类
  18. */
  19. class Region extends Model
  20. {
  21. //初始化
  22. protected function initialize()
  23. {
  24. // 需要调用`Model`的`initialize`方法
  25. parent::initialize();
  26. }
  27. /**
  28. * 获取单条地区
  29. * @author wengxianhu by 2017-7-26
  30. */
  31. public function getInfo($id, $field = '*')
  32. {
  33. $result = Db::name('region')->field($field)->find($id);
  34. return $result;
  35. }
  36. /**
  37. * 获取多个地区
  38. * @author wengxianhu by 2017-7-26
  39. */
  40. public function getListByIds($ids = array(), $field = '*', $index_key = '')
  41. {
  42. $map = array(
  43. 'id' => array('IN', $ids),
  44. );
  45. $result = Db::name('region')->field($field)
  46. ->where($map)
  47. ->select();
  48. if (!empty($index_key)) {
  49. $result = convert_arr_key($result, $index_key);
  50. }
  51. return $result;
  52. }
  53. /**
  54. * 获取子地区
  55. * @author wengxianhu by 2017-7-26
  56. */
  57. public function getList($parent_id = 0, $field = '*', $index_key = '',$level = 0)
  58. {
  59. $result = $this->getAll($parent_id, $field, $index_key,$level);
  60. return $result;
  61. }
  62. /**
  63. * 获取全部地区
  64. * @author wengxianhu by 2017-7-26
  65. */
  66. public function getAll($parent_id = false, $field = '*', $index_key = '',$level = 0)
  67. {
  68. // $args = [$parent_id, $field, $index_key, $level];
  69. // $cacheKey = 'region-'.md5(__CLASS__.__FUNCTION__.json_encode($args));
  70. // $result = cache($cacheKey);
  71. // if (empty($result)) {
  72. $map = [];
  73. if (false !== $parent_id) {
  74. if (is_array($parent_id)) {
  75. $map['parent_id'] = ['IN', $parent_id];
  76. } else {
  77. $map['parent_id'] = $parent_id;
  78. }
  79. }
  80. if (0 !== $level) {
  81. $map['level'] = $level;
  82. }
  83. $result = Db::name('region')->field($field)
  84. ->where($map)
  85. ->select();
  86. if (!empty($index_key)) {
  87. $result = convert_arr_key($result, $index_key);
  88. }
  89. // cache($cacheKey, $result, null, "region");
  90. // }
  91. return $result;
  92. }
  93. /**
  94. * 获取级别的地区
  95. * @author wengxianhu by 2017-7-26
  96. */
  97. public function getListByLevel($level = 1, $field = '*', $index_key = '')
  98. {
  99. $map = array(
  100. 'level' => $level,
  101. );
  102. $result = Db::name('region')->field($field)
  103. ->where($map)
  104. ->select();
  105. if (!empty($index_key)) {
  106. $result = convert_arr_key($result, $index_key);
  107. }
  108. return $result;
  109. }
  110. }