GoodsCategoryController.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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\Controller;
  15. class GoodsCategoryController extends CommonController{
  16. protected function _initialize(){
  17. parent::_initialize();
  18. $this->breadcrumb1='商品管理';
  19. $this->breadcrumb2='商品分类';
  20. }
  21. public function index(){
  22. $sql='SELECT id,pid,name,logo FROM '
  23. .C('DB_PREFIX').'goods_category';
  24. $cate = M()->query($sql);
  25. foreach($cate as $key => $val)
  26. {
  27. $val['name'] = $val['name'].'( id = '.$val['id'].' )';
  28. $cate[$key] = $val;
  29. }
  30. $list =list_to_tree($cate);
  31. //$this->list=json_encode($list);
  32. $this->list = $list;
  33. $this->display();
  34. }
  35. function add(){
  36. if(IS_POST){
  37. $d = array();
  38. $d['name']=I('name');
  39. $d['pid']=I('id');
  40. $d['sort_order']=I('sort_order');
  41. $d['c_sort_order']=I('c_sort_order');
  42. $d['is_search'] = I('is_search');
  43. $d['is_hot'] = I('is_hot');
  44. $d['is_haitao'] = I('is_haitao');
  45. $d['logo'] = I('image');
  46. $id=M('goods_category')->add($d);
  47. if($id){
  48. $data['name'] =$d['name'];
  49. $data['id']=$id;
  50. $this->ajaxReturn($data);
  51. die();
  52. }else{
  53. die();
  54. }
  55. }
  56. }
  57. function edit(){
  58. if(IS_POST){
  59. $d['id']=I('id');
  60. $d['name']=I('name');
  61. $d['sort_order']=I('sort_order');
  62. $d['c_sort_order']=I('c_sort_order');
  63. $d['logo'] = I('image');
  64. $d['is_search'] = I('is_search');
  65. $d['is_hot'] = I('is_hot');
  66. $d['is_haitao'] = I('is_haitao');
  67. $category=M('goods_category')->find($d['id']);
  68. $r=M('goods_category')->save($d);
  69. if($r){
  70. $data['success']='修改成功';
  71. $data['name']=$d['name'];
  72. $this->ajaxReturn($data);
  73. die();
  74. }else{
  75. $data['err']='修改失败';
  76. $this->ajaxReturn($data);
  77. die();
  78. }
  79. }
  80. }
  81. function get_info(){
  82. if(IS_POST){
  83. $id=I('id');
  84. $d=M('goods_category')->find($id);
  85. $data['name']=$d['name'];
  86. $data['logo']=$d['logo'];
  87. $data['is_search'] = $d['is_search'];
  88. $data['is_hot']=$d['is_hot'];
  89. $data['is_haitao']=$d['is_haitao'];
  90. $data['c_sort_order']=$d['c_sort_order'];
  91. if(!empty($d['logo']))
  92. {
  93. $data['thumb_image'] = resize($d['logo'], 100, 100);
  94. }else {
  95. $data['thumb_image'] = '';
  96. }
  97. $data['sort_order']=$d['sort_order'];
  98. $this->ajaxReturn($data);
  99. }
  100. }
  101. function del(){
  102. if(IS_POST){
  103. $id=I('post.id');
  104. if(M('goods_category')->where('pid='.$id)->find()){
  105. $data['err']='请先删除子节点!!';
  106. $this->ajaxReturn($data);
  107. die;
  108. }
  109. $res1 = M('goods_to_category')->where(array('class_id1'=>$id))->select();
  110. if(!empty($res1))
  111. {
  112. //goods"
  113. foreach($res1 as $val)
  114. {
  115. M('goods')->where( array('goods_id' => $val['goods_id']) )->save( array('status' => 0) );
  116. }
  117. }
  118. $res2 = M('goods_to_category')->where(array('class_id2'=>$id))->select();
  119. if(!empty($res2))
  120. {
  121. foreach($res2 as $val)
  122. {
  123. M('goods')->where( array('goods_id' => $val['goods_id']) )->save( array('status' => 0) );
  124. }
  125. }
  126. $res3 = M('goods_to_category')->where(array('class_id3'=>$id))->select();
  127. if(!empty($res3))
  128. {
  129. foreach($res3 as $val)
  130. {
  131. M('goods')->where( array('goods_id' => $val['goods_id']) )->save( array('status' => 0) );
  132. }
  133. }
  134. if( !empty($res1) || !empty($res2) || !empty($res3)){
  135. //$data['err']='请先删除该分类下商品!!';
  136. //$this->ajaxReturn($data);
  137. //die;
  138. }
  139. if(M('goods_category')->where('id='.$id)->delete()){
  140. $data['success']='删除成功';
  141. $this->ajaxReturn($data);
  142. die();
  143. }
  144. }
  145. }
  146. function autocomplete(){
  147. $json = array();
  148. $filter_name=I('filter_name');
  149. if (isset($filter_name)) {
  150. $sql='SELECT id,name FROM '.c('DB_PREFIX')."goods_category where name LIKE'%".$filter_name."%' LIMIT 0,20";
  151. }else{
  152. $sql='SELECT id,name FROM '.c('DB_PREFIX')."goods_category LIMIT 0,20";
  153. }
  154. $results = M('goods_category')->query($sql);
  155. foreach ($results as $result) {
  156. $json[] = array(
  157. 'category_id' => $result['id'],
  158. 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
  159. );
  160. }
  161. $this->ajaxReturn($json);
  162. }
  163. }
  164. ?>