| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?php
- /**
- * 活动模块
- * @author wesmiler
- */
- namespace app\api\controller;
- use app\admin\model\ActivityModel;
- use app\portal\model\PortalPostModel;
- use app\weixin\model\Books;
- use app\weixin\model\HeartMatch;
- use app\weixin\model\UserProfile;
- use app\weixin\model\Wechat;
- use app\weixin\model\Member;
- use app\weixin\service\Activity;
- use app\weixin\service\PRedis;
- class ActivityController extends BaseController
- {
- /**
- * 活动列表数据
- * @return mixed
- */
- public function getList()
- {
- $pageSize = input('pageSize', 12);
- $dataList = Activity::getList(input(), $pageSize);
- Member::visitCount($this->userId, 'activity');
- showJson(1005, 1001, $dataList);
- }
- /**
- * 获取活动详情
- */
- public function getInfo()
- {
- $id = input('id');
- $type = input('type', 1);
- $field = $type == 1 ? 'id,title,cover_img as thumb,addtime,url,is_match,service_time,act_nums,starttime,endtime,description,address,join_address,content' : '';
- $info = Activity::getInfo(['id' => $id, 'status'=> 1], $field);
- if ($info) {
- $bookData = Books::where(['uid' => $this->userId, 'aid' => $id])
- ->where('status', 'in', [2, 3])
- ->field('book_num,is_signin,status')
- ->find();
- $info['activity_time'] = '';
- $startTime = $info['start_at']? strtotime(str_replace('.','-', $info['start_at'])) : 0;
- $endTime = $info['end_at']? strtotime(str_replace('.','-', $info['end_at'])) : 0;
- $startTime = strtotime(date('Y-m-d', $startTime));
- $endTime = strtotime(date('Y-m-d', $endTime));
- if($startTime && $endTime == $startTime){
- $times = $info['end_at']? explode(' ', $info['end_at']) : '';
- $endAt = isset($times[1])? $times[1] : '';
- $info['activity_time'] = $info['start_at'].($endAt? '~'.$endAt : '');
- }
- $info['is_book'] = isset($bookData['status']) ? intval($bookData['status']) : 0;
- $info['is_signin'] = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
- $info['book_no'] = isset($bookData['book_num']) ? trim($bookData['book_num']) : '';
- $info['book_num'] = Books::getBookCount($id);
- $price = isset($info['price']) ? moneyFormat($info['price'], 2) : '0.00';
- // 早市价
- if(isset($info['market_price'])){
- $marketPrice = moneyFormat($info['market_price'],2);
- $marketTime = isset($info['market_time']) ? intval($info['market_time']) : 0;
- $info['price'] = $marketTime>=time() && $marketPrice>0? $marketPrice : $price;
- $info['old_price'] = $price;
- }
- // 会员价
- $memberDiscount = isset($info['member_discount']) ? floatval($info['member_discount']) : 0;
- if($memberDiscount && ($type == 2 || isset($info['price']))){
- $memberInfo = Member::where(['id' => $this->userId])->field('vip_auth,vip_expire')->find();
- $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
- $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
- if($vipAuth && $vipExpire > time() && $memberDiscount && $memberDiscount < 1){
- $info['vip_price'] = moneyFormat($memberDiscount * $info['price'],2);
- }
- }
- // 匹配模式默认已匹配
- $siteInfo = $siteInfo = cmf_get_site_info();
- $info['match_type'] = isset($siteInfo['contact_type']) ? intval($siteInfo['contact_type']) : 1;
- if($info['match_type'] == 3){
- $info['is_match'] = 1;
- }
- $articles = config('weixin.articles');
- $articleId = isset($articles['about_activity']) ? intval($articles['about_activity']) : 0;
- $about = PortalPostModel::where(['id' => $articleId, 'post_type' => 2, 'post_status' => 1])->value('post_content');
- $info['about_activity'] = $about ? htmlspecialchars_decode($about) : '';
- showJson(1005, 1001, $info);
- } else {
- showJson(1004, 1002);
- }
- }
- /**
- * 关注活动
- */
- public function collect()
- {
- $id = input('id');
- $opType = input('type', 1);
- $result = Activity::collect($this->userId, $id, $opType);
- if ($result === true) {
- showJson(1005, $opType == 1 ? 2106 : 2108);
- } else {
- showJson(1004, $result);
- }
- }
- /**
- * 活动报名
- */
- public function booking()
- {
- // 验证
- $this->checkUser();
- if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
- showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
- }
- // 完善个人信息
- if (!UserProfile::checkUserProfile($this->userId)) {
- showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
- }
- // 隐身不可申请单身推荐
- $id = input('id');
- $isHeart = Member::where(['id'=> $this->userId])->value('is_heart');
- if($isHeart != 1 && $id != 15){
- showJson(1006, 2038, ['type'=> 'check']);
- }
- Member::visitCount($this->userId, 'book', 0,24);
- $result = Activity::catchBook($this->userId, $id);
- if (is_array($result)) {
- showJson(1005, 5012, $result);
- } else {
- showJson(1004, $result ? $result : 5013);
- }
- }
- /**
- * 置顶报名
- */
- public function topBooking()
- {
- // 验证
- $this->checkUser();
- if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
- showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
- }
- // 完善个人信息
- if (!UserProfile::checkUserProfile($this->userId)) {
- showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
- }
- // 隐身不可报名置顶
- $id = input('id');
- $isHeart = Member::where(['id'=> $this->userId])->value('is_heart');
- if($isHeart != 1 && $id != 16){
- showJson(1006, 2038, ['type'=> 'check']);
- }
- $result = Activity::catchBook($this->userId, $id);
- if (is_array($result)) {
- showJson(1005, 5012, $result);
- } else {
- showJson(1004, $result ? $result : 5013);
- }
- }
- /**
- * 获取互选报名用户列表
- */
- public function getChooseList()
- {
- // 验证
- $this->checkUser();
- $uid = input('uid',0);
- $id = input('id');
- $pageSize = input('pageSize', 12);
- // 验证是否签到
- $userId = $uid>0? $uid : $this->userId;
- $bookData = Books::where(['uid' => $userId, 'aid' => $id])
- ->where('status', 'in', [2, 3])
- ->field('book_num,is_signin,status')
- ->find();
- $endTime = ActivityModel::where(['id'=> $id])->value('endtime');
- $isHide = floor((time()-$endTime)/86400)>=3? 1 : 0;
- $isBook = isset($bookData['status']) ? intval($bookData['status']) : 0;
- $isSignin = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
- if (!$isHide && $isBook == 3 && ($isSignin == 2 || $isSignin == 3)) {
- $field = 'b.id,b.uid,b.aid,b.book_num as book_no,b.book_at,m.user_nickname,m.avatar,m.sex,m.birthday,m.real_name,up.age,up.height,up.weight,up.company,m.vip_auth,m.vip_expire,up.occupation,up.graduate,up.education,up.province,up.city,up.home_province,up.home_city,up.show_company,up.show_graduate,up.idcard_check,up.education_check,up.position_check';
- $dataList = Books::getBookList($id, $pageSize, $field, $userId);
- showJson(1005, 1001, $dataList);
- }else if ($isHide){
- showJson(1004, 5002);
- }else if ($isBook != 3){
- showJson(1004, 5025);
- }else{
- showJson(1004, 5024);
- }
- }
-
- /**
- * 获取互选报名用户列表
- */
- public function getChooseList1()
- {
- // 验证
- //$this->checkUser();
- $uid = input('uid',0);
- $id = input('id');
- $pageSize = input('pageSize', 12);
- // 验证是否签到
- $userId = $uid>0? $uid : $this->userId;
- $bookData = Books::where(['uid' => $userId, 'aid' => $id])
- ->where('status', 'in', [2, 3])
- ->field('book_num,is_signin,status')
- ->find();
- $endTime = ActivityModel::where(['id'=> $id])->value('endtime');
- $isHide = floor((time()-$endTime)/86400)>=3? 1 : 0;
- PRedis::set('test', $bookData, 600);
- $isBook = isset($bookData['status']) ? intval($bookData['status']) : 0;
- $isSignin = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
- if (!$isHide && $isBook == 3 && ($isSignin == 2 || $isSignin == 3)) {
- $field = 'b.id,b.uid,b.aid,b.book_num as book_no,b.book_at,m.user_nickname,m.avatar,m.sex,m.birthday,m.real_name,up.age,up.height,up.weight,up.company,up.occupation,up.graduate,up.education,up.province,up.city,up.home_province,up.home_city,up.show_company,up.show_graduate';
- $dataList = Books::getBookList($id, $pageSize, $field, $userId);
- showJson(1005, 1001, $dataList);
- }else if ($isHide){
- showJson(1004, 5002);
- }else if ($isBook != 3){
- showJson(1004, 5025);
- }else{
- showJson(1004, 5024);
- }
- }
- /**
- * 选我的人
- */
- public function getChoosenList()
- {
- $id = $id = input('id');
- $pageSize = input('pageSize', 12);
- // 验证是否签到
- $bookData = Books::where(['uid' => $this->userId, 'aid' => $id])
- ->where('status', 'in', [2, 3])
- ->field('book_num,is_signin,status')
- ->find();
- $endTime = ActivityModel::where(['id'=> $id])->value('endtime');
- $isHide = floor((time()-$endTime)/86400)>=3? 1 : 0;
- $isBook = isset($bookData['status']) ? intval($bookData['status']) : 0;
- $isSignin = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
- if (!$isHide && $isBook == 3 && ($isSignin == 2 || $isSignin == 3)) {
- $dataList = Books::getMatchList($id, $this->userId, $pageSize);
- showJson(1005, 1001, $dataList);
- }else if ($isHide){
- showJson(1004, 5002);
- }else if ($isBook != 3){
- showJson(1004, 5025);
- }else{
- showJson(1004, 5024);
- }
- }
- /**
- * 获取匹配结果
- */
- public function getMatchResult()
- {
- $aid = input('aid', 0);
- $result = HeartMatch::getMatchResult($aid, $this->userId);
- showJson(1005, 1001, $result);
- }
- /**
- * 设置互选匹配用户
- */
- public function setMatchUser()
- {
- $aid = input('aid');
- $uids = input('uids', '');
- $result = Books::setMatchUser($aid, $this->userId, $uids);
- if (is_array($result)) {
- showJson(1005, 6006);
- } else {
- showJson(1004, $result ? $result : 6007);
- }
- }
- /**
- * 获取我设置互选的人
- */
- public function getMatchUser()
- {
- $aid = input('aid');
- $result = HeartMatch::getHeartUids($aid, $this->userId);
- showJson(1005, 1001, $result ? $result : []);
- }
- }
- ?>
|