ActivityController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  112. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  113. }
  114. // 完善个人信息
  115. if (!UserProfile::checkUserProfile($this->userId)) {
  116. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  117. }
  118. // 隐身不可申请单身推荐
  119. $id = input('id');
  120. $isHeart = Member::where(['id'=> $this->userId])->value('is_heart');
  121. if($isHeart != 1 && $id != 15){
  122. showJson(1006, 2038, ['type'=> 'check']);
  123. }
  124. $inviteCode = input('invite_code','');
  125. Member::visitCount($this->userId, 'book', 0,24);
  126. $result = Activity::catchBook($this->userId, $id, $inviteCode);
  127. if (is_array($result)) {
  128. showJson(1005, 5012, $result);
  129. } else {
  130. showJson(1004, $result ? $result : 5013);
  131. }
  132. }
  133. /**
  134. * 置顶报名
  135. */
  136. public function topBooking()
  137. {
  138. // 验证
  139. $this->checkUser();
  140. if (UserProfile::where(['userid' => $this->userId])->value('idcard_check') != 2) {
  141. showJson(1006, 2132, ['url' => Wechat::makeRedirectUrl(url('/weixin/auth/idcard', '', '', true))]);
  142. }
  143. // 完善个人信息
  144. if (!UserProfile::checkUserProfile($this->userId)) {
  145. showJson(1006, 2103, ['url' => Wechat::makeRedirectUrl(url('/weixin/member/profile', '', '', true))]);
  146. }
  147. // 隐身不可报名置顶
  148. $id = input('id');
  149. $isHeart = Member::where(['id'=> $this->userId])->value('is_heart');
  150. if($isHeart != 1 && $id != 16){
  151. showJson(1006, 2038, ['type'=> 'check']);
  152. }
  153. $result = Activity::catchBook($this->userId, $id);
  154. if (is_array($result)) {
  155. showJson(1005, 5012, $result);
  156. } else {
  157. showJson(1004, $result ? $result : 5013);
  158. }
  159. }
  160. /**
  161. * 获取互选报名用户列表
  162. */
  163. public function getChooseList()
  164. {
  165. // 验证
  166. $this->checkUser();
  167. $uid = input('uid',0);
  168. $id = input('id');
  169. $pageSize = input('pageSize', 12);
  170. // 验证是否签到
  171. $userId = $uid>0? $uid : $this->userId;
  172. $bookData = Books::where(['uid' => $userId, 'aid' => $id])
  173. ->where('status', 'in', [2, 3])
  174. ->field('book_num,is_signin,status')
  175. ->find();
  176. $endTime = ActivityModel::where(['id'=> $id])->value('endtime');
  177. $isHide = floor((time()-$endTime)/86400)>=3? 1 : 0;
  178. $isBook = isset($bookData['status']) ? intval($bookData['status']) : 0;
  179. $isSignin = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
  180. if (!$isHide && $isBook == 3 && ($isSignin == 2 || $isSignin == 3)) {
  181. $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';
  182. $dataList = Books::getBookList($id, $pageSize, $field, $userId);
  183. showJson(1005, 1001, $dataList);
  184. }else if ($isHide){
  185. showJson(1004, 5002);
  186. }else if ($isBook != 3){
  187. showJson(1004, 5025);
  188. }else{
  189. showJson(1004, 5024);
  190. }
  191. }
  192. /**
  193. * 获取互选报名用户列表
  194. */
  195. public function getChooseList1()
  196. {
  197. // 验证
  198. //$this->checkUser();
  199. $uid = input('uid',0);
  200. $id = input('id');
  201. $pageSize = input('pageSize', 12);
  202. // 验证是否签到
  203. $userId = $uid>0? $uid : $this->userId;
  204. $bookData = Books::where(['uid' => $userId, 'aid' => $id])
  205. ->where('status', 'in', [2, 3])
  206. ->field('book_num,is_signin,status')
  207. ->find();
  208. $endTime = ActivityModel::where(['id'=> $id])->value('endtime');
  209. $isHide = floor((time()-$endTime)/86400)>=3? 1 : 0;
  210. PRedis::set('test', $bookData, 600);
  211. $isBook = isset($bookData['status']) ? intval($bookData['status']) : 0;
  212. $isSignin = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
  213. if (!$isHide && $isBook == 3 && ($isSignin == 2 || $isSignin == 3)) {
  214. $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';
  215. $dataList = Books::getBookList($id, $pageSize, $field, $userId);
  216. showJson(1005, 1001, $dataList);
  217. }else if ($isHide){
  218. showJson(1004, 5002);
  219. }else if ($isBook != 3){
  220. showJson(1004, 5025);
  221. }else{
  222. showJson(1004, 5024);
  223. }
  224. }
  225. /**
  226. * 选我的人
  227. */
  228. public function getChoosenList()
  229. {
  230. $id = $id = input('id');
  231. $pageSize = input('pageSize', 12);
  232. // 验证是否签到
  233. $bookData = Books::where(['uid' => $this->userId, 'aid' => $id])
  234. ->where('status', 'in', [2, 3])
  235. ->field('book_num,is_signin,status')
  236. ->find();
  237. $endTime = ActivityModel::where(['id'=> $id])->value('endtime');
  238. $isHide = floor((time()-$endTime)/86400)>=3? 1 : 0;
  239. $isBook = isset($bookData['status']) ? intval($bookData['status']) : 0;
  240. $isSignin = isset($bookData['is_signin']) ? intval($bookData['is_signin']) : 0;
  241. if (!$isHide && $isBook == 3 && ($isSignin == 2 || $isSignin == 3)) {
  242. $dataList = Books::getMatchList($id, $this->userId, $pageSize);
  243. showJson(1005, 1001, $dataList);
  244. }else if ($isHide){
  245. showJson(1004, 5002);
  246. }else if ($isBook != 3){
  247. showJson(1004, 5025);
  248. }else{
  249. showJson(1004, 5024);
  250. }
  251. }
  252. /**
  253. * 获取匹配结果
  254. */
  255. public function getMatchResult()
  256. {
  257. $aid = input('aid', 0);
  258. $result = HeartMatch::getMatchResult($aid, $this->userId);
  259. showJson(1005, 1001, $result);
  260. }
  261. /**
  262. * 设置互选匹配用户
  263. */
  264. public function setMatchUser()
  265. {
  266. $aid = input('aid');
  267. $uids = input('uids', '');
  268. $result = Books::setMatchUser($aid, $this->userId, $uids);
  269. if (is_array($result)) {
  270. showJson(1005, 6006);
  271. } else {
  272. showJson(1004, $result ? $result : 6007);
  273. }
  274. }
  275. /**
  276. * 获取我设置互选的人
  277. */
  278. public function getMatchUser()
  279. {
  280. $aid = input('aid');
  281. $result = HeartMatch::getHeartUids($aid, $this->userId);
  282. showJson(1005, 1001, $result ? $result : []);
  283. }
  284. }
  285. ?>