checkFansLead($user->channel_id, $user->id)->data; if ($export) { //书币赠送次数超限 if ($valid = $this->checkGiveKandianValid($export)->data) { $cache = CacheConstants::getExportFansGiveKandianCount($user->id); $share_times = ArrayHelper::array_get($export, 'share_times'); if (Redis::instance()->get($cache) >= $share_times) { return $this->setData($data)->getReturn(); } } //拉取未充值弹窗 $unrechargeKey = CacheConstants::getFansUnrecharge($user->id); if (Redis::instance()->get($unrechargeKey)) { //获取未充值弹窗 $cookieKey = 'unrecharge_tips_show_times'; $cookie = Cookie::get($cookieKey); if (is_null($cookie) || $cookie < 1) { $data = [ 'id' => $export['id'], 'img' => ArrayHelper::array_get($export, 'recharge_back_img'), 'lead_img' => ArrayHelper::array_get($export, 'recharge_back_lead_img'), 'type' => 'recharge_back', ]; } } if (!$data) { switch ($path) { case '/index/user/recent': case '/index/book/shelf': //最近阅读 $cookieKey = 'recent_tips_show_times'; $cookie = Cookie::get($cookieKey); if (is_null($cookie) || $cookie < 1) { $data = [ 'id' => $export['id'], 'img' => ArrayHelper::array_get($export, 'recent_img'), 'lead_img' => ArrayHelper::array_get($export, 'recent_lead_img'), 'type' => 'recent', ]; } break; case '/index/index/index': //最近阅读 $cookieKey = 'home_tips_show_times'; $cookie = Cookie::get($cookieKey); if (is_null($cookie) || $cookie < 1) { $data = [ 'id' => $export['id'], 'img' => ArrayHelper::array_get($export, 'recent_img'), 'lead_img' => ArrayHelper::array_get($export, 'recent_lead_img'), 'type' => 'recent', ]; } break; case '/index/book/list': //排行等 $cookieKey = 'rank_tips_show_times'; $cookie = Cookie::get($cookieKey); if (is_null($cookie) || $cookie < 1) { $data = [ 'id' => $export['id'], 'img' => ArrayHelper::array_get($export, 'rank_img'), 'lead_img' => ArrayHelper::array_get($export, 'rank_lead_img'), 'type' => 'rank', ]; } break; case '/index/user/index': //个人中心 $cookieKey = 'user_tips_show_times'; $cookie = Cookie::get($cookieKey); if (is_null($cookie) || $cookie < 1) { $data = [ 'id' => $export['id'], 'img' => ArrayHelper::array_get($export, 'user_index_img'), 'lead_img' => ArrayHelper::array_get($export, 'user_index_lead_img'), 'type' => 'user_index', ]; } break; case '/index/user/sign': $cookieKey = 'sign_tips_show_times'; $cookie = Cookie::get($cookieKey); if (is_null($cookie) || $cookie < 1) { $data = [ 'id' => $export['id'], 'img' => ArrayHelper::array_get($export, 'sign_success_img'), 'lead_img' => ArrayHelper::array_get($export, 'sign_success_lead_img'), 'type' => 'sign_success', ]; } break; } } if ($data) { $data['cookiekey'] = $cookieKey; $data['expiretime'] = 1 - (time() - strtotime(date("Ymd"))) / 86400; $data['tpl'] = 'export_fans'; //缺少弹窗图片 if (!$data['img']) { $data = []; } else { //满足导量条件 if ($valid && $data['lead_img']) { $data['lead_url'] = getCurrentDomain($user->channel_id, '/index/share/landpage?id=' . $export['id'] . '&type=' . $data['type']); } else { $data['lead_url'] = ''; } } } } return $this->setData($data)->getReturn(); } /** * 获取活动弹窗 * @param UserObject $user * @param $path * @return \app\main\model\object\ReturnObject */ public function getActivityPop(UserObject $user, $path) { $pathArr = explode('/', $path); $controllerName = $pathArr[1] ?? ''; $actionName = $pathArr[2] ?? ''; $cookieKey = 'ac_val'; $cookie = Cookie::get('ac_val'); if (!is_null($cookie) && $cookie >= 4) { $data = []; } else { $data = ActivityService::instance()->getActivityFront( $controllerName, $actionName, $user->channel_id, $user->id ); if ($data) { $info = [ 'img' => $data['popimage'], 'jump_url' => "/s/0?rid={$data['id']}&aid={$data['aid']}", 'cookie_key' => $cookieKey, 'expiretime' => 1 / 3, 'dot_key' => 'activity_tips', 'tpl' => 'activity', ]; $data = array_merge($data, $info); } } return $this->setData($data)->getReturn(); } /** * 新用户继续阅读弹窗 * @param UserObject $user * @return \app\main\model\object\ReturnObject */ public function getRegisterContinuePop(UserObject $user) { $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($user->channel_id); $isWater = WaterBookService::instance()->showBook($adminConfig['admin_id'],$user->id,Ip::ip()); $data = []; if ($user->is_subscribe && time() - $user->createtime < 3600 && !$user->referral_id_permanent) { //一个小时新注册用户 //先判断cookie是否设置了不弹 if (!Cookie::has('close_continue_tips')) { //开启了自动回复 $switch = AdminService::instance()->getSubscribeSwitchCache($user->channel_id); if (!empty($switch) && $switch['status'] == 1) { if ($switch['type'] == 2) {//自定义 $replyModel = AdminService::instance()->getSubscribeConfigCache($user->channel_id); if (!empty($replyModel) && !empty($replyModel['event_keys'])) { $json = json_decode($replyModel['event_keys'],true); $responseModel = model("WechatResponse")->where( [ 'admin_id' => $adminConfig['admin_id'], 'eventkey' => $json[$replyModel['type']] ?? '', 'status' => 'normal' ] )->find(); if (!empty($responseModel)) { $data = $this->getContinueTipData($responseModel, $adminConfig, $isWater); //被关注回复可能为空 if ($data) { $data['tpl'] = 'continue'; $data['expiretime'] = 1 / 3; } } } } } } } return $this->setData($data)->getReturn(); } /** * 获取消耗活动弹窗 * @param UserObject $user * @param $path * @return \app\main\model\object\ReturnObject */ public function getCampPop(UserObject $user, $path) { //消耗活动弹窗 $actionIndex = UrlConstants::getLocation($path); $campData = []; if (in_array($actionIndex, [CampaignConstants::CAMPAIGN_POPUP_POSITION_ONE, CampaignConstants::CAMPAIGN_POPUP_POSITION_TWO, CampaignConstants::CAMPAIGN_POPUP_POSITION_THR])) { $campActData = CampaignService::instance()->getLatestCampaign($user); if ($campActData) { if ($campActData['popup_position']) { $position = explode(',', $campActData['popup_position']); if (in_array($actionIndex, $position)) { $campData = [ 'id' => $campActData['id'], 'image' => $campActData['popup_img'], 'url' => '/index/recharge/campaignIndex?active_id=' . $campActData['id'], 'expiretime' => 1 / 3, 'tpl' => 'camp' ]; $tipsnums = Cookie::get('camp_ac_val'); if ($tipsnums && $tipsnums >= 4) { $campData = []; } } } } } return $this->setData($campData)->getReturn(); } /** * 获取客服消息弹窗 * @param UserObject $user * @param $path * @return \app\main\model\object\ReturnObject */ public function getCustomPop(UserObject $user, $path) { $customData = []; if (in_array($path, OpenPlatformConstants::$customTipsUrlArr)) { $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($user->channel_id); $customData = CustomService::instance()->getLastSendSuccessCustom($adminConfig['admin_id'], $adminConfig['appid']); //判断cookie if ($customData) { $customData['tpl'] = 'custom'; $customData['expiretime'] = 2.5; $customId = $customData['custom_id']; if (Cookie::has('close_custom_tips_' . $customId)) { //已弹过了 $customData = []; } else { //判断redis $userOtherData = UserService::instance()->getOtherDataFromRedis(UserService::instance()->getUserInfo()->id); if (isset($userOtherData['last_custom_id']) && $userOtherData['last_custom_id'] == $customId ) { $customData = []; } } } } return $this->setData($customData)->getReturn(); } /** * 关注回复资源继续阅读 * @param $responseModel * @param $adminConfig * @param $isWater * @return array */ protected function getContinueTipData($responseModel, $adminConfig, $isWater=false) { $push_time = time(); $replace = []; $appid = $adminConfig['appid']; $content = UrlService::instance()->replaceReferralHost( $adminConfig['admin_id'], $responseModel['content'], false )->data; switch ($responseModel['type']) { case "text": $mark = MarkConstants::MARK_RESOURCE; preg_match_all("", $content, $match); if ($match) { foreach ($match[1] as $index => $item) { $push_idx = $index + 1; $parse = parse_url($item); $host = $parse['host'] ?? ''; $path = $parse['path'] ?? ''; if (preg_match('/^' . $appid . '/', $host)) { if (array_key_exists('query', $parse)) { $query = parse_query($parse['query']); if (!empty($query)) { if (array_key_exists('book_id', $query)) { $push_id = $query['book_id']; $replace = [ 'book_id' => $query['book_id'], 'url' => $item .= '&' . OfficialAccountsEventService::instance()->processExt($mark, $push_id, $push_idx, $push_time), ]; break; } elseif (array_key_exists('t', $query)) { $push_id = $query['t']; $replace = [ 'book_id' => '', 'url' => $item .= '&' . OfficialAccountsEventService::instance()->processExt($mark, $push_id, $push_idx, $push_time), 'referral_id' => $query['t'], ]; break; } } } if (!empty($path)) { $path = explode('/', $parse['path']); if ($keyIndex = array_search('t', $path)) { $push_id = $path[$keyIndex+1]; $replace = [ 'book_id' => '', 'url' => $item .= '?' . OfficialAccountsEventService::instance()->processExt($mark, $push_id, $push_idx, $push_time), 'referral_id' => $push_id, ]; break; } } } } } break; case "news": $mark = MarkConstants::MARK_RESOURCE; $items = json_decode($content, true); foreach ($items as $index => $item) { $push_idx = $index + 1; $parse = parse_url($item['url']); $path = $parse['path'] ?? ''; if (array_key_exists('query', $parse)) { $query = parse_query($parse['query']); if (array_key_exists('book_id', $query)) { $push_id = $query['book_id']; $replace = [ 'book_id' => $query['book_id'], 'url' => $item['url'] .= '&' . OfficialAccountsEventService::instance()->processExt($mark, $push_id, $push_idx, $push_time), 'referral_id' => '' ]; break; } elseif (array_key_exists('t', $query)) { $push_id = $query['t']; $replace = [ 'book_id' => '', 'url' => $item['url'] .= '&' . OfficialAccountsEventService::instance()->processExt($mark, $push_id, $push_idx, $push_time), 'referral_id' => $query['t'], ]; break; } else { continue; } } if (!empty($path)) { $path = explode('/', $parse['path']); if ($keyIndex = array_search('t', $path)) { $push_id = $path[$keyIndex+1]; $replace = [ 'book_id' => '', 'url' => $item['url'] .= '?' . OfficialAccountsEventService::instance()->processExt($mark, $push_id, $push_idx, $push_time), 'referral_id' => $push_id, ]; break; } } } break; } if (!empty($replace)) { //查询小说标题 if (isset($replace['referral_id']) && $replace['referral_id']) { $referralinfo = model('referral')->getone($replace['referral_id'], false); if (empty($referralinfo) || !$referralinfo['book_id']) { return []; } $replace['book_id'] = $referralinfo['book_id']; } $bookinfo = BookService::instance()->getBookModel()->BookInfo($replace['book_id']); $replace['book_name'] = $bookinfo['name']; $replace['image'] = $bookinfo['image']; $replace['description'] = $bookinfo['description']; if ($isWater && (!isset($bookinfo['classify_white_list']) || $bookinfo['classify_white_list'] != 1)){ LogService::info('清水用户,非清水书籍,过滤掉'.$bookinfo['id']); $replace = []; } } return $replace; } /** * 检测是否符合导量条件 * @param $export * @return \app\main\model\object\ReturnObject */ public function checkGiveKandianValid($export) { $fields = [ 'share_free_kandian', 'share_times', 'share_icon', 'share_title', 'share_desc', 'share_url', ]; foreach ($fields as $field) { if (!ArrayHelper::array_get($export, $field)) { return $this->setData(false)->getReturn(); } } return $this->setData(true)->getReturn(); } public function getSubscribePop(UserObject $user, $path) { $data = SubscripService::instance()->getActPop($user,$path); $subData = []; if ($data && $data['act_pop_img']){ $subData = [ 'id' => $data['id']??1, 'image' => $data['act_pop_img'], 'url' => '/index/recharge/subscription?type='.$data['type'], 'expiretime' => 1 / 3, 'tpl' => 'subscribe' ]; } return $this->setData($subData)->getReturn(); } }