VipVoteController.class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * 投票管理
  5. * @author brent
  6. * @version 0.0.1
  7. */
  8. class VipVoteController 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_vip_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/VipVote')->get_vote_list($where, $page, $listRows, $count);
  45. $Page = new \Think\Page($count, $listRows);
  46. $Page->parameter .= "&p=[PAGE]";
  47. $Page->parameter .= "&listRows=" . $listRows;
  48. $Page->parameter .= "&keyword=" .$keyword;
  49. $Page = $this->page_config($Page);
  50. $show = $Page->show();
  51. $this->assign('page', $show);
  52. $this->assign('List', $list);
  53. $this->assign('Mengbaos', $mengbaos);
  54. $this->display('Index');
  55. }
  56. /**
  57. * [SaveInfo 文章添加/编辑页面]
  58. * @author Devil
  59. * @blog http://gong.gg/
  60. * @version 0.0.1
  61. * @datetime 2016-12-14T21:37:02+0800
  62. */
  63. public function SaveInfo() {
  64. // 文章信息
  65. if (empty($_REQUEST['id'])) {
  66. $data = array();
  67. } else {
  68. $data = $this->table->find(I('id'));
  69. if (empty($data)) {
  70. $data = array('id' => I('id'));
  71. }
  72. }
  73. $this->assign('data', $data);
  74. $this->display('SaveInfo');
  75. }
  76. /**
  77. * [Save 文章添加/编辑]
  78. * @author Devil
  79. * @blog http://gong.gg/
  80. * @version 0.0.1
  81. * @datetime 2016-12-14T21:37:02+0800
  82. */
  83. public function Save() {
  84. // 是否ajax请求
  85. if (!IS_AJAX) {
  86. $this->error(L('common_unauthorized_access'));
  87. }
  88. // 添加
  89. if (empty($_POST['id'])) {
  90. $this->Add();
  91. // 编辑
  92. } else {
  93. $this->Edit();
  94. }
  95. }
  96. /**
  97. * [Add 文章添加]
  98. * @author Devil
  99. * @blog http://gong.gg/
  100. * @version 0.0.1
  101. * @datetime 2016-12-18T16:20:59+0800
  102. */
  103. private function Add() {
  104. $data['uid'] = I('uid');
  105. $data['num'] = I('num');
  106. $data['act_id'] = I('act_id');
  107. // 数据添加
  108. if ($this->table->add($data)) {
  109. $this->ajaxReturn(L('common_operation_add_success'));
  110. } else {
  111. $this->ajaxReturn(L('common_operation_add_error'), -100);
  112. }
  113. }
  114. /**
  115. * [Edit 文章编辑]
  116. * @author Devil
  117. * @blog http://gong.gg/
  118. * @version 0.0.1
  119. * @datetime 2016-12-17T22:13:40+0800
  120. */
  121. private function Edit() {
  122. $id = I('id');
  123. $data = array();
  124. $data['uid'] = I('uid');
  125. $data['num'] = I('num');
  126. $data['act_id'] = I('act_id');
  127. // 数据更新
  128. if (false !== $this->table->where(array('id' => $id))->save($data)) {
  129. $this->ajaxReturn(L('common_operation_edit_success'));
  130. } else {
  131. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  132. }
  133. }
  134. /**
  135. * [Delete 删除]
  136. * @author Devil
  137. * @blog http://gong.gg/
  138. * @version 0.0.1
  139. * @datetime 2016-12-15T11:03:30+0800
  140. */
  141. public function Delete() {
  142. // 是否ajax请求
  143. if (!IS_AJAX) {
  144. $this->error(L('common_unauthorized_access'));
  145. }
  146. // 删除数据
  147. if (!empty($_POST['id'])) {
  148. // 更新
  149. if ($this->table->delete(I('id'))) {
  150. $this->ajaxReturn(L('common_operation_delete_success'));
  151. } else {
  152. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  153. }
  154. } else {
  155. $this->ajaxReturn(L('common_param_error'), -1);
  156. }
  157. }
  158. }