123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 老猫 <thinkcmf@126.com>
- // +----------------------------------------------------------------------
- namespace app\love\controller;
- use app\common\Fun;
- use app\love\model\ActiveApplyModel;
- use app\love\model\ActiveModel;
- use app\love\model\UserFriendModel;
- use app\love\model\UserInviteModel;
- class ActiveController extends LoveBaseController
- {
- private $_age = [[0, 100], [18, 25], [25, 30], [30, 40], [40, 50], [50, 100]];
- private $_high = [[0, 250], [150, 160], [161, 170], [171, 180], [180, 250]];
- private $_weight = [[0, 150], [40, 50], [51, 60], [61, 70], [71, 80], [81, 150]];
- /**
- * 活动列表
- */
- public function index()
- {
- $list = ActiveModel::where('status', 1)->order('create_time desc')->select();
- foreach ($list as $v) {
- $v['main_image'] = cmf_get_image_preview_url($v['main_image']);
- $v['start_time'] = date('m-d', $v['start_time']);
- $v['end_time'] = date('m-d', $v['end_time']);
- }
- $this->assign('list', $list);
- //未读消息数
- $unread_num = UserFriendModel::where('user_id', cmf_get_current_user_id())->sum('unread_num');
- $invite_num = UserInviteModel::where('to_id', cmf_get_current_user_id())
- ->where('status', 1)
- ->count();
- $this->assign('unread_num', $unread_num + $invite_num);
- return $this->fetch();
- }
- /**
- * 详情
- */
- public function detail()
- {
- $id = $this->request->param('id');
- if (empty($id)) {
- $this->error('活动不存在或已结束');
- }
- $active = ActiveModel::get($id);
- if (empty($active)) {
- $this->error('活动不存在或已结束');
- }
- $this->assign('id', $id);
- $active = ActiveModel::get($id);
- $active['time_status'] = 0;
- if ($active['start_time'] > time()) {
- $active['time_status'] = 1;
- }
- if ($active['end_time'] < time()) {
- $active['time_status'] = 2;
- }
- $active['start_time'] = date('m-d', $active['start_time']);
- $active['end_time'] = date('m-d', $active['end_time']);
- $active['main_image'] = cmf_get_image_preview_url($active['main_image']);
- $this->assign('info', $active);
- //状态
- $apply = ActiveApplyModel::where([
- ['user_id', '=', $this->user['id']],
- ['active_id', '=', $id],
- ])->find();
- $this->assign('apply', $apply ?: 'false');
- if ($apply && $apply['check_status'] == 2) {
- $this->assign('share_image_url', $active['main_image']);
- $this->assign('share_title', $active['title']);
- $this->assign('share_link', url('love/login/index', '', true, true) . '?active_id=' . $id);
- $this->assign('share_desc', $active['describe']);
- }
- return $this->fetch();
- }
- /**
- * 参加活动
- */
- public function apply()
- {
- $id = $this->request->param('id');
- if (empty($id)) {
- $this->error('活动不存在或已结束');
- }
- $active = ActiveModel::get($id);
- if (empty($active)) {
- $this->error('活动不存在或已结束');
- }
- $check = ActiveApplyModel::get(['active_id'=>$id,'user_id'=>$this->user['id']]);
- if (!empty($check)) {
- $this->error('您已报名!');
- }
- //参加
- ActiveApplyModel::create([
- 'active_id' => $id,
- 'user_id' => $this->user['id'],
- 'create_time' => time(),
- ]);
- $this->success('报名成功');
- }
- /**
- * 取消参加活动
- */
- public function cancel()
- {
- $id = $this->request->param('id');
- if (empty($id)) {
- $this->error('活动不存在或已结束');
- }
- $active = ActiveModel::get($id);
- if (empty($active)) {
- $this->error('活动不存在或已结束');
- }
- $check = ActiveApplyModel::get(['active_id'=>$id,'user_id'=>$this->user['id']]);
- if (empty($check)) {
- $this->error('您未报名,无需取消!');
- }
- $check->delete();
- $this->success('取消成功');
- }
- /**
- * 嘉宾
- */
- public function people()
- {
- $id = $this->request->param('id');
- if (empty($id)) {
- $this->error('活动不存在或已结束');
- }
- $active = ActiveModel::get($id);
- if (empty($active)) {
- $this->error('活动不存在或已结束');
- }
- $this->assign('id', $id);
- $where = [
- ['a.active_id', '=', $id],
- ['a.check_status', '=', 2],
- ['u.check_status', '=', 2],
- ['u.is_complete', '=', 1],
- ['u.id', '<>', cmf_get_current_user_id()],
- ];
- $list = ActiveApplyModel::alias('a')
- ->field('u.*,a.site_status,a.user_no')
- ->leftJoin('cmf_user u', 'a.user_id = u.id')
- ->where($where)
- ->order('a.site_status asc')
- ->limit(6)
- ->select();
- foreach ($list as $v) {
- $v['age'] = Fun::getAgeByBirth($v['birthday']);
- }
- $this->assign('list', $list);
- return $this->fetch();
- }
- /**
- * 列表
- */
- public function peopleList()
- {
- $param = $this->request->post();
- $where = [
- ['a.active_id', '=', $param['active_id']],
- ['a.check_status', '=', 2],
- ['u.check_status', '=', 2],
- ['u.is_complete', '=', 1],
- ['u.id', '<>', cmf_get_current_user_id()],
- ];
- if (!empty($param['age'])) {
- $age = $this->_age[$param['age']];
- $start_time = strtotime("-{$age[1]} year");
- $end_time = strtotime("-{$age[0]} year");
- $where[] = ['u.birthday', 'between', [$start_time, $end_time]];
- }
- if (!empty($param['site_status'])) {
- $where[] = ['a.site_status', '=', $param['site_status']];
- }
- if (!empty($param['sex'])) {
- $where[] = ['u.sex', '=', $param['sex']];
- }
- if (!empty($param['high'])) {
- $high = $this->_high[$param['high']];
- $where[] = ['u.high', 'between', [$high[0], $high[1]]];
- }
- if (!empty($param['weight'])) {
- $weight = $this->_weight[$param['weight']];
- $where[] = ['u.weight', 'between', [$weight[0], $weight[1]]];
- }
- if (!empty($param['education'])) {
- $where[] = ['u.education', '=', $param['education']];
- }
- if (!empty($param['id'])) {
- $where[] = ['a.user_no', '=', $param['id']];
- }
- $list = ActiveApplyModel::alias('a')
- ->field('u.*,a.site_status')
- ->leftJoin('cmf_user u', 'a.user_id = u.id')
- ->where($where)
- ->order('a.site_status asc')
- ->limit(6)
- ->page($param['page'])
- ->select();
- foreach ($list as $v) {
- $v['age'] = Fun::getAgeByBirth($v['birthday']);
- }
- $this->result($list, 1);
- }
- /**
- * 排行榜
- */
- public function rank()
- {
- $id = $this->request->param('id');
- if (empty($id)) {
- $this->error('活动不存在或已结束');
- }
- $active = ActiveModel::get($id);
- if (empty($active)) {
- $this->error('活动不存在或已结束');
- }
- $this->assign('id', $id);
- //列表
- $where = [
- ['a.active_id', '=', $id],
- ['a.check_status', '=', 2],
- ['u.check_status', '=', 2],
- ['u.is_complete', '=', 1],
- ];
- $list1 = ActiveApplyModel::alias('a')
- ->field('u.*,a.site_status')
- ->leftJoin('cmf_user u', 'a.user_id = u.id')
- ->where($where)
- ->where('sex', 2)
- ->order('u.invite_num desc')
- ->limit(10)
- ->select();
- foreach ($list1 as $v) {
- $v['age'] = Fun::getAgeByBirth($v['birthday']);
- }
- $this->assign('list1', $list1);
- $list2 = ActiveApplyModel::alias('a')
- ->field('u.*,a.site_status')
- ->leftJoin('cmf_user u', 'a.user_id = u.id')
- ->where($where)
- ->where('sex', 1)
- ->order('u.invite_num desc')
- ->limit(10)
- ->select();
- foreach ($list2 as $v) {
- $v['age'] = Fun::getAgeByBirth($v['birthday']);
- }
- $this->assign('list2', $list2);
- return $this->fetch();
- }
- }
|