Groupbuyclass.php 4.9 KB

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