Groupbuyclass.php 5.3 KB

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