getStoregradeList($condition); // 获取分页显示 View::assign('storegrade_list', $storegrade_list); View::assign('like_storegrade_name', $like_storegrade_name); $this->setAdminCurItem('index'); return View::fetch(); } public function add() { if (!request()->isPost()) { return View::fetch('form'); } else { $data = array( 'storegrade_name' => input('post.storegrade_name'), 'storegrade_goods_limit' => input('post.storegrade_goods_limit'), 'storegrade_album_limit' => input('post.storegrade_album_limit'), 'storegrade_space_limit' => input('post.storegrade_space_limit'), 'storegrade_price' => intval(input('post.storegrade_price')), 'storegrade_description' => input('post.storegrade_description'), 'storegrade_sort' => input('post.storegrade_sort'), ); $storegrade_validate = ds_validate('storegrade'); if (!$storegrade_validate->scene('add')->check($data)) { $this->error($storegrade_validate->getError()); } //验证等级名称 if (!$this->checkGradeName(array('storegrade_name' => trim(input('post.storegrade_name'))))) { $this->error(lang('now_store_grade_name_is_there')); } //验证级别是否存在 if (!$this->checkGradeSort(array('storegrade_sort' => trim(input('post.storegrade_sort'))))) { $this->error(lang('add_gradesortexist')); } $result = model('storegrade')->addStoregrade($data); if ($result) { dsLayerOpenSuccess(lang('ds_common_op_succ'), (string)url('Storegrade/index')); } else { $this->error(lang('ds_common_op_fail')); } } } public function edit() { //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量” $storegrade_id = input('param.storegrade_id'); if (empty($storegrade_id)) { $this->error(lang('param_error')); } if (!request()->isPost()) { $storegrade = model('storegrade')->getOneStoregrade($storegrade_id); View::assign('storegrade', $storegrade); return View::fetch('form'); } else { $data = array( 'storegrade_name' => input('post.storegrade_name'), 'storegrade_goods_limit' => input('post.storegrade_goods_limit'), 'storegrade_album_limit' => input('post.storegrade_album_limit'), 'storegrade_space_limit' => input('post.storegrade_space_limit'), 'storegrade_price' => intval(input('post.storegrade_price')), 'storegrade_description' => input('post.storegrade_description'), 'storegrade_sort' => input('post.storegrade_sort'), ); $storegrade_validate = ds_validate('storegrade'); if (!$storegrade_validate->scene('edit')->check($data)) { $this->error($storegrade_validate->getError()); } //验证等级名称 if (!$this->checkGradeName(array('storegrade_name' => trim(input('post.storegrade_name')), 'storegrade_id' => intval(input('param.storegrade_id'))))) { $this->error(lang('now_store_grade_name_is_there')); } //验证级别是否存在 if (!$this->checkGradeSort(array('storegrade_sort' => trim(input('post.storegrade_sort')), 'storegrade_id' => intval(input('param.storegrade_id'))))) { $this->error(lang('add_gradesortexist')); } $result = model('storegrade')->editStoregrade($storegrade_id, $data); if ($result >= 0) { dsLayerOpenSuccess(lang('ds_common_op_succ'), (string)url('Storegrade/index')); } else { $this->error(lang('ds_common_op_fail')); } } } public function drop() { //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量” $storegrade_id = intval(input('param.storegrade_id')); if ($storegrade_id <= 0) { ds_json_encode(10001, lang('param_error')); } if ($storegrade_id == '1') { ds_json_encode(10001, lang('default_store_grade_no_del')); } //判断该等级下是否存在店铺,存在的话不能删除 if (!$this->isable_delStoregrade($storegrade_id)) { $this->error(lang('del_gradehavestore'), (string)url('Storegrade/index')); } $result = model('storegrade')->delStoregrade($storegrade_id); if ($result) { ds_json_encode(10000, lang('ds_common_del_succ')); } else { ds_json_encode(10001, lang('ds_common_del_fail')); } } /** * 查询店铺等级名称是否存在 */ private function checkGradeName($param) { $storegrade_model = model('storegrade'); $condition[] = array('storegrade_name', '=', $param['storegrade_name']); if (isset($param['storegrade_id'])) { $storegrade_id = intval($param['storegrade_id']); $condition[] = array('storegrade_id', '<>', $storegrade_id); } $list = $storegrade_model->getStoregradeList($condition); if (empty($list)) { return true; } else { return false; } } /** * 查询店铺等级是否存在 */ private function checkGradeSort($param) { $storegrade_model = model('storegrade'); $condition = array(); $condition[] = array('storegrade_sort', '=', $param['storegrade_sort']); if (isset($param['storegrade_id'])) { $storegrade_id = intval($param['storegrade_id']); $condition[] = array('storegrade_id', '<>', $storegrade_id); } $list = array(); $list = $storegrade_model->getStoregradeList($condition); if (is_array($list) && count($list) > 0) { return false; } else { return true; } } /** * 判断店铺等级是否能删除 */ public function isable_delStoregrade($storegrade_id) { //判断该等级下是否存在店铺,存在的话不能删除 $store_model = model('store'); $store_list = $store_model->getStoreList(array('grade_id' => $storegrade_id)); if (count($store_list) > 0) { return false; } return true; } /** * 获取卖家栏目列表,针对控制器下的栏目 */ protected function getAdminItemList() { $menu_array = array( array( 'name' => 'index', 'text' => lang('ds_storegrade'), 'url' => (string)url('Storegrade/index') ), ); if (request()->action() == 'add' || request()->action() == 'index') { $menu_array[] = array( 'name' => 'add', 'text' => lang('ds_new'), 'url' => "javascript:dsLayerOpen('" . (string)url('Storegrade/add') . "','" . lang('ds_new') . "')" ); } return $menu_array; } }