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