123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?php
- namespace Admin\Controller;
- /**
- * 玩家管理
- * @author 晓宇
- * @version 0.0.1
- * @datetime 2019-03-29
- */
- class CultureUserController extends CommonController
- {
- /**
- * [_initialize 前置操作-继承公共前置方法]
- */
- public function _initialize()
- {
- // 调用父类前置方法
- parent::_initialize();
- // 登录校验
- $this->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);
- }
- }
- }
|