DaojuController.class.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * 样式管理
  5. * @author brent
  6. * @version 0.0.1
  7. */
  8. class DaojuController 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_daoju');
  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. //关键字
  36. $keyword = I('keyword');
  37. if($keyword){
  38. $where['uid'] = ['like',"%$keyword%"];
  39. }
  40. $listRows = I('listRows',100,'intval');
  41. if($p = I('p',1,'intval')){
  42. $offset = ($p-1)*$listRows;
  43. }
  44. $acts = M('activity_v2')->field('id,activity_name')->select();
  45. $this->assign('acts', $acts);
  46. //活动id
  47. $act_id = trim(I('act_id'));
  48. if($act_id){
  49. $where['act_id'] = $act_id;
  50. }else{
  51. $this->display('Index');
  52. die;
  53. }
  54. $List = M('activity_daoju')
  55. ->where($where)
  56. ->limit($offset,$listRows)
  57. ->select();
  58. $activitys = M('activity_v2')->field('id,activity_name,prize_list')->where(['id'=>$act_id])->select();
  59. foreach($activitys as $row){
  60. $activity_info[$row['id']] = ['activity_name'=>$row['activity_name']];
  61. }
  62. // var_dump($activity_info);die;
  63. foreach ($List as $key=>$row) {
  64. $List[$key]['activity_name'] = $activity_info[$row['act_id']]['activity_name'];
  65. }
  66. if(I('model')=='exportExcel'){
  67. $this->exportPrizeLog($List);
  68. die;
  69. }
  70. // var_dump($List);die;
  71. $count = $this->table->alias('pl')->where($where)->count();
  72. $Page = new \Think\Page($count, $listRows);
  73. $Page->parameter .= "&p=[PAGE]";
  74. $Page->parameter .= "&act_id=".$act_id;
  75. $Page->parameter .= "&keyword=".$keyword;
  76. $Page = $this->page_config($Page);
  77. $show = $Page->show();
  78. $this->assign('page', $show);
  79. $this->assign('List', $List);
  80. //获取所有活动
  81. $this->assign('keyword', $keyword);
  82. $this->assign('act_id', $act_id);
  83. $this->display('Index');
  84. }
  85. public function exportPrizeLog($data)
  86. {
  87. $title = array(
  88. 'id' => array('col' => 'A', 'name' => '抽奖记录ID'),
  89. 'iptv_user_id' => array('col' => 'B', 'name' => '用户ID'),
  90. 'prize_name' => array('col' => 'C', 'name' => '中奖产品'),
  91. 'user_phone' => array('col' => 'D', 'name' => '联系方式'),
  92. 'activity_name' => array('col' => 'E', 'name' => '活动名称'),
  93. 'created_at' => array('col' => 'F', 'name' => '中奖时间'),
  94. );
  95. // Excel驱动导出数据
  96. $excel = new \My\Excel(array('filename' => '中奖记录', 'title' => $title, 'data' => $data, 'msg' => L('common_not_data_tips')));
  97. $excel->Export();
  98. }
  99. /**
  100. * [SaveInfo 文章添加/编辑页面]
  101. * @author Devil
  102. * @blog http://gong.gg/
  103. * @version 0.0.1
  104. * @datetime 2016-12-14T21:37:02+0800
  105. */
  106. public function SaveInfo() {
  107. // 文章信息
  108. if (empty($_REQUEST['id'])) {
  109. $data = array();
  110. } else {
  111. $data = $this->table->find(I('id'));
  112. if (empty($data)) {
  113. $data = array('id' => I('id'));
  114. }
  115. }
  116. $this->assign('data', $data);
  117. $this->display('SaveInfo');
  118. }
  119. /**
  120. * [Save 文章添加/编辑]
  121. * @author Devil
  122. * @blog http://gong.gg/
  123. * @version 0.0.1
  124. * @datetime 2016-12-14T21:37:02+0800
  125. */
  126. public function Save() {
  127. // 是否ajax请求
  128. if (!IS_AjAX) {
  129. $this->error(L('common_unauthorized_access'));
  130. }
  131. // 添加
  132. if (empty($_POST['id'])) {
  133. $this->Add();
  134. // 编辑
  135. } else {
  136. $this->Edit();
  137. }
  138. }
  139. /**
  140. * [Add 文章添加]
  141. * @author Devil
  142. * @blog http://gong.gg/
  143. * @version 0.0.1
  144. * @datetime 2016-12-18T16:20:59+0800
  145. */
  146. private function Add() {
  147. $m = $this->table;
  148. $data['created_at'] = date('Y-m-d H:i:s', time());
  149. $data['prize_name'] = I('prize_name');
  150. $data['prize_img'] = I('prize_img');
  151. $data['prize_num'] = I('prize_num');
  152. // 数据添加
  153. if ($m->add($data)) {
  154. echo 100;
  155. } else {
  156. echo -100;
  157. }
  158. }
  159. /**
  160. * [Edit 文章编辑]
  161. * @author Devil
  162. * @blog http://gong.gg/
  163. * @version 0.0.1
  164. * @datetime 2016-12-17T22:13:40+0800
  165. */
  166. private function Edit() {
  167. $data = array();
  168. $m=$this->table;
  169. // 额外数据处理
  170. $data['created_at'] = date('Y-m-d H:i:s', time());
  171. $data['created_at'] = date('Y-m-d H:i:s', time());
  172. $data['prize_name'] = I('prize_name');
  173. $data['prize_img'] = I('prize_img');
  174. $data['prize_num'] = I('prize_num');
  175. // 数据更新
  176. if ($m->where(array('id' => I('id')))->save($data)) {
  177. echo 100;
  178. } else {
  179. echo -100;
  180. }
  181. }
  182. /**
  183. * [Delete 删除]
  184. * @author Devil
  185. * @blog http://gong.gg/
  186. * @version 0.0.1
  187. * @datetime 2016-12-15T11:03:30+0800
  188. */
  189. public function Delete() {
  190. // 是否ajax请求
  191. if (!IS_AJAX) {
  192. $this->error(L('common_unauthorized_access'));
  193. }
  194. // 删除数据
  195. if (!empty($_POST['id'])) {
  196. // 更新
  197. if ($this->table->delete(I('id'))) {
  198. $this->ajaxReturn(L('common_operation_delete_success'));
  199. } else {
  200. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  201. }
  202. } else {
  203. $this->ajaxReturn(L('common_param_error'), -1);
  204. }
  205. }
  206. }