Fleaarea.php 6.2 KB

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