getUserInfo()->channel_id; $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channel_id); $appGuideInfo = AppGuideService::instance()->getAppGuideInfo($channel_id); $hasGuide = count($appGuideInfo) ?? 0 ; $this->assign('hasGuide', $hasGuide); $this->assign('appGuideInfo', $appGuideInfo); $this->assignconfig('float_id', $this->request->get('float_id', '')); //跳转到支付域名 $this->redirectPayHost($adminConfig); $showBookShelf = BookService::instance()->showBookShelfFun(); $this->assign('showBookShelf', $showBookShelf); $is_show_tabbar = model("ChannelSpecialManage")->isWhite("show_tabbar", $channel_id); $this->assign('is_show_tabbar', $is_show_tabbar); $this->assign('tab_choice', 'recharge'); $this->assign('channel_id',$channel_id); $recentUrl = getCurrentDomain($channel_id, '/index/user/recent'); //判断是不是消耗活动的跳转 $activeId = 0; if($this->request->has('type')){ $type = $this->request->get('type'); $activeId = $this->request->get('active_id'); switch ($type){ case 1://消耗活动跳转 $recentUrl = $activeId ? '/index/recharge/campaignIndex?active_id='.$activeId : $recentUrl; break; case 2://翻牌活动 $recentUrl = $activeId ? '/index/activity/cardFlip?actId='.$activeId : $recentUrl; break; } } $this->assign('active_id', $activeId); $this->assign('recent_url', $recentUrl); $payment_method = empty($adminConfig['payment_method']) ? '0' : '1'; $this->assign('payment_method',$payment_method); $is_pay = 0; //0未充值 1已充值 UserService::instance()->setUserCache(Request::instance()->get('user_id')); if ($this->request->has('visitor')) { Cookie::set('visitor', $this->request->get('visitor')); } $kandian = 0; if (UserService::instance()->isLogin()) { $user = UserService::instance()->getUserInfo(true); // 引导位访问展示打点 AppGuideService::instance()->appGuideViewDot($channel_id, $user->id, MqConstants::APP_GUIDE_POSITION_IDX_4); $kandian = FinancialService::instance()->getTotalKandianAndFreeKandian($user->id)->data; $is_pay = $user->is_pay; $this->assign('user_id', $user->id); $this->assign('user', $user->toArray()); } else { $this->redirect($recentUrl); } $this->assign('kandian',$kandian); $is_test = AdminService::instance()->checkIsTestChannel( UserService::instance()->getUserInfo()->agent_id, UserService::instance()->getUserInfo()->channel_id ); if (Config::get('site.goods_type_new_user') == GoodsConstants::GOODS_TYPE_NEW_DAY) { $is_new = date('Ymd', UserService::instance()->getUserInfo()->createtime) == date('Ymd'); } else { $is_new = time() - UserService::instance()->getUserInfo()->createtime < 86400; } if (Ua::isWeiXin()) { $this->assign('business_line',PayConstants::BUSINESS_WECHAT); // $list = model('Goods')->getGoodsList( // PayConstants::BUSINESS_WECHAT, // PayConstants::GOODS_CATEGORY_RECHARGE, // PayConstants::GOODS_TYPE_KD, // $is_test, // $is_pay); $list = GoodsService::instance()->getCustomGoodsForFront($channel_id, $is_pay, $is_new, PayConstants::BUSINESS_WECHAT); $activityList = ActivityService::instance()->getRechargePageChannelActivity($user); if (!empty($activityList)) { $list = array_merge($list, $activityList); } } else { $this->assign('business_line',PayConstants::BUSINESS_APP); $list = model('Goods')->getGoodsList(PayConstants::BUSINESS_APP,PayConstants::GOODS_CATEGORY_RECHARGE,PayConstants::GOODS_TYPE_KD,$is_test,$is_pay); } $cpBook = false; if ($book_id = $this->request->param('book_id')) { $cpBook = VipCpService::instance()->isVipCpBook($book_id); } //VIP充值开关开启时,充值页,VIP商品,看点充值都显示 $show_vip_at_home = ArrayHelper::array_get($this->adminconfig, 'show_vip_at_home'); if (!$cpBook && $show_vip_at_home && ($adminConfig['vip_state'] ?? false) && ($adminConfig['vip_goods_id'] ?? null)) { if ($goods_info = model('goods')->getGoodsInfoById($adminConfig['vip_goods_id'])) { if (GoodsService::instance()->checkGoodsTypeValid($goods_info['show_type'], $user)->data) { array_push($list, $goods_info); } } } $selectGoodsId = intval($this->request->param('goods_id')); $this->assign('select_goods_id', $selectGoodsId); $defaultGoods = $list[0]; if ($selectGoodsId) { foreach ($list as $item) { if ($item['id'] == $selectGoodsId) { $defaultGoods = $item; break; } } } else { foreach ($list as $item) { if($item['default']??0){ $defaultGoods = $item; break; } } } $defaultGoods['activity_id'] = $defaultGoods['activity_id'] ?? 0; $this->assign('list', $list); $this->assign('default_goods', $defaultGoods); $track = '{}'; $user_id = UserService::instance()->getUserInfo()->id; if ($this->request->has('book_id')) { $book_id = $this->request->get('book_id'); $bookInfo = model('Book')->BookInfo($book_id); if ($bookInfo) { if ($bookInfo['price'] > 0) { if ($bookInfo['billing_type'] == 1) { $price = FinancialService::instance()->getChapterPrice($book_id); $this->assign('bookBillingTip', '本章是VIP章节(' . $price . '书币/章)'); } elseif ($bookInfo['billing_type'] == 2 && $bookInfo['price'] > 0) { $this->assign('bookBillingTip', '本书是VIP书籍(' . $bookInfo['price'] . '书币/本)'); } else { $this->assign('bookBillingTip', '本章是VIP章节(' . Config::get('site.book_chapter_price') . '书币/章)'); } } } $cache = UserdotService::instance()->getTrackCache($user_id, $book_id); if ($cache) { $track = $cache; } } else { $zone = $this->request->get('zone'); $adid = $this->request->get('adid'); $book_id = 0; $url = $this->request->get('from_url'); if (!empty($zone) && !empty($adid)) { UserdotService::instance()->saveTrackInfo($url, $zone, $adid, $book_id); $cache = UserdotService::instance()->getTrackCache($user_id, $book_id); if ($cache) { $track = $cache; } } } $this->assign('track', $track); $buyMore = PayConstants::getBuyMore(UserService::instance()->getUserInfo()->id); $this->assign('buyMore', $buyMore); $buyMoreView = false; if (Config::get('site.theme') == 'yg' && $viewConfig = Config::get('site.buymoreview')) { if ($viewConfig == 2) { $buyMoreView = true; } else if($user_id % 2 == 0){ $buyMoreView = true; } } $isOpenMishuTips = 0; $imgTimes = 1; if (Config::get('site.is_open_mishu_tip') == 1) { $isOpenMishuTips = 1; //判断IP 北京区域不弹 $city = Ip::city(); if (strrpos('北京市', $city) !== false) { $isOpenMishuTips = 0; } } $export_fans = ExportFansService::instance()->checkFansPayToExport($channel_id, $user_id)->data; $this->view->assign('fans', $export_fans); $this->view->assign('is_mishu', $isOpenMishuTips); $this->view->assign('img_times', $imgTimes); //未充值的redis $unRechargeKey = CacheConstants::getFansUnrecharge($user_id); Redis::instance()->set($unRechargeKey, '1', 180); if ($buyMoreView) { return $this->view->fetch('paymore'); }else{ return $this->view->fetch(); } } //VIP充值页面 public function vip() { //跳转支付域名 $this->redirectPayHost($this->adminconfig,true); $this->assignconfig('float_id', $this->request->get('float_id', '')); $recentUrl = getCurrentDomain(UserService::instance()->getUserInfo()->channel_id, '/index/user/recent'); //visitor设置 UserService::instance()->setUserCache(Request::instance()->get('user_id')); if ($this->request->has('visitor')) { Cookie::set('visitor', $this->request->get('visitor')); } $this->view->assign('business_line',PayConstants::BUSINESS_WECHAT); if ($this->request->get('vip_custom_money') && !empty($this->adminconfig['vip_goods_id_custom'])) { $goodsId = $this->adminconfig['vip_goods_id_custom']; } else { $goodsId = $this->adminconfig['vip_goods_id']; } $goods_info = false; $isend = !!!$this->adminconfig['vip_state']; if ($goodsId) { $goods_info = GoodsService::instance()->getGoodsModel()->getGoodsInfoById($goodsId); if (!GoodsService::instance()->checkGoodsTypeValid($goods_info['show_type'], UserService::instance()->getUserInfo())->data) { $goods_info = false; $isend = true; } } $this->assign('goods_info',$goods_info); $this->assign('recent_url', $recentUrl); $this->assign('isend', $isend); return $this->view->fetch('index@recharge/vip/'.$this->adminconfig['vip_pay_tpl']); } //小额充值 public function smallpay() { $this->assignconfig('float_id', $this->request->get('float_id', '')); $channelId = UserService::instance()->getUserInfo()->channel_id; $userId = UserService::instance()->getUserInfo()->id; $recentUrl = getCurrentDomain($channelId, '/index/user/recent'); $configChannelIds = Config::get('site.smallpay_channel_id') ?? ''; if ($configChannelIds == '*') { $open = true; } else { $list = explode(',', $configChannelIds); $open = in_array($channelId, $list); } $id = Config::get('site.smallpay_goods_id'); if (!$id || !$open) { $this->error('未开启小额充值', $recentUrl); } $goods_info = model('Goods')->getGoodsInfoById($id); if (!$goods_info) { $this->error('商品不存在', $recentUrl); } $cacheKey = CacheConstants::getSmallPayCache($userId); if (Redis::instance()->exists($cacheKey)) { $this->error('用户已支付过此商品', $recentUrl); } $this->redirectPayWithUri($this->adminconfig,'/index/recharge/smallpay?'); $this->view->assign('business_line',PayConstants::BUSINESS_WECHAT); $this->assign('goods_info',$goods_info); $this->assign('recent_url', $recentUrl); return $this->view->fetch('index@recharge/smallpay/default'); } public function redirectPayWithUri($adminConfig, $uri) { if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD){ //推广域名 //Log::write('是推广域名进来的','cctest4'); $params = $this->request->get(); if (UserService::instance()->isLogin()) { $params['user_id'] = UserService::instance()->getUserInfo()->id; } elseif (Cookie::has('visitor')) { $params['visitor'] = Cookie::get('visitor'); } if ($this->request->has('book_id')) { $params['book_id'] = $this->request->get('book_id'); } if ($this->request->has('chapter_id')) { $params['chapter_id'] = $this->request->get('chapter_id'); } if($this->request->has('redirect')){ $params['redirect'] = $this->request->get('redirect'); } if(isset($params['code'])){ unset($params['code']); } //有菜单支付域名时,跳转菜单支付域名 $menuophost = $adminConfig['menuophost'] ?? null; $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null; if($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()){ $payHost = Config::get('site.scheme') . '://' . $adminConfig['menuwxpay_host']; }else{ $payHost = Config::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host']; } $payHost .= $uri; $payHost .= http_build_query($params); $this->redirect($payHost); } } /** * 跳转到支付域名 * @param $adminConfig * @param $is_vip */ public function redirectPayHost($adminConfig,$is_vip = false){ if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD){ //推广域名 //Log::write('是推广域名进来的','cctest4'); $params = $this->request->get(); $params['user_id'] = UserService::instance()->getUserInfo()->id; if ($this->request->has('book_id')) { $params['book_id'] = $this->request->get('book_id'); } if ($this->request->has('chapter_id')) { $params['chapter_id'] = $this->request->get('chapter_id'); } if($this->request->has('redirect')){ $params['redirect'] = $this->request->get('redirect'); } if(isset($params['code'])){ unset($params['code']); } //有菜单支付域名时,跳转菜单支付域名 $user_id = UserService::instance()->getUserInfo()->id; $channel_id = UserService::instance()->getUserChannelId()->data; $payHost = FufenService::instance()->getPayUrl($user_id, $channel_id)->data; // $menuophost = $adminConfig['menuophost'] ?? null; // $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null; // if($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()){ // $payHost = Config::get('site.scheme') . '://' . $adminConfig['menuwxpay_host']; // }else{ // $payHost = Config::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host']; // } //VIP充值检查 if(!$is_vip){ $payHost .= '/index/recharge/pay?'; }else{ $payHost .= '/index/recharge/vip?'; } $payHost .= http_build_query($params); $this->redirect($payHost); } } //充值记录 public function record() { $userId = Cookie::get('user_id'); if($this->request->isAjax()){ //如果是ajax请求 $pageNo = $this->request->post('pageNo'); $pageSize = intval($this->request->post('pagesize')); $startNo = ($pageNo-1)*$pageSize; $recharge = model('Recharge')->setConnect($userId)->where('user_id',$userId)->order('createtime','desc')->limit($startNo,$pageSize)->select(); if(!$recharge){ $recharge = []; } $data = []; foreach($recharge as $key=>$val){ $data[$key] = is_array($val)?$val:$val->toArray(); if($val['type']=='1' || $val['type']=='3' || $val['type']=='5' || $val['type']=='6'){ //书币 $data[$key]['showItem'] = ''; if(intval($val['kandian']) == 0){ //免费书币 if(intval($val['free_kandian'])>0){ $data[$key]['showItem'] = '+'.$val['free_kandian'].'书币'; //int转string $data[$key]['endDate'] = Date('Y-m-d',$val['free_endtime']); //书币失效日期 }else{ $data[$key]['showItem'] = $val['free_kandian'].'书币'; //int转string $data[$key]['endDate'] = '永久'; //书币失效日期 } if($val['type']==1){ $data[$key]['type_text'] = '充值赠送书币'; } elseif(intval($val['type'])==6) { $data[$key]['type_text'] = '活动赠送书币'; } }else{ //永久书币 if(intval($val['kandian'])>0){ $data[$key]['showItem'] = '+'.$val['kandian'].'书币'; //int转string }else{ $data[$key]['showItem'] = $val['kandian'].'书币'; //int转string } $data[$key]['endDate'] = '永久'; //书币失效日期 } }else{ //vip $data[$key]['showItem'] = ''; if(intval($val['day']) > 0 || intval($val['hour'])>0){ //加vip时长 if(intval($val['day'])>0){ $data[$key]['showItem'] = '+'.$val['day'].'天'; if(intval($val['hour']) > 0){ $data[$key]['showItem'] = $data[$key]['showItem'].$val['hour'].'小时'; } }else{ $data[$key]['showItem'] ='+'.$val['hour'].'小时'; } }else{ //减少vip时长 if(intval($val['day']) <0){ $data[$key]['showItem'] = $val['day'].'天'; if(intval($val['hour'])<0){ $data[$key]['showItem']= $data[$key]['showItem'].abs($val['hour']).'小时'; } }else{ if(intval($val['hour']) < 0){ $data[$key]['showItem'] = $val['hour'].'小时'; } } } //$data[$key]['endDate'] = '永久'; $days = $val['day'] ?? 0; $hour = $val['hour'] ?? 0; //$data[$key]['endDate'] = '永久'; if($val['vip_starttime']){ $data[$key]['endDate'] = date('Y-m-d H:i:s', strtotime("+{$days} days {$hour} hours", $val['vip_starttime'])); }else{ $data[$key]['endDate'] = '-'; } } } return json($data); }else{ //渲染第一页 $recharge = model('Recharge')->setConnect($userId)->where('user_id',$userId)->order('createtime','desc')->limit(0,20)->select(); if(!$recharge){ $recharge = []; } $data = []; foreach($recharge as $key=>$val){ $data[$key] = is_array($val)?$val:$val->toArray(); $data[$key]['showItem'] = ''; if($val['type']=='1' || $val['type']=='3' || $val['type']=='5' || $val['type']=='6'){ //书币 if(intval($val['kandian']) == 0){ //免费书币 if(intval($val['free_kandian'])>0){ $data[$key]['showItem'] = '+'.$val['free_kandian'].'书币'; //int转string $data[$key]['endDate'] = Date('Y-m-d',$val['free_endtime']); //书币失效日期 }else{ $data[$key]['showItem'] = $val['free_kandian'].'书币'; //int转string $data[$key]['endDate'] = '永久'; //书币失效日期 } if($val['type']==1){ $data[$key]['type_text'] = '充值赠送书币'; } elseif(intval($val['type'])==6) { $data[$key]['type_text'] = '活动赠送书币'; } }else{ //永久书币 if(intval($val['kandian'])>0){ $data[$key]['showItem'] = '+'.$val['kandian'].'书币'; //int转string }else{ $data[$key]['showItem'] = $val['kandian'].'书币'; //int转string } $data[$key]['endDate'] = '永久'; //书币失效日期 } }else{ //vip if(intval($val['day']) > 0 || intval($val['hour'])>0){ //加vip时长 if(intval($val['day'])>0){ $data[$key]['showItem'] = '+'.$val['day'].'天'; if(intval($val['hour']) > 0){ $data[$key]['showItem'] = $data[$key]['showItem'].$val['hour'].'小时'; } }else{ $data[$key]['showItem'] ='+'.$val['hour'].'小时'; } }else{ //减少vip时长 if(intval($val['day']) <0){ $data[$key]['showItem'] = $val['day'].'天'; if(intval($val['hour'])<0){ $data[$key]['showItem']= $data[$key]['showItem'].abs($val['hour']).'小时'; } }else{ if(intval($val['hour']) < 0){ $data[$key]['showItem'] = $val['hour'].'小时'; } } } $days = $val['day'] ?? 0; $hour = $val['hour'] ?? 0; if($val['vip_starttime']){ $data[$key]['endDate'] = date('Y-m-d H:i:s', strtotime("+{$days} days {$hour} hours ", $val['vip_starttime'])); }else{ $data[$key]['endDate'] = '-'; } } if ( in_array($val['extend_type'], [1,2]) ){ $data[$key]['type_text'] = $val['extend_type'] == 1 ? '活动报名' : ($val['extend_type'] == 2 ? '活动赠送书币' : $data[$key]['type_text']); } } $adminconfig = $this->adminconfig; $this->view->assign('adminconfig',$adminconfig); $this->assign('res',$data); return $this->view->fetch(); } } /** * @return mixed * @throws \think\Exception */ public function activity() { $this->assignconfig('float_id', $this->request->get('float_id', '')); $id = intval($_GET['id']); $aid = intval($_GET['aid'] ?? 0); $is_range = 0; $user_id = UserService::instance()->getUserInfo()->id; $admin_id = UserService::instance()->getAdminId()->data; $channel_id = UserService::instance()->getUserInfo()->channel_id; if ($this->request->has('isrange') || $this->request->has('isRange')) { $is_range = 1; } /** * 获取渠道商/代理商资料 */ $adminExtend = AdminService::instance()->getAdminExtendModel()->getInfo($admin_id); $recent_url = getCurrentDomain($channel_id, '/index/user/recent'); if (!$adminExtend) { $this->error('管理员信息获取失败', $recent_url); } $activityInfo = model('Activity')->getInfo($aid); $isGiveAct = false; if ($activityInfo && in_array($activityInfo['type'], [ActivityConstants::ACTIVITY_TYPE_CUSTOM, ActivityConstants::ACTIVITY_TYPE_GIVE])) { $isGiveAct = $activityInfo['type'] == ActivityConstants::ACTIVITY_TYPE_GIVE; $resource_info = model("Resource")->getInfo($id); if (empty($resource_info)) { $this->error('活动不存在', $recent_url); } $res['starttime'] = $activityInfo['starttime']; $res['endtime'] = $activityInfo['endtime']; $res['astatus'] = $activityInfo['status']; $res['aname'] = $activityInfo['name']; $res = array_merge($res, $resource_info); $res['activity_id'] = $aid; if (intval($activityInfo['limited'])) { $redis = Redis::instance(); //用户在渠道自定义的活动充值次数统计 if ($activityInfo['type'] == ActivityConstants::ACTIVITY_TYPE_CUSTOM) { $pay_count = intval($redis->hGet("ATPU:{$aid}", $user_id)); if (intval($activityInfo['limited']) <= $pay_count) { $this->error("该活动限购 {$activityInfo['limited']} 次"); } } //用户在赠币的活动充值次数统计 if ($isGiveAct) { $this->assign('the_max_time', $activityInfo['limited']); $pay_count = intval($redis->hGet("ATGP:{$aid}", $user_id)); if (intval($activityInfo['limited']) <= $pay_count) { $this->assign('is_max_end',1); } } } } else { //平台活动 缓存 $key = 'P-A:'.$id; if (Redis::instance()->exists($key)) { $res = json_decode(Redis::instance()->get($key), true); } else { $res = model('resource')->join('activity a', 'a.id=resource.activity_id')->where('resource.id', $id) ->field('a.starttime,a.endtime,a.status as astatus,a.name as aname,resource.*')->find(); if ($res) { Redis::instance()->set($key, json_encode($res, JSON_UNESCAPED_UNICODE), 60); } } } if(!$res){ $this->error('活动不存在', $recent_url); } if ($res['goods_id'] > 0) { $goodsInfo = model("Goods")->getGoodsInfoById($res['goods_id']); if ($goodsInfo) { $res['money'] = $goodsInfo['money']; } } $this->assign('recent_url', $recent_url); if ($res['activity_id'] == 100) { if (UserService::instance()->getUserInfo()->is_pay == UserConstants::USER_IS_PAY_YES) { $is_range = 1; } } if($res['endtime'] < $this->time||empty($res['astatus'])){ $this->assign('isend',1); } if($res['starttime'] > $this->time && !empty($res['astatus'])){ $this->assign('needWait',1); $lastTime = $this->lastTime($res['starttime']); $this->assign('lastTime',$lastTime); } $arr = []; array_push($arr,"\r\n"); array_push($arr,"\r"); array_push($arr,"\n"); $pay_url = ''; $res['warning'] = str_replace($arr,"
",$res['warning']); $to_url = getCurrentDomain($channel_id,'/index/user/recent'); if ($admin_id) { $admin_info = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($admin_id); if (!empty($admin_info) && $admin_info['appid']) { $to_url = getCurrentDomain($admin_id, '/index/user/recent'); } if ($admin_info) { $menuophost = $info['menuophost'] ?? null; $menuwxpay_host = $info['menuwxpay_host'] ?? null; if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) { $pay_url = Config::get('site.scheme') . '://' . $admin_info['menuwxpay_host'] . '/index/recharge/pay?from=wechat&admin_id=' . $admin_id . '&channel_id=' . $channel_id . '&user_id=' . $user_id; } else { $pay_url = Config::get('site.scheme') . '://' . $admin_info['wxpay_pay_host'] . '/index/recharge/pay?from=wechat&admin_id=' . $admin_id . '&channel_id=' . $channel_id . '&user_id=' . $user_id; } } } $payment_method = empty($admin_info['payment_method']) ? '0' : '1'; $this->assign('res', $res); $this->assign('isGiveAct', $isGiveAct); $this->assign('payment_method', $payment_method); $this->assign('aid', $res['activity_id']); $this->assign('payUrl', $pay_url); $this->assign('toUrl', $to_url); $this->assign('isRange', $is_range); $track = '{}'; $cache = UserdotService::instance()->getTrackCache($user_id, $res['activity_id']); if ($cache) { $track = $cache; } $this->assign('track', $track); if ($res['activity_id'] == 100 && Config::get("site.theme") == 'yg') { //首冲9块9 阳光主题加载另外模板 return $this->fetch('activity_first_pay'); } $oAna = new AnalysisObject(); $oAna->type = KafkaDotConstants::TYPE_VISIT; $oAna->user_from = [ 'activity_id' => $res['activity_id'], ]; KafkaDotService::instance()->sendMsg($user_id, $oAna); return $this->fetch(); } /** * 剩余时间 * @param int $unixEndTime * @return string */ function lastTime($unixEndTime=0) { if ($unixEndTime <= $this->time) { // 如果过了活动终止日期 return '0天0时0分'; } // 使用当前日期时间到活动截至日期时间的毫秒数来计算剩余天时分 $time = $unixEndTime - $this->time; $days = 0; if ($time >= 86400) { // 如果大于1天 $days = (int)($time / 86400); $time = $time % 86400; // 计算天后剩余的毫秒数 } $xiaoshi = 0; if ($time >= 3600) { // 如果大于1小时 $xiaoshi = (int)($time / 3600); $time = $time % 3600; // 计算小时后剩余的毫秒数 } $fen = (int)($time / 60); // 剩下的毫秒数都算作分 if(empty($fen)){ $fen = 1; } return $days.'天'.$xiaoshi.'时'.$fen.'分'; } /** * 自定义链接充值 */ public function special() { $this->assignconfig('float_id', $this->request->get('float_id', '')); $id = intval($_GET['id']); UserService::instance()->setUserCache(Request::instance()->get('user_id')); $user_id = UserService::instance()->getUserInfo()->id; $admin_id = UserService::instance()->getAdminId()->data; $channel_id = UserService::instance()->getUserInfo()->channel_id; if ($this->request->has('visitor')) { Cookie::set('visitor', $this->request->get('visitor')); } /** * 获取渠道商/代理商资料 */ $adminExtend = AdminService::instance()->getAdminExtendModel()->getInfo($admin_id); if (!$adminExtend) { $this->error('管理员信息获取失败'); } //检测链接 $urlInfo = model("SpecialRechargeUrl")->checkUrl($id); if ($urlInfo['code'] == 201 || $urlInfo['code'] == 202) { $this->error('链接不存在'); die; } $is_range = $urlInfo['code'] == 203 ? 1 : 0; //获取商品信息 $tplInfo = model("SpecialRechargeTpl")->getOne($urlInfo['data']['tpl_id']); if (empty($tplInfo)) { $this->error('链接信息不存在'); die; } $res['title'] = $tplInfo['title']; $goodsInfo = model('Goods')->getGoodsInfoById($tplInfo['goods_id']); if (empty($goodsInfo)) { $this->error('商品信息不存在'); } $res['money'] = $goodsInfo['money']; $res['kandian'] = $goodsInfo['kandian']; $res['free_kandian'] = $goodsInfo['free_kandian']; $res['day'] = $goodsInfo['day']; $res['free_day'] = $goodsInfo['free_day']; $res['type'] = $goodsInfo['type']; $res['category_id'] = $goodsInfo['category_id']; $res['goods_id'] = $tplInfo['goods_id']; $res['url_id'] = $id; $res['cost'] = $tplInfo['cost']; $to_url = getCurrentDomain($channel_id,'/index/user/recent'); $pay_url = ''; if ($admin_id) { $admin_info = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($admin_id); if (!empty($admin_info) && $admin_info['appid']) { $to_url = getCurrentDomain($admin_id, '/index/user/recent'); } if ($admin_info) { $menuophost = $info['menuophost'] ?? null; $menuwxpay_host = $info['menuwxpay_host'] ?? null; if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) { $pay_url = Config::get('site.scheme') . '://' . $admin_info['menuwxpay_host'] . '/index/recharge/pay?from=wechat&admin_id=' . $admin_id . '&channel_id=' . $channel_id . '&user_id=' . $user_id; } else { $pay_url = Config::get('site.scheme') . '://' . $admin_info['wxpay_pay_host'] . '/index/recharge/pay?from=wechat&admin_id=' . $admin_id . '&channel_id=' . $channel_id . '&user_id=' . $user_id . ''; } } } $payment_method = empty($admin_info['payment_method']) ? '0' : '1'; $this->assign('res', $res); $this->assign('payment_method', $payment_method); $this->assign('url_id', $id); $this->assign('payUrl', $pay_url); $this->assign('toUrl', $to_url); $this->assign('isRange', $is_range); $this->assign('business_line', PayConstants::BUSINESS_WECHAT); if ($res['type'] == '2') { return $this->fetch('special_vip'); } return $this->fetch(); } /** * 读书挑战赛 活动入口 * wud */ public $campaginArr; public function campaignIndex(){ //跳转到支付域名 if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD) { //推广域名 $this->campaginArr['activeId'] = $this->request->get('active_id') ?? 1; $this->campaginArr['userInfo'] = UserService::instance()->getUserInfo(); $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($this->campaginArr['userInfo']->channel_id); $menuophost = $adminConfig['menuophost'] ?? null; $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null; if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) { $payHost = Config ::get('site.scheme') . '://' . $adminConfig['menuwxpay_host']; } else { $payHost = Config ::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host']; } $payHost .= '/index/recharge/campaignIndex?'; $params['from'] = 'wechat'; $params['admin_id'] = $adminConfig['admin_id']; $params['channel_id'] = $this->campaginArr['userInfo']->channel_id; $params['user_id'] = $this -> campaginArr['userInfo']->id; $params['active_id'] = $this -> campaginArr['activeId']; $payHost .= http_build_query($params); $this -> redirect($payHost); } $this->campaignInit(); $this->assign('percent', rand(80,99)); $this->assign('channelUrl', $this->campaginArr['channelUrl']); $this->assign('active', $this->campaginArr['active']); $this->assign('log_host', Config::get('site.loghost')); //设置打点域名 $matchLevel = [ $this->campaginArr['active']['elementary_need'], $this->campaginArr['active']['intermediate_need'], $this->campaginArr['active']['advanced_need'] ]; switch ($this->campaginArr['status']) { case -1://活动未开始页面 return $this->view->fetch('index@recharge/campaign/nullactive'); break; case 0://报名页面 $time = time(); $curDate = date('Ymd', $time); // $predate = date('Ymd', $time-3600*24*8 ); //随机返回弹幕 $barrage = CampaignService::instance()->getBarrage10($matchLevel); // dump($barrage);exit; //获取最近一场得信息 $preMatch = CampaignService::instance()->lastTimeMatch(); //获取 前一天和今天的场次信息 $Campaign = CampaignService::instance()->getMatchBatch( $matchLevel ,[$curDate] ); //组装数据 $assignData = [ 'curDate'=>[], 'preDate'=>[] ]; $goodsInfo = []; if ( !empty($Campaign) ){ foreach ($Campaign as $k =>$v){ if ( $curDate == $v['match_date'] ) { //获得当天场次的商品信息 $goodsInfo = model('Goods')->getGoodsInfoById($v['goods_id']); $v['money'] = $goodsInfo['money']; $assignData['curDate'][$v['kandian']] = $v; } } } //计算上期瓜分书币 foreach ($assignData['curDate'] as $kk=>&$vv){ $vv['preAward'] = $preMatch[$vv['kandian']]??0; } //获得当前的总奖池 报名人数 预期奖励 $dateNum = CampaignService::instance()->getAward($assignData['curDate'],$this->campaginArr['active']); $userKandian = FinancialService::instance()->getTotalKandian($this->campaginArr['userInfo']->id)->data; $this->assign('dateNum', $dateNum); $this->assign('barrage', $barrage ); $this->assign('userKanDian', $userKandian); $this->assign('curData', $assignData['curDate'] ); $this->assign('match', $matchLevel ); $this->assign('goodsInfo', $goodsInfo ); $this->assign('assignData', $assignData ); $this->assign('webStatus', $this->campaginArr['status']); return $this->view->fetch('index@recharge/campaign/index'); break; default://打卡页面 //获取当前场次信息 // $curMatch = CampaignService::instance()->getMatchByTime( $this->campaginArr['userMatch']['match_date'], $this->campaginArr['userMatch']['kandian']); $dateMatch = CampaignService::instance()->getMatchBatch($matchLevel,[$this->campaginArr['userMatch']['match_date']]); foreach ( $dateMatch as $key=>$val ){ if ( $val['kandian'] == $this->campaginArr['userMatch']['kandian']){ $curMatch = $val; } } //获得当前的总奖池 报名人数 预期奖励 $dateNum = CampaignService::instance()->getAward($dateMatch,$this->campaginArr['active']); $curMatch['preKandian'] = intval($curMatch['kandian']*$dateNum['awardPercent']); //获取当天阅读章节 $redisKey = CampaignConstants::getUserMatchReadKey($this->campaginArr['userInfo']->id); $curMatch['cur_read_num'] = Redis::instance()->get($redisKey); $curMatch['cur_read_num'] = !empty($curMatch['cur_read_num']) ? $curMatch['cur_read_num'] : 0 ; //自动打卡 if ( $this->campaginArr['status'] == 5 && $curMatch['cur_read_num'] >= $this->campaginArr['active']['read_number'] ){//更新书库状态 $sign = MyScene::getInstance($this->campaginArr['userInfo']->id, $this->campaginArr['userMatch']['match_id'])->sign(); if ( $sign['code'] == 200 ){ //打卡成功 $this->campaginArr['status'] = 11; } } //累计报名人数 $levelArr = [ $this->campaginArr['active']['elementary_need']=>'elementary_num', $this->campaginArr['active']['intermediate_need']=>'intermediate_num', $this->campaginArr['active']['advanced_need']=>'advanced_num' ]; //本场次得基础人数 $baseNum = $this->campaginArr['active'][$levelArr[$this->campaginArr['userMatch']['kandian']]]; $dateNum['lSignNum'] = $baseNum + $curMatch['participator_num']; //更新上期活动的数据库状态 if ( in_array( $this->campaginArr['status'], [9,12] ) ){ CampaignService::instance()->updateUserMatch($this->campaginArr['userInfo']->id,$this->campaginArr['userMatch']['id'],5); } if( $this->campaginArr['status'] == 14 ){//未领奖 CampaignService::instance()->updateUserMatch($this->campaginArr['userInfo']->id,$this->campaginArr['userMatch']['id'],6); } //更新当天的打卡次数 // dump($curMatch);exit; $todaySignNUM = redis::instance()->get(CampaignConstants::getMatchSignNumToday($curMatch['id'])); $dateNum['signNum'] = empty($todaySignNUM) ? $baseNum : $todaySignNUM+$baseNum; $dateNum['canquer'] = $dateNum['lSignNum']-$curMatch['success_num']; //打卡页面底部推荐书 $this->campaginArr['userInfo']->sex = (int)$this->campaginArr['userInfo']->sex == 2 ? 2 : 1; $like = GussNovelService::instance()->getLikedNovels($this->campaginArr['userInfo']->sex,6); $this->assign('popType', $this->campaginArr['popType']); $this->assign('like', $like); $this->assign('dateNum', $dateNum); $this->assign('webStatus', $this->campaginArr['status']); $this->assign('userMatch', $this->campaginArr['userMatch'] ); $this->assign('curMatch', $curMatch); $this->assign('userId', $this->campaginArr['userInfo']->id); return $this->view->fetch('index@recharge/campaign/clockIn'); break; } } /** * 初始化 状态 */ private function campaignInit(){ $this->campaginArr['activeId'] = $this->request->get('active_id') ?? 1; $this->campaginArr['userInfo'] = UserService::instance()->getUserInfo(); // if( $realKandian = FinancialService::instance()->getTotalKandian($this->campaginArr['userInfo']->id)->data ){ // $this->campaginArr['userInfo']->kandian = $realKandian; // }; $this->campaginArr['popType'] = 0;//弹窗状态 $this->campaginArr['channelUrl'] = getCurrentDomain($this->campaginArr['userInfo']->channel_id); $this->campaginArr['active'] = CampaignService::instance()->getActivityById( $this->campaginArr['activeId']); $this->campaginArr['userMatch'] = CampaignService ::instance()->getUserMatch( $this->campaginArr['userInfo']->id ); //失败时判断活动是否结束 $this->campaginArr['active']['next'] = 0;//给前端提供状态 是否有下一场 $curDate = time(); $status = -1; //没有活动 if ( empty( $this->campaginArr['active'] ) ){ $status = -1; //活动未开 $this->campaginArr['status'] = $status; return ; } //活动设置为无效 if ( $this->campaginArr['active']['status'] == 'hidden' && empty($this->campaginArr['userMatch']) ){ $status = -1; //活动暂停 $this->campaginArr['status'] = $status; return ; } // dump($this->campaginArr['active']);exit; //活动不在时间范围内 if ( ($this->campaginArr['active']['start_time'] > $curDate || $this->campaginArr['active']['end_time'] < $curDate) ){ if ( empty($this->campaginArr['userMatch']) || in_array( $this->campaginArr['userMatch']['status'], [4,5,6])){//已领奖 或 失败状态 未领奖 显示报名下一场 $status = -1; //活动未开 $this->campaginArr['status'] = $status; return ; } }else{ //活动进行中 if ( empty($this->campaginArr['userMatch']) || in_array( $this->campaginArr['userMatch']['status'], [4,5,6]) ){ $status = 0; //活动开始 ,没有报名 $this->campaginArr['status'] = $status; return ; } } //判断用户最后一次参加的活动是不是 当前推广的活动 try{ if ( $this->campaginArr['activeId'] != $this->campaginArr['userMatch']['active_id'] ){ $this->campaginArr['activeId'] = $this->campaginArr['userMatch']['active_id']; $this->campaginArr['active'] = CampaignService::instance()->getActivityById( $this->campaginArr['userMatch']['active_id'] ); } }catch ( \Throwable $th ){ LogService::error('活动首页 error001'.$th->getMessage()); } $days = intval(($curDate-strtotime($this->campaginArr['userMatch']['match_date']))/86400); $day = $days - $this->campaginArr['userMatch']['num']; //应该打卡天数-实际打卡天数 switch ( $day ){ case 0: switch ( $this->campaginArr['userMatch']['status'] ){ case 1: $status = 2; //报名成功, 明日打卡 break; case 2: $status = 3; //打卡成功 break; case 3: $status = 4; //挑战成功 明天领奖 break; default: $status = 8; //成功推荐下一场 break; } break; case 1: switch ($this->campaginArr['userMatch']['status'] ){ case 3: $status = 6; //领奖页面 break; default: $status = 5; //打卡 break; } break; case 2: switch ( $this->campaginArr['userMatch']['status'] ){ case 3: $status = 6; //领奖页面 break; default: if ($this->campaginArr['userMatch']['is_again'] >=1){ $status = 9; //失败 }else{ $status = 7; //补卡 } break; } break; case 3: if ($this->campaginArr['userMatch']['status'] == 3){ $status = 6;//领奖 }else{ $status = 9; } break; default: if ($this->campaginArr['userMatch']['status'] == 3){ $status = 14;//未领奖 }else{ $status = 9; } break; } if ( $this->campaginArr['active']['end_time'] > time() ){ $this->campaginArr['active']['next'] = 1; $status = $status == 9 ? 12 : $status; }else{ $this->campaginArr['active']['next'] = 0;//给前端提供状态 是否有下一场 } //自动补卡 if ($status == 7){ $cSign = MyScene::getInstance($this->campaginArr['userInfo']->id, $this->campaginArr['userMatch']['match_id'])->cSign(); if ( $cSign['code'] == 200 ){ //补卡成功 $status = 10; //重新加载页面 }else{ $obj = CampaignService::instance()->setUserMatchFirstLogin($this->campaginArr['userInfo']->id); $status = $obj ? $status : 13; //状态13 不进行页面弹窗 } } if ( $status == 2 ){//是否需要弹窗 $this->campaginArr['popType'] = Redis::instance()->del(CampaignConstants::getUserMatchFirstLogin($this->campaginArr['userInfo']->id)); } $this->campaginArr['status'] = $status; return ; } /** * 我的挑战页面 * wud */ public function myRecharge(){ $statusArr = [ 3=>'挑战中', 4=>'挑战成功', 5=>'挑战失败', ]; $statusClass = [ 6=>'recharge_success ', 4=>'recharge_success ', 5=>'recharge_fail ', ]; $sum = [ 'kandian_sum'=>0, 'success_num'=>0, 'reward_sum'=>0 ]; $userId = UserService::instance()->getUserInfo()->id; $data = CampaignService::instance()->getUserRecharge( $userId ); $res=[ 'success'=>[], 'ing'=>[], 'fail'=>[], ]; if ( !empty($data) ){ foreach( $data as $kk => $vv){ $sum['kandian_sum'] += $vv['kandian']; if ($vv['status'] == 4 || $vv['status'] == 6){ $res['success'][] = $vv; $sum['success_num'] ++; $sum['reward_sum'] += $vv['reward']; } if ($vv['status'] <=3 ){ $res['ing'][] = $vv; } if ( $vv['status'] == 5 ){ $res['fail'][] = $vv; } } unset($data); } $this->assign('sum', $sum ); $this->assign('match', $res ); return $this->fetch('index@recharge/campaign/myRecharge'); } /** * 测试 */ public function getRedisKeyTest() { // $userInfo['id'] = 135180; // $userInfo['openid'] = "oxoco5zkESE0wf-IzxzUzZ0pytvQ"; // $orders = [ // 'order_id'=>62, // 'money'=>1, // 'kandian'=>20, // 'channel_id'=>183, // ]; // echo 'begin'; // MqUserPayCancelService::instance()->sendActiveToUser( $orders,$userInfo ); // $key = $this->request->get('key'); // $func = $this->request->get('func'); // $res = Redis::instance()->$func($key); // dump($res); } public function subscription() { //跳转到支付域名 if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD) { //推广域名 $userInfo = UserService::instance()->getUserInfo(); $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($userInfo->channel_id); $menuophost = $adminConfig['menuophost'] ?? null; $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null; if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) { $payHost = Config ::get('site.scheme') . '://' . $adminConfig['menuwxpay_host']; } else { $payHost = Config ::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host']; } $payHost .= '/index/recharge/subscription?'; $params['from'] = 'wechat'; $params['admin_id'] = $adminConfig['admin_id']; $params['channel_id'] = $userInfo->channel_id; $params['user_id'] = $userInfo->id; $params['sub_code'] = $this->request->param('sub_code'); $params['type'] = $this->request->param('type'); $payHost .= http_build_query($params); $this -> redirect($payHost); } //获取分享码 $subCode = $this->request->request('sub_code',0); $userInfo = UserService::instance()->getUserInfo(); if (empty($userInfo)){ return $this->error('用户信息错误'); } //获取业务域名 $channelUrl = getCurrentDomain($userInfo->channel_id); //是否关注 $isFan = $userInfo->is_subscribe; //是否已经报名活动 $subSer = SubscripService::instance(); $actUserInfo = $subSer->getActivityUser($userInfo); $today = date('Ymd',time()); //acting 0 没有报名 1 报名当天 2 活动中 $actIng = empty($actUserInfo) ? 0 : ($actUserInfo['act_date'] == $today ? 1 : 2); if (!empty($actUserInfo) && $actUserInfo['act_end_date'] < $today){//如果用户参加的活动已经结束 $actIng = 0; } //如果报名 获取报名场次的活动信息 $date = $actIng ? $actUserInfo['act_date'] : $today; $activity = $subSer->getActivity($date); //活动结束 if (empty($activity)){ return $this->error('活动未开始'); } //获取最近的阅读记录 $recent = model('UserRecentlyRead')->getRecentlyRead(0, 1, null, true); $channelUrl .= $recent['totalNum'] ? "index/user/recent" : "index/index/index"; $this->assign('ishaveRecent',$recent['totalNum']); $this->assign('channelUrl',$channelUrl); $this->assign('subCode',$subCode); $this->assign('acting',$actIng); $this->assign('isfan',$isFan); return $this->fetch('index@recharge/subscrip/index',['activity'=>$activity]); } //充值单页 public function singlepage() { //跳转到支付域名 if(UserService::instance()->getRunTimeObject()->urlType == UrlConstants::REFERRAL_GROUND_PAGE_SPREAD) { //推广域名 $userInfo = UserService::instance()->getUserInfo(); $adminConfig = $this->adminconfig; $menuophost = $adminConfig['menuophost'] ?? null; $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null; if ($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()) { $payHost = Config ::get('site.scheme') . '://' . $adminConfig['menuwxpay_host']; } else { $payHost = Config ::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host']; } $params['from'] = 'wechat'; $params['user_id'] = $userInfo->id; $payHost .= '/index/recharge/singlepage?'; $payHost .= http_build_query($params); $this -> redirect($payHost); } if (!isset($userInfo)){ $userInfo = UserService::instance()->getUserInfo(); } $pageId = $this->request->param('page_id',1); $data = model("PrivateBookPage")->getResourceList($pageId); if (empty($data) || !isset($data['resource'])){ $this->success('活动结束'); } $data['end_time'] = ($data['end_time'] - time())*1000; // dump($data); $bookIds = array_column($data['resource'],'book_id'); $payBookIds = SinglePushService::instance()->isPayBook($bookIds,$userInfo); foreach ($data['resource'] as $k =>&$v){ $v['is_pay'] = in_array($v['book_id'],$payBookIds) ? 1 : 0; } $tpl = 'page_single_push'; $channelUrl = getCurrentDomain($userInfo->channel_id); $this->view->assign('channelUrl', $channelUrl); $this->view->assign('data', $data); return $this->fetch('index@recharge/singlepage/'.$tpl); } }