Fleaclass.php 9.4 KB

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