Fleaarea.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Fleaarea extends BaseModel
  16. {
  17. /**
  18. * 读取系统设置列表
  19. * @access public
  20. * @author csdeshang
  21. * @param array $condition 检索条件
  22. * @param string $order 排序条件
  23. * @return array 数组格式的返回结果
  24. */
  25. public function getFleaareaList($condition, $field='*', $order='fleaarea_sort desc',$limit=0){
  26. $result = Db::name('fleaarea')->field($field)->limit($limit)->order($order)->where($condition)->select()->toArray();
  27. return $result;
  28. }
  29. /**
  30. * 新增
  31. * @access public
  32. * @author csdeshang
  33. * @param array $data 参数内容
  34. * @return bool 布尔类型的返回结果
  35. */
  36. public function addFleaarea($data) {
  37. $result = Db::name('fleaarea')->insertGetId($data);
  38. return $result;
  39. }
  40. /**
  41. * 取单个地区的内容
  42. * @access public
  43. * @author csdeshang
  44. * @param array $condition 检索条件
  45. * @return array 数组类型的返回结果
  46. */
  47. public function getOneFleaarea($condition){
  48. if (!empty($condition)){
  49. $result = Db::name('fleaarea')->where($condition)->find();
  50. return $result;
  51. }else {
  52. return false;
  53. }
  54. }
  55. /**
  56. * 更新信息
  57. * @access public
  58. * @author csdeshang
  59. * @param array $data 更新数据
  60. * @return bool 布尔类型的返回结果
  61. */
  62. public function editFleaarea($condition, $data) {
  63. $result = Db::name('fleaarea')->where($condition)->update($data);
  64. return $result;
  65. }
  66. /**
  67. * 删除地区
  68. * @access public
  69. * @author csdeshang
  70. * @param int/array $id 删除ID
  71. * @param int $deep 删除深度,默认为1
  72. * @return array $rs_row 返回数组形式的查询结果
  73. */
  74. public function delFleaarea($id,$deep=1){
  75. if (!empty($id)){
  76. if (!is_array($id)){
  77. $id = array($id);
  78. }
  79. /**
  80. * 取得地区缓存内容
  81. */
  82. $child_deep = $deep+1;
  83. for ($i=$child_deep; $i<=4; $i++){
  84. $cache_file = ROOT_PATH . "extend" . DIRECTORY_SEPARATOR . "area" . DIRECTORY_SEPARATOR . "area_" . $deep . ".php";
  85. if (file_exists($cache_file)){
  86. require_once($cache_file);
  87. $tmp = 'cache_data_'.$i;
  88. $$tmp = $area_array;
  89. unset($tmp,$area_array);
  90. }
  91. }
  92. foreach ($id as $k => $v){
  93. if (intval($v) > 0){
  94. $del_tmp[] = "fleaarea_id = '". $v ."'";
  95. /**
  96. * 判断子类中是否还有内容
  97. */
  98. if ($child_deep <= 4){
  99. $del_parent_id = array($v);
  100. for ($i=$child_deep; $i<=4; $i++){
  101. $tmp = 'cache_data_'.$i;
  102. if (isset($$tmp) && is_array($$tmp) && !empty($del_parent_id)){
  103. foreach ($del_parent_id as $k_parent => $v_parent){
  104. foreach ($$tmp as $k_2 => $v_2){
  105. if ($v_2['fleaarea_parent_id'] == $v_parent){
  106. $del_tmp[] = "fleaarea_id = '". $v_2['fleaarea_id'] ."'";
  107. $next_parent_id[] = $v_2['fleaarea_id'];
  108. }
  109. }
  110. }
  111. /**
  112. * 再下一级的父ID
  113. */
  114. $del_parent_id = $next_parent_id;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. $where = implode(' or ',$del_tmp);
  121. $result = Db::name('fleaarea')->where($where)->delete();
  122. return $result;
  123. }else {
  124. return false;
  125. }
  126. }
  127. /**
  128. * 地址展示
  129. * @access public
  130. * @author csdeshang
  131. * @return type
  132. */
  133. public function fleaarea_show(){
  134. $area_one_level = array();
  135. $area_two_level = array();
  136. $condition = array();
  137. $condition[]=array('fleaarea_parent_id','=',1);
  138. $area_list=$this->getFleaareaList($condition,'fleaarea_id,fleaarea_name,fleaarea_parent_id','fleaarea_parent_id asc,fleaarea_sort asc,fleaarea_id asc');
  139. if(is_array($area_list) && !empty($area_list)) {
  140. foreach ($area_list as $val) {
  141. if($val['fleaarea_parent_id'] == 0) {
  142. $fleaarea_id = $val['fleaarea_id'];
  143. $area_one_level[] = $val;
  144. $area_two_level[$fleaarea_id]['id']=$fleaarea_id;
  145. } else {
  146. $fleaarea_parent_id = $val['fleaarea_parent_id'];
  147. if(isset($area_two_level[$fleaarea_parent_id])) {
  148. $area_two_level[$fleaarea_parent_id]['children'][] = $val;
  149. $area_children = $area_two_level[$fleaarea_parent_id]['children'];
  150. $area_two_level[$fleaarea_parent_id]['content'] = json_encode($area_children);
  151. }
  152. }
  153. }
  154. }
  155. return(array('area_one_level'=>$area_one_level, 'area_two_level'=>$area_two_level));
  156. }
  157. }