Sellergoodsclass.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Sellergoodsclass extends BaseSeller
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize(); // TODO: Change the autogenerated stub
  21. }
  22. /**
  23. * 卖家商品分类
  24. *
  25. * @param
  26. * @return
  27. */
  28. public function index()
  29. {
  30. $storegoodsclass_model = model('storegoodsclass');
  31. $goods_class = $storegoodsclass_model->getTreeClassList(array('store_id' => session('store_id')), 2);
  32. $str = '';
  33. if (is_array($goods_class) and count($goods_class) > 0) {
  34. foreach ($goods_class as $key => $val) {
  35. $row[$val['storegc_id']] = $key + 1;
  36. if ($val['storegc_parent_id'] != '0'){
  37. $str .= intval($row[$val['storegc_parent_id']]) . ",";
  38. }else{
  39. $str .= "0,";
  40. }
  41. }
  42. $str = substr($str, 0, -1);
  43. }
  44. else {
  45. $str = '0';
  46. }
  47. View::assign('map', $str);
  48. View::assign('class_num', count($goods_class) - 1);
  49. View::assign('goods_class', $goods_class);
  50. $this->setSellerCurMenu('sellergoodsclass');
  51. $this->setSellerCurItem('index');
  52. return View::fetch($this->template_dir . 'index');
  53. }
  54. /*分类添加*/
  55. public function goods_class_add(){
  56. $storegoodsclass_model = model('storegoodsclass');
  57. $goods_class = $storegoodsclass_model->getStoregoodsclassList(array(
  58. 'store_id' => session('store_id'),
  59. 'storegc_parent_id' => 0
  60. ));
  61. View::assign('goods_class', $goods_class);
  62. View::assign('class_info', array('storegc_parent_id'=>input('top_class_id')));
  63. View::assign('type','add');
  64. return View::fetch($this->template_dir . 'class_add');
  65. }
  66. /*分类编辑*/
  67. public function goods_class_edit(){
  68. $class_id=input('param.top_class_id');
  69. $storegoodsclass_model = model('storegoodsclass');
  70. $class_info = $storegoodsclass_model->getStoregoodsclassInfo(array('storegc_id' => intval($class_id)));
  71. $goods_class = $storegoodsclass_model->getStoregoodsclassList(array(
  72. 'store_id' => session('store_id'),
  73. 'storegc_parent_id' => 0
  74. ));
  75. View::assign('goods_class', $goods_class);
  76. View::assign('class_info', $class_info);
  77. View::assign('type','edit');
  78. return View::fetch($this->template_dir . 'class_add');
  79. }
  80. /**
  81. * 卖家商品分类保存
  82. *
  83. * @param
  84. * @return
  85. */
  86. public function goods_class_save()
  87. {
  88. $storegoodsclass_model = model('storegoodsclass');
  89. if (input('post.type') =='edit') {
  90. $storegc_id = intval(input('post.storegc_id'));
  91. if ($storegc_id <= 0) {
  92. ds_json_encode(10001,lang('param_error'));
  93. }
  94. $class_array = array();
  95. if (input('post.storegc_name') != '') {
  96. $class_array['storegc_name'] = input('post.storegc_name');
  97. }
  98. if (input('post.storegc_parent_id') != '') {
  99. $class_array['storegc_parent_id'] = input('post.storegc_parent_id');
  100. }
  101. if (input('post.storegc_state') != '') {
  102. $class_array['storegc_state'] = input('post.storegc_state');
  103. }
  104. if (input('post.storegc_sort') != '') {
  105. $class_array['storegc_sort'] = input('post.storegc_sort');
  106. }
  107. $condition = array();
  108. $condition[] = array('store_id','=',session('store_id'));
  109. $condition[] = array('storegc_id','=',intval(input('post.storegc_id')));
  110. $state = $storegoodsclass_model->editStoregoodsclass($class_array, $condition,session('store_id'));
  111. if ($state) {
  112. ds_json_encode(10000,lang('ds_common_save_succ'));
  113. }
  114. else {
  115. ds_json_encode(10001,lang('ds_common_save_fail'));
  116. }
  117. }
  118. else {
  119. $class_array = array();
  120. $class_array['storegc_name'] = input('post.storegc_name');
  121. $class_array['storegc_parent_id'] = input('post.storegc_parent_id',0);
  122. $class_array['storegc_state'] = input('post.storegc_state');
  123. $class_array['store_id'] = session('store_id');
  124. $class_array['storegc_sort'] = input('post.storegc_sort');
  125. $state = $storegoodsclass_model->addStoregoodsclass($class_array);
  126. if ($state) {
  127. ds_json_encode(10000,lang('ds_common_save_succ'));
  128. }
  129. else {
  130. ds_json_encode(10001,lang('ds_common_save_fail'));
  131. }
  132. }
  133. }
  134. /**
  135. * 卖家商品分类删除
  136. *
  137. * @param
  138. * @return
  139. */
  140. public function drop_goods_class()
  141. {
  142. $storegoodsclass_model = model('storegoodsclass');
  143. $stcid_array = explode(',', input('param.class_id'));
  144. foreach ($stcid_array as $key => $val) {
  145. if (!is_numeric($val))
  146. unset($stcid_array[$key]);
  147. }
  148. $where = array();
  149. $where[]=array('storegc_id|storegc_parent_id','in', $stcid_array);
  150. $where[]=array('store_id','=',session('store_id'));
  151. $drop_state = $storegoodsclass_model->delStoregoodsclass($where,session('store_id'));
  152. if ($drop_state) {
  153. ds_json_encode(10000,lang('ds_common_del_succ'));
  154. }
  155. else {
  156. ds_json_encode(10001,lang('ds_common_del_fail'));
  157. }
  158. }
  159. /**
  160. * 用户中心右边,小导航
  161. *
  162. * @param string $menu_type 导航类型
  163. * @param string $name 当前导航的name
  164. * @return
  165. */
  166. protected function getSellerItemList()
  167. {
  168. $menu_array = array(
  169. array(
  170. 'name' => 'index', 'text' => lang('ds_store_class'), 'url' => (string)url('Sellergoodsclass/index')
  171. )
  172. );
  173. return $menu_array;
  174. }
  175. }