123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- <?php
- /**
- * 前台控制器
- * 用户
- */
- namespace app\index\controller;
- use app\common\controller\Frontend;
- use app\common\library\Ip;
- use app\common\library\Redis;
- use app\common\library\Ua;
- use app\common\service\ActiveShareService;
- use app\common\service\AdService;
- use app\common\service\CampaignService;
- use app\common\service\CardFlipService;
- use app\common\service\ClientuserService;
- use app\common\service\WaterBookService;
- use app\main\constants\AdConstants;
- use app\main\constants\CacheConstants;
- use app\main\constants\MqConstants;
- use app\main\constants\UcCacheConstants;
- use app\main\helper\ArrayHelper;
- use app\main\service\AppGuideService;
- use app\main\service\FinancialService;
- use app\main\service\BookService;
- use app\main\service\GoodsService;
- use app\main\service\LogService;
- use app\main\service\SubscripService;
- use app\main\service\ToutiaoNotifyService;
- use app\main\service\UcNotifyService;
- use app\main\service\UserService;
- use think\Config;
- use think\Cookie;
- class User extends Frontend
- {
- protected $layout = '';
- public function _initialize()
- {
- parent::_initialize();
- $this->view->assign('adminconfig',$this->adminconfig);
- $is_show_tabbar = 0;
- $showBookShelf = 0;
- //$isAdPick = 0;
- if($this->user->isLogin()){
- $showBookShelf = BookService::instance()->showBookShelfFun();
- $is_show_tabbar = model("ChannelSpecialManage")->isWhite("show_tabbar", $this->user->channel_id);
- $this->assign('channel_id', $this->user->channel_id);
- //渠道是否开启了广告功能
- //$isAdPick = model("ChannelSpecialManage")->isWhite("ad_pick", $this->user->channel_id);
- }
- //$this->assign('isAdPick', $isAdPick);
- $this->assign('showBookShelf', $showBookShelf);
- $this->assign('is_show_tabbar', $is_show_tabbar);
- }
- //用户个人中心
- public function index()
- {
- $this->assign('tab_choice', 'my');
- $flag = 0;
- $kandian = 0;
- $kandian_permanent = 0;
- $kandian_fee = 0;
- //分享活动标记
- $is_share_open = 0;
- $share_url = '';
- $guideArr = [];
- if ($this->user->isLogin()) {
- $guideArr = AppGuideService::instance()->getAppGuideInfo($this->user->channel_id);
- if (ActiveShareService::instance()->checkChannel($this->user->channel_id)) {
- $is_share_open = 1;
- $share_url = ActiveShareService::instance()->getActiveUrl($this->user->channel_id, 2);
- }
- $this->assign('user', $this->user->getUserModel()->getUserInfo($this->user->id));
- $kandian_permanent = FinancialService::instance()->getTotalKandian($this->user->id)->data; #永久可用的看点数
- $kandian_fee = FinancialService::instance()->getTotalFreeKandian($this->user->id)->data; #带有效期的免费看点数
- $kandian = $kandian_permanent + $kandian_fee; #总可用的看点
- $flag = 1;
- }
- $this->view->assign('sex', $this->user->sex ? $this->user->sex : '1');
- $hasGuide = count($guideArr) ?? 0 ;
- //最新的竞赛信息
- $latestCampaign = CampaignService::instance()->getLatestCampaign($this->user);
- // 保存用户IP地址信息到Redis,跳转到消耗活动后,直充直销 户画像打点使用
- $ip_redis_key = CacheConstants::USER_IP_PREFIX . Cookie::get('user_id');
- Redis::instance()->set(
- $ip_redis_key,
- json_encode([
- 'ip' => Ip::ip(),
- 'country' => Ip::country(Ip::ip()),
- 'province' => Ip::province(Ip::ip()),
- 'city' => Ip::city(Ip::ip()),
- 'ua' => Ua::getUa()
- ]),
- 300
- );
- $good_desc = '';
- $vip = false;
- $show_vip_at_home = ArrayHelper::array_get($this->adminconfig, 'show_vip_at_home');
- if ($show_vip_at_home && $this->adminconfig['vip_state'] && $this->adminconfig['vip_goods_id']) {
- $goods_info = GoodsService::instance()->getGoodsModel()->getGoodsInfoById($this->adminconfig['vip_goods_id']);
- if ($goods_info && GoodsService::instance()->checkGoodsTypeValid($goods_info['show_type'], UserService::instance()->getUserInfo())->data) {
- $vip = true;
- $good_desc = $goods_info['desc'];
- }
- }
- //翻牌活动的banner
- $cardInfo = CardFlipService::instance()->getBannerImage($this->user);
- $this->assign('cardInfo',$cardInfo);
- //查看用户是否参加过订阅活动
- $isSubActUser = SubscripService::instance()->checkUserSign($this->user);
- $subBannerImg = SubscripService::instance()->checkSubBanner($this->user);
- $this->assign('isSubActUser',$isSubActUser);
- $this->assign('subBannerImg',$subBannerImg);
- $this->assign('vip', $vip);
- $this->assign('good_desc', $good_desc);
- $this->assign('share_url', $share_url);
- $this->assign('is_share_open', $is_share_open);
- $this->assign('latestCampaign', $latestCampaign);
- $this->assign('hasGuideArr', $hasGuide);
- $this->assign('flag', $flag);
- $this->assign('kandian', $kandian);
- $this->assign('kandian_permanent', $kandian_permanent);
- $this->assign('kandian_fee', $kandian_fee);
- return $this->view->fetch();
- }
- //用户最近阅读
- public function recent()
- {
- $this->assign('tab_choice', 'bookshelf');
- $res = [];
- $res['totalNum'] = 0;
- $recently = [];
- $userId = UserService::instance()->getUserInfo()->id;
- $channelId = UserService::instance()->getUserChannelId()->data;
- $isWater = WaterBookService::instance()->showBook($channelId, $userId, Ip::ip());
- if (Cookie::has('user_id')) {
- //已支付用户
- $res = model('UserRecentlyRead')->getRecentlyRead(0, 10, null, true);
- $recently = $res['totalNum'] == 0 ? [] : $res['data'];
- foreach ($recently as &$item) {
- if (empty($item['chapter_id'])) {
- unset($item);
- }
- if($isWater){
- $bookinfo = model('Book')->BookInfo($item['book_id']);
- if((!isset($bookinfo['classify_white_list']) || $bookinfo['classify_white_list'] != 1)){
- $item['state'] = 0;
- }
- }
- }
- $this->view->assign('login', 1);//登录
- }else {
- $cookread = Cookie::has('read')?Cookie::get('read'):[];
- $recently = array_reverse($cookread);
- $res['totalNum'] = count($recently);
- foreach ($recently as &$value) {
- $bookinfo = model('Book')->BookInfo($value['book_id']);
- $value['image'] = empty($bookinfo['image']) ? '' : $bookinfo['image'];
- $value['state'] = $bookinfo['state'];
- if ($isWater && (!isset($bookinfo['classify_white_list']) || $bookinfo['classify_white_list'] != 1)) {
- $value['state'] = 0;
- }
- $value['book_name'] = $bookinfo['name'];
- $value['last_chapter_name'] = empty($bookinfo['last_chapter_name']) ? '' : $bookinfo['last_chapter_name'];
- $value['last_chapter_utime'] = $bookinfo['last_chapter_utime'];
- }
- $this->view->assign('login', 0);//未登录
- }
- $this->assign('rencently', $recently);
- $this->assign('totalNum', $res['totalNum']);
- Cookie::set('rc', $res['totalNum']);//阅读书籍数
- $this->view->assign('sex', $this->user->sex ? $this->user->sex : '1');
- $showBookShelf = BookService::instance()->showBookShelfFun();
- $this->view->assign('ranklist', ['idx' => []]);
- $this->view->assign('type', 'recently');
- $this->view->assign('avatar', $this->user->avatar ?: cdnurl('/assets/img/frontend/icon/nav_icon_4.png'));
- $this->view->assign('isVip', $this->user->vip_endtime > time());
- $this->view->assign('show_book_shelf', $showBookShelf);
- return $this->view->fetch();
- }
- public function bookselfremove(){
- $uid = Cookie::get('user_id');
- $book_id = $this->request->get('book_id');
- $chapter_id = $this->request->get('chapter_id');
- if($uid){
- model('UserRecentlyRead')->setConnect($uid)->remove($book_id,$chapter_id,$uid);
- }
- }
- /**
- * 签到
- * @return string|\think\response\Json
- * @throws \Exception
- * err:0 签到成功,1 用户今日已签到,2 签到失败,3 用户未登录
- */
- public function sign()
- {
- $isSign = $this->isSign();
- //判断用户今日是否签到
- $this->assign('isSign',$isSign);
- return $this->view->fetch();
- }
- /**
- * 判断当前用户今日有没有签到
- * @return bool
- */
- public function isSign(){
- $uid = Cookie::get('user_id');
- $todayDate = Date('Ymd',time());
- if(Cookie::get('sign'.$todayDate)=='1'){
- return true;
- }else{
- $isSign = model('Sign')->setConnect($uid)->where(['uid'=>$uid,'createdate'=>$todayDate])->find();
- if(empty($isSign)){
- return false;
- }else{
- return true;
- }
- }
- }
- public function recommend()
- {
- return '';
- }
- public function readlist()
- {
- }
- /*
- * 登录页
- */
- public function login(){
- return $this->view->fetch();
- }
- /**
- * 跳转到智齿客服
- */
- public function visitZhiChi()
- {
- //$url = "https://www.sobot.com/chat/h5/index.html?sysNum=50d393e83a4d46d8857e8395e774f18d&source=1";
- //$url = "https://chat.sobot.com/chat/h5/v2/index.html?sysnum=50d393e83a4d46d8857e8395e774f18d&source=1";
- $url = "https://zc.sobot.com/chat/h5/v2/index.html?sysnum=50d393e83a4d46d8857e8395e774f18d&source=1";
- if ($this->user->isLogin()) {
- $userInfo = $this->user->getUserInfo(true)->toArray();
- $platename = Config::get('site.theme') ?? '';
- $servicename = $this->adminconfig['json']['authorizer_info']['nick_name'] ?? '';
- $url .= "&uname={$userInfo['nickname']}&face={$userInfo['avatar']}";
- $url .= "&customer_fields={'customField1':'$platename-$servicename'}";
- }
- header('Location: ' . $url);
- exit;
- }
- /**
- * 客户端绑定动态码
- * @return string
- * @throws \think\Exception
- */
- public function dycode()
- {
- if ($this->user->isLogin()) {
- $channel_id = Cookie::get('channel_id') ?? 0;
- $user_id = Cookie::get('user_id') ?? 0;
- $user_info = ClientuserService::instance()->getUserInfoByUid($user_id);
- // 引导位访问展示打点
- AppGuideService::instance()->appGuideViewDot($channel_id, $user_id, MqConstants::APP_GUIDE_POSITION_IDX_3);
- $this->assign('channel_id', $channel_id);
- $this->assign('user_id', $user_id);
- $this->assign('mobile', $user_info['mobile']);
- return $this->view->fetch();
- }else{
- echo '请先登录';
- exit();
- }
- }
- /**
- * 头条支付测试
- */
- public function ttpaytest()
- {
- if (UserService::instance()->isLogin()) {
- $id = UserService::instance()->getUserInfo()->id;
- if ($link = Redis::instance()->get(CacheConstants::getGuideWxPay($id))) {
- ToutiaoNotifyService::instance()->notify($link, $id, ToutiaoNotifyService::EVENT_TYPE_PAY, 1);
- echo "<h1>支付测试成功!</h1>";
- } else {
- echo "<h1>用户非头条引导用户或已过引导期</h1>";
- }
- } else {
- echo "<h1>未登陆!</h1>";
- }
- }
- /**
- * 高级群发消息 继续阅读
- */
- public function keepReading(){
- $data = model('UserRecentlyRead')->getRecentlyRead(0,1,UserService::instance()->getUserInfo()->id);
- if(empty($data['data'])){
- $this->redirect('/index/user/recent');
- }else {
- $url = '/index/book/chapter?book_id=' . $data['data'][0]['book_id'] . '&chapter_id=' . $data['data'][0]['chapter_id'];
- $this->redirect($url);
- }
- }
- /*
- * uc支付测试
- */
- public function ucpaytest()
- {
- if (UserService::instance()->isLogin()) {
- $id = UserService::instance()->getUserInfo()->id;
- if ($link = Redis::instance()->get(UcCacheConstants::getGuideWxPay($id))) {
- //UC回传
- UcNotifyService::instance()->notify(UserService::instance()->getUserInfo(), $link, UcNotifyService::EVENT_TYPE_PAY, 1);
- echo "<h1>支付测试成功!</h1>";
- } else {
- echo "<h1>用户非头条引导用户或已过引导期</h1>";
- }
- } else {
- echo "<h1>未登陆!</h1>";
- }
- }
- }
|