CardFlipService.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <?php
  2. namespace app\common\service;
  3. use app\api\controller\Recharge;
  4. use app\common\library\Redis;
  5. use app\main\constants\ActivityConstants;
  6. use app\main\constants\BookConstants;
  7. use app\main\constants\KafkaDotConstants;
  8. use app\main\model\object\AnalysisObject;
  9. use app\main\service\ApiService;
  10. use app\main\service\BuyMoreService;
  11. use app\main\service\FinancialService;
  12. use app\main\service\KafkaDotService;
  13. use app\main\service\UserDdFlushService;
  14. use app\main\service\UserService;
  15. use app\source\model\UserUpdate;
  16. use BaconQrCode\Common\Mode;
  17. class CardFlipService extends BaseService
  18. {
  19. /**
  20. * @var CardFlipService
  21. */
  22. protected static $self = NULL;
  23. /**
  24. * @return CardFlipService
  25. */
  26. public static function instance()
  27. {
  28. if (self::$self == NULL) {
  29. self::$self = new self();
  30. }
  31. return self::$self;
  32. }
  33. //后台 促销活动->消耗活动菜单
  34. public function checkAuth($auth)
  35. {
  36. $campaign = model('ChannelSpecialManage')->isWhite('campaign', $auth);
  37. if ($campaign){
  38. return '/admin/campaign/read';
  39. }
  40. $card = model('ChannelSpecialManage')->isWhite('cardflip', $auth);
  41. if ($card){
  42. return '/admin/card/flip';
  43. }
  44. return '';
  45. }
  46. /**
  47. * 后台 消耗活动-翻牌、读书 权限
  48. * @param $group
  49. * @param $auth
  50. * @return array
  51. */
  52. public function getAuth($group,$auth)
  53. {
  54. $camAuth = ['campaign','cardflip'];
  55. if ( in_array($group,[1,2,6]) ){
  56. return $camAuth;
  57. }
  58. $campaign = model('ChannelSpecialManage')->isWhite('campaign', $auth);
  59. if (!$campaign){
  60. unset($camAuth[0]);
  61. }
  62. $card = model('ChannelSpecialManage')->isWhite('cardflip', $auth);
  63. if (!$card){
  64. unset($camAuth[1]);
  65. }
  66. return $camAuth;
  67. }
  68. /**
  69. * @param $actId
  70. * @return array
  71. */
  72. public function winList($actId)
  73. {
  74. $redisKey = ActivityConstants::CARD_AWARD_WIN_LIST.$actId;
  75. $redislist = Redis::instance()->lRange($redisKey,0,-1);
  76. $res = [];
  77. foreach ($redislist as $k=>$v){
  78. $res[] = json_decode($v,true);
  79. }
  80. unset($redislist);
  81. return $res;
  82. }
  83. /**
  84. * 获取本次活动的详情-后台刷到redis
  85. * @param $id
  86. * @return array
  87. */
  88. public function getCardInfo($id)
  89. {
  90. $redisKey = ActivityConstants::CARD_FLIP_INFO.$id;
  91. $cardInfo = Redis::instance()->hGetAll($redisKey);
  92. return $cardInfo;
  93. }
  94. /**
  95. * 查看用户是否在用户组中
  96. * @param $userGroupId
  97. * @param $userInfo
  98. * @return bool
  99. */
  100. public function checkUserAuth($userGroupId,$userInfo)
  101. {
  102. return true;
  103. $redisKey = ActivityConstants::USER_GROUP_SET.$userGroupId.$userInfo->channel_id;
  104. $isHave = Redis::instance()->sIsMember($redisKey,$userInfo->id);
  105. return (bool)$isHave;
  106. }
  107. /**
  108. * 获取banner
  109. * @param $userInfo
  110. * @return array|mixed
  111. */
  112. public function getBannerImage($userInfo)
  113. {
  114. return [];//去掉banner图
  115. $redisKey = ActivityConstants::CARD_FLIP_LISTS;
  116. $list = Redis::instance()->sMembers($redisKey);
  117. if (empty($list)){
  118. return [];
  119. }
  120. foreach ($list as $k=>$v){
  121. $temp = json_decode($v,true);
  122. if ($temp['end_time'] < time()){
  123. continue;
  124. }
  125. if ($this->checkUserAuth($temp['group_id'],$userInfo)){
  126. return $temp;
  127. };
  128. }
  129. return [];
  130. }
  131. /**
  132. * @param $actId
  133. * @return array
  134. */
  135. public function getCardAwardList($actId)
  136. {
  137. $redisKey = ActivityConstants::CARD_FLIP_AWARD_LIST.$actId;
  138. $list = Redis::instance()->sMembers($redisKey);
  139. $res = [];
  140. if (empty($list)){
  141. return [];
  142. }
  143. $awardList = $this->getAwardList();
  144. if (empty($awardList)){
  145. return [];
  146. }
  147. foreach ($list as $k =>$v){
  148. $temp = json_decode($v,true);
  149. $award = $awardList[$temp['a_id']] ?? [];
  150. $temp['image'] = $award['image'] ?? '';
  151. $temp['type'] = $award['type'] ?? '';
  152. $temp['content'] = $award['content'] ?? '';
  153. $res[] = $temp;
  154. }
  155. return $res;
  156. }
  157. /**
  158. * 奖品库
  159. * @return array
  160. */
  161. public function getAwardList()
  162. {
  163. $redisKey = ActivityConstants::AWARD_LIST_SET;
  164. $list = Redis::instance()->sMembers($redisKey);
  165. $res = [];
  166. if(!empty($list))foreach ($list as $k=>$v){
  167. $temp = json_decode($v,true);
  168. $res[$temp['id']] = $temp;
  169. }
  170. return $res;
  171. }
  172. /**
  173. * 获取我的奖品列表
  174. * @param $actId
  175. * @param $userId
  176. * @return array
  177. */
  178. public function getMyAward($actId,$userId)
  179. {
  180. $redisKey = ActivityConstants::CARD_USER_AWARD_LIST.$userId.':'.$actId;
  181. $list = Redis::instance()->sMembers($redisKey);
  182. $res = [];
  183. if (!$list){
  184. $dbList = model('CardLog')->where(['c_id'=>$actId,'user_id'=>$userId,'state'=>1])->order('createtime','desc')->limit(30)->select();
  185. $rdList = [];
  186. if ($dbList){
  187. foreach ($dbList as $k=>$v){
  188. $rdList[] = json_encode($v);
  189. }
  190. }else{
  191. $rdList[] = json_encode(['id'=>0]);
  192. }
  193. Redis::instance()->sAddArray($redisKey,$rdList);
  194. Redis::instance()->expire($redisKey,86400);
  195. $res = (array)$dbList;
  196. }else{
  197. foreach ($list as $kk =>$vv){
  198. $temp = json_decode($vv,true);
  199. if ($temp['id'] == 0){
  200. continue;
  201. }
  202. $res[] = $temp;
  203. }
  204. }
  205. return $res;
  206. }
  207. /**
  208. * @param $actId
  209. * @param $userInfo
  210. * @return array|bool|mixed
  211. * @throws \think\Exception
  212. */
  213. public function lottery($actId,$userInfo)
  214. {
  215. //获取活动
  216. $res = ['code'=>1,'msg'=>'','data'=>[]];
  217. $cardInfo = $this->getCardInfo($actId);
  218. if (empty($cardInfo) || $cardInfo['begin_time'] > time() || $cardInfo['end_time'] < time()){
  219. $res['code'] = 0;
  220. $res['msg'] = '活动未开始';
  221. return $res;
  222. }
  223. $consumeKandian = 0;
  224. //用户今天的抽奖次数加一
  225. $isLimit = $this->incrLimit($cardInfo,$userInfo->id);
  226. if (!$isLimit){
  227. $res['code'] = 2;
  228. $res['msg'] = '今天抽奖次数达到'.$cardInfo['limit'].',明日再来!';
  229. return $res;
  230. }
  231. //是否消费成功的标识
  232. $isConsume = false;
  233. //扣减抽奖次数
  234. if ($this->getDrawNum($actId,$userInfo->id)){
  235. $isConsume = $this->decrDrawsNum($actId,$userInfo->id);
  236. }
  237. //获取用户的书币数
  238. if (!$isConsume){
  239. $obj = FinancialService::instance()->getTotalKandianAndFreeKandian($userInfo->id);
  240. if ($cardInfo['kandian'] > $obj->data){
  241. $res['code'] = 3;
  242. $res['msg'] = '书币不足';
  243. $this->decrLimit($cardInfo,$userInfo->id);
  244. return $res;
  245. }
  246. //扣减书币
  247. $isConsume = $this->cardConsumeKandian($userInfo->id,$cardInfo);
  248. $consumeKandian = $cardInfo['kandian'];
  249. }
  250. //消费失败 退回抽奖次数
  251. if (!$isConsume){
  252. $this->decrLimit($cardInfo,$userInfo->id);
  253. }
  254. $awardInfo = [];
  255. //如果消费成功,随机获取奖品
  256. if ($isConsume){
  257. $awardId = $this->getAwardId($actId);
  258. $awardInfo = $this->getCardAwardOne($actId,$awardId);
  259. //给用户分配奖品
  260. if ($awardInfo){
  261. $awardInfo = $this->setUserAward($awardInfo,$userInfo,$cardInfo);
  262. }
  263. //打点pv uv
  264. $this->sendDraws($cardInfo['id'],$userInfo);
  265. if ($consumeKandian){//消耗看点的打点
  266. $this->sendKandian($cardInfo['id'],$userInfo,$consumeKandian);
  267. }
  268. }
  269. if (!$awardInfo){
  270. $awardInfo['id'] = $userInfo->id;
  271. $awardInfo['name'] = '未中奖';
  272. $awardInfo['image'] = cdnurl('/assets/img/frontend/activity/card/result-thank.png');
  273. $awardInfo['type'] = 1;
  274. LogService::info('翻牌活动-抽奖异常'.$userInfo->id);
  275. }
  276. $res['data'] = $awardInfo;
  277. return $res;
  278. }
  279. /**
  280. * 获取当前用户的抽奖次数
  281. * @param $actId
  282. * @param $userId
  283. * @return int
  284. */
  285. public function getDrawNum($actId,$userId)
  286. {
  287. $redisKey = ActivityConstants::CARD_USER_DRAWS_NUM.$actId.$userId;
  288. return (int)Redis::instance()->get($redisKey);
  289. }
  290. /**
  291. * 增加抽奖次数
  292. * @param $actId
  293. * @param $userId
  294. * @param $ttl
  295. * @return bool
  296. */
  297. private function incrDrawsNum($actId,$userId,$ttl)
  298. {
  299. $redisKey = ActivityConstants::CARD_USER_DRAWS_NUM.$actId.$userId;
  300. if(Redis::instance()->exists($redisKey)){
  301. Redis::instance()->incr($redisKey);
  302. }else{
  303. Redis::instance()->setex($redisKey,$ttl,1);
  304. }
  305. LogService::info('翻牌活动-分配奖励-再来一次'.$redisKey);
  306. return true;
  307. }
  308. /**
  309. * 扣除抽奖次数
  310. * @param $actId
  311. * @param $userId
  312. * @return bool
  313. */
  314. private function decrDrawsNum($actId,$userId)
  315. {
  316. $redisKey = ActivityConstants::CARD_USER_DRAWS_NUM.$actId.$userId;
  317. $re = Redis::instance()->decr($redisKey);
  318. if ($re < 0){
  319. Redis::instance()->del($redisKey);
  320. return false;
  321. }
  322. return true;
  323. }
  324. /**
  325. * 查看用户今天的抽奖次数
  326. * @param $cardInfo
  327. * @param $userId
  328. * @return bool
  329. */
  330. private function incrLimit($cardInfo,$userId)
  331. {
  332. if ($cardInfo['limit'] <= 0){
  333. return true;
  334. }
  335. $redisKey = ActivityConstants::CARD_USER_LAST_NUM.$cardInfo['id'].':'.date('Ymd',time()).':'.$userId;
  336. $limitNum = (int)Redis::instance()->get($redisKey);
  337. if ($limitNum >= $cardInfo['limit']){
  338. return false;
  339. }
  340. $re = Redis::instance()->incr($redisKey);
  341. if ($re == 1){//第一次
  342. Redis::instance()->expire($redisKey,86400);
  343. }
  344. return true;
  345. }
  346. /**
  347. * 消费失败-退回用户抽奖次数
  348. * @param $cardInfo
  349. * @param $userId
  350. * @return bool
  351. */
  352. private function decrLimit($cardInfo,$userId)
  353. {
  354. if ($cardInfo['limit'] <= 0){
  355. return true;
  356. }
  357. $redisKey = ActivityConstants::CARD_USER_LAST_NUM.$cardInfo['id'].':'.date('Ymd',time()).':'.$userId;
  358. Redis::instance()->decr($redisKey);
  359. return true;
  360. }
  361. /**
  362. * 翻牌活动的消费
  363. * @param $userId
  364. * @param $cardInfo
  365. * @return bool
  366. */
  367. private function cardConsumeKandian($userId,$cardInfo)
  368. {
  369. UserDdFlushService::instance()->checkUserFlushState($userId);
  370. //扣除永久书币
  371. $res = FinancialService::instance()->payKandian($cardInfo['kandian'], $userId, '翻牌活动-抽奖');
  372. if ( $res->code == 0 ) {
  373. // 增加消费记录
  374. $campJson = json_encode([
  375. 'card_id' => (int)$cardInfo['id'],
  376. 'name' => $cardInfo['name'],
  377. ]);
  378. $consumeData = [
  379. 'user_id' => (int)$userId,
  380. 'type' => 3,
  381. 'chapter_name' => '',
  382. 'free_kandian'=>$res->data['free_kandian'],
  383. 'dd_free_kandian'=>$res->data['dd_free_kandian'],
  384. 'kandian' => $res->data['kandian'],
  385. 'dd_kandian' => $res->data['dd_kandian'],
  386. 'createtime' => time(),
  387. 'updatetime' => time(),
  388. 'camp_info' => $campJson,
  389. ];
  390. FinancialService::instance()->getConsumeModel()->setConnect($userId)->insert($consumeData);
  391. LogService::info('翻牌活动消费成功'.$userId);
  392. return true;
  393. }
  394. LogService::info('翻牌活动消费失败'.json_decode($res));
  395. return false;
  396. }
  397. /**
  398. * 抽奖动作 返回中奖的奖品ID
  399. * @param $actId
  400. * @return int
  401. */
  402. private function getAwardId($actId)
  403. {
  404. if (empty($actId)){
  405. return 0;
  406. }
  407. $codeRedisKey = ActivityConstants::CARD_AWARD_CODES.$actId;
  408. $codes = Redis::instance()->hGetAll($codeRedisKey);
  409. if (empty($codes)){
  410. return 0;
  411. }
  412. $userCode = rand(0,100);
  413. $userAward = 0;
  414. ksort($codes);
  415. foreach ($codes as $k=>$v){
  416. if ($k >= $userCode){
  417. $userAward = $v;
  418. break;
  419. }
  420. }
  421. LogService::info('翻牌活动-中奖种子:'.$userCode.'--'.json_encode($userAward));
  422. return (int)$userAward;
  423. }
  424. /**
  425. * @param $actId
  426. * @param $id
  427. * @return array|mixed
  428. * @throws \think\Exception
  429. */
  430. private function getCardAwardOne($actId,$awardId)
  431. {
  432. $list = $this->getCardAwardList($actId);
  433. $cardAwardList = array_column($list,null,'id');
  434. return $cardAwardList[$awardId] ?? [];
  435. }
  436. /**
  437. * 赠送奖品
  438. * @param $awardInfo
  439. * @param $userInfo
  440. * @param $cardInfo
  441. * @return array|bool
  442. */
  443. private function setUserAward($awardInfo,$userInfo,$cardInfo)
  444. {
  445. $type = $awardInfo['type'];
  446. $insert = [];
  447. $res = [
  448. 'id'=>$userInfo->id,
  449. 'image'=>$awardInfo['image'],
  450. 'name'=>$awardInfo['show_name'],
  451. 'type'=>$type,
  452. ];
  453. $isGet = true;
  454. switch ($type){
  455. case 1:
  456. //无奖励
  457. break;
  458. case 2:
  459. $bookInfo = $this->addBook($userInfo->id,$awardInfo);
  460. if ($bookInfo){
  461. $insert['show_name'] = $bookInfo['name'];
  462. $insert['book_id'] = $bookInfo['id'];
  463. $res['name'] = $bookInfo['name'];
  464. break;
  465. }
  466. $isGet = false;
  467. break;
  468. case 3:
  469. //赠送vip
  470. $isGet = $this->editVipTime($userInfo,(int)$awardInfo['content']);
  471. // $insert['book_id'] = (int)$awardInfo['content'];
  472. break;
  473. case 4:
  474. //赠送书币
  475. $kandian = (int)$awardInfo['content'];
  476. $obj = FinancialService::instance()->modifyUserKandian($userInfo->id,1,1,0,$kandian,'翻牌活动赠送',1);
  477. $isGet = $obj->code == 0 ? true : false;
  478. $res['kandian'] = $kandian;
  479. break;
  480. case 5:
  481. //抽奖次数
  482. $ttl = $cardInfo['end_time'] - time();
  483. $isGet = $this->incrDrawsNum($awardInfo['c_id'], $userInfo->id, $ttl);
  484. break;
  485. default:
  486. break;
  487. }
  488. if (!$isGet){
  489. LogService::info('翻牌活动-分配奖励异常'.json_encode($cardInfo));
  490. return false;
  491. }
  492. LogService::info('翻牌活动-分配奖励成功'.$type);
  493. if (in_array( $type,[2,3,4]) ){
  494. $insert['user_id'] = $userInfo->id;
  495. $insert['state'] = 1;
  496. $insert['show_name'] = $insert['show_name'] ?? $awardInfo['show_name'];
  497. $insert['c_id'] = $awardInfo['c_id'];
  498. $insert['a_id'] = $awardInfo['a_id'];
  499. $insert['create_date'] = date('Ymd',time());
  500. $insert['createtime'] = time();
  501. $insert['success_time'] = 0;
  502. $insert['id'] = model('CardLog')->insertGetId($insert);
  503. //插入缓存
  504. $redisKey = ActivityConstants::CARD_USER_AWARD_LIST.$userInfo->id.':'.$awardInfo['c_id'];
  505. Redis::instance()->del($redisKey);
  506. $redisKey = ActivityConstants::CARD_AWARD_WIN_LIST.$awardInfo['c_id'];
  507. $userList['name'] = $insert['show_name'];
  508. $userList['id'] = $this->hideUserId($userInfo->id);
  509. Redis::instance()->rPush($redisKey,json_encode($userList));
  510. Redis::instance()->lpop($redisKey);
  511. }
  512. return $res;
  513. }
  514. private function hideUserId(string $userId)
  515. {
  516. for ($i = 3;$i<6;$i++){
  517. if (!isset($userId[$i])){
  518. break;
  519. }
  520. $userId[$i] = '*';
  521. }
  522. return $userId;
  523. }
  524. /**
  525. * 增送vip
  526. * @param $userInfo
  527. * @param $awardInfo
  528. * @return bool
  529. */
  530. private function editVipTime($userInfo,$days,$type=6,$notes='翻牌活动赠送')
  531. {
  532. $saveDate = []; //新增充值记录
  533. $userDate = []; //修改用户数据
  534. $userDate['id'] = $userInfo->id;
  535. $saveDate['user_id'] = $userInfo->id;
  536. $saveDate['type'] = $type;
  537. $saveDate['notes'] = $notes;
  538. $saveDate['edit_type'] = 1;
  539. $saveDate['createtime'] = time();
  540. $saveDate['day'] = $days;
  541. if(intval($userInfo->vip_endtime)>time()){
  542. $userDate['vip_endtime'] = $days*86400 + intval($userInfo->vip_endtime);
  543. $saveDate['vip_starttime'] = intval($userInfo->vip_endtime);
  544. }else{
  545. $userDate['vip_endtime'] = $days*86400 +time();
  546. $saveDate['vip_starttime'] = time();
  547. }
  548. $saveDate['vip_starttime'] = model('Recharge')->getVipStartTime($userInfo->id);
  549. $saveDate['channel_vip_starttime'] = model('Recharge')->getChannelVipStartTime($userInfo->id);
  550. if (ApiService::instance()->checkApiOn()) {
  551. $userUpdate = new UserUpdate();
  552. $userUpdate->setId($userInfo->id);
  553. $userUpdate->setAddvipday($days * 86400);
  554. \app\source\service\UserService::instance()->updateUser($userUpdate);
  555. } else {
  556. $flagUser = model('User')->setConnect($userInfo->id)->update($userDate); //更改用户表数据
  557. }
  558. //user加入redis缓存
  559. $userKey = 'UN:'.$userInfo->id;
  560. Redis::instance()->del($userKey);
  561. $flagRecharge = model('Recharge')->setConnect($userInfo->id)->insert($saveDate); //插入充值记录
  562. if(!$flagRecharge){
  563. return false;
  564. }
  565. return true;
  566. }
  567. /**
  568. * 赠送书籍
  569. * @param $userId
  570. * @param $awardInfo
  571. * @return array|bool
  572. */
  573. private function addBook($userId,$awardInfo)
  574. {
  575. //获取书籍ID
  576. $bookIds = explode(',', $awardInfo['content']);
  577. //查看用户已经购买的书
  578. $existBookIds = FinancialService::instance()->getConsumeModel()->setConnect($userId)
  579. ->field('book_id')
  580. ->where('user_id', $userId)
  581. ->where('type', BookConstants::BOOK_BILLING_MODEL_BOOK)
  582. ->select();
  583. if ($existBookIds) {
  584. $existBookIds = array_column($existBookIds, 'book_id');
  585. }
  586. $bookIds = array_diff($bookIds, $existBookIds);
  587. if (!$bookIds) {
  588. return false;
  589. }
  590. $bookId = $bookIds[array_rand($bookIds)];
  591. $bookInfo = model('Book')->BookInfo($bookId);
  592. if (empty($bookInfo)) {
  593. LogService::info('添加的数据信息有误' . $bookId);
  594. return false;
  595. }
  596. BuyMoreService::instance()->addFreeBook($userId, $bookId);
  597. return $bookInfo;
  598. }
  599. public function getCardFlipPvKey($actId, $adminId, $date = null)
  600. {
  601. $date = empty($date) ? date('Ymd') : $date;
  602. return sprintf('PVCF:%s:%s:%s', $date, $adminId, $actId);
  603. }
  604. public function getCardFlipUvKey($actId, $adminId, $date = null)
  605. {
  606. $date = empty($date) ? date('Ymd') : $date;
  607. return sprintf('UVCF:%s:%s:%s', $date, $adminId, $actId);
  608. }
  609. public function getCardFlipDrawsPvKey($actId, $adminId, $date = null)
  610. {
  611. $date = empty($date) ? date('Ymd') : $date;
  612. return sprintf('PVCFD:%s:%s:%s', $date, $adminId, $actId);
  613. }
  614. public function getCardFlipDrawsUvKey($actId, $adminId, $date = null)
  615. {
  616. $date = empty($date) ? date('Ymd') : $date;
  617. return sprintf('UVCFD:%s:%s:%s', $date, $adminId, $actId);
  618. }
  619. public function getCardFlipKandianKey($actId, $adminId, $date = null)
  620. {
  621. $date = empty($date) ? date('Ymd') : $date;
  622. return sprintf('CFKD:%s:%s:%s', $date, $adminId, $actId);
  623. }
  624. /**
  625. * 展示打点
  626. * @param $actId
  627. * @param $userInfo
  628. */
  629. public function sendShow($actId, $userInfo)
  630. {
  631. $timeOutStamp = strtotime(date('Y-m-d 01:00:00', strtotime('+1 day')));
  632. $userInfo = UserService::instance()->getUserInfo();
  633. $channelId = $userInfo->channel_id;
  634. $userId = $userInfo->id;
  635. #region PV
  636. $wholePvKey = $this->getCardFlipPvKey($actId, 0);
  637. Redis::instance()->incr($wholePvKey);
  638. Redis::instance()->expireAt($wholePvKey, $timeOutStamp);
  639. $adminPvKey = $this->getCardFlipPvKey($actId, $channelId);
  640. Redis::instance()->incr($adminPvKey);
  641. Redis::instance()->expireAt($adminPvKey, $timeOutStamp);
  642. #endregion
  643. #region UV
  644. $wholeUvKey = $this->getCardFlipUvKey($actId, 0);
  645. Redis::instance()->pfAdd($wholeUvKey, $userId);
  646. Redis::instance()->expireAt($wholeUvKey, $timeOutStamp);
  647. $adminUvKey = $this->getCardFlipUvKey($actId, $channelId);
  648. Redis::instance()->pfAdd($adminUvKey, $userId);
  649. Redis::instance()->expireAt($adminUvKey, $timeOutStamp);
  650. #endregion
  651. }
  652. /**
  653. * 抽奖打点
  654. * @param $actId
  655. * @param $userInfo
  656. */
  657. private function sendDraws($actId, $userInfo)
  658. {
  659. $timeOutStamp = strtotime(date('Y-m-d 01:00:00', strtotime('+1 day')));
  660. $userInfo = UserService::instance()->getUserInfo();
  661. $channelId = $userInfo->channel_id;
  662. $userId = $userInfo->id;
  663. #region PV
  664. $wholePvKey = $this->getCardFlipDrawsPvKey($actId, 0);
  665. Redis::instance()->incr($wholePvKey);
  666. Redis::instance()->expireAt($wholePvKey, $timeOutStamp);
  667. $adminPvKey = $this->getCardFlipDrawsPvKey($actId, $channelId);
  668. Redis::instance()->incr($adminPvKey);
  669. Redis::instance()->expireAt($adminPvKey, $timeOutStamp);
  670. #endregion
  671. #region UV
  672. $wholeUvKey = $this->getCardFlipDrawsUvKey($actId, 0);
  673. Redis::instance()->pfAdd($wholeUvKey, $userId);
  674. Redis::instance()->expireAt($wholeUvKey, $timeOutStamp);
  675. $adminUvKey = $this->getCardFlipDrawsUvKey($actId, $channelId);
  676. Redis::instance()->pfAdd($adminUvKey, $userId);
  677. Redis::instance()->expireAt($adminUvKey, $timeOutStamp);
  678. #endregion
  679. }
  680. /**
  681. *抽奖消耗看点打点
  682. * @param $actId
  683. * @param $userInfo
  684. * @param int $kandian
  685. */
  686. private function sendKandian($actId, $userInfo, $kandian = 0)
  687. {
  688. $timeOutStamp = strtotime(date('Y-m-d 01:00:00', strtotime('+1 day')));
  689. $channelId = $userInfo->channel_id;
  690. $wholeKey = $this->getCardFlipKandianKey($actId, 0);
  691. Redis::instance()->incrBy($wholeKey, $kandian);
  692. Redis::instance()->expireAt($wholeKey, $timeOutStamp);
  693. $adminKey = $this->getCardFlipKandianKey($actId, $channelId);
  694. Redis::instance()->incrBy($adminKey, $kandian);
  695. Redis::instance()->expireAt($adminKey, $timeOutStamp);
  696. }
  697. }