Groupbuyclass.php 5.1 KB

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