Fleaclass.php 9.1 KB

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