AdminActiveController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: Powerless < wzxaini9@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\love\controller;
  12. use app\common\Excel;
  13. use app\common\Fun;
  14. use app\love\model\ActiveApplyModel;
  15. use app\love\model\ActiveModel;
  16. use cmf\controller\AdminBaseController;
  17. class AdminActiveController extends AdminBaseController
  18. {
  19. /**
  20. * 列表
  21. */
  22. public function index()
  23. {
  24. $list = ActiveModel::paginate(10);
  25. foreach ($list as $v) {
  26. $v['url'] = urlencode(url('love/Scene/wechat', ['active_id' => $v['id']], true, true));
  27. }
  28. // 获取分页显示
  29. $page = $list->render();
  30. $this->assign('list', $list);
  31. $this->assign('page', $page);
  32. // 渲染模板输出
  33. return $this->fetch();
  34. }
  35. /**
  36. * 添加
  37. */
  38. public function add()
  39. {
  40. return $this->fetch();
  41. }
  42. /**
  43. * 添加提交
  44. */
  45. public function addPost()
  46. {
  47. if ($this->request->isPost()) {
  48. $data = $this->request->param();
  49. $post = $data['post'];
  50. if (empty($post['start_time'])) {
  51. $this->error('请选择开始时间');
  52. }
  53. if (empty($post['end_time'])) {
  54. $this->error('请选择结束时间');
  55. }
  56. $post['create_time'] = $post['update_time'] = time();
  57. $post['start_time'] = strtotime($post['start_time']);
  58. $post['end_time'] = strtotime($post['end_time']);
  59. ActiveModel::create($post);
  60. $this->success('添加成功!', url('index'));
  61. }
  62. }
  63. /**
  64. * 编辑
  65. */
  66. public function edit()
  67. {
  68. $id = $this->request->param('id', 0, 'intval');
  69. $post = ActiveModel::get($id);
  70. $this->assign('post', $post);
  71. return $this->fetch();
  72. }
  73. /**
  74. * 编辑提交
  75. */
  76. public function editPost()
  77. {
  78. if ($this->request->isPost()) {
  79. $data = $this->request->param();
  80. $post = $data['post'];
  81. if (empty($post['start_time'])) {
  82. $this->error('请选择开始时间');
  83. }
  84. if (empty($post['end_time'])) {
  85. $this->error('请选择结束时间');
  86. }
  87. $post['create_time'] = $post['update_time'] = time();
  88. $post['start_time'] = strtotime($post['start_time']);
  89. $post['end_time'] = strtotime($post['end_time']);
  90. ActiveModel::update($post, ['id' => $post['id']]);
  91. $this->success('编辑成功!', url('index'));
  92. }
  93. }
  94. /**
  95. * 审核列表
  96. */
  97. public function applyList()
  98. {
  99. $param = $this->request->param();
  100. $this->assign('id', $param['id']);
  101. $this->assign('check_status', $param['check_status'] ?? 0);
  102. $this->assign('sex', $param['sex'] ?? 0);
  103. $where = [
  104. ['active_id', '=', $param['id']],
  105. ];
  106. if (!empty($param['check_status'])) {
  107. $where[] = ['cmf_active_apply.check_status', '=', $param['check_status']];
  108. }
  109. $sexWhere = [];
  110. if (!empty($param['sex'])) {
  111. $sexWhere = ['sex'=>$param['sex']];
  112. }
  113. $total = ActiveApplyModel::hasWhere('user',$sexWhere)->where($where)->count();
  114. $this->assign('total', $total);
  115. $list = ActiveApplyModel::hasWhere('user',$sexWhere)->with('user')->where($where)->order('check_status asc')->paginate(10, false, [
  116. 'query' => $param,//不丢失已存在的url参数
  117. ]);
  118. foreach ($list as $v) {
  119. $v['age'] = Fun::getAgeByBirth($v['user']['birthday']);
  120. }
  121. $page = $list->render();
  122. $this->assign('list', $list);
  123. $this->assign('page', $page);
  124. return $this->fetch();
  125. }
  126. /**
  127. * 审核
  128. */
  129. public function checkPost()
  130. {
  131. $data = $this->request->post();
  132. ActiveApplyModel::update($data, ['id' => $data['id']]);
  133. $this->success('操作成功');
  134. }
  135. /**
  136. * 报名列表导出
  137. */
  138. public function applyExport()
  139. {
  140. $param = $this->request->param();
  141. $where = [
  142. ['active_id', '=', $param['id']],
  143. ];
  144. if (!empty($param['check_status'])) {
  145. $where[] = ['cmf_active_apply.check_status', '=', $param['check_status']];
  146. }
  147. $sexWhere = [];
  148. if (!empty($param['sex'])) {
  149. $sexWhere = ['sex'=>$param['sex']];
  150. }
  151. $list = ActiveApplyModel::hasWhere('user',$sexWhere)->with('user')->where($where)->order('check_status asc')->select();
  152. $data = [];
  153. foreach ($list as $v) {
  154. $data[] = [
  155. 'name' => $v['user']['realname'],
  156. 'sex' => $v['user']['sex_text'],
  157. 'age' => Fun::getAgeByBirth($v['user']['birthday']),
  158. 'mobile' => $v['user']['mobile'],
  159. 'company' => $v['user']['company'],
  160. 'native' => $v['user']['native'],
  161. 'marry' => $v['user']['marry'],
  162. 'check_status' => $v['status_text'],
  163. ];
  164. }
  165. if (empty($data)) {
  166. return '暂无数据';
  167. }
  168. $excel = new Excel();
  169. $title = [
  170. ['name','姓名'],
  171. ['sex','性别'],
  172. ['age','年龄'],
  173. ['mobile','电话'],
  174. ['company','单位'],
  175. ['native','籍贯'],
  176. ['marry','婚姻状况'],
  177. ['check_status','审核状态'],
  178. ];
  179. $excel->export('报名列表',$title,$data,['mobile']);
  180. }
  181. }