Is_Login(); // 权限校验 $this->Is_Power(); } /** * [Index 场景背景列表] */ public function Index() { // 参数 $param = array_merge($_POST, $_GET); // 模型模型 $m = D('Culture/CultureSceneBackground'); // 条件 $where = $this->GetIndexWhere(); // 分页 $number = MyC('admin_page_number'); $page_param = array( 'number' => $number, 'total' => $m->where($where)->count(), 'where' => $param, 'url' => U('Culture/CultureSceneBackground/Index'), ); $page = new \My\Page($page_param); // 获取列表 $field = array('scene_background_id', 'scene_background_name', 'thumb', 'description', 'sale_price', 'is_lock', 'is_unlock_buy', 'created_at', 'updated_at'); $list = $this->SetDataHandle($m->field($field)->where($where)->limit($page->GetPageStarNumber(), $number)->order('scene_background_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( 'scene_background_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['scene_background_id']) ? array() : D('Culture/CultureSceneBackground')->find(I('scene_background_id')); $this->assign('data', $data); // 场景列表 $map['deleted_at'] = ["exp", "is null"]; $scenes = D("Culture/CultureScene")->where($map)->select(); $this->assign('scenes', $scenes); $this->display('SaveInfo'); } /** * [Save 场景背景添加/编辑] */ public function Save() { // 是否ajax请求 if(!IS_AJAX) { $this->error(L('common_unauthorized_access')); } if(isset($_POST['is_lock'])){ $_POST['is_lock'] = 1; }else{ $_POST['is_lock'] = 0; } if(isset($_POST['is_unlock_buy'])){ $_POST['is_unlock_buy'] = 1; }else{ $_POST['is_unlock_buy'] = 0; } // 添加 if(empty($_POST['scene_background_id'])) { $this->Add(); // 编辑 } else { $this->Edit(); } } /** * [Add 场景背景添加] */ private function Add() { // 场景背景模型 $m = D('Culture/CultureSceneBackground'); // 数据自动校验 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/CultureSceneBackground'); // 数据自动校验 if($m->create($_POST, 2)) { $m->updated_at = date('Y-m-d H:i:s'); // 更新数据库 if($m->where(array('scene_background_id'=>I('scene_background_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/CultureSceneBackground'); // 场景背景是否存在 $scene_background = $m->where(array('scene_background_id'=>$id))->count(); if(empty($scene_background)) { $this->ajaxReturn(L('common_user_no_exist_error'), -2); } // 删除场景背景 $update_data['deleted_at'] = date('Y-m-d H:i:s'); $state = $m->where(array('scene_background_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); } } }