AdminActiveController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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\admin\model\UserModel;
  13. use app\common\Excel;
  14. use app\common\Fun;
  15. use app\love\model\ActiveApplyModel;
  16. use app\love\model\ActiveModel;
  17. use app\love\model\QuestionModel;
  18. use app\love\model\UserOutlookModel;
  19. use cmf\controller\AdminBaseController;
  20. class AdminActiveController extends AdminBaseController
  21. {
  22. /**
  23. * 列表
  24. */
  25. public function index()
  26. {
  27. $list = ActiveModel::paginate(10);
  28. foreach ($list as $v) {
  29. $v['url'] = urlencode(url('love/Scene/wechat', ['active_id' => $v['id']], true, true));
  30. }
  31. // 获取分页显示
  32. $page = $list->render();
  33. $this->assign('list', $list);
  34. $this->assign('page', $page);
  35. // 渲染模板输出
  36. return $this->fetch();
  37. }
  38. /**
  39. * 添加
  40. */
  41. public function add()
  42. {
  43. return $this->fetch();
  44. }
  45. /**
  46. * 添加提交
  47. */
  48. public function addPost()
  49. {
  50. if ($this->request->isPost()) {
  51. $data = $this->request->param();
  52. $post = $data['post'];
  53. if (empty($post['start_time'])) {
  54. $this->error('请选择开始时间');
  55. }
  56. if (empty($post['end_time'])) {
  57. $this->error('请选择结束时间');
  58. }
  59. $post['create_time'] = $post['update_time'] = time();
  60. $post['start_time'] = strtotime($post['start_time']);
  61. $post['end_time'] = strtotime($post['end_time']);
  62. ActiveModel::create($post);
  63. $this->success('添加成功!', url('index'));
  64. }
  65. }
  66. /**
  67. * 编辑
  68. */
  69. public function edit()
  70. {
  71. $id = $this->request->param('id', 0, 'intval');
  72. $post = ActiveModel::get($id);
  73. $this->assign('post', $post);
  74. return $this->fetch();
  75. }
  76. /**
  77. * 编辑提交
  78. */
  79. public function editPost()
  80. {
  81. if ($this->request->isPost()) {
  82. $data = $this->request->param();
  83. $post = $data['post'];
  84. if (empty($post['start_time'])) {
  85. $this->error('请选择开始时间');
  86. }
  87. if (empty($post['end_time'])) {
  88. $this->error('请选择结束时间');
  89. }
  90. $post['create_time'] = $post['update_time'] = time();
  91. $post['start_time'] = strtotime($post['start_time']);
  92. $post['end_time'] = strtotime($post['end_time']);
  93. ActiveModel::update($post, ['id' => $post['id']]);
  94. $this->success('编辑成功!', url('index'));
  95. }
  96. }
  97. /**
  98. * 审核列表
  99. */
  100. public function applyList()
  101. {
  102. $param = $this->request->param();
  103. $this->assign('id', $param['id']);
  104. $this->assign('check_status', $param['check_status'] ?? 0);
  105. $this->assign('sex', $param['sex'] ?? 0);
  106. $where = [
  107. ['active_id', '=', $param['id']],
  108. ];
  109. if (!empty($param['check_status'])) {
  110. $where[] = ['cmf_active_apply.check_status', '=', $param['check_status']];
  111. }
  112. $sexWhere = [];
  113. if (!empty($param['sex'])) {
  114. $sexWhere = ['sex' => $param['sex']];
  115. }
  116. $total = ActiveApplyModel::hasWhere('user', $sexWhere)->where($where)->count();
  117. $this->assign('total', $total);
  118. $list = ActiveApplyModel::hasWhere('user', $sexWhere)->with('user')->where($where)->order('check_status asc')->paginate(10, false, [
  119. 'query' => $param,//不丢失已存在的url参数
  120. ]);
  121. foreach ($list as $v) {
  122. $v['age'] = Fun::getAgeByBirth($v['user']['birthday']);
  123. }
  124. $page = $list->render();
  125. $this->assign('list', $list);
  126. $this->assign('page', $page);
  127. return $this->fetch();
  128. }
  129. /**
  130. * 审核
  131. */
  132. public function checkPost()
  133. {
  134. $data = $this->request->post();
  135. ActiveApplyModel::update($data, ['id' => $data['id']]);
  136. $this->success('操作成功');
  137. }
  138. /**
  139. * 报名列表导出
  140. */
  141. public function applyExport()
  142. {
  143. $param = $this->request->param();
  144. $where = [
  145. ['active_id', '=', $param['id']],
  146. ];
  147. if (!empty($param['check_status'])) {
  148. $where[] = ['cmf_active_apply.check_status', '=', $param['check_status']];
  149. }
  150. $sexWhere = [];
  151. if (!empty($param['sex'])) {
  152. $sexWhere = ['sex' => $param['sex']];
  153. }
  154. $list = ActiveApplyModel::hasWhere('user', $sexWhere)->with('user')->where($where)->order('check_status asc')->select();
  155. $data = [];
  156. foreach ($list as $v) {
  157. $data[] = [
  158. 'name' => $v['user']['realname'],
  159. 'sex' => $v['user']['sex_text'],
  160. 'age' => Fun::getAgeByBirth($v['user']['birthday']),
  161. 'mobile' => $v['user']['mobile'],
  162. 'company' => $v['user']['company'],
  163. 'native' => $v['user']['native'],
  164. 'marry' => $v['user']['marry'],
  165. 'check_status' => $v['status_text'],
  166. ];
  167. }
  168. if (empty($data)) {
  169. return '暂无数据';
  170. }
  171. $excel = new Excel();
  172. $title = [
  173. ['name', '姓名'],
  174. ['sex', '性别'],
  175. ['age', '年龄'],
  176. ['mobile', '电话'],
  177. ['company', '单位'],
  178. ['native', '籍贯'],
  179. ['marry', '婚姻状况'],
  180. ['check_status', '审核状态'],
  181. ];
  182. $excel->export('报名列表', $title, $data, ['mobile']);
  183. }
  184. public function exportoutlook()
  185. {
  186. $id = $this->request->param('id');
  187. $outlook = UserOutlookModel::all();
  188. $question = QuestionModel::all();
  189. $user_ids = $outlook->column('user_id');
  190. $user = UserModel::where('id', 'in', $user_ids)->column('user_nickname,sex', 'id');
  191. $active = ActiveApplyModel::where('active_id', $id)->column('user_no', 'user_id');
  192. if ($outlook->isEmpty()) {
  193. return '暂时无人填写三观';
  194. }
  195. //分出男女
  196. $outlook_man = [];
  197. $outlook_woman = [];
  198. foreach ($outlook as $v) {
  199. $v['user_nickname'] = $user[$v['user_id']]['user_nickname'];
  200. $v['sex'] = $user[$v['user_id']]['sex'];
  201. if ($v['sex'] == 1) {
  202. $outlook_man[] = $v;
  203. } else {
  204. $outlook_woman[] = $v;
  205. }
  206. }
  207. if (empty($outlook_man)) {
  208. return '暂无男生填写三观';
  209. }
  210. if (empty($outlook_woman)) {
  211. return '暂无女生填写三观';
  212. }
  213. $data = [];
  214. $options = [1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D'];
  215. foreach ($outlook_man as $man) {
  216. foreach ($outlook_woman as $woman) {
  217. $item = [];
  218. $item['man_nickname'] = $man['user_nickname'];
  219. $item['man_no'] = empty($active[$man['user_id']]) ? '未签到' : $active[$man['user_id']];
  220. $item['woman_nickname'] = $woman['user_nickname'];
  221. $item['woman_no'] = empty($active[$woman['user_id']]) ? '未签到' : $active[$woman['user_id']];;
  222. $item['match_num'] = $this->_matchOption($man, $woman);
  223. $item['match'] = $item['match_num'] . '0%';
  224. $item['title1'] = "男:" . $options[$man['question1']] . ",女:" . $options[$woman['question1']] . "。";
  225. $item['title2'] = "男:" . $options[$man['question2']] . ",女:" . $options[$woman['question2']] . "。";
  226. $item['title3'] = "男:" . $options[$man['question3']] . ",女:" . $options[$woman['question3']] . "。";
  227. $item['title4'] = "男:" . $options[$man['question4']] . ",女:" . $options[$woman['question4']] . "。";
  228. $item['title5'] = "男:" . $options[$man['question5']] . ",女:" . $options[$woman['question5']] . "。";
  229. $item['title6'] = "男:" . $options[$man['question6']] . ",女:" . $options[$woman['question6']] . "。";
  230. $item['title7'] = "男:" . $options[$man['question7']] . ",女:" . $options[$woman['question7']] . "。";
  231. $item['title8'] = "男:" . $options[$man['question8']] . ",女:" . $options[$woman['question8']] . "。";
  232. $item['title9'] = "男:" . $options[$man['question9']] . ",女:" . $options[$woman['question9']] . "。";
  233. $item['title10'] = "男:" . $options[$man['question10']] . ",女:" . $options[$woman['question10']] . "。";
  234. $data[] = $item;
  235. }
  236. }
  237. usort($data, function ($a, $b) {
  238. return $b['match_num'] - $a['match_num']; // 倒序排列
  239. });
  240. //抬头
  241. $title1 = "题目:{$question[0]['title']}。选项:A.{$question[0]['option1']}。B.{$question[0]['option2']}。C.{$question[0]['option3']}。D.{$question[0]['option4']}。";
  242. $title2 = "题目:{$question[1]['title']}。选项:A.{$question[1]['option1']}。B.{$question[1]['option2']}。C.{$question[1]['option3']}。D.{$question[1]['option4']}。";
  243. $title3 = "题目:{$question[2]['title']}。选项:A.{$question[2]['option1']}。B.{$question[2]['option2']}。C.{$question[2]['option3']}。D.{$question[2]['option4']}。";
  244. $title4 = "题目:{$question[3]['title']}。选项:A.{$question[3]['option1']}。B.{$question[3]['option2']}。C.{$question[3]['option3']}。D.{$question[3]['option4']}。";
  245. $title5 = "题目:{$question[4]['title']}。选项:A.{$question[4]['option1']}。B.{$question[4]['option2']}。C.{$question[4]['option3']}。D.{$question[4]['option4']}。";
  246. $title6 = "题目:{$question[5]['title']}。选项:A.{$question[5]['option1']}。B.{$question[5]['option2']}。C.{$question[5]['option3']}。D.{$question[5]['option4']}。";
  247. $title7 = "题目:{$question[6]['title']}。选项:A.{$question[6]['option1']}。B.{$question[6]['option2']}。C.{$question[6]['option3']}。D.{$question[6]['option4']}。";
  248. $title8 = "题目:{$question[7]['title']}。选项:A.{$question[7]['option1']}。B.{$question[7]['option2']}。C.{$question[7]['option3']}。D.{$question[7]['option4']}。";
  249. $title9 = "题目:{$question[8]['title']}。选项:A.{$question[8]['option1']}。B.{$question[8]['option2']}。C.{$question[8]['option3']}。D.{$question[8]['option4']}。";
  250. $title10 = "题目:{$question[9]['title']}。选项:A.{$question[9]['option1']}。B.{$question[9]['option2']}。C.{$question[9]['option3']}。D.{$question[9]['option4']}。";
  251. $title = [
  252. ['man_nickname', '男生'],
  253. ['man_no', '男生编号'],
  254. ['woman_nickname', '女生编号'],
  255. ['woman_no', '女生编号'],
  256. ['match', '匹配度'],
  257. ['title1', $title1],
  258. ['title2', $title2],
  259. ['title3', $title3],
  260. ['title4', $title4],
  261. ['title5', $title5],
  262. ['title6', $title6],
  263. ['title7', $title7],
  264. ['title8', $title8],
  265. ['title9', $title9],
  266. ['title10', $title10],
  267. ];
  268. $excel = new Excel();
  269. $excel->export('三观匹配度', $title, $data);
  270. }
  271. private function _matchOption($man, $woman)
  272. {
  273. $match_num = 0;
  274. for ($i = 1; $i <= 10; $i++) {
  275. if ($man['question' . $i] == $woman['question' . $i]) {
  276. $match_num++;
  277. }
  278. }
  279. return $match_num;
  280. }
  281. }