123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- class Sellerspec extends BaseSeller
- {
- var $_store_id;
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerspec.lang.php');
- $this->_store_id = session('store_id');
- }
-
- public function index()
- {
-
- $goodsclass_model = model('goodsclass');
- $gc_list = $goodsclass_model->getGoodsclass($this->_store_id);
- View::assign('gc_list', $gc_list);
- $this->setSellerCurItem('spec');
- $this->setSellerCurMenu('sellerspec');
- return View::fetch($this->template_dir . 'index');
- }
-
- public function add_spec()
- {
- $sp_id = intval(input('param.spid'));
- $gc_id = intval(input('param.gcid'));
-
- if ($sp_id <= 0) {
- $this->error(lang('param_error'));
- }
-
- $gc_info = model('goodsclass')->getGoodsclassInfoById($gc_id);
- View::assign('gc_info', $gc_info);
-
- $spec_model = model('spec');
- $sp_info = $spec_model->getSpecInfo($sp_id, 'sp_id,sp_name');
-
- View::assign('sp_info', $sp_info);
-
- $sp_value_list = $spec_model->getSpecvalueList(array(
- 'store_id' => $this->_store_id, 'sp_id' => $sp_id,
- 'gc_id' => $gc_id
- ));
- View::assign('sp_value_list', $sp_value_list);
- return View::fetch($this->template_dir . 'spec_add');
- }
-
- public function save_spec()
- {
- $sp_id = intval(input('post.sp_id'));
- $gc_id = intval(input('post.gc_id'));
- if ($sp_id <= 0 || $gc_id <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $spec_model = model('spec');
-
- $sv_array = input('post.sv/a');
- if (!empty($sv_array['old']) && is_array($sv_array['old'])) {
- foreach ($sv_array['old'] as $key => $value) {
- if (empty($value['name'])) {
- continue;
- }
- $where = array('spvalue_id' => $key);
- $update = array(
- 'spvalue_name' => $value['name'], 'sp_id' => $sp_id, 'gc_id' => $gc_id,
- 'store_id' => $this->_store_id,
- 'spvalue_color' => isset($value['color']) ? $value['color'] : '',
- 'spvalue_sort' => intval($value['sort'])
- );
- $spec_model->editSpecvalue($update, $where);
- }
- }
-
- if (!empty($sv_array['new']) && is_array($sv_array['new'])) {
- $insert_array = array();
- foreach ($sv_array['new'] as $value) {
- if (empty($value['name'])) {
- continue;
- }
- $tmp_insert = array(
- 'spvalue_name' => $value['name'], 'sp_id' => $sp_id, 'gc_id' => $gc_id,
- 'store_id' => $this->_store_id,
- 'spvalue_color' => isset($value['color']) ? $value['color'] : '',
- 'spvalue_sort' => intval($value['sort'])
- );
- $insert_array[] = $tmp_insert;
- }
- $spec_model->addSpecvalueALL($insert_array);
- }
- ds_json_encode(10000, lang('ds_common_op_succ'));
- }
-
- public function ajax_delspec()
- {
- $spvalue_id = intval(input('param.id'));
- if ($spvalue_id <= 0) {
- echo 'false';
- exit();
- }
- $rs = model('spec')->delSpecvalue(array('spvalue_id' => $spvalue_id, 'store_id' => $this->_store_id));
- if ($rs) {
- echo 'true';
- exit();
- } else {
- echo 'false';
- exit();
- }
- }
-
- public function ajax_class()
- {
- $id = intval(input('param.id'));
- $deep = intval(input('param.deep'));
- if ($id <= 0 || $deep <= 0 || $deep >= 4) {
- echo 'false';
- exit();
- }
- $deep += 1;
- $goodsclass_model = model('goodsclass');
-
- $gc_info = $goodsclass_model->getGoodsclassInfoById($id);
- if (empty($gc_info)) {
- echo 'false';
- exit();
- }
-
- if ($deep != 4) {
- $gc_list = $goodsclass_model->getGoodsclass($this->_store_id, $id, $deep);
- }
-
- if (!empty($gc_list)) {
- $data = array('type' => 'class', 'data' => $gc_list, 'deep' => $deep);
- } else {
-
- $type_model = model('type');
- $spec_list = $type_model->getSpecByType(array('type_id' => $gc_info['type_id']), 't.type_id, s.*');
- $data = array('type' => 'spec', 'data' => $spec_list, 'gcid' => $id, 'deep' => $deep);
- }
- echo json_encode($data);
- exit();
- }
-
- protected function getSellerItemList()
- {
- $menu_array = array(
- array('name' => 'spec', 'text' => lang('edit_product_specifications'), 'url' => 'index')
- );
- return $menu_array;
- }
- }
|