User.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <?php
  2. /**
  3. * 前台控制器
  4. * 用户
  5. */
  6. namespace app\index\controller;
  7. use app\common\controller\Frontend;
  8. use app\common\library\Ip;
  9. use app\common\library\Redis;
  10. use app\common\library\Ua;
  11. use app\common\service\ActiveShareService;
  12. use app\common\service\AdService;
  13. use app\common\service\CampaignService;
  14. use app\common\service\CardFlipService;
  15. use app\common\service\ClientuserService;
  16. use app\common\service\WaterBookService;
  17. use app\main\constants\AdConstants;
  18. use app\main\constants\CacheConstants;
  19. use app\main\constants\MqConstants;
  20. use app\main\constants\UcCacheConstants;
  21. use app\main\helper\ArrayHelper;
  22. use app\main\service\AppGuideService;
  23. use app\main\service\FinancialService;
  24. use app\main\service\BookService;
  25. use app\main\service\GoodsService;
  26. use app\main\service\LogService;
  27. use app\main\service\SubscripService;
  28. use app\main\service\ToutiaoNotifyService;
  29. use app\main\service\UcNotifyService;
  30. use app\main\service\UserService;
  31. use think\Config;
  32. use think\Cookie;
  33. class User extends Frontend
  34. {
  35. protected $layout = '';
  36. public function _initialize()
  37. {
  38. parent::_initialize();
  39. $this->view->assign('adminconfig',$this->adminconfig);
  40. $is_show_tabbar = 0;
  41. $showBookShelf = 0;
  42. //$isAdPick = 0;
  43. if($this->user->isLogin()){
  44. $showBookShelf = BookService::instance()->showBookShelfFun();
  45. $is_show_tabbar = model("ChannelSpecialManage")->isWhite("show_tabbar", $this->user->channel_id);
  46. $this->assign('channel_id', $this->user->channel_id);
  47. //渠道是否开启了广告功能
  48. //$isAdPick = model("ChannelSpecialManage")->isWhite("ad_pick", $this->user->channel_id);
  49. }
  50. //$this->assign('isAdPick', $isAdPick);
  51. $this->assign('showBookShelf', $showBookShelf);
  52. $this->assign('is_show_tabbar', $is_show_tabbar);
  53. }
  54. //用户个人中心
  55. public function index()
  56. {
  57. $this->assign('tab_choice', 'my');
  58. $flag = 0;
  59. $kandian = 0;
  60. $kandian_permanent = 0;
  61. $kandian_fee = 0;
  62. //分享活动标记
  63. $is_share_open = 0;
  64. $share_url = '';
  65. $guideArr = [];
  66. if ($this->user->isLogin()) {
  67. $guideArr = AppGuideService::instance()->getAppGuideInfo($this->user->channel_id);
  68. if (ActiveShareService::instance()->checkChannel($this->user->channel_id)) {
  69. $is_share_open = 1;
  70. $share_url = ActiveShareService::instance()->getActiveUrl($this->user->channel_id, 2);
  71. }
  72. $this->assign('user', $this->user->getUserModel()->getUserInfo($this->user->id));
  73. $kandian_permanent = FinancialService::instance()->getTotalKandian($this->user->id)->data; #永久可用的看点数
  74. $kandian_fee = FinancialService::instance()->getTotalFreeKandian($this->user->id)->data; #带有效期的免费看点数
  75. $kandian = $kandian_permanent + $kandian_fee; #总可用的看点
  76. $flag = 1;
  77. }
  78. $this->view->assign('sex', $this->user->sex ? $this->user->sex : '1');
  79. $hasGuide = count($guideArr) ?? 0 ;
  80. //最新的竞赛信息
  81. $latestCampaign = CampaignService::instance()->getLatestCampaign($this->user);
  82. // 保存用户IP地址信息到Redis,跳转到消耗活动后,直充直销 户画像打点使用
  83. $ip_redis_key = CacheConstants::USER_IP_PREFIX . Cookie::get('user_id');
  84. Redis::instance()->set(
  85. $ip_redis_key,
  86. json_encode([
  87. 'ip' => Ip::ip(),
  88. 'country' => Ip::country(Ip::ip()),
  89. 'province' => Ip::province(Ip::ip()),
  90. 'city' => Ip::city(Ip::ip()),
  91. 'ua' => Ua::getUa()
  92. ]),
  93. 300
  94. );
  95. $good_desc = '';
  96. $vip = false;
  97. $show_vip_at_home = ArrayHelper::array_get($this->adminconfig, 'show_vip_at_home');
  98. if ($show_vip_at_home && $this->adminconfig['vip_state'] && $this->adminconfig['vip_goods_id']) {
  99. $goods_info = GoodsService::instance()->getGoodsModel()->getGoodsInfoById($this->adminconfig['vip_goods_id']);
  100. if ($goods_info && GoodsService::instance()->checkGoodsTypeValid($goods_info['show_type'], UserService::instance()->getUserInfo())->data) {
  101. $vip = true;
  102. $good_desc = $goods_info['desc'];
  103. }
  104. }
  105. //翻牌活动的banner
  106. $cardInfo = CardFlipService::instance()->getBannerImage($this->user);
  107. $this->assign('cardInfo',$cardInfo);
  108. //查看用户是否参加过订阅活动
  109. $isSubActUser = SubscripService::instance()->checkUserSign($this->user);
  110. $subBannerImg = SubscripService::instance()->checkSubBanner($this->user);
  111. $this->assign('isSubActUser',$isSubActUser);
  112. $this->assign('subBannerImg',$subBannerImg);
  113. $this->assign('vip', $vip);
  114. $this->assign('good_desc', $good_desc);
  115. $this->assign('share_url', $share_url);
  116. $this->assign('is_share_open', $is_share_open);
  117. $this->assign('latestCampaign', $latestCampaign);
  118. $this->assign('hasGuideArr', $hasGuide);
  119. $this->assign('flag', $flag);
  120. $this->assign('kandian', $kandian);
  121. $this->assign('kandian_permanent', $kandian_permanent);
  122. $this->assign('kandian_fee', $kandian_fee);
  123. return $this->view->fetch();
  124. }
  125. //用户最近阅读
  126. public function recent()
  127. {
  128. $this->assign('tab_choice', 'bookshelf');
  129. $res = [];
  130. $res['totalNum'] = 0;
  131. $recently = [];
  132. $userId = UserService::instance()->getUserInfo()->id;
  133. $channelId = UserService::instance()->getUserChannelId()->data;
  134. $isWater = WaterBookService::instance()->showBook($channelId, $userId, Ip::ip());
  135. if (Cookie::has('user_id')) {
  136. //已支付用户
  137. $res = model('UserRecentlyRead')->getRecentlyRead(0, 10, null, true);
  138. $recently = $res['totalNum'] == 0 ? [] : $res['data'];
  139. foreach ($recently as &$item) {
  140. if (empty($item['chapter_id'])) {
  141. unset($item);
  142. }
  143. if($isWater){
  144. $bookinfo = model('Book')->BookInfo($item['book_id']);
  145. if((!isset($bookinfo['classify_white_list']) || $bookinfo['classify_white_list'] != 1)){
  146. $item['state'] = 0;
  147. }
  148. }
  149. }
  150. $this->view->assign('login', 1);//登录
  151. }else {
  152. $cookread = Cookie::has('read')?Cookie::get('read'):[];
  153. $recently = array_reverse($cookread);
  154. $res['totalNum'] = count($recently);
  155. foreach ($recently as &$value) {
  156. $bookinfo = model('Book')->BookInfo($value['book_id']);
  157. $value['image'] = empty($bookinfo['image']) ? '' : $bookinfo['image'];
  158. $value['state'] = $bookinfo['state'];
  159. if ($isWater && (!isset($bookinfo['classify_white_list']) || $bookinfo['classify_white_list'] != 1)) {
  160. $value['state'] = 0;
  161. }
  162. $value['book_name'] = $bookinfo['name'];
  163. $value['last_chapter_name'] = empty($bookinfo['last_chapter_name']) ? '' : $bookinfo['last_chapter_name'];
  164. $value['last_chapter_utime'] = $bookinfo['last_chapter_utime'];
  165. }
  166. $this->view->assign('login', 0);//未登录
  167. }
  168. $this->assign('rencently', $recently);
  169. $this->assign('totalNum', $res['totalNum']);
  170. Cookie::set('rc', $res['totalNum']);//阅读书籍数
  171. $this->view->assign('sex', $this->user->sex ? $this->user->sex : '1');
  172. $showBookShelf = BookService::instance()->showBookShelfFun();
  173. $this->view->assign('ranklist', ['idx' => []]);
  174. $this->view->assign('type', 'recently');
  175. $this->view->assign('avatar', $this->user->avatar ?: cdnurl('/assets/img/frontend/icon/nav_icon_4.png'));
  176. $this->view->assign('isVip', $this->user->vip_endtime > time());
  177. $this->view->assign('show_book_shelf', $showBookShelf);
  178. return $this->view->fetch();
  179. }
  180. public function bookselfremove(){
  181. $uid = Cookie::get('user_id');
  182. $book_id = $this->request->get('book_id');
  183. $chapter_id = $this->request->get('chapter_id');
  184. if($uid){
  185. model('UserRecentlyRead')->setConnect($uid)->remove($book_id,$chapter_id,$uid);
  186. }
  187. }
  188. /**
  189. * 签到
  190. * @return string|\think\response\Json
  191. * @throws \Exception
  192. * err:0 签到成功,1 用户今日已签到,2 签到失败,3 用户未登录
  193. */
  194. public function sign()
  195. {
  196. $isSign = $this->isSign();
  197. //判断用户今日是否签到
  198. $this->assign('isSign',$isSign);
  199. return $this->view->fetch();
  200. }
  201. /**
  202. * 判断当前用户今日有没有签到
  203. * @return bool
  204. */
  205. public function isSign(){
  206. $uid = Cookie::get('user_id');
  207. $todayDate = Date('Ymd',time());
  208. if(Cookie::get('sign'.$todayDate)=='1'){
  209. return true;
  210. }else{
  211. $isSign = model('Sign')->setConnect($uid)->where(['uid'=>$uid,'createdate'=>$todayDate])->find();
  212. if(empty($isSign)){
  213. return false;
  214. }else{
  215. return true;
  216. }
  217. }
  218. }
  219. public function recommend()
  220. {
  221. return '';
  222. }
  223. public function readlist()
  224. {
  225. }
  226. /*
  227. * 登录页
  228. */
  229. public function login(){
  230. return $this->view->fetch();
  231. }
  232. /**
  233. * 跳转到智齿客服
  234. */
  235. public function visitZhiChi()
  236. {
  237. //$url = "https://www.sobot.com/chat/h5/index.html?sysNum=50d393e83a4d46d8857e8395e774f18d&source=1";
  238. //$url = "https://chat.sobot.com/chat/h5/v2/index.html?sysnum=50d393e83a4d46d8857e8395e774f18d&source=1";
  239. $url = "https://zc.sobot.com/chat/h5/v2/index.html?sysnum=50d393e83a4d46d8857e8395e774f18d&source=1";
  240. if ($this->user->isLogin()) {
  241. $userInfo = $this->user->getUserInfo(true)->toArray();
  242. $platename = Config::get('site.theme') ?? '';
  243. $servicename = $this->adminconfig['json']['authorizer_info']['nick_name'] ?? '';
  244. $url .= "&uname={$userInfo['nickname']}&face={$userInfo['avatar']}";
  245. $url .= "&customer_fields={'customField1':'$platename-$servicename'}";
  246. }
  247. header('Location: ' . $url);
  248. exit;
  249. }
  250. /**
  251. * 客户端绑定动态码
  252. * @return string
  253. * @throws \think\Exception
  254. */
  255. public function dycode()
  256. {
  257. if ($this->user->isLogin()) {
  258. $channel_id = Cookie::get('channel_id') ?? 0;
  259. $user_id = Cookie::get('user_id') ?? 0;
  260. $user_info = ClientuserService::instance()->getUserInfoByUid($user_id);
  261. // 引导位访问展示打点
  262. AppGuideService::instance()->appGuideViewDot($channel_id, $user_id, MqConstants::APP_GUIDE_POSITION_IDX_3);
  263. $this->assign('channel_id', $channel_id);
  264. $this->assign('user_id', $user_id);
  265. $this->assign('mobile', $user_info['mobile']);
  266. return $this->view->fetch();
  267. }else{
  268. echo '请先登录';
  269. exit();
  270. }
  271. }
  272. /**
  273. * 头条支付测试
  274. */
  275. public function ttpaytest()
  276. {
  277. if (UserService::instance()->isLogin()) {
  278. $id = UserService::instance()->getUserInfo()->id;
  279. if ($link = Redis::instance()->get(CacheConstants::getGuideWxPay($id))) {
  280. ToutiaoNotifyService::instance()->notify($link, $id, ToutiaoNotifyService::EVENT_TYPE_PAY, 1);
  281. echo "<h1>支付测试成功!</h1>";
  282. } else {
  283. echo "<h1>用户非头条引导用户或已过引导期</h1>";
  284. }
  285. } else {
  286. echo "<h1>未登陆!</h1>";
  287. }
  288. }
  289. /**
  290. * 高级群发消息 继续阅读
  291. */
  292. public function keepReading(){
  293. $data = model('UserRecentlyRead')->getRecentlyRead(0,1,UserService::instance()->getUserInfo()->id);
  294. if(empty($data['data'])){
  295. $this->redirect('/index/user/recent');
  296. }else {
  297. $url = '/index/book/chapter?book_id=' . $data['data'][0]['book_id'] . '&chapter_id=' . $data['data'][0]['chapter_id'];
  298. $this->redirect($url);
  299. }
  300. }
  301. /*
  302. * uc支付测试
  303. */
  304. public function ucpaytest()
  305. {
  306. if (UserService::instance()->isLogin()) {
  307. $id = UserService::instance()->getUserInfo()->id;
  308. if ($link = Redis::instance()->get(UcCacheConstants::getGuideWxPay($id))) {
  309. //UC回传
  310. UcNotifyService::instance()->notify(UserService::instance()->getUserInfo(), $link, UcNotifyService::EVENT_TYPE_PAY, 1);
  311. echo "<h1>支付测试成功!</h1>";
  312. } else {
  313. echo "<h1>用户非头条引导用户或已过引导期</h1>";
  314. }
  315. } else {
  316. echo "<h1>未登陆!</h1>";
  317. }
  318. }
  319. }