123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <?php
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Sellerplate extends BaseSeller
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerplate.lang.php');
- }
- public function index()
- {
- $this->plate_list();
- }
- /**
- * 关联版式列表
- */
- public function plate_list()
- {
- // 版式列表
- $where = array();
- $where[] = array('store_id', '=', session('store_id'));
- $p_name = trim(input('get.p_name'));
- if ($p_name != '') {
- $where[] = array('storeplate_name', 'like', '%' . $p_name . '%');
- }
- $p_position = trim(input('get.p_position'));
- if (in_array($p_position, array('0', '1'))) {
- $where[] = array('storeplate_position', '=', $p_position);
- }
- $store_plate = model('storeplate');
- $plate_list = $store_plate->getStoreplateList($where, '*', 10);
- View::assign('show_page', $store_plate->page_info->render());
- View::assign('plate_list', $plate_list);
- View::assign('position', array(0 => lang('bottom'), 1 => lang('top')));
- /* 设置卖家当前菜单 */
- $this->setSellerCurMenu('sellerplate');
- /* 设置卖家当前栏目 */
- $this->setSellerCurItem('plate_list');
- echo View::fetch($this->template_dir . 'plate_list');
- exit;
- }
- /**
- * 关联版式添加
- */
- public function plate_add()
- {
- if (!request()->isPost()) {
- $plate_info = array(
- 'storeplate_name' => '',
- 'storeplate_position' => '',
- 'storeplate_content' => '',
- );
- View::assign('plate_info', $plate_info);
- /* 设置卖家当前菜单 */
- $this->setSellerCurMenu('sellerplate');
- /* 设置卖家当前栏目 */
- $this->setSellerCurItem('plate_add');
- return View::fetch($this->template_dir . 'plate_add');
- } else {
- $insert = array();
- $insert['storeplate_name'] = input('post.p_name');
- $insert['storeplate_position'] = input('post.p_position');
- $insert['storeplate_content'] = input('post.p_content');
- $insert['store_id'] = session('store_id');
- $sellerplate_validate = ds_validate('sellerplate');
- if (!$sellerplate_validate->scene('plate_add')->check($insert)) {
- ds_json_encode(10001, lang('error') . $sellerplate_validate->getError());
- }
- $result = model('storeplate')->addStoreplate($insert);
- if ($result) {
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_op_fail'));
- }
- }
- }
- /**
- * 关联版式编辑
- */
- public function plate_edit()
- {
- $storeplate_id = intval(input('param.p_id'));
- if ($storeplate_id <= 0) {
- $this->error(lang('param_error'));
- }
- if (!request()->isPost()) {
- $plate_info = model('storeplate')->getStoreplateInfo(array('storeplate_id' => $storeplate_id, 'store_id' => session('store_id')));
- View::assign('plate_info', $plate_info);
- /* 设置卖家当前菜单 */
- $this->setSellerCurMenu('sellerplate');
- /* 设置卖家当前栏目 */
- $this->setSellerCurItem('plate_edit');
- return View::fetch($this->template_dir . 'plate_add');
- } else {
- $update = array();
- $update['storeplate_name'] = input('post.p_name');
- $update['storeplate_position'] = input('post.p_position');
- $update['storeplate_content'] = input('post.p_content');
- //验证数据 BEGIN
- $sellerplate_validate = ds_validate('sellerplate');
- if (!$sellerplate_validate->scene('plate_edit')->check($update)) {
- ds_json_encode(10001, lang('error') . $sellerplate_validate->getError());
- }
- //验证数据 END
- $condition = array();
- $condition[] = array('storeplate_id', '=', $storeplate_id);
- $condition[] = array('store_id', '=', session('store_id'));
- $result = model('storeplate')->editStoreplate($update, $condition);
- if ($result) {
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_op_fail'));
- }
- }
- }
- /**
- * 删除关联版式
- */
- public function drop_plate()
- {
- $storeplate_id = input('param.p_id');
- if (!preg_match('/^[\d,]+$/i', $storeplate_id)) {
- ds_json_encode(10001, lang('param_error'));
- }
- $plateid_array = explode(',', $storeplate_id);
- $return = model('storeplate')->delStoreplate(array(array('storeplate_id', 'in', $plateid_array), array('store_id', '=', session('store_id'))));
- if ($return) {
- 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 $menu_key 当前导航的menu_key
- * @return
- */
- function getSellerItemList()
- {
- $item_list = array(
- array(
- 'name' => 'plate_list',
- 'text' => lang('associated_format'),
- 'url' => (string) url('Sellerplate/plate_list'),
- ),
- );
- if (request()->action() == 'plate_add') {
- $item_list[] = array(
- 'name' => 'plate_add',
- 'text' => lang('ds_new'),
- 'url' => (string) url('Sellerplate/plate_add'),
- );
- }
- if (request()->action() == 'plate_edit') {
- $item_list[] = array(
- 'name' => 'plate_add',
- 'text' => lang('ds_new'),
- 'url' => (string) url('Sellerplate/plate_add'),
- );
- $item_list[] = array(
- 'name' => 'plate_edit',
- 'text' => lang('ds_edit'),
- 'url' => (string) url('Sellerplate/plate_edit'),
- );
- }
- return $item_list;
- }
- }
|