Sellergoodsclass.php 7.4 KB

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