Fleaclass.php 9.5 KB

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