123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Sellergoodsclass extends BaseSeller
- {
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellergoodsclass.lang.php');
- }
- /**
- * 卖家商品分类
- *
- * @param
- * @return
- */
- public function index()
- {
- $storegoodsclass_model = model('storegoodsclass');
- $goods_class = $storegoodsclass_model->getTreeClassList(array('store_id' => session('store_id')), 2);
- $str = '';
- if (is_array($goods_class) and count($goods_class) > 0) {
- foreach ($goods_class as $key => $val) {
- $row[$val['storegc_id']] = $key + 1;
- if ($val['storegc_parent_id'] != '0') {
- $str .= intval($row[$val['storegc_parent_id']]) . ",";
- } else {
- $str .= "0,";
- }
- }
- $str = substr($str, 0, -1);
- } else {
- $str = '0';
- }
- View::assign('map', $str);
- View::assign('class_num', count($goods_class) - 1);
- View::assign('goods_class', $goods_class);
- $this->setSellerCurMenu('sellergoodsclass');
- $this->setSellerCurItem('index');
- return View::fetch($this->template_dir . 'index');
- }
- /*分类添加*/
- public function goods_class_add()
- {
- $storegoodsclass_model = model('storegoodsclass');
- $goods_class = $storegoodsclass_model->getStoregoodsclassList(array(
- 'store_id' => session('store_id'),
- 'storegc_parent_id' => 0
- ));
- View::assign('goods_class', $goods_class);
- View::assign('class_info', array('storegc_parent_id' => input('top_class_id')));
- View::assign('type', 'add');
- return View::fetch($this->template_dir . 'class_add');
- }
- /*分类编辑*/
- public function goods_class_edit()
- {
- $class_id = input('param.top_class_id');
- $storegoodsclass_model = model('storegoodsclass');
- $class_info = $storegoodsclass_model->getStoregoodsclassInfo(array('storegc_id' => intval($class_id)));
- $goods_class = $storegoodsclass_model->getStoregoodsclassList(array(
- 'store_id' => session('store_id'),
- 'storegc_parent_id' => 0
- ));
- View::assign('goods_class', $goods_class);
- View::assign('class_info', $class_info);
- View::assign('type', 'edit');
- return View::fetch($this->template_dir . 'class_add');
- }
- /**
- * 卖家商品分类保存
- *
- * @param
- * @return
- */
- public function goods_class_save()
- {
- $storegoodsclass_model = model('storegoodsclass');
- if (input('post.type') == 'edit') {
- $storegc_id = intval(input('post.storegc_id'));
- if ($storegc_id <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $class_array = array();
- if (input('post.storegc_name') != '') {
- $class_array['storegc_name'] = input('post.storegc_name');
- }
- if (input('post.storegc_parent_id') != '') {
- $class_array['storegc_parent_id'] = input('post.storegc_parent_id');
- }
- if (input('post.storegc_state') != '') {
- $class_array['storegc_state'] = input('post.storegc_state');
- }
- if (input('post.storegc_sort') != '') {
- $class_array['storegc_sort'] = input('post.storegc_sort');
- }
- if ($class_array['storegc_parent_id'] == $storegc_id) {
- ds_json_encode(10001, lang('storegc_parent_goods_class_equal_self_error'));
- }
- $condition = array();
- $condition[] = array('store_id', '=', session('store_id'));
- $condition[] = array('storegc_id', '=', intval(input('post.storegc_id')));
- $state = $storegoodsclass_model->editStoregoodsclass($class_array, $condition, session('store_id'));
- if ($state) {
- ds_json_encode(10000, lang('ds_common_save_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_save_fail'));
- }
- } else {
- $class_array = array();
- $class_array['storegc_name'] = input('post.storegc_name');
- $class_array['storegc_parent_id'] = input('post.storegc_parent_id', 0);
- $class_array['storegc_state'] = input('post.storegc_state');
- $class_array['store_id'] = session('store_id');
- $class_array['storegc_sort'] = input('post.storegc_sort');
- $state = $storegoodsclass_model->addStoregoodsclass($class_array);
- if ($state) {
- ds_json_encode(10000, lang('ds_common_save_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_save_fail'));
- }
- }
- }
- /**
- * 卖家商品分类删除
- *
- * @param
- * @return
- */
- public function drop_goods_class()
- {
- $storegoodsclass_model = model('storegoodsclass');
- $stcid_array = explode(',', input('param.class_id'));
- foreach ($stcid_array as $key => $val) {
- if (!is_numeric($val))
- unset($stcid_array[$key]);
- }
- $where = array();
- $where[] = array('storegc_id|storegc_parent_id', 'in', $stcid_array);
- $where[] = array('store_id', '=', session('store_id'));
- $drop_state = $storegoodsclass_model->delStoregoodsclass($where, session('store_id'));
- if ($drop_state) {
- ds_json_encode(10000, lang('ds_common_del_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_del_fail'));
- }
- }
- /**
- * 用户中心右边,小导航
- *
- * @param string $menu_type 导航类型
- * @param string $name 当前导航的name
- * @return
- */
- protected function getSellerItemList()
- {
- $menu_array = array(
- array(
- 'name' => 'index', 'text' => lang('ds_store_class'), 'url' => (string)url('Sellergoodsclass/index')
- )
- );
- return $menu_array;
- }
- }
|