ActiveController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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\love\model\ActiveApplyModel;
  14. use app\love\model\ActiveModel;
  15. use app\love\model\UserFriendModel;
  16. use app\love\model\UserInviteModel;
  17. class ActiveController extends LoveBaseController
  18. {
  19. private $_age = [[0, 100], [18, 25], [25, 30], [30, 40], [40, 50], [50, 100]];
  20. private $_high = [[0, 250], [150, 160], [161, 170], [171, 180], [180, 250]];
  21. private $_weight = [[0, 150], [40, 50], [51, 60], [61, 70], [71, 80], [81, 150]];
  22. /**
  23. * 活动列表
  24. */
  25. public function index()
  26. {
  27. $list = ActiveModel::where('status', 1)->order('create_time desc')->select();
  28. foreach ($list as $v) {
  29. $v['main_image'] = cmf_get_image_preview_url($v['main_image']);
  30. $v['start_time'] = date('m-d', $v['start_time']);
  31. $v['end_time'] = date('m-d', $v['end_time']);
  32. }
  33. $this->assign('list', $list);
  34. //未读消息数
  35. $unread_num = UserFriendModel::where('user_id', cmf_get_current_user_id())->sum('unread_num');
  36. $invite_num = UserInviteModel::where('to_id', cmf_get_current_user_id())
  37. ->where('status', 1)
  38. ->count();
  39. $this->assign('unread_num', $unread_num + $invite_num);
  40. return $this->fetch();
  41. }
  42. /**
  43. * 详情
  44. */
  45. public function detail()
  46. {
  47. $id = $this->request->param('id');
  48. if (empty($id)) {
  49. $this->error('活动不存在或已结束');
  50. }
  51. $active = ActiveModel::get($id);
  52. if (empty($active)) {
  53. $this->error('活动不存在或已结束');
  54. }
  55. $this->assign('id', $id);
  56. $active = ActiveModel::get($id);
  57. $active['time_status'] = 0;
  58. if ($active['start_time'] > time()) {
  59. $active['time_status'] = 1;
  60. }
  61. if ($active['end_time'] < time()) {
  62. $active['time_status'] = 2;
  63. }
  64. $active['start_time'] = date('m-d', $active['start_time']);
  65. $active['end_time'] = date('m-d', $active['end_time']);
  66. $active['main_image'] = cmf_get_image_preview_url($active['main_image']);
  67. $this->assign('info', $active);
  68. //状态
  69. $apply = ActiveApplyModel::where([
  70. ['user_id', '=', $this->user['id']],
  71. ['active_id', '=', $id],
  72. ])->find();
  73. $this->assign('apply', $apply ?: 'false');
  74. if ($apply && $apply['check_status'] == 2) {
  75. $this->assign('share_image_url', $active['main_image']);
  76. $this->assign('share_title', $active['title']);
  77. $this->assign('share_link', url('love/login/index', '', true, true) . '?active_id=' . $id);
  78. $this->assign('share_desc', $active['describe']);
  79. }
  80. return $this->fetch();
  81. }
  82. /**
  83. * 参加活动
  84. */
  85. public function apply()
  86. {
  87. $id = $this->request->param('id');
  88. if (empty($id)) {
  89. $this->error('活动不存在或已结束');
  90. }
  91. $active = ActiveModel::get($id);
  92. if (empty($active)) {
  93. $this->error('活动不存在或已结束');
  94. }
  95. $check = ActiveApplyModel::get(['active_id'=>$id,'user_id'=>$this->user['id']]);
  96. if (!empty($check)) {
  97. $this->error('您已报名!');
  98. }
  99. //参加
  100. ActiveApplyModel::create([
  101. 'active_id' => $id,
  102. 'user_id' => $this->user['id'],
  103. 'create_time' => time(),
  104. ]);
  105. $this->success('报名成功');
  106. }
  107. /**
  108. * 取消参加活动
  109. */
  110. public function cancel()
  111. {
  112. $id = $this->request->param('id');
  113. if (empty($id)) {
  114. $this->error('活动不存在或已结束');
  115. }
  116. $active = ActiveModel::get($id);
  117. if (empty($active)) {
  118. $this->error('活动不存在或已结束');
  119. }
  120. $check = ActiveApplyModel::get(['active_id'=>$id,'user_id'=>$this->user['id']]);
  121. if (empty($check)) {
  122. $this->error('您未报名,无需取消!');
  123. }
  124. $check->delete();
  125. $this->success('取消成功');
  126. }
  127. /**
  128. * 嘉宾
  129. */
  130. public function people()
  131. {
  132. $id = $this->request->param('id');
  133. if (empty($id)) {
  134. $this->error('活动不存在或已结束');
  135. }
  136. $active = ActiveModel::get($id);
  137. if (empty($active)) {
  138. $this->error('活动不存在或已结束');
  139. }
  140. $this->assign('id', $id);
  141. $where = [
  142. ['a.active_id', '=', $id],
  143. ['a.check_status', '=', 2],
  144. ['u.check_status', '=', 2],
  145. ['u.is_complete', '=', 1],
  146. ['u.id', '<>', cmf_get_current_user_id()],
  147. ];
  148. $list = ActiveApplyModel::alias('a')
  149. ->field('u.*,a.site_status,a.user_no')
  150. ->leftJoin('cmf_user u', 'a.user_id = u.id')
  151. ->where($where)
  152. ->order('a.site_status asc')
  153. ->limit(6)
  154. ->select();
  155. foreach ($list as $v) {
  156. $v['age'] = Fun::getAgeByBirth($v['birthday']);
  157. }
  158. $this->assign('list', $list);
  159. return $this->fetch();
  160. }
  161. /**
  162. * 列表
  163. */
  164. public function peopleList()
  165. {
  166. $param = $this->request->post();
  167. $where = [
  168. ['a.active_id', '=', $param['active_id']],
  169. ['a.check_status', '=', 2],
  170. ['u.check_status', '=', 2],
  171. ['u.is_complete', '=', 1],
  172. ['u.id', '<>', cmf_get_current_user_id()],
  173. ];
  174. if (!empty($param['age'])) {
  175. $age = $this->_age[$param['age']];
  176. $start_time = strtotime("-{$age[1]} year");
  177. $end_time = strtotime("-{$age[0]} year");
  178. $where[] = ['u.birthday', 'between', [$start_time, $end_time]];
  179. }
  180. if (!empty($param['site_status'])) {
  181. $where[] = ['a.site_status', '=', $param['site_status']];
  182. }
  183. if (!empty($param['sex'])) {
  184. $where[] = ['u.sex', '=', $param['sex']];
  185. }
  186. if (!empty($param['high'])) {
  187. $high = $this->_high[$param['high']];
  188. $where[] = ['u.high', 'between', [$high[0], $high[1]]];
  189. }
  190. if (!empty($param['weight'])) {
  191. $weight = $this->_weight[$param['weight']];
  192. $where[] = ['u.weight', 'between', [$weight[0], $weight[1]]];
  193. }
  194. if (!empty($param['education'])) {
  195. $where[] = ['u.education', '=', $param['education']];
  196. }
  197. if (!empty($param['id'])) {
  198. $where[] = ['a.user_no', '=', $param['id']];
  199. }
  200. $list = ActiveApplyModel::alias('a')
  201. ->field('u.*,a.site_status')
  202. ->leftJoin('cmf_user u', 'a.user_id = u.id')
  203. ->where($where)
  204. ->order('a.site_status asc')
  205. ->limit(6)
  206. ->page($param['page'])
  207. ->select();
  208. foreach ($list as $v) {
  209. $v['age'] = Fun::getAgeByBirth($v['birthday']);
  210. }
  211. $this->result($list, 1);
  212. }
  213. /**
  214. * 排行榜
  215. */
  216. public function rank()
  217. {
  218. $id = $this->request->param('id');
  219. if (empty($id)) {
  220. $this->error('活动不存在或已结束');
  221. }
  222. $active = ActiveModel::get($id);
  223. if (empty($active)) {
  224. $this->error('活动不存在或已结束');
  225. }
  226. $this->assign('id', $id);
  227. //列表
  228. $where = [
  229. ['a.active_id', '=', $id],
  230. ['a.check_status', '=', 2],
  231. ['u.check_status', '=', 2],
  232. ['u.is_complete', '=', 1],
  233. ];
  234. $list1 = ActiveApplyModel::alias('a')
  235. ->field('u.*,a.site_status')
  236. ->leftJoin('cmf_user u', 'a.user_id = u.id')
  237. ->where($where)
  238. ->where('sex', 2)
  239. ->order('u.invite_num desc')
  240. ->limit(10)
  241. ->select();
  242. foreach ($list1 as $v) {
  243. $v['age'] = Fun::getAgeByBirth($v['birthday']);
  244. }
  245. $this->assign('list1', $list1);
  246. $list2 = ActiveApplyModel::alias('a')
  247. ->field('u.*,a.site_status')
  248. ->leftJoin('cmf_user u', 'a.user_id = u.id')
  249. ->where($where)
  250. ->where('sex', 1)
  251. ->order('u.invite_num desc')
  252. ->limit(10)
  253. ->select();
  254. foreach ($list2 as $v) {
  255. $v['age'] = Fun::getAgeByBirth($v['birthday']);
  256. }
  257. $this->assign('list2', $list2);
  258. return $this->fetch();
  259. }
  260. }