Sellergoodsclass.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  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. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/sellergoodsclass.lang.php');
  22. }
  23. /**
  24. * 卖家商品分类
  25. *
  26. * @param
  27. * @return
  28. */
  29. public function index()
  30. {
  31. $storegoodsclass_model = model('storegoodsclass');
  32. $goods_class = $storegoodsclass_model->getTreeClassList(array('store_id' => session('store_id')), 2);
  33. $str = '';
  34. if (is_array($goods_class) and count($goods_class) > 0) {
  35. foreach ($goods_class as $key => $val) {
  36. $row[$val['storegc_id']] = $key + 1;
  37. if ($val['storegc_parent_id'] != '0'){
  38. $str .= intval($row[$val['storegc_parent_id']]) . ",";
  39. }else{
  40. $str .= "0,";
  41. }
  42. }
  43. $str = substr($str, 0, -1);
  44. }
  45. else {
  46. $str = '0';
  47. }
  48. View::assign('map', $str);
  49. View::assign('class_num', count($goods_class) - 1);
  50. View::assign('goods_class', $goods_class);
  51. $this->setSellerCurMenu('sellergoodsclass');
  52. $this->setSellerCurItem('index');
  53. return View::fetch($this->template_dir . 'index');
  54. }
  55. /*分类添加*/
  56. public function goods_class_add(){
  57. $storegoodsclass_model = model('storegoodsclass');
  58. $goods_class = $storegoodsclass_model->getStoregoodsclassList(array(
  59. 'store_id' => session('store_id'),
  60. 'storegc_parent_id' => 0
  61. ));
  62. View::assign('goods_class', $goods_class);
  63. View::assign('class_info', array('storegc_parent_id'=>input('top_class_id')));
  64. View::assign('type','add');
  65. return View::fetch($this->template_dir . 'class_add');
  66. }
  67. /*分类编辑*/
  68. public function goods_class_edit(){
  69. $class_id=input('param.top_class_id');
  70. $storegoodsclass_model = model('storegoodsclass');
  71. $class_info = $storegoodsclass_model->getStoregoodsclassInfo(array('storegc_id' => intval($class_id)));
  72. $goods_class = $storegoodsclass_model->getStoregoodsclassList(array(
  73. 'store_id' => session('store_id'),
  74. 'storegc_parent_id' => 0
  75. ));
  76. View::assign('goods_class', $goods_class);
  77. View::assign('class_info', $class_info);
  78. View::assign('type','edit');
  79. return View::fetch($this->template_dir . 'class_add');
  80. }
  81. /**
  82. * 卖家商品分类保存
  83. *
  84. * @param
  85. * @return
  86. */
  87. public function goods_class_save()
  88. {
  89. $storegoodsclass_model = model('storegoodsclass');
  90. if (input('post.type') =='edit') {
  91. $storegc_id = intval(input('post.storegc_id'));
  92. if ($storegc_id <= 0) {
  93. ds_json_encode(10001,lang('param_error'));
  94. }
  95. $class_array = array();
  96. if (input('post.storegc_name') != '') {
  97. $class_array['storegc_name'] = input('post.storegc_name');
  98. }
  99. if (input('post.storegc_parent_id') != '') {
  100. $class_array['storegc_parent_id'] = input('post.storegc_parent_id');
  101. }
  102. if (input('post.storegc_state') != '') {
  103. $class_array['storegc_state'] = input('post.storegc_state');
  104. }
  105. if (input('post.storegc_sort') != '') {
  106. $class_array['storegc_sort'] = input('post.storegc_sort');
  107. }
  108. if ($class_array['storegc_parent_id'] == $storegc_id) {
  109. ds_json_encode(10001,lang('storegc_parent_goods_class_equal_self_error'));
  110. }
  111. $condition = array();
  112. $condition[] = array('store_id','=',session('store_id'));
  113. $condition[] = array('storegc_id','=',intval(input('post.storegc_id')));
  114. $state = $storegoodsclass_model->editStoregoodsclass($class_array, $condition,session('store_id'));
  115. if ($state) {
  116. ds_json_encode(10000,lang('ds_common_save_succ'));
  117. }
  118. else {
  119. ds_json_encode(10001,lang('ds_common_save_fail'));
  120. }
  121. }
  122. else {
  123. $class_array = array();
  124. $class_array['storegc_name'] = input('post.storegc_name');
  125. $class_array['storegc_parent_id'] = input('post.storegc_parent_id',0);
  126. $class_array['storegc_state'] = input('post.storegc_state');
  127. $class_array['store_id'] = session('store_id');
  128. $class_array['storegc_sort'] = input('post.storegc_sort');
  129. $state = $storegoodsclass_model->addStoregoodsclass($class_array);
  130. if ($state) {
  131. ds_json_encode(10000,lang('ds_common_save_succ'));
  132. }
  133. else {
  134. ds_json_encode(10001,lang('ds_common_save_fail'));
  135. }
  136. }
  137. }
  138. /**
  139. * 卖家商品分类删除
  140. *
  141. * @param
  142. * @return
  143. */
  144. public function drop_goods_class()
  145. {
  146. $storegoodsclass_model = model('storegoodsclass');
  147. $stcid_array = explode(',', input('param.class_id'));
  148. foreach ($stcid_array as $key => $val) {
  149. if (!is_numeric($val))
  150. unset($stcid_array[$key]);
  151. }
  152. $where = array();
  153. $where[]=array('storegc_id|storegc_parent_id','in', $stcid_array);
  154. $where[]=array('store_id','=',session('store_id'));
  155. $drop_state = $storegoodsclass_model->delStoregoodsclass($where,session('store_id'));
  156. if ($drop_state) {
  157. ds_json_encode(10000,lang('ds_common_del_succ'));
  158. }
  159. else {
  160. ds_json_encode(10001,lang('ds_common_del_fail'));
  161. }
  162. }
  163. /**
  164. * 用户中心右边,小导航
  165. *
  166. * @param string $menu_type 导航类型
  167. * @param string $name 当前导航的name
  168. * @return
  169. */
  170. protected function getSellerItemList()
  171. {
  172. $menu_array = array(
  173. array(
  174. 'name' => 'index', 'text' => lang('ds_store_class'), 'url' => (string)url('Sellergoodsclass/index')
  175. )
  176. );
  177. return $menu_array;
  178. }
  179. }