SubscripService.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <?php
  2. namespace app\main\service;
  3. use app\admin\library\ShortUrl;
  4. use app\common\library\Redis;
  5. use app\main\constants\ActivityConstants;
  6. use app\main\constants\BookConstants;
  7. use app\main\constants\CacheConstants;
  8. use app\main\constants\ConsumeConstants;
  9. use app\main\constants\UrlConstants;
  10. use think\Cookie;
  11. use think\Exception;
  12. use think\Model;
  13. use think\Config;
  14. /**
  15. * 订阅活动
  16. * Class SubscripService
  17. * @package app\main\service
  18. */
  19. class SubscripService extends BaseService
  20. {
  21. private static $self=null;
  22. public static function instance()
  23. {
  24. if (self::$self == null) {
  25. self::$self = new self();
  26. }
  27. return self::$self;
  28. }
  29. //根据日期获取活动
  30. /**
  31. * @param $date
  32. * @return array
  33. */
  34. public function getActivity($date)
  35. {
  36. $redisKey = ActivityConstants::SUBSCRIP_ACTIVITY.$date;
  37. $active = Redis::instance()->hGetAll($redisKey);
  38. if (empty($active)){
  39. $active = model('SubscripActivity')
  40. ->where('begin_date',$date)
  41. ->where('state',1)
  42. ->find();
  43. if (empty($active)){
  44. $active['id'] = 0;
  45. }
  46. $active = is_object($active)?$active->toArray():$active;
  47. Redis::instance()->hMSet($redisKey,$active);
  48. Redis::instance()->expire($redisKey,3600*24);
  49. }
  50. if ( isset($active['id']) && !$active['id'] ){
  51. $active = [];
  52. }
  53. $active = self::formatActivity($active);
  54. return (array)$active;
  55. }
  56. /**
  57. * @param $Id
  58. * @return array
  59. */
  60. public function getActivityById($id)
  61. {
  62. $redisKey = ActivityConstants::SUBSCRIP_ACTIVITY.$id;
  63. $active = Redis::instance()->hGetAll($redisKey);
  64. if (empty($active)){
  65. $active = model('SubscripActivity')
  66. ->where('id',$id)
  67. ->find();
  68. if (empty($active)){
  69. $active['id'] = 0;
  70. }
  71. $active = is_object($active) ? $active->toArray() : $active;
  72. Redis::instance()->hmSet($redisKey,$active);
  73. Redis::instance()->expire($redisKey,3600*24);
  74. }
  75. if ( isset($active['id']) && !$active['id'] ){
  76. $active = [];
  77. }
  78. $active = self::formatActivity($active);
  79. return (array)$active;
  80. }
  81. /**
  82. * 处理活动状态 0 未开始 1 进行中 2 结束
  83. * @param $act
  84. * @return array
  85. */
  86. public static function formatActivity($act)
  87. {
  88. if (empty($act)){
  89. return [];
  90. }
  91. $act['status'] = $act['end_date'] >= date('Ymd',time()) ? 1 : 2;
  92. $act['md'] = substr($act['begin_date'],4);
  93. $act['md_bt'] = substr($act['begin_date'],4,2).'月'.substr($act['begin_date'],6).'日';
  94. $act['md_et'] = substr($act['end_date'],4,2).'月'.substr($act['end_date'],6).'日';
  95. return $act;
  96. }
  97. /**
  98. * 取出用户在进行中的活动
  99. * @param $userId
  100. * @return array
  101. */
  102. public function getActivityUser($userInfo)
  103. {
  104. $isWrite = model('ChannelSpecialManage')->isWhite('subscribe', $userInfo->channel_id);
  105. if (!$isWrite){
  106. return [];
  107. }
  108. $userId = $userInfo->id;
  109. $redisKey = ActivityConstants::SUBSCRIP_ACT_USER.$userId;
  110. $actUser = Redis::instance()->hGetAll($redisKey);
  111. LogService::info('订阅活动'.json_encode($actUser));
  112. if (empty($actUser)){
  113. $actUser = model('SubscripUser')
  114. ->where('user_id',$userId)
  115. ->where('act_end_date','>=',date('Ymd',time()))
  116. ->find();
  117. if (empty($actUser)){
  118. $actUser['id'] = 0;
  119. }
  120. $actUser = is_object($actUser) ? $actUser->toArray() : $actUser;
  121. Redis::instance()->hmSet($redisKey,$actUser);
  122. Redis::instance()->expire($redisKey,3600*24);
  123. }
  124. if ( !isset($actUser['id']) || $actUser['id'] == 0 ){
  125. $actUser = [];
  126. }
  127. return $actUser;
  128. }
  129. /**
  130. * 获取用户参加的所有活动
  131. * @param $userId
  132. * @return array
  133. */
  134. public function getUserActList($userId)
  135. {
  136. $redisKey = ActivityConstants::SUBSCRIP_ACT_USER_LIST.$userId;
  137. $ids = Redis::instance()->sMembers($redisKey);
  138. $actList = [];
  139. if (empty($ids)){
  140. $actL = model('SubscripUser')
  141. ->where('user_id',$userId)
  142. ->where('state','>',0)
  143. ->select();
  144. if ($actL){
  145. foreach($actL as &$act){
  146. $act = is_object($act) ? $act->toArray() : $act;
  147. $ids[] = $act['act_id'];
  148. Redis::instance()->sadd($redisKey,$act['act_id']);
  149. }
  150. }else{
  151. $ids[] = -1;
  152. Redis::instance()->sadd($redisKey,-1);
  153. }
  154. }
  155. $ids = array_unique($ids);
  156. if (!empty($ids)){
  157. foreach($ids as $id){
  158. $actemp = $this->getActivityById($id);
  159. if (!empty($actemp)){
  160. $actList[] = $actemp;
  161. }
  162. }
  163. }
  164. return (array)$actList;
  165. }
  166. public function checkUserState($userId,$actId)
  167. {
  168. $actL = model('SubscripUser')
  169. ->where('user_id',$userId)
  170. ->where('act_id',$actId)
  171. ->find();
  172. $state = !empty($actL) && $actL['state'] ? $actL['state'] : 3;
  173. return $state;
  174. }
  175. /**
  176. * 获取用户的打卡记录
  177. * @param $userInfo
  178. * @param $actId
  179. */
  180. public function getUserActLog($userInfo,$actId,$activity)
  181. {
  182. $redisKey = ActivityConstants::SUBSCRIP_USER_LOG.$userInfo->id.':'.$actId;
  183. $logList = Redis::instance()->sMembers($redisKey);
  184. LogService::info('SQL'.json_encode($logList));
  185. if (!$logList){
  186. $logList = model('SubscripLog')
  187. ->where('user_id',$userInfo->id)
  188. ->where('act_id',$actId)
  189. ->where('state','>',0)
  190. ->order('date','asc')
  191. ->select();
  192. if ($logList){
  193. $logList = array_column($logList,null,'date');
  194. foreach ($logList as $key =>$value){
  195. Redis::instance()->sadd($redisKey,json_encode($value));
  196. }
  197. }else{
  198. Redis::instance()->sadd($redisKey,json_encode(['date'=>0]));
  199. }
  200. Redis::instance()->expire($redisKey,86400);
  201. }else{
  202. $tempList = [];
  203. foreach ($logList as $key =>$value){
  204. $value = json_decode($value,true);
  205. $tempList[$value['date']] = $value;
  206. }
  207. $logList = $tempList;
  208. }
  209. $dateList = $this->getDateList($activity['begin_date'],$activity['days']);
  210. $log = [];
  211. //本次活动是否补卡
  212. $activity['re_sign'] = 0;
  213. foreach($dateList as $k =>$v){
  214. $temp = [
  215. 'id'=>$actId,
  216. 'user_id'=>$userInfo->id,
  217. 'date'=>isset($logList[$v]) ? $logList[$v]['date'] : $v,
  218. 'state'=>isset($logList[$v]) ? $logList[$v]['state'] : 0,
  219. 'sort'=>$k+1,
  220. 'days'=>$activity['days'],
  221. ];
  222. if ($temp['state'] == 2){
  223. $activity['re_sign'] = 1;
  224. }
  225. //如果是当天的就标记为-1 未完成状态(前端显示)
  226. $temp['state'] = ($temp['state'] == 0 && $temp['date'] == date('Ymd')) ? -1 : $temp['state'];
  227. $temp['d_text'] = substr($temp['date'],4,2).'月'.substr($temp['date'],6).'日';
  228. $log[] = $temp;
  229. }
  230. $activity['sort_day'] = count($dateList);
  231. $result['activity'] = $activity;
  232. $result['log'] = $log;
  233. $param = [
  234. 'sub_code'=>$userInfo->id.'_'.$actId,
  235. 'book_id'=>$activity['book_id'],
  236. 'sid'=>(int)$activity['chapter_id'],
  237. ];
  238. //获取分享内容
  239. $result['con'] = $this->getShareCon($userInfo->channel_id,$param,$activity);
  240. return $result;
  241. }
  242. /**
  243. * 生成日期列表
  244. * @param $beginDate
  245. * @param $days
  246. * @return array
  247. */
  248. public function getDateList($beginDate,$days)
  249. {
  250. $dateList = [];
  251. $beginTime = strtotime($beginDate);
  252. $today = date('Ymd',time());
  253. for ($i = 1;$i<=$days;$i++){
  254. $date = date('Ymd',$beginTime+3600*24*$i);
  255. if ($date > $today){
  256. break;
  257. }
  258. $dateList[] = $date;
  259. }
  260. return $dateList;
  261. }
  262. /**
  263. * 生成分析内容
  264. * @param $channelId
  265. * @param $params
  266. * @return string
  267. */
  268. public function getShareCon($channelId,$params)
  269. {
  270. $url = getCurrentDomain($channelId,'/index/book/chapter',$params);
  271. $shareUrl = '';
  272. $shortUrl = new ShortUrl();
  273. $shareUrl = $shortUrl->tencent($channelId, $url);
  274. $shareUrl = $shareUrl ? $shareUrl : $url;
  275. $con = "[微信红包]恭喜发财,大吉大利!       
  276. 【 亲爱的,麻烦帮我一下吧,我正在参加阅读打卡返现活动,拜托帮帮我 】
  277. {$shareUrl}(链接地址)
  278. 帮我點上面链接,一起参加活动
  279. 从此告别书荒,热门小说应有尽有!~
  280. (悄悄告诉你,他们家书里有福利哟~你懂得)
  281. 爱你哟~!";
  282. return $con;
  283. }
  284. /**
  285. * 报名
  286. * @param $userInfo
  287. * @param $actId
  288. * @param $subCode
  289. * @return bool
  290. */
  291. public function insertActUser($userInfo,$actId,$orderInfo)
  292. {
  293. $actInfo = $this->getActivityById($actId);
  294. if (empty($actInfo)){
  295. LogService::info('订阅活动不存在'.$actId);
  296. return '';
  297. }
  298. //获取充值记录
  299. $recharge = FinancialService::instance()->getRechargeModel()->setConnect($orderInfo['user_id'])
  300. ->where('user_id', $orderInfo['user_id'])
  301. ->where('orders_id', $orderInfo['id'])
  302. ->find();
  303. //消费掉这条记录
  304. if (!empty($recharge)){
  305. $kandian = $recharge['remain_kandian'];
  306. $freeKandian = $recharge['remain_free_kandian'];
  307. FinancialService::instance()->getRechargeModel()->setConnect($orderInfo['user_id'])->update(['remain_kandian'=>0,'remain_free_kandian'=>0], ['id' => $recharge['id']]);
  308. $cache = CacheConstants::getFreeKandianUserRechargeListCacheKey($orderInfo['user_id']);
  309. $fcache = CacheConstants::getKandianUserRechargeListCacheKey($orderInfo['user_id']);
  310. Redis::instance()->del($cache);
  311. Redis::instance()->del($fcache);
  312. $consume = [
  313. 'user_id' => $orderInfo['user_id'],
  314. 'book_id' => 0,
  315. 'book_name' => '',
  316. 'type' => 0,
  317. 'chapter_id' => '',
  318. 'chapter_name' => '',
  319. 'kandian' => intval($kandian),
  320. 'free_kandian'=>(int)$freeKandian,
  321. 'dd_kandian' => $recharge['dd'] == 1 ? intval($kandian) : 0,
  322. 'createtime' => time(),
  323. 'updatetime' => time(),
  324. 'extend1' => '',
  325. 'extend2' => '',
  326. ];
  327. $info = [
  328. 'id' => $recharge['id'],
  329. 'kandian' => $kandian,
  330. 'free_kandian' => $freeKandian,
  331. 'dd_kandian' => $recharge['dd'] == 1 ? $recharge['kandian'] : 0,
  332. 'dd_free_kandian' => 0,
  333. 'remark'=>'读书订阅活动直接消费'
  334. ];
  335. $consume['consume_info'] = json_encode($info,JSON_UNESCAPED_UNICODE);
  336. FinancialService::instance()->getConsumeModel()->setConnect($orderInfo['user_id'])->insertGetId($consume);
  337. }
  338. //活动报名
  339. $insert = [
  340. 'user_id'=>$userInfo['id'],
  341. 'open_id'=>$userInfo['openid'],
  342. 'channel_id'=>$userInfo['channel_id'],
  343. 'act_id'=>$actId,
  344. 'act_date'=>$actInfo['begin_date'],
  345. 'act_end_date'=>$actInfo['end_date'],
  346. 'state'=>1,
  347. 'sub_code'=>$userInfo['id'].'_'.$actId,
  348. 'created_at'=>time(),
  349. 'updated_at' =>time()
  350. ];
  351. try {
  352. model('SubscripUser')->insert($insert);
  353. $this->delCache($userInfo['id']);
  354. LogService::info('订阅活动报名成功'.json_encode($userInfo));
  355. }catch (Exception $e){
  356. LogService::info('订阅活动重复报名'.$e->getMessage());
  357. }
  358. return true;
  359. }
  360. /**
  361. * 补卡
  362. * @param $toUserId
  363. * @param $actId
  364. * @return bool
  365. */
  366. public function insertOldLog($userInfo)
  367. {
  368. $channelIds = model('ChannelSpecialManage')->isWhite('subscribe', $userInfo['channel_id']);
  369. if (empty($channelIds)){
  370. return '';
  371. }
  372. //获取要补卡的用户
  373. $userId = $userInfo['id'];
  374. $fatherUser = model('SubscripUserRelation')
  375. ->where('user_id',$userId)
  376. ->where('state',1)
  377. ->where('lasttime','>',time())
  378. ->select();
  379. if (empty($fatherUser)){
  380. LogService::info('订阅活动-没有要补卡用户:'.$userId);
  381. return true;
  382. }
  383. foreach ($fatherUser as $k =>$v){
  384. $isFind = model('SubscripLog')->where('user_id',$v['father_user_id'])->where('act_id',$v['act_id'])->where('state',2)->find();
  385. if (!$isFind){
  386. $fatherUser = $v;
  387. break;
  388. }
  389. }
  390. if ($isFind){
  391. return false;
  392. }
  393. //查看所有打卡记录
  394. $logList = model('SubscripLog')
  395. ->field('date,id')
  396. ->where('user_id',$fatherUser['father_user_id'])
  397. ->where('act_id',$fatherUser['act_id'])
  398. ->select();
  399. $activity = $this->getActivityById($fatherUser['act_id']);
  400. $logList = array_column($logList,null,'date');
  401. $dateList = $this->getDateList($activity['begin_date'],$activity['days']);
  402. $count = count($dateList);
  403. //得到未补卡的时间
  404. $date = 0;
  405. for ($i=0;$i<$count;$i++){
  406. if (!isset($logList[$dateList[$i]])){
  407. $date = $dateList[$i];
  408. break;
  409. }
  410. }
  411. //写入打卡记录
  412. $insert = [
  413. 'user_id'=>$fatherUser['father_user_id'],
  414. 'act_id'=>$fatherUser['act_id'],
  415. 'date'=>$date,
  416. 'state'=>2,
  417. 'to_user_id'=>$userId,
  418. 'created_at'=>time(),
  419. 'updated_at'=>time(),
  420. ];
  421. //如果是活动的最后一天,标记用户的完成状态
  422. if ($activity['end_date'] == date('Ymd',time())){
  423. $count = model('SubscripLog')->where('user_id',$fatherUser['father_user_id'])->where('act_id',$fatherUser['act_id'])->group('date')->count();
  424. if($activity['days'] - $count <= 1){
  425. $this->updateUserState($fatherUser['father_user_id'],$fatherUser['act_id'],2);
  426. }
  427. }
  428. model('SubscripLog')->insert($insert);
  429. //更新所有关联用户为补卡状态
  430. model('SubscripUserRelation')->update(['state'=>2],['father_user_id'=>$fatherUser['father_user_id'],'act_id'=>$fatherUser['act_id']]);
  431. //删除打卡日志redis
  432. $this->delUserLogRedis($userId,$activity['id']);
  433. LogService::info('订阅活动补卡信息:'.json_encode($insert));
  434. return true;
  435. }
  436. /**
  437. * 分享的用户 写入关系表
  438. * @param $subCode
  439. * @param $userId
  440. * @return bool
  441. */
  442. public function insertUserRelation($subCode,$userId)
  443. {
  444. $subCode = explode('_',$subCode);
  445. if (!isset($subCode[0]) || !isset($subCode[1])){
  446. LogService::info('订阅活动补卡code错误:'.$subCode);
  447. return true;
  448. }
  449. $activity = $this->getActivityById($subCode[1]);
  450. if (empty($activity)){
  451. LogService::info('订阅活动无效:'.$subCode);
  452. return true;
  453. }
  454. //写入打卡记录
  455. $insert = [
  456. 'user_id'=>$userId,
  457. 'father_user_id'=>$subCode[0],
  458. 'act_id'=>$subCode[1],
  459. 'state'=>1,
  460. 'lasttime'=>strtotime($activity['end_date'])+3600*24,
  461. 'createtime'=>time()
  462. ];
  463. try {
  464. model('SubscripUserRelation')->save($insert);
  465. }catch (Exception $exception){
  466. LogService::info('订阅活动-插入关联表重复');
  467. }
  468. }
  469. /**
  470. * 打卡接口
  471. * @param $actUser
  472. * @return int|string
  473. */
  474. public function insertLog($actUser)
  475. {
  476. //查看用户今天有没打卡
  477. $today = date('Ymd',time());
  478. $redisKey = ActivityConstants::SUBSCRIP_USER_SIGN.$today.':'.$actUser['user_id'];
  479. if(Redis::instance()->exists($redisKey) || $today == $actUser['act_date']){//今天打过卡
  480. LogService::info('活动第一天,或者今日已经打卡:'.json_encode($actUser));
  481. return false;
  482. }
  483. $activity = $this->getActivityById($actUser['act_id']);
  484. //活动结束
  485. if (empty($activity) || $activity['end_date']<$today){
  486. $this->updateUserState($actUser['user_id'],$actUser['act_id'],3);
  487. LogService::info('本次活动完成:'.json_encode($activity));
  488. return false;
  489. }
  490. //如果是最后一天
  491. $state = 0;
  492. if ($activity['end_date'] == $today){
  493. $count = model('SubscripLog')->where('user_id',$actUser['user_id'])->where('act_id',$actUser['act_id'])->group('date')->count();
  494. if($activity['days'] - $count <= 1){
  495. $state = 2;
  496. }
  497. }
  498. $insert = [
  499. 'user_id'=>$actUser['user_id'],
  500. 'act_id'=>$actUser['act_id'],
  501. 'date'=>$today,
  502. 'state'=>1,
  503. 'created_at'=>time(),
  504. 'updated_at'=>time()
  505. ];
  506. $res = model('SubscripLog')->insert($insert);
  507. if ($res){
  508. Redis::instance()->set($redisKey,1,3600*24);
  509. //更新用户的最后打卡时间
  510. $this->updateUserState($actUser['user_id'],$actUser['act_id'],$state,date('Ymd',time()));
  511. //更新用户打卡日志缓存
  512. $this->delUserLogRedis($actUser['user_id'],$actUser['act_id']);
  513. }
  514. LogService::info('打卡完成:'.json_encode($actUser));
  515. return (int)$res;
  516. }
  517. /**
  518. * @param $userId
  519. * @param $actId
  520. * @param $state
  521. * @return false|int
  522. */
  523. public function updateUserState($userId,$actId,$state=0,$last_date='')
  524. {
  525. $actUser = model('SubscripUser')->where('user_id',$userId)
  526. ->where('act_id',$actId)
  527. ->find();
  528. if ($state){
  529. $actUser->state = $state;
  530. }
  531. if ($last_date){
  532. $actUser->last_date = $last_date;
  533. }
  534. $re = $actUser->save();
  535. $redisKey = ActivityConstants::SUBSCRIP_ACT_USER.$actUser['user_id'];
  536. Redis::instance()->del($redisKey);
  537. return $re;
  538. }
  539. /**
  540. * 清除用户打卡日志的缓存
  541. * @param $userId
  542. * @param $actId
  543. * @return bool
  544. */
  545. public function delUserLogRedis($userId,$actId)
  546. {
  547. $redisKey = ActivityConstants::SUBSCRIP_USER_LOG.$userId.':'.$actId;
  548. Redis::instance()->del($redisKey);
  549. return true;
  550. }
  551. /**
  552. * 获得弹窗信息
  553. * @param $userInfo
  554. * @param $actionUrl //当前用户访问的方法
  555. * @return array
  556. */
  557. public function getActPop($userInfo,$actionUrl)
  558. {
  559. $date = date('Ymd',time());
  560. $channelIds = model('ChannelSpecialManage')->isWhite('subscribe', $userInfo->channel_id);
  561. //活动是不是开启
  562. if (empty($channelIds)){
  563. return [];
  564. }
  565. //今天没活动
  566. $activity = $this->getActivity($date);
  567. if (empty($activity)){
  568. return [];
  569. }
  570. //查看用户是否有权限
  571. $redisKey = ActivityConstants::SUBSCRIP_USER_AUTH.$userInfo->id;
  572. $actAuth= Redis::instance()->SISMEMBER($redisKey,$activity['id']);
  573. if (empty($actAuth)){
  574. return [];
  575. }
  576. //当前位置能不能弹窗
  577. $location = [
  578. '/index/user/recent' => 2,
  579. '/index/user/index' => 1,
  580. '/index/index/index' => 3
  581. ];
  582. $actionIndex = $location[$actionUrl] ?? 0;
  583. // LogService::info($actionUrl.'--'.$activity['pop_space'].'订阅活动弹窗');
  584. // LogService::info(strstr((string)$activity['pop_space'],(string)$actionIndex).'订阅活动弹窗');
  585. if( strstr((string)$activity['pop_space'],(string)$actionIndex) === false ){
  586. return [];
  587. }
  588. $res['act_pop_img'] = $activity['pop_img'];
  589. $res['act_banner_img'] = $activity['banner_img'];
  590. $res['type'] = $actionIndex;
  591. //判断今天的弹窗次数
  592. $sub_pop_num = Cookie::get('sub_act_val');
  593. if ($sub_pop_num && $sub_pop_num >= 4) {
  594. $res['act_pop_img'] = '';
  595. }
  596. LogService::info(json_encode($res).'订阅活动弹窗');
  597. return $res;
  598. }
  599. /**
  600. * 检查是否需要banner
  601. */
  602. public function checkSubBanner($userInfo)
  603. {
  604. $date = date('Ymd',time());
  605. $channelIds = model('ChannelSpecialManage')->isWhite('subscribe', $userInfo->channel_id);
  606. //活动是不是开启
  607. if (empty($channelIds)){
  608. return '';
  609. }
  610. //今天没活动
  611. $activity = $this->getActivity($date);
  612. if (empty($activity)){
  613. return '';
  614. }
  615. //查看用户是否有权限
  616. $redisKey = ActivityConstants::SUBSCRIP_USER_AUTH.$userInfo->id;
  617. $actAuth= Redis::instance()->SISMEMBER($redisKey,$activity['id']);
  618. if (empty($actAuth)){
  619. return '';
  620. }
  621. $bannerImg = $activity['banner_img'];
  622. return $bannerImg;
  623. }
  624. /**
  625. * @param $userInfo
  626. * @return int
  627. * 检查用户是否报名过
  628. */
  629. public function checkUserSign($userInfo)
  630. {
  631. $channelIds = model('ChannelSpecialManage')->isWhite('subscribe', $userInfo->channel_id);
  632. LogService::info('订阅活动check'.$channelIds);
  633. //活动是不是开启
  634. if (empty($channelIds)){
  635. return 0;
  636. }
  637. $res = $this->getUserActList($userInfo->id);
  638. // LogService::info('订阅活动'.$res);
  639. return (int)$res;
  640. }
  641. public function delCache($userId)
  642. {
  643. $redisKey = ActivityConstants::SUBSCRIP_ACT_USER_LIST.$userId;
  644. Redis::instance()->del($redisKey);
  645. $redisKey = ActivityConstants::SUBSCRIP_ACT_USER.$userId;
  646. Redis::instance()->del($redisKey);
  647. return;
  648. }
  649. }