GoodsCategoryModel.class.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Model;
  15. use Think\Model;
  16. class GoodsCategoryModel extends Model{
  17. public function update($data,$cate_type='normal')
  18. {
  19. $ins_data = array();
  20. $ins_data['is_hot'] = $data['is_hot'];
  21. $ins_data['is_show'] = intval($data['is_show']);
  22. if($data['is_show_topic']){
  23. $ins_data['is_show_topic'] = intval($data['is_show_topic']);
  24. }else{
  25. $ins_data['is_show_topic'] = 0;
  26. }
  27. $ins_data['is_type_show'] = intval($data['is_type_show']);
  28. $ins_data['is_express_show'] = intval($data['is_express_show']);
  29. $ins_data['name'] = $data['name'];
  30. $ins_data['logo'] = save_media($data['logo']);
  31. $ins_data['banner'] = save_media($data['banner']);
  32. $ins_data['sort_order'] = $data['sort_order'];
  33. $ins_data['cate_type'] = $cate_type;
  34. if(isset($data['id']) && !empty($data['id']))
  35. {
  36. //更新
  37. M('lionfish_comshop_goods_category')->where( array('id' => $data['id']) )->save($ins_data);
  38. D('Seller/Operatelog')->addOperateLog('goods','修改商品分类--'.$data['name']);
  39. $id = $data['id'];
  40. } else{
  41. $ins_data['pid'] = $data['pid'];
  42. //新增
  43. M('lionfish_comshop_goods_category')->add($ins_data);
  44. D('Seller/Operatelog')->addOperateLog('goods','新增商品分类--'.$data['name']);
  45. }
  46. }
  47. public function goodscategory_modify($datas)
  48. {
  49. $datas = json_decode(html_entity_decode($datas), true);
  50. if (!is_array($datas)) {
  51. show_json(0, '分类保存失败,请重试!');
  52. }
  53. $cateids = array();
  54. $displayorder = count($datas);
  55. foreach ($datas as $row) {
  56. $cateids[] = $row['id'];
  57. M('lionfish_comshop_goods_category')->where( array('id' => $row['id']) )->save(array('pid' => 0, 'sort_order' => $displayorder));
  58. if ($row['children'] && is_array($row['children'])) {
  59. $displayorder_child = count($row['children']);
  60. foreach ($row['children'] as $child) {
  61. $cateids[] = $child['id'];
  62. M('lionfish_comshop_goods_category')->where( array('id' => $child['id']) )->save( array('pid' => $row['id'], 'sort_order' => $displayorder_child) );
  63. --$displayorder_child;
  64. if ($child['children'] && is_array($child['children'])) {
  65. $displayorder_third = count($child['children']);
  66. foreach ($child['children'] as $third) {
  67. $cateids[] = $third['id'];
  68. M('lionfish_comshop_goods_category')->where( array('id' => $third['id']) )->save( array('pid' => $child['id'], 'sort_order' => $displayorder_third) );
  69. --$displayorder_third;
  70. if ($third['children'] && is_array($third['children'])) {
  71. $displayorder_fourth = count($third['children']);
  72. foreach ($child['children'] as $fourth) {
  73. $cateids[] = $fourth['id'];
  74. M('lionfish_comshop_goods_category')->where( array('id' => $fourth['id']) )->save( array('pid' => $third['id'], 'sort_order' => $displayorder_third) );
  75. --$displayorder_fourth;
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. --$displayorder;
  83. }
  84. if (!empty($cateids)) {
  85. M('lionfish_comshop_goods_category')->where( 'id not in (' . implode(',', $cateids) . ')' )->delete();
  86. }
  87. }
  88. public function getFullCategory($fullname = false, $enabled = false,$cate_type = 'normal')
  89. {
  90. $allcategory = array();
  91. $category = M('lionfish_comshop_goods_category')->where(' cate_type="'.$cate_type.'" ')->order('pid ASC, sort_order DESC')->select();
  92. if (empty($category)) {
  93. return array();
  94. }
  95. foreach ($category as &$c) {
  96. if (empty($c['pid'])) {
  97. $allcategory[] = $c;
  98. foreach ($category as &$c1) {
  99. if ($c1['pid'] != $c['id']) {
  100. continue;
  101. }
  102. if ($fullname) {
  103. $c1['name'] = $c['name'] . '-' . $c1['name'];
  104. }
  105. $allcategory[] = $c1;
  106. foreach ($category as &$c2) {
  107. if ($c2['pid'] != $c1['id']) {
  108. continue;
  109. }
  110. if ($fullname) {
  111. $c2['name'] = $c1['name'] . '-' . $c2['name'];
  112. }
  113. $allcategory[] = $c2;
  114. foreach ($category as &$c3) {
  115. if ($c3['pid'] != $c2['id']) {
  116. continue;
  117. }
  118. if ($fullname) {
  119. $c3['name'] = $c2['name'] . '-' . $c3['name'];
  120. }
  121. $allcategory[] = $c3;
  122. }
  123. unset($c3);
  124. }
  125. unset($c2);
  126. }
  127. unset($c1);
  128. }
  129. unset($c);
  130. }
  131. return $allcategory;
  132. }
  133. public function get_parent_cateory($pid,$store_id)
  134. {
  135. $bind_list = M('store_bind_class')->where(array('seller_id' => $store_id) )->select();
  136. $list = array();
  137. if(!empty($bind_list))
  138. {
  139. $cate_ids = array();
  140. $cate_ids_str = '';
  141. foreach($bind_list as $val)
  142. {
  143. if(!empty($val['class_1']))
  144. {
  145. $cate_ids[] = $val['class_1'];
  146. }
  147. if(!empty($val['class_2']))
  148. {
  149. $cate_ids[] = $val['class_2'];
  150. }
  151. if(!empty($val['class_3']))
  152. {
  153. $cate_ids[] = $val['class_3'];
  154. }
  155. }
  156. $cate_ids_str = implode(',',$cate_ids);
  157. $list = M('goods_category')->field('id,pid,name')->where( array('pid'=>$pid,'id' => array('in',$cate_ids_str)) )->order('sort_order asc')->select();
  158. if($pid > 0)
  159. {
  160. $list = M('goods_category')->field('id,pid,name')->where( array('pid'=>$pid) )->order('sort_order asc')->select();
  161. }
  162. }
  163. return $list;
  164. }
  165. public function getInfoById($id,$field="*")
  166. {
  167. return M('goods_category')->field($field)->where( array('id'=>$id) )->find();
  168. }
  169. /**
  170. * 获取所有商品分类的子分类编号
  171. * @param $id
  172. */
  173. public function getChildCategorys($id,$field="id"){
  174. $cate_list = array();
  175. $cate_list[] = $id;
  176. $list = M('lionfish_comshop_goods_category')->field($field)->where( array('pid'=>$id) )->select();
  177. foreach($list as $k=>$v){
  178. $cate_list[] = $v['id'];
  179. $c_list = M('lionfish_comshop_goods_category')->field($field)->where( array('pid'=>$v['id']) )->select();
  180. foreach($c_list as $ck=>$cv){
  181. $cate_list[] = $cv['id'];
  182. }
  183. }
  184. return implode(',',$cate_list);
  185. }
  186. /**
  187. * 全部分类树形结构
  188. */
  189. public function getThreeCategory($enabled = false,$cate_type = 'normal')
  190. {
  191. $allcategory = array();
  192. $category = M('lionfish_comshop_goods_category')->where(' cate_type="'.$cate_type.'" ')->order('pid ASC, sort_order DESC')->select();
  193. if (empty($category)) {
  194. return array();
  195. }
  196. foreach ($category as $pk=>&$c) {
  197. if (empty($c['pid'])) {
  198. $c['level'] = 1;
  199. $c['category_id_1'] = $c['id'];
  200. $c['category_id_2'] = 0;
  201. $c['category_id_3'] = 0;
  202. if (!empty($c['logo'])) { $c['logo'] = tomedia($c['logo']);}
  203. $allcategory[$pk] = $c;
  204. foreach ($category as $sec_k=>&$c1) {
  205. if ($c1['pid'] != $c['id']) {
  206. continue;
  207. }
  208. $c1['level'] = 2;
  209. $c1['category_id_1'] = $c['id'];
  210. $c1['category_id_2'] = $c1['id'];
  211. $c1['category_id_3'] = 0;
  212. if (!empty($c1['logo'])) { $c1['logo'] = tomedia($c1['logo']);}
  213. $allcategory[$pk]['child_list'][$sec_k] = $c1;
  214. foreach ($category as $three_k=>&$c2) {
  215. if ($c2['pid'] != $c1['id']) {
  216. continue;
  217. }
  218. $c2['level'] = 3;
  219. $c2['category_id_1'] = $c['id'];
  220. $c2['category_id_2'] = $c1['id'];
  221. $c2['category_id_3'] = $c2['id'];
  222. if (!empty($c2['logo'])) { $c2['logo'] = tomedia($c2['logo']);}
  223. $allcategory[$pk]['child_list'][$sec_k]['child_list'][$three_k] = $c2;
  224. }
  225. unset($c2);
  226. }
  227. unset($c1);
  228. }
  229. unset($c);
  230. }
  231. return $allcategory;
  232. }
  233. }
  234. ?>