GoodsCategoryModel.class.php 7.4 KB

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