Groupbuyclass.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Groupbuyclass extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 读取抢购分类列表
  16. * @access public
  17. * @author csdeshang
  18. * @param array $condition 条件
  19. * @param int $pagesize 分页
  20. * @param str $order 排序
  21. * @return array
  22. */
  23. public function getGroupbuyclassList($condition = '', $pagesize = '', $order = 'gclass_id desc')
  24. {
  25. return Db::name('groupbuyclass')->where($condition)->order($order)->select()->toArray();
  26. }
  27. /**
  28. * 读取列表
  29. * @access public
  30. * @author csdeshang
  31. * @param array $condition 条件
  32. * @param int $pagesize 分页
  33. * @param int $max_deep 最大深度
  34. * @return array
  35. */
  36. public function getTreeList($condition = '', $pagesize = '', $max_deep = 1)
  37. {
  38. $gclass_list = $this->getGroupbuyclassList($condition, $pagesize);
  39. $tree_list = array();
  40. if (is_array($gclass_list)) {
  41. $tree_list = $this->_getTreeList($gclass_list, 0, 0, $max_deep);
  42. }
  43. return $tree_list;
  44. }
  45. /**
  46. * 按照顺序显示树形结构
  47. * @access public
  48. * @author csdeshang
  49. * @param array $list 列表
  50. * @param int $parent_id 父ID
  51. * @param int $deep 深度
  52. * @param int $max_deep 最大深度
  53. * @return array
  54. */
  55. private function _getTreeList($list, $parent_id, $deep = 0, $max_deep)
  56. {
  57. $result = array();
  58. foreach ($list as $node) {
  59. if ($node['gclass_parent_id'] == $parent_id) {
  60. if ($deep <= $max_deep) {
  61. $temp = $this->_getTreeList($list, $node['gclass_id'], $deep + 1, $max_deep);
  62. if (!empty($temp)) {
  63. $node['have_child'] = 1;
  64. } else {
  65. $node['have_child'] = 0;
  66. }
  67. //标记是否为叶子节点
  68. if ($deep == $max_deep) {
  69. $node['node'] = 1;
  70. } else {
  71. $node['node'] = 0;
  72. }
  73. $node['deep'] = $deep;
  74. $result[] = $node;
  75. if (!empty($temp)) {
  76. $result = array_merge($result, $temp);
  77. }
  78. unset($temp);
  79. }
  80. }
  81. }
  82. return $result;
  83. }
  84. /**
  85. * 根据编号获取所有下级编号的数组
  86. * @access public
  87. * @author csdeshang
  88. * @param array $gclass_id_array 分类id数组
  89. * @return array 数组类型的返回结果
  90. */
  91. public function getAllClassId($gclass_id_array)
  92. {
  93. $all_gclass_id_array = array();
  94. $gclass_list = $this->getGroupbuyclassList();
  95. foreach ($gclass_id_array as $gclass_id) {
  96. $all_gclass_id_array[] = $gclass_id;
  97. foreach ($gclass_list as $class) {
  98. if ($class['gclass_parent_id'] == $gclass_id) {
  99. $all_gclass_id_array[] = $class['gclass_id'];
  100. }
  101. }
  102. }
  103. return $all_gclass_id_array;
  104. }
  105. /**
  106. * 判断是否存在
  107. * @access public
  108. * @author csdeshang
  109. * @param type $condition 条件
  110. * @return boolean
  111. */
  112. public function isGroupbuyclassExist($condition)
  113. {
  114. $list = Db::name('groupbuyclass')->where($condition)->select()->toArray();
  115. if (empty($list)) {
  116. return false;
  117. } else {
  118. return true;
  119. }
  120. }
  121. /**
  122. * 增加
  123. * @access public
  124. * @author csdeshang
  125. * @param array $data 参数内容
  126. * @return bool
  127. */
  128. public function addGroupbuyclass($data)
  129. {
  130. return Db::name('groupbuyclass')->insertGetId($data);
  131. }
  132. /**
  133. * 更新
  134. * @access public
  135. * @author csdeshang
  136. * @param array $update_array 更新数据数组
  137. * @param array $where_array 更新条件数组
  138. * @return bool
  139. */
  140. public function editGroupbuyclass($update_array, $where_array)
  141. {
  142. return Db::name('groupbuyclass')->where($where_array)->update($update_array);
  143. }
  144. /**
  145. * 删除
  146. * @access public
  147. * @author csdeshang
  148. * @param array $condition 条件
  149. * @return bool
  150. */
  151. public function delGroupbuyclass($condition)
  152. {
  153. return Db::name('groupbuyclass')->where($condition)->delete();
  154. }
  155. }