Sellergoodsclass.php 6.7 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. * ============================================================================
  13. * 控制器
  14. */
  15. class Sellergoodsclass extends BaseSeller
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellergoodsclass.lang.php');
  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. } else {
  44. $str = '0';
  45. }
  46. View::assign('map', $str);
  47. View::assign('class_num', count($goods_class) - 1);
  48. View::assign('goods_class', $goods_class);
  49. $this->setSellerCurMenu('sellergoodsclass');
  50. $this->setSellerCurItem('index');
  51. return View::fetch($this->template_dir . 'index');
  52. }
  53. /*分类添加*/
  54. public function goods_class_add()
  55. {
  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. {
  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. } else {
  118. ds_json_encode(10001, lang('ds_common_save_fail'));
  119. }
  120. } else {
  121. $class_array = array();
  122. $class_array['storegc_name'] = input('post.storegc_name');
  123. $class_array['storegc_parent_id'] = input('post.storegc_parent_id', 0);
  124. $class_array['storegc_state'] = input('post.storegc_state');
  125. $class_array['store_id'] = session('store_id');
  126. $class_array['storegc_sort'] = input('post.storegc_sort');
  127. $state = $storegoodsclass_model->addStoregoodsclass($class_array);
  128. if ($state) {
  129. ds_json_encode(10000, lang('ds_common_save_succ'));
  130. } else {
  131. ds_json_encode(10001, lang('ds_common_save_fail'));
  132. }
  133. }
  134. }
  135. /**
  136. * 卖家商品分类删除
  137. *
  138. * @param
  139. * @return
  140. */
  141. public function drop_goods_class()
  142. {
  143. $storegoodsclass_model = model('storegoodsclass');
  144. $stcid_array = explode(',', input('param.class_id'));
  145. foreach ($stcid_array as $key => $val) {
  146. if (!is_numeric($val))
  147. unset($stcid_array[$key]);
  148. }
  149. $where = array();
  150. $where[] = array('storegc_id|storegc_parent_id', 'in', $stcid_array);
  151. $where[] = array('store_id', '=', session('store_id'));
  152. $drop_state = $storegoodsclass_model->delStoregoodsclass($where, session('store_id'));
  153. if ($drop_state) {
  154. ds_json_encode(10000, lang('ds_common_del_succ'));
  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. }