Fleaclass.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 Fleaclass extends BaseModel
  17. {
  18. /**
  19. * 类别列表
  20. * @access public
  21. * @author csdeshang
  22. * @param array $condition 检索条件
  23. * @return array 数组结构的返回结果
  24. */
  25. public function getFleaclassList($condition,$field = '*',$order='fleaclass_parent_id asc,fleaclass_sort asc,fleaclass_id asc')
  26. {
  27. $result = Db::name('fleaclass')->field($field)->where($condition)->order($order)->select()->toArray();
  28. return $result;
  29. }
  30. /**
  31. * 取单个分类的内容
  32. * @access public
  33. * @author csdeshang
  34. * @param int $id 分类ID
  35. * @return array 数组类型的返回结果
  36. */
  37. public function getOneFleaclass($id)
  38. {
  39. if (intval($id) > 0) {
  40. $result = Db::name('fleaclass')->where(array('fleaclass_id'=>$id))->find();
  41. return $result;
  42. }
  43. else {
  44. return false;
  45. }
  46. }
  47. /**
  48. * 取指定分类ID的导航链接
  49. * @access public
  50. * @author csdeshang
  51. * @param int $id 父类ID/子类ID
  52. * @return array $nav_link 返回数组形式类别导航连接
  53. */
  54. public function getFleaclassNow($id = 0)
  55. {
  56. /**
  57. * 初始化链接数组
  58. */
  59. if (intval($id) > 0) {
  60. /**
  61. * 取当前类别信息
  62. */
  63. $class = self::getOneFleaclass(intval($id));
  64. /**
  65. * 是否是子类
  66. */
  67. if ($class['fleaclass_parent_id'] != 0) {
  68. $parent_1 = self::getOneFleaclass($class['fleaclass_parent_id']);
  69. if ($parent_1['fleaclass_parent_id'] != 0) {
  70. $parent_2 = self::getOneFleaclass($parent_1['fleaclass_parent_id']);
  71. if ($parent_2['fleaclass_parent_id'] != 0) {
  72. $parent_3 = self::getOneFleaclass($parent_2['fleaclass_parent_id']);
  73. $nav_link[] = array('name' => $parent_3['fleaclass_name'], 'fleaclass_id' => $parent_3['fleaclass_id']);
  74. }
  75. $nav_link[] = array('name' => $parent_2['fleaclass_name'], 'fleaclass_id' => $parent_2['fleaclass_id']);
  76. }
  77. $nav_link[] = array('name' => $parent_1['fleaclass_name'], 'fleaclass_id' => $parent_1['fleaclass_id']);
  78. }
  79. $nav_link[] = array('name' => $class['fleaclass_name'], 'fleaclass_id' => $id);
  80. }
  81. return $nav_link;
  82. }
  83. /**
  84. * 新增
  85. * @access public
  86. * @author csdeshang
  87. * @param array $data 参数内容
  88. * @return bool 布尔类型的返回结果
  89. */
  90. public function addFleaclass($data) {
  91. $result = Db::name('fleaclass')->insertGetId($data);
  92. return $result;
  93. }
  94. /**
  95. * 更新信息
  96. * @access public
  97. * @author csdeshang
  98. * @param array $data 更新数据
  99. * @return bool 布尔类型的返回结果
  100. */
  101. public function editFleaclass($condition, $data) {
  102. $result = Db::name('fleaclass')->where($condition)->update($data);
  103. return $result;
  104. }
  105. /**
  106. * 删除分类
  107. * @access public
  108. * @author csdeshang
  109. * @param int $id 记录ID
  110. * @return bool 布尔类型的返回结果
  111. */
  112. public function delFleaclass($id)
  113. {
  114. if (intval($id) > 0) {
  115. $where = " fleaclass_id = '" . intval($id) . "'";
  116. $result = Db::name('fleaclass')->where($where)->delete();
  117. return $result;
  118. }
  119. else {
  120. return false;
  121. }
  122. }
  123. /**
  124. * 取分类列表,按照深度归类
  125. * @access public
  126. * @author csdeshang
  127. * @param int $show_deep 显示深度 为空 则为不限制
  128. * @param array $condition 条件数组
  129. * @return array 数组类型的返回结果
  130. */
  131. public function getTreeClassList($show_deep = '', $condition = array())
  132. {
  133. $class_list = $this->getFleaclassList($condition);
  134. $result = $this->_getTreeClassList('0', $class_list);
  135. if (is_array($result)) {
  136. if (!empty($show_deep)) {
  137. foreach ($result as $k => $v) {
  138. if ($v['deep'] > $show_deep) {
  139. unset($result[$k]);
  140. }
  141. }
  142. }
  143. }
  144. return $result;
  145. }
  146. /**
  147. * 递归 整理分类
  148. * @access public
  149. * @author csdeshang
  150. * @param int $parent_id 父ID
  151. * @param array $class_list 类别内容集合
  152. * @param int $deep 深度
  153. * @return array $rs_row 返回数组形式的查询结果
  154. */
  155. private function _getTreeClassList($parent_id, $class_list, $deep = 1)
  156. {
  157. $result=array();
  158. if (is_array($class_list)) {
  159. foreach ($class_list as $k => $v) {
  160. if ($v['fleaclass_parent_id'] == $parent_id) {
  161. $v['deep'] = $deep;
  162. $result[] = $v;
  163. $tmp = $this->_getTreeClassList($v['fleaclass_id'], $class_list, $deep + 1);
  164. if (!empty($tmp)) {
  165. $result = @array_merge($result, $tmp);
  166. }
  167. unset($tmp);
  168. }
  169. }
  170. }
  171. return $result;
  172. }
  173. /**
  174. * 取指定分类ID下的所有子类
  175. * @access public
  176. * @author csdeshang
  177. * @param int/array $parent_id 父ID 可以单一可以为数组
  178. * @return array $rs_row 返回数组形式的查询结果
  179. */
  180. public function getChildClass($parent_id)
  181. {
  182. $all_class = $this->getFleaclassList(array());
  183. if (is_array($all_class)) {
  184. if (!is_array($parent_id)) {
  185. $parent_id = array($parent_id);
  186. }
  187. $result = array();
  188. foreach ($all_class as $k => $v) {
  189. $fleaclass_id = $v['fleaclass_id'];//返回的结果包括父类
  190. $fleaclass_parent_id = $v['fleaclass_parent_id'];
  191. if (in_array($fleaclass_id, $parent_id) || in_array($fleaclass_parent_id, $parent_id)) {
  192. $parent_id[] = $v['fleaclass_id'];
  193. $result[] = $v;
  194. }
  195. }
  196. return $result;
  197. }
  198. else {
  199. return false;
  200. }
  201. }
  202. /**
  203. * 获取指定分类的所有下一级别分类
  204. * @access public
  205. * @author csdeshang
  206. * @param int $fleaclass_id 分类ID
  207. * @return type
  208. */
  209. public function getNextLevelGoodsclassById($fleaclass_id)
  210. {
  211. return Db::name('fleaclass')->where('fleaclass_parent_id',$fleaclass_id)->select()->toArray();
  212. }
  213. /**
  214. * 更新闲置主页显示
  215. * @access public
  216. * @author csdeshang
  217. * @param array $data 更新数据
  218. * @return boolean
  219. */
  220. public function setFleaclassindex($data)
  221. {
  222. if (empty($data)) {
  223. return false;
  224. }
  225. if (is_array($data)) {
  226. $tmp = array();
  227. if (isset($data['fcindex_id1']) && $data['fcindex_id1'] != '') {
  228. $tmp['fcindex_id1'] = $data['fcindex_id1'];
  229. }
  230. if (isset($data['fcindex_id2']) && $data['fcindex_id2'] != '') {
  231. $tmp['fcindex_id2'] = $data['fcindex_id2'];
  232. }
  233. if (isset($data['fcindex_id3']) && $data['fcindex_id3'] != '') {
  234. $tmp['fcindex_id3'] = $data['fcindex_id3'];
  235. }
  236. if (isset($data['fcindex_id4']) && $data['fcindex_id4'] != '') {
  237. $tmp['fcindex_id4'] = $data['fcindex_id4'];
  238. }
  239. if (isset($data['fcindex_name1']) && $data['fcindex_name1'] != '') {
  240. $tmp['fcindex_name1'] = $data['fcindex_name1'];
  241. }
  242. if (isset($data['fcindex_name2']) && $data['fcindex_name2'] != '') {
  243. $tmp['fcindex_name2'] = $data['fcindex_name2'];
  244. }
  245. if (isset($data['fcindex_name3']) && $data['fcindex_name3'] != '') {
  246. $tmp['fcindex_name3'] = $data['fcindex_name3'];
  247. }
  248. if (isset($data['fcindex_name4']) && $data['fcindex_name4'] != '') {
  249. $tmp['fcindex_name4'] = $data['fcindex_name4'];
  250. }
  251. $where = " fcindex_code = '" . $data['fcindex_code'] . "'";
  252. $result = Db::name('fleaclassindex')->where($where)->update($tmp);
  253. return true;
  254. }
  255. else {
  256. return false;
  257. }
  258. }
  259. /**
  260. * 查询闲置主页显示设置
  261. * @access public
  262. * @author csdeshang
  263. * @param array $condition 查询条件
  264. * @param string $field 查询字段
  265. * @return type
  266. */
  267. public function getFleaclassindex($condition, $field = '*')
  268. {
  269. $result = Db::name('fleaclassindex')->field($field)->where($condition)->select()->toArray();
  270. return $result;
  271. }
  272. }