VoteController.class.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * 投票管理
  5. * @author brent
  6. * @version 0.0.1
  7. */
  8. class VoteController extends CommonController {
  9. protected $table = ''; //表名
  10. /**
  11. * [_initialize 前置操作-继承公共前置方法]
  12. * @author Devil
  13. * @blog http://gong.gg/
  14. * @version 0.0.1
  15. * @datetime 2016-12-03T12:39:08+0800
  16. */
  17. public function _initialize() {
  18. // 调用父类前置方法
  19. parent::_initialize();
  20. // 登录校验
  21. $this->Is_Login();
  22. // 权限校验
  23. $this->Is_Power();
  24. //要执行的表
  25. $this->table = M('activity_vote');
  26. }
  27. /**
  28. * [Index 列表]
  29. * @author Devil
  30. * @blog http://gong.gg/
  31. * @version 0.0.1
  32. * @datetime 2016-12-06T21:31:53+0800
  33. */
  34. public function Index() {
  35. $where = array();
  36. $listRows = I('listRows') ? I('listRows') : 100;
  37. $keyword = I("keyword", "", "trim");
  38. $keyword && $where['uid'] = array('like', '%' . $keyword . '%');
  39. if (isset($keyword) && !empty($keyword)) {
  40. $this->assign('keyword', $keyword);
  41. }
  42. $page = I('p') ? I('p') : 1;
  43. $this->assign('p', $page);
  44. $list = D('Admin/Vote')->get_vote_list($where, $page, $listRows, $count);
  45. $mengbaos = M('activity_mengbao')->getField('id,name',true);
  46. $Page = new \Think\Page($count, $listRows);
  47. $Page->parameter .= "&p=[PAGE]";
  48. $Page->parameter .= "&listRows=" . $listRows;
  49. $Page->parameter .= "&keyword=" .$keyword;
  50. $Page = $this->page_config($Page);
  51. $show = $Page->show();
  52. $this->assign('page', $show);
  53. $this->assign('List', $list);
  54. $this->assign('Mengbaos', $mengbaos);
  55. $this->display('Index');
  56. }
  57. /**
  58. * [SaveInfo 文章添加/编辑页面]
  59. * @author Devil
  60. * @blog http://gong.gg/
  61. * @version 0.0.1
  62. * @datetime 2016-12-14T21:37:02+0800
  63. */
  64. public function SaveInfo() {
  65. // 文章信息
  66. if (empty($_REQUEST['id'])) {
  67. $data = array();
  68. } else {
  69. $data = $this->table->find(I('id'));
  70. if (empty($data)) {
  71. $data = array('id' => I('id'));
  72. }
  73. }
  74. $this->assign('data', $data);
  75. $this->display('SaveInfo');
  76. }
  77. /**
  78. * [Save 文章添加/编辑]
  79. * @author Devil
  80. * @blog http://gong.gg/
  81. * @version 0.0.1
  82. * @datetime 2016-12-14T21:37:02+0800
  83. */
  84. public function Save() {
  85. // 是否ajax请求
  86. if (!IS_AJAX) {
  87. $this->error(L('common_unauthorized_access'));
  88. }
  89. // 添加
  90. if (empty($_POST['id'])) {
  91. $this->Add();
  92. // 编辑
  93. } else {
  94. $this->Edit();
  95. }
  96. }
  97. /**
  98. * [Add 文章添加]
  99. * @author Devil
  100. * @blog http://gong.gg/
  101. * @version 0.0.1
  102. * @datetime 2016-12-18T16:20:59+0800
  103. */
  104. private function Add() {
  105. $data['uid'] = I('uid');
  106. $data['num'] = I('num');
  107. $data['act_id'] = I('act_id');
  108. $data['date'] = I('date');
  109. $data['created_at'] = I('created_at');
  110. // 数据添加
  111. if ($this->table->add($data)) {
  112. $this->ajaxReturn(L('common_operation_add_success'));
  113. } else {
  114. $this->ajaxReturn(L('common_operation_add_error'), -100);
  115. }
  116. }
  117. /**
  118. * [Edit 文章编辑]
  119. * @author Devil
  120. * @blog http://gong.gg/
  121. * @version 0.0.1
  122. * @datetime 2016-12-17T22:13:40+0800
  123. */
  124. private function Edit() {
  125. $id = I('id');
  126. $data = array();
  127. $data['uid'] = I('uid');
  128. $data['num'] = I('num');
  129. $data['act_id'] = I('act_id');
  130. $data['date'] = I('date');
  131. $data['created_at'] = I('created_at');
  132. // 数据更新
  133. if (false !== $this->table->where(array('id' => $id))->save($data)) {
  134. $this->ajaxReturn(L('common_operation_edit_success'));
  135. } else {
  136. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  137. }
  138. }
  139. /**
  140. * [Delete 删除]
  141. * @author Devil
  142. * @blog http://gong.gg/
  143. * @version 0.0.1
  144. * @datetime 2016-12-15T11:03:30+0800
  145. */
  146. public function Delete() {
  147. // 是否ajax请求
  148. if (!IS_AJAX) {
  149. $this->error(L('common_unauthorized_access'));
  150. }
  151. // 删除数据
  152. if (!empty($_POST['id'])) {
  153. // 更新
  154. if ($this->table->delete(I('id'))) {
  155. $this->ajaxReturn(L('common_operation_delete_success'));
  156. } else {
  157. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  158. }
  159. } else {
  160. $this->ajaxReturn(L('common_param_error'), -1);
  161. }
  162. }
  163. }