Is_Login(); // 权限校验 $this->Is_Power(); } /** * [Index 宠物类型列表] */ public function Index() { // 参数 $param = array_merge($_POST, $_GET); // 模型模型 $m = D('Culture/CulturePetType'); // 条件 $where = $this->GetIndexWhere(); // 分页 $number = MyC('admin_page_number'); $page_param = array( 'number' => $number, 'total' => $m->where($where)->count(), 'where' => $param, 'url' => U('Culture/CulturePetType/Index'), ); $page = new \My\Page($page_param); // 获取列表 $field = array('pet_type_id', 'pet_type_name', 'thumb', 'description', 'created_at', 'updated_at'); $list = $this->SetDataHandle($m->field($field)->where($where)->limit($page->GetPageStarNumber(), $number)->order('pet_type_id desc')->select()); // 参数 $this->assign('param', $param); // 分页 $this->assign('page_html', $page->GetPageHtml()); // 数据列表 $this->assign('list', $list); $this->display('Index'); } /** * [SetDataHandle 数据处理] * @param [array] $data [宠物类型数据] * @return [array] [处理好的数据] */ private function SetDataHandle($data) { return $data; } /** * [GetIndexWhere 宠物类型列表条件] */ private function GetIndexWhere() { $where = array(); // 模糊 if(!empty($_REQUEST['keyword'])) { $like_keyword = array('like', '%'.I('keyword').'%'); $where[] = array( 'pet_type_name' => $like_keyword, ); } // 是否更多条件 if(I('is_more', 0) == 1) { // 表达式 if(!empty($_REQUEST['time_start'])) { $where['created_at'][] = array('gt', I('time_start') . ' 00:00:00'); } if(!empty($_REQUEST['time_end'])) { $where['created_at'][] = array('lt', I('time_end') . ' 23:59:59'); } } $where['deleted_at'] = ["exp", "is null"]; return $where; } /** * [SaveInfo 宠物类型添加/编辑页面] */ public function SaveInfo() { // 宠物类型信息 $data = empty($_REQUEST['pet_type_id']) ? array() : D('Culture/CulturePetType')->find(I('pet_type_id')); $this->assign('data', $data); // 场景信息 $scene_list = D('Culture/CultureScene')->field("scene_id, scene_name")->where($map)->select(); $this->assign('scene_list', $scene_list); $this->display('SaveInfo'); } /** * [Save 宠物类型添加/编辑] */ public function Save() { // 是否ajax请求 if(!IS_AJAX) { $this->error(L('common_unauthorized_access')); } // 添加 if(empty($_POST['pet_type_id'])) { $this->Add(); // 编辑 } else { $this->Edit(); } } /** * [Add 宠物类型添加] */ private function Add() { // 宠物类型模型 $m = D('Culture/CulturePetType'); // 数据自动校验 if($m->create($_POST, 1)) { $m->created_at = date('Y-m-d H:i:s'); $m->updated_at = date('Y-m-d H:i:s'); // 数据添加 if($m->add()) { $this->ajaxReturn(L('common_operation_add_success')); } else { $this->ajaxReturn(L('common_operation_add_error'), -100); } } else { $this->ajaxReturn($m->getError(), -1); } } /** * [Edit 宠物类型编辑] */ private function Edit() { // 宠物类型模型 $m = D('Culture/CulturePetType'); // 数据自动校验 if($m->create($_POST, 2)) { $m->updated_at = date('Y-m-d H:i:s'); // 更新数据库 if($m->where(array('pet_type_id'=>I('pet_type_id')))->save()) { $this->ajaxReturn(L('common_operation_edit_success')); } else { $this->ajaxReturn(L('common_operation_edit_error'), -100); } } else { $this->ajaxReturn($m->getError(), -1); } } /** * [Delete 宠物类型删除] */ public function Delete() { // 是否ajax请求 if(!IS_AJAX) { $this->error(L('common_unauthorized_access')); } // 参数处理 $id = I('id'); // 删除数据 if(!empty($id)) { // 宠物类型模型 $m = D('Culture/CulturePetType'); // 宠物类型是否存在 $scene = $m->where(array('pet_type_id'=>$id))->count(); if(empty($scene)) { $this->ajaxReturn(L('common_user_no_exist_error'), -2); } // 删除宠物类型 $update_data['deleted_at'] = date('Y-m-d H:i:s'); $state = $m->where(array('pet_type_id'=>$id))->save($update_data); if($state !== false) { $this->ajaxReturn(L('common_operation_delete_success')); } else { $this->ajaxReturn(L('common_operation_delete_error'), -100); } } else { $this->ajaxReturn(L('common_param_error'), -1); } } }