Sellergoodsclass.php 6.5 KB

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