ActivityController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <?php
  2. /**
  3. * 活动模块
  4. * @author wesmiler
  5. */
  6. namespace app\api\controller;
  7. use app\admin\model\ActivityModel;
  8. use app\portal\model\PortalPostModel;
  9. use app\weixin\model\Books;
  10. use app\weixin\model\HeartMatch;
  11. use app\weixin\model\UserProfile;
  12. use app\weixin\model\Wechat;
  13. use app\weixin\model\Member;
  14. use app\weixin\service\Activity;
  15. use app\weixin\service\PRedis;
  16. class ActivityController extends BaseController
  17. {
  18. /**
  19. * 活动列表数据
  20. * @return mixed
  21. */
  22. public function getList()
  23. {
  24. $pageSize = input('pageSize', 12);
  25. $dataList = Activity::getList(input(), $pageSize);
  26. Member::visitCount($this->userId, 'activity');
  27. showJson(1005, 1001, $dataList);
  28. }
  29. /**
  30. * 获取活动详情
  31. */
  32. public function getInfo()
  33. {
  34. $id = input('id');
  35. $type = input('type', 1);
  36. $field = $type == 1 ? 'id,title,cover_img as thumb,addtime,url,is_match,service_time,act_nums,starttime,endtime,description,address,join_address,content' : '';
  37. $info = Activity::getInfo(['id' => $id, 'status'=> 1], $field);
  38. if ($info) {
  39. $bookData = Books::where(['uid' => $this->userId, 'aid' => $id])
  40. ->where('status', 'in', [2, 3])
  41. ->field('book_num,is_signin,status')
  42. ->find();
  43. $info['activity_time'] = '';
  44. $startTime = $info['start_at']? strtotime(str_replace('.','-', $info['start_at'])) : 0;
  45. $endTime = $info['end_at']? strtotime(str_replace('.','-', $info['end_at'])) : 0;
  46. $startTime = strtotime(date('Y-m-d', $startTime));
  47. $endTime = strtotime(date('Y-m-d', $endTime));
  48. if($startTime && $endTime == $startTime){
  49. $times = $info['end_at']? explode(' ', $info['end_at']) : '';
  50. $endAt = isset($times[1])? $times[1] : '';
  51. $info['activity_time'] = $info['start_at'].($endAt? '~'.$endAt : '');
  52. }
  53. $info['is_book'] = isset($bookData['status']) ? intval($bookData['status']) : 0;
  54. $info['is_signin'] = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
  55. $info['book_no'] = isset($bookData['book_num']) ? trim($bookData['book_num']) : '';
  56. $info['book_num'] = Books::getBookCount($id);
  57. $price = isset($info['price']) ? moneyFormat($info['price'], 2) : '0.00';
  58. // 早市价
  59. if(isset($info['market_price'])){
  60. $marketPrice = moneyFormat($info['market_price'],2);
  61. $marketTime = isset($info['market_time']) ? intval($info['market_time']) : 0;
  62. $info['price'] = $marketTime>=time() && $marketPrice>0? $marketPrice : $price;
  63. $info['old_price'] = $price;
  64. }
  65. // 会员价
  66. $memberDiscount = isset($info['member_discount']) ? floatval($info['member_discount']) : 0;
  67. if($memberDiscount && ($type == 2 || isset($info['price']))){
  68. $memberInfo = Member::where(['id' => $this->userId])->field('vip_auth,vip_expire')->find();
  69. $vipAuth = isset($memberInfo['vip_auth']) ? intval($memberInfo['vip_auth']) : 0;
  70. $vipExpire = isset($memberInfo['vip_expire']) ? intval($memberInfo['vip_expire']) : 0;
  71. if($vipAuth && $vipExpire > time() && $memberDiscount && $memberDiscount < 1){
  72. $info['vip_price'] = moneyFormat($memberDiscount * $info['price'],2);
  73. }
  74. }
  75. // 匹配模式默认已匹配
  76. $siteInfo = $siteInfo = cmf_get_site_info();
  77. $info['match_type'] = isset($siteInfo['contact_type']) ? intval($siteInfo['contact_type']) : 1;
  78. if($info['match_type'] == 3){
  79. $info['is_match'] = 1;
  80. }
  81. $articles = config('weixin.articles');
  82. $articleId = isset($articles['about_activity']) ? intval($articles['about_activity']) : 0;
  83. $about = PortalPostModel::where(['id' => $articleId, 'post_type' => 2, 'post_status' => 1])->value('post_content');
  84. $info['about_activity'] = $about ? htmlspecialchars_decode($about) : '';
  85. showJson(1005, 1001, $info);
  86. } else {
  87. showJson(1004, 1002);
  88. }
  89. }
  90. /**
  91. * 关注活动
  92. */
  93. public function collect()
  94. {
  95. $id = input('id');
  96. $opType = input('type', 1);
  97. $result = Activity::collect($this->userId, $id, $opType);
  98. if ($result === true) {
  99. showJson(1005, $opType == 1 ? 2106 : 2108);
  100. } else {
  101. showJson(1004, $result);
  102. }
  103. }
  104. /**
  105. * 活动报名
  106. */
  107. public function booking()
  108. {
  109. // 验证
  110. $this->checkUser();
  111. $profileData = UserProfile::where(['userid'=> $this->userId])->field('id,idcard_check')->find();
  112. $idcardCheck = isset($profileData['idcard_check'])? $profileData['idcard_check'] : 0;
  113. $profileId = isset($profileData['id'])? $profileData['id'] : 0;
  114. if ($idcardCheck != 2) {
  115. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  116. }
  117. // 完善个人信息
  118. if (!$profileId) {
  119. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile?id='.$this->userId, '', '', true))]);
  120. }
  121. // 隐身不可申请单身推荐
  122. $id = input('id');
  123. $isHeart = Member::where(['id'=> $this->userId])->value('is_heart');
  124. if($isHeart != 1 && $id != 15){
  125. showJson(1006, 2038, ['type'=> 'check']);
  126. }
  127. $inviteCode = input('invite_code','');
  128. Member::visitCount($this->userId, 'book', 0,24);
  129. $result = Activity::catchBook($this->userId, $id, $inviteCode);
  130. if (is_array($result)) {
  131. showJson(1005, 5012, $result);
  132. } else {
  133. showJson(1004, $result ? $result : 5013);
  134. }
  135. }
  136. /**
  137. * 置顶报名
  138. */
  139. public function topBooking()
  140. {
  141. // 验证
  142. $this->checkUser();
  143. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  144. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  145. }
  146. // 完善个人信息
  147. if (!UserProfile::checkUserProfile($this->userId)) {
  148. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  149. }
  150. // 隐身不可报名置顶
  151. $id = input('id');
  152. $isHeart = Member::where(['id'=> $this->userId])->value('is_heart');
  153. if($isHeart != 1 && $id != 16){
  154. showJson(1006, 2038, ['type'=> 'check']);
  155. }
  156. $result = Activity::catchBook($this->userId, $id);
  157. if (is_array($result)) {
  158. showJson(1005, 5012, $result);
  159. } else {
  160. showJson(1004, $result ? $result : 5013);
  161. }
  162. }
  163. /**
  164. * 获取互选报名用户列表
  165. */
  166. public function getChooseList()
  167. {
  168. // 验证
  169. $this->checkUser();
  170. $uid = input('uid',0);
  171. $id = input('id');
  172. $pageSize = input('pageSize', 12);
  173. // 验证是否签到
  174. $userId = $uid>0? $uid : $this->userId;
  175. $bookData = Books::where(['uid' => $userId, 'aid' => $id])
  176. ->where('status', 'in', [2, 3])
  177. ->field('book_num,is_signin,status')
  178. ->find();
  179. $endTime = ActivityModel::where(['id'=> $id])->value('endtime');
  180. $isHide = floor((time()-$endTime)/86400)>=3? 1 : 0;
  181. $isBook = isset($bookData['status']) ? intval($bookData['status']) : 0;
  182. $isSignin = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
  183. if (!$isHide && $isBook == 3 && ($isSignin == 2 || $isSignin == 3)) {
  184. $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';
  185. $dataList = Books::getBookList($id, $pageSize, $field, $userId);
  186. showJson(1005, 1001, $dataList);
  187. }else if ($isHide){
  188. showJson(1004, 5002);
  189. }else if ($isBook != 3){
  190. showJson(1004, 5025);
  191. }else{
  192. showJson(1004, 5024);
  193. }
  194. }
  195. /**
  196. * 获取互选报名用户列表
  197. */
  198. public function getChooseList1()
  199. {
  200. // 验证
  201. //$this->checkUser();
  202. $uid = input('uid',0);
  203. $id = input('id');
  204. $pageSize = input('pageSize', 12);
  205. // 验证是否签到
  206. $userId = $uid>0? $uid : $this->userId;
  207. $bookData = Books::where(['uid' => $userId, 'aid' => $id])
  208. ->where('status', 'in', [2, 3])
  209. ->field('book_num,is_signin,status')
  210. ->find();
  211. $endTime = ActivityModel::where(['id'=> $id])->value('endtime');
  212. $isHide = floor((time()-$endTime)/86400)>=3? 1 : 0;
  213. PRedis::set('test', $bookData, 600);
  214. $isBook = isset($bookData['status']) ? intval($bookData['status']) : 0;
  215. $isSignin = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
  216. if (!$isHide && $isBook == 3 && ($isSignin == 2 || $isSignin == 3)) {
  217. $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';
  218. $dataList = Books::getBookList($id, $pageSize, $field, $userId);
  219. showJson(1005, 1001, $dataList);
  220. }else if ($isHide){
  221. showJson(1004, 5002);
  222. }else if ($isBook != 3){
  223. showJson(1004, 5025);
  224. }else{
  225. showJson(1004, 5024);
  226. }
  227. }
  228. /**
  229. * 选我的人
  230. */
  231. public function getChoosenList()
  232. {
  233. $id = $id = input('id');
  234. $pageSize = input('pageSize', 12);
  235. // 验证是否签到
  236. $bookData = Books::where(['uid' => $this->userId, 'aid' => $id])
  237. ->where('status', 'in', [2, 3])
  238. ->field('book_num,is_signin,status')
  239. ->find();
  240. $endTime = ActivityModel::where(['id'=> $id])->value('endtime');
  241. $isHide = floor((time()-$endTime)/86400)>=3? 1 : 0;
  242. $isBook = isset($bookData['status']) ? intval($bookData['status']) : 0;
  243. $isSignin = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
  244. if (!$isHide && $isBook == 3 && ($isSignin == 2 || $isSignin == 3)) {
  245. $dataList = Books::getMatchList($id, $this->userId, $pageSize);
  246. showJson(1005, 1001, $dataList);
  247. }else if ($isHide){
  248. showJson(1004, 5002);
  249. }else if ($isBook != 3){
  250. showJson(1004, 5025);
  251. }else{
  252. showJson(1004, 5024);
  253. }
  254. }
  255. /**
  256. * 获取匹配结果
  257. */
  258. public function getMatchResult()
  259. {
  260. $aid = input('aid', 0);
  261. $result = HeartMatch::getMatchResult($aid, $this->userId);
  262. showJson(1005, 1001, $result);
  263. }
  264. /**
  265. * 设置互选匹配用户
  266. */
  267. public function setMatchUser()
  268. {
  269. $aid = input('aid');
  270. $uids = input('uids', '');
  271. $result = Books::setMatchUser($aid, $this->userId, $uids);
  272. if (is_array($result)) {
  273. showJson(1005, 6006);
  274. } else {
  275. showJson(1004, $result ? $result : 6007);
  276. }
  277. }
  278. /**
  279. * 获取我设置互选的人
  280. */
  281. public function getMatchUser()
  282. {
  283. $aid = input('aid');
  284. $result = HeartMatch::getHeartUids($aid, $this->userId);
  285. showJson(1005, 1001, $result ? $result : []);
  286. }
  287. }
  288. ?>