CultureUserController.class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * 玩家管理
  5. * @author 晓宇
  6. * @version 0.0.1
  7. * @datetime 2019-03-29
  8. */
  9. class CultureUserController extends CommonController
  10. {
  11. /**
  12. * [_initialize 前置操作-继承公共前置方法]
  13. */
  14. public function _initialize()
  15. {
  16. // 调用父类前置方法
  17. parent::_initialize();
  18. // 登录校验
  19. $this->Is_Login();
  20. // 权限校验
  21. $this->Is_Power();
  22. }
  23. /**
  24. * [Index 玩家列表]
  25. */
  26. public function Index()
  27. {
  28. // 参数
  29. $param = array_merge($_POST, $_GET);
  30. // 模型模型
  31. $m = D('Culture/CultureUser');
  32. // 条件
  33. $where = $this->GetIndexWhere();
  34. // 分页
  35. $number = MyC('admin_page_number');
  36. $page_param = array(
  37. 'number' => $number,
  38. 'total' => $m->where($where)->count(),
  39. 'where' => $param,
  40. 'url' => U('Culture/CultureUser/Index'),
  41. );
  42. $page = new \My\Page($page_param);
  43. // 获取列表
  44. $field = array('user_id', 'thumb', 'description', 'sale_price', 'created_at', 'updated_at');
  45. $list = $this->SetDataHandle($m->field($field)->where($where)->limit($page->GetPageStarNumber(), $number)->order('user_id desc')->select());
  46. // 参数
  47. $this->assign('param', $param);
  48. // 分页
  49. $this->assign('page_html', $page->GetPageHtml());
  50. // 数据列表
  51. $this->assign('list', $list);
  52. $this->display('Index');
  53. }
  54. /**
  55. * [SetDataHandle 数据处理]
  56. * @param [array] $data [玩家数据]
  57. * @return [array] [处理好的数据]
  58. */
  59. private function SetDataHandle($data)
  60. {
  61. return $data;
  62. }
  63. /**
  64. * [GetIndexWhere 玩家列表条件]
  65. */
  66. private function GetIndexWhere()
  67. {
  68. $where = array();
  69. // 模糊
  70. if(!empty($_REQUEST['keyword']))
  71. {
  72. $like_keyword = array('like', '%'.I('keyword').'%');
  73. $where[] = array(
  74. 'user_name' => $like_keyword,
  75. );
  76. }
  77. // 是否更多条件
  78. if(I('is_more', 0) == 1)
  79. {
  80. // 表达式
  81. if(!empty($_REQUEST['time_start']))
  82. {
  83. $where['created_at'][] = array('gt', I('time_start') . ' 00:00:00');
  84. }
  85. if(!empty($_REQUEST['time_end']))
  86. {
  87. $where['created_at'][] = array('lt', I('time_end') . ' 23:59:59');
  88. }
  89. }
  90. $where['deleted_at'] = ["exp", "is null"];
  91. return $where;
  92. }
  93. /**
  94. * [SaveInfo 玩家添加/编辑页面]
  95. */
  96. public function SaveInfo()
  97. {
  98. // 玩家信息
  99. $data = empty($_REQUEST['id']) ? array() : D('Culture/CultureUser')->find(I('id'));
  100. $this->assign('data', $data);
  101. $this->display('SaveInfo');
  102. }
  103. /**
  104. * [Save 玩家添加/编辑]
  105. */
  106. public function Save()
  107. {
  108. // 是否ajax请求
  109. if(!IS_AJAX)
  110. {
  111. $this->error(L('common_unauthorized_access'));
  112. }
  113. // 添加
  114. if(empty($_POST['id']))
  115. {
  116. $this->Add();
  117. // 编辑
  118. } else {
  119. $this->Edit();
  120. }
  121. }
  122. /**
  123. * [Add 玩家添加]
  124. */
  125. private function Add()
  126. {
  127. // 玩家模型
  128. $m = D('Culture/CultureUser');
  129. // 数据自动校验
  130. if($m->create($_POST, 1))
  131. {
  132. $m->created_at = date('Y-m-d H:i:s');
  133. $m->updated_at = date('Y-m-d H:i:s');
  134. // 数据添加
  135. if($m->add())
  136. {
  137. $this->ajaxReturn(L('common_operation_add_success'));
  138. } else {
  139. $this->ajaxReturn(L('common_operation_add_error'), -100);
  140. }
  141. } else {
  142. $this->ajaxReturn($m->getError(), -1);
  143. }
  144. }
  145. /**
  146. * [Edit 玩家编辑]
  147. */
  148. private function Edit()
  149. {
  150. // 玩家模型
  151. $m = D('Culture/CultureUser');
  152. // 数据自动校验
  153. if($m->create($_POST, 2))
  154. {
  155. $m->updated_at = date('Y-m-d H:i:s');
  156. // 更新数据库
  157. if($m->where(array('user_id'=>I('id')))->save())
  158. {
  159. $this->ajaxReturn(L('common_operation_edit_success'));
  160. } else {
  161. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  162. }
  163. } else {
  164. $this->ajaxReturn($m->getError(), -1);
  165. }
  166. }
  167. /**
  168. * [Delete 玩家删除]
  169. */
  170. public function Delete()
  171. {
  172. // 是否ajax请求
  173. if(!IS_AJAX)
  174. {
  175. $this->error(L('common_unauthorized_access'));
  176. }
  177. // 参数处理
  178. $id = I('id');
  179. // 删除数据
  180. if(!empty($id))
  181. {
  182. // 玩家模型
  183. $m = D('Culture/CultureUser');
  184. // 玩家是否存在
  185. $user = $m->where(array('user_id'=>$id))->count();
  186. if(empty($user))
  187. {
  188. $this->ajaxReturn(L('common_user_no_exist_error'), -2);
  189. }
  190. // 删除玩家
  191. $update_data['deleted_at'] = date('Y-m-d H:i:s');
  192. $state = $m->where(array('user_id'=>$id))->save($update_data);
  193. if($state !== false)
  194. {
  195. $this->ajaxReturn(L('common_operation_delete_success'));
  196. } else {
  197. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  198. }
  199. } else {
  200. $this->ajaxReturn(L('common_param_error'), -1);
  201. }
  202. }
  203. }