flea_class.model.php 7.6 KB

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