ActivityController.php 12 KB

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