SceneController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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: 老猫 <thinkcmf@126.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\love\controller;
  12. use app\common\Fun;
  13. use app\common\Wechat;
  14. use app\love\model\ActiveApplyModel;
  15. use app\love\model\ActiveModel;
  16. use app\love\model\UserMatingModel;
  17. use app\love\model\UserModel;
  18. use app\love\model\UserSelectLogModel;
  19. use cmf\controller\HomeBaseController;
  20. use think\facade\Request;
  21. use think\facade\Session;
  22. class SceneController extends HomeBaseController
  23. {
  24. public function initialize()
  25. {
  26. parent::initialize();
  27. //分享页面
  28. $wx_api_sign = Wechat::instance()->getJsSign(Request::url(true));
  29. $this->assign('domain', $this->request->domain());
  30. $this->assign('wx_api_sign', json_encode($wx_api_sign));
  31. }
  32. /**
  33. * 签到
  34. */
  35. public function wechat()
  36. {
  37. $active_id = $this->request->param('active_id', 0);
  38. if (empty($active_id)) {
  39. $this->error('您的二维码有误,请联系工作人员', url('/'));
  40. }
  41. $active = ActiveModel::get($active_id);
  42. if (empty($active)) {
  43. $this->error('您的二维码有误,请联系工作人员', url('/'));
  44. }
  45. Session::set('sign_in_id', $active_id);
  46. $this->redirect('https://www.jucai.gov.cn/api/auth/wechat_auth?url=' . urlencode(url('love/Scene/signIn', '', true, true)));
  47. }
  48. /**
  49. * 签到回调
  50. */
  51. public function signIn()
  52. {
  53. $param = $this->request->param();
  54. $open_id = $param['openid'];
  55. $active_id = Session::pull('sign_in_id');
  56. //获取用户
  57. $user = UserModel::where('open_id', $open_id)->find();
  58. if (empty($user)) {
  59. $this->assign('content', '请先注册');
  60. $this->assign('btn', '点击注册');
  61. $this->assign('url', url('love/login/index') . '?id=' . $active_id);
  62. return $this->fetch();
  63. }
  64. //用户状态
  65. if ($user['is_complete'] == 2) {
  66. $this->assign('content', '请先完善资料');
  67. $this->assign('btn', '完善资料');
  68. if (empty($user['sex'])) {
  69. $this->assign('url', url('love/register/sex'));
  70. } else {
  71. $this->assign('url', url('love/register/intro'));
  72. }
  73. return $this->fetch();
  74. }
  75. if ($user['user_status'] != 1) {
  76. $this->redirect(url('love/register/ban'));
  77. }
  78. if ($user['check_status'] != 2) {
  79. $this->assign('content', '请等待后台审核');
  80. $this->assign('btn', '前往首页');
  81. $this->assign('url', url('/'));
  82. return $this->fetch();
  83. }
  84. //活动
  85. $apply = ActiveApplyModel::where([
  86. ['active_id', '=', $active_id],
  87. ['user_id', '=', $user['id']],
  88. ])->find();
  89. if (empty($apply)) {
  90. $this->assign('content', '请先报名活动');
  91. $this->assign('btn', '进入活动');
  92. $this->assign('url', url('love/active/detail') . '?id=' . $active_id);
  93. return $this->fetch();
  94. }
  95. if ($apply['check_status'] != 2) {
  96. $this->assign('content', '活动还未审核通过');
  97. $this->assign('btn', '进入活动');
  98. $this->assign('url', url('love/active/detail') . '?id=' . $active_id);
  99. return $this->fetch();
  100. }
  101. //签到
  102. if ($apply->site_status == 2) {
  103. $apply->site_status = 1;
  104. $apply->site_time = time();
  105. $apply->save();
  106. }
  107. //嘉宾编号
  108. if (empty($apply['user_no'])) {
  109. $user_no = ActiveApplyModel::where('active_id', $active_id)->max('user_no');
  110. $apply->user_no = ++$user_no;
  111. $apply->save();
  112. }
  113. $this->assign('content', '签到成功<br/>您的嘉宾编号是' . $apply['user_no']);
  114. $this->assign('btn', '进入活动');
  115. $this->assign('url', url('love/active/detail') . '?id=' . $active_id);
  116. return $this->fetch();
  117. }
  118. /**
  119. * 现场轮播图
  120. */
  121. public function sceneList()
  122. {
  123. $id = $this->request->param('id', 0);
  124. if (empty($id)) {
  125. return '0';
  126. }
  127. $this->assign('id', $id);
  128. $active = ActiveModel::get($id);
  129. if (empty($active)) {
  130. return '0';
  131. }
  132. $this->assign('active', $active);
  133. //获取列表
  134. $where = [
  135. ['a.active_id', '=', $id],
  136. ['a.site_status', '=', 1],
  137. ];
  138. $list = $this->_getList($where);
  139. $this->assign('list', $list);
  140. //最后到场时间
  141. $this->assign('last_time', $list->isEmpty() ? 0 : $list[0]['site_time']);
  142. return $this->fetch();
  143. }
  144. /**
  145. * 现场轮播图信息
  146. */
  147. public function sceneListPost()
  148. {
  149. $param = $this->request->param();
  150. //获取列表
  151. $where = [
  152. ['a.active_id', '=', $param['id']],
  153. ['a.site_status', '=', 1],
  154. ['a.site_time', '>', $param['time']],
  155. ];
  156. $list = $this->_getList($where);
  157. $this->success('', '', $list);
  158. }
  159. /**
  160. * 获取列表
  161. */
  162. private function _getList($where)
  163. {
  164. $list = ActiveApplyModel::alias('a')
  165. ->field('u.*,a.user_no,a.site_time')
  166. ->leftJoin('cmf_user u', 'a.user_id = u.id')
  167. ->where($where)->order('site_time desc')->select();
  168. if ($list->isEmpty()) {
  169. return $list;
  170. }
  171. //获取择偶要求
  172. $age_list = $list->column('id');
  173. $mating = UserMatingModel::where('user_id', 'in', $age_list)->column('*', 'user_id');
  174. foreach ($list as $v) {
  175. $v['age'] = Fun::getAgeByBirth($v['birthday']);
  176. $v['mating'] = $mating[$v['id']];
  177. $v['url'] = urlencode(url('love/userwall/detail', ['id' => $v['id']], true, true));
  178. }
  179. return $list;
  180. }
  181. /**
  182. * 选择特效开始
  183. */
  184. public function selectStart()
  185. {
  186. return $this->fetch();
  187. }
  188. /**
  189. * 选择特效
  190. */
  191. public function selectView()
  192. {
  193. $info = UserSelectLogModel::with('user1,user2')->where('is_top', 1)->find();
  194. $this->assign('info', $info);
  195. return $this->fetch();
  196. }
  197. /**
  198. * 帮助中心
  199. */
  200. public function helpCenter()
  201. {
  202. $this->assign('share_title', '速看 | 泉州人才联谊平台操作手册!');
  203. $this->assign('share_desc', '点击查看>>>>');
  204. $this->assign('share_link', $this->request->url(true));
  205. return $this->fetch();
  206. }
  207. /**
  208. * 随机抽人
  209. */
  210. public function randomPeople()
  211. {
  212. $id = $this->request->param('id', 0);
  213. $man = ActiveApplyModel::alias('a')
  214. ->field('u.realname,u.main_image,u.username,u.star,a.user_no')
  215. ->leftJoin('cmf_user u', 'a.user_id = u.id')
  216. ->where([
  217. ['a.active_id', '=', $id],
  218. ['a.user_no', '>', 0],
  219. ['u.sex', '=', 1],
  220. ])->select();
  221. $this->assign('man', json_encode($man));
  222. $this->assign('man_count', $man->count() - 1);
  223. $woman = ActiveApplyModel::alias('a')
  224. ->field('u.realname,u.main_image,u.username,u.star,a.user_no')
  225. ->leftJoin('cmf_user u', 'a.user_id = u.id')
  226. ->where([
  227. ['a.active_id', '=', $id],
  228. ['a.user_no', '>', 0],
  229. ['u.sex', '=', 2],
  230. ])->select();
  231. $this->assign('woman', json_encode($woman));
  232. $this->assign('woman_count', $woman->count() - 1);
  233. return $this->fetch();
  234. }
  235. }