Index.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. <?php
  2. namespace app\index\controller;
  3. use app\admin\service\ShortUrlService;
  4. use app\common\controller\Frontend;
  5. use app\common\library\Ip;
  6. use app\common\service\VipCpService;
  7. use app\common\service\WaterBookService;
  8. use app\main\constants\MarkConstants;
  9. use app\main\service\ActivityService;
  10. use app\main\service\AdminService;
  11. use app\main\service\BookService;
  12. use app\main\service\FufenService;
  13. use app\main\service\UrlService;
  14. use app\main\service\UserService;
  15. use think\Config;
  16. use think\Cookie;
  17. class Index extends Frontend
  18. {
  19. protected $layout = '';
  20. protected $tpname = ['1' => 'lunbo', '2' => 'cainixihuan', '3' => 'remenshuangwen', '4' => 'nav', '5' => 'searchbox', '6' => 'blcoknav', '7' => 'changxiao','8'=>'recently'];
  21. //1=轮播,2=横4,3=竖4,4=标题导航,5=搜索,6=块导航,7=榜单
  22. protected $ranklivetime = 600; //榜单生存时间秒
  23. protected $hotsearch_extime = 86400; //热门搜索书籍默认保存1天
  24. protected $wxNoNeedLogin = ['dev', 'clear'];
  25. public function _initialize()
  26. {
  27. parent::_initialize();
  28. }
  29. public function index()
  30. {
  31. $is_show_tabbar = 0;
  32. $showBookShelf = 0;
  33. if($this->user->isLogin()){
  34. // 是否已经加入到书架 TRUE | FALSE
  35. $showBookShelf = BookService::instance()->showBookShelfFun();
  36. $is_show_tabbar = model("ChannelSpecialManage")->isWhite("show_tabbar", $this->user->channel_id);
  37. $this->assign('channel_id', $this->user->channel_id);
  38. }
  39. $this->assign('showBookShelf', $showBookShelf);
  40. $this->assign('is_show_tabbar', $is_show_tabbar);
  41. $this->assign('tab_choice', 'bookcity');
  42. // 联盟推广页 && 充值页 不读取用户信息
  43. if ($this->urlType == 1 || $this->urlType == 2) {
  44. $domain_coms = [
  45. '温江区雨见源日用百货店' => [
  46. 'yjreadc.cn',
  47. 'yjreada.cn',
  48. 'yjreadd.cn',
  49. 'yjreadb.cn',
  50. ],
  51. '莱可广告设计工作室' => [
  52. 'laiked.cn',
  53. 'laikeb.cn',
  54. 'laikef.cn',
  55. 'laikec.cn',
  56. ],
  57. '内蒙古林信科技发展有限公司' => [
  58. 'lxtee.com',
  59. 'lxten.com',
  60. 'lxted.com',
  61. 'lxtee.cn',
  62. 'lxten.cn',
  63. 'lxtes.cn',
  64. 'linxine.cn',
  65. 'linjs.com',
  66. 'lintd.com',
  67. 'linpd.com',
  68. 'linxind.cn',
  69. ],
  70. '天津每日趣阅网络技术有限公司' => [
  71. 'hzinc.cn',
  72. 'hzdue.cn'
  73. ],
  74. '北京快乐农夫科技有限公司' => [
  75. 'klfuny.cn',
  76. 'karea.cn'
  77. ]
  78. ];
  79. $domainArr = [
  80. 'lxtee.com' => '蒙ICP备18004074号-1',
  81. 'lxten.com' => '蒙ICP备18004074号-1',
  82. 'lxted.com' => '蒙ICP备18004074号-1',
  83. 'lxtee.cn' => '蒙ICP备18004074号-1',
  84. 'lxten.cn' => '蒙ICP备18004074号-1',
  85. 'lxtes.cn' => '蒙ICP备18004074号-1',
  86. 'linxine.cn' => '蒙ICP备18004074号-3',
  87. 'linjs.com' => '蒙ICP备18004074号-7',
  88. 'lintd.com' => '蒙ICP备18004074号-8',
  89. 'linpd.com' => '蒙ICP备18004074号-9',
  90. 'linxind.cn' => '蒙ICP备18004074号-6',
  91. 'laiked.cn' => '蜀ICP备18024149号-22',
  92. 'laikeb.cn' => '蜀ICP备18024149号-23',
  93. 'laikef.cn' => '蜀ICP备18024149号-24',
  94. 'laikec.cn' => '蜀ICP备18024149号-21',
  95. 'yjreadc.cn' => '蜀ICP备18034038号-10',
  96. 'yjreada.cn' => '蜀ICP备18034038号-11',
  97. 'yjreadd.cn' => '蜀ICP备18034038号-12',
  98. 'yjreadb.cn' => '蜀ICP备18034038号-9',
  99. 'hzinc.cn' => '津ICP备18006783号-2',
  100. 'hzdue.cn' => '津ICP备18006783号-3',
  101. 'klfuny.cn' => '京ICP备17030462号-36',
  102. 'karea.cn' => '京ICP备17030462号-32'
  103. ];
  104. $host = get_host_no_port();
  105. $domain_put = '';
  106. $title = '';
  107. if(!empty($host)){
  108. $arr = explode('.',$host);
  109. $this_domain = $arr[sizeof($arr)-2].'.'.$arr[sizeof($arr)-1];
  110. if(array_key_exists($this_domain,$domainArr)){
  111. $com_name = '内蒙古林信科技发展有限公司';
  112. foreach($domain_coms as $key => $dom){
  113. if(array_search($this_domain,$dom) !== false){
  114. $com_name = $key;
  115. break;
  116. }
  117. }
  118. $domain_put .= "本站隶属于{$com_name}<br/>备案号:<a href='http://www.beian.miit.gov.cn'>{$domainArr[$this_domain]}</a>";
  119. }
  120. if (in_array($this_domain, ['karea.cn'])) {
  121. $title = '快乐农夫';
  122. }
  123. }
  124. //dump($domain);die;
  125. $this->assign('domain_put',$domain_put);
  126. $this->assign('title',$title);
  127. return $this->fetch();
  128. }
  129. if ($this->user->sex && $this->user->sex == 2) {
  130. $type = 'girl';
  131. } else {
  132. $type = 'boy';
  133. }
  134. $pagesex = $this->request->get('type') ? $this->request->get('type') : $type;
  135. $adminconfig = $this->adminconfig;
  136. if (!isset($adminconfig['index_title'])) {
  137. $adminconfig['index_title'] = '首页';
  138. }
  139. // $sql = "select r.*,a.name as aname,a.copywriting from resource as r INNER JOIN activity as a ON r.activity_id = a.id WHERE a.status = '1' AND r.status = '1' AND FIND_IN_SET({$tag},r.pop_range) AND a.starttime<" . time() . " AND a.endtime>" . time() . " ORDER BY a.createtime desc,r.weigh desc limit 1";
  140. // $res = model('resource')->query($sql);
  141. // if ($res) {
  142. // $this->assign('activity', $res['0']);
  143. // }
  144. if ($adminconfig['page_sex'] == 1) {
  145. $pagesex = 'boy';
  146. } elseif ($adminconfig['page_sex'] == 2) {
  147. $pagesex = 'girl';
  148. }
  149. Cookie::set('sex', $pagesex);
  150. if ($pagesex == 'girl') {
  151. $sexid = 2;
  152. } else {
  153. $sexid = 1;
  154. }
  155. $rencently[] = [];
  156. if (Cookie::has('user_id')) {
  157. $res = model('UserRecentlyRead')->getRecentlyRead(0, 10, null, true);
  158. $rencently = $res['totalNum'] == 0 ? [] : $res['data'];
  159. $this->view->assign('login', 1);//登录
  160. }else {
  161. $cookread = Cookie::has('read')?Cookie::get('read'):[];
  162. $rencently = array_reverse($cookread);
  163. $res['totalNum'] = count($rencently);
  164. foreach ($rencently as &$value){
  165. $bookinfo = model('Book')->BookInfo($value['book_id']);
  166. $value['book_name'] = $bookinfo['name'];
  167. }
  168. $this->view->assign('login',0);//未登录
  169. }
  170. $this->assign('rencently', $rencently);
  171. $this->view->assign('adminconfig', $adminconfig);
  172. $pagedata = $this->page_block_resource($pagesex);
  173. $ranklist = $this->ranklist($pagesex);
  174. $this->assign('sexid', $sexid);
  175. $this->view->assign('type', $pagesex);
  176. $this->view->assign('pagedata', $pagedata);
  177. $this->view->assign('ranklist', $ranklist);
  178. //$this->view->assign('sex', model('User')->getUserSex($this->user->sex, $adminconfig, false, $pagesex));
  179. $this->view->assign('sex', $this->user->sex ? $this->user->sex : '1');
  180. $this->view->assign('avatar', $this->user->avatar ?: cdnurl('/assets/img/frontend/icon/nav_icon_4.png'));
  181. $this->view->assign('isVip', $this->user->vip_endtime > time());
  182. return $this->view->fetch();
  183. }
  184. public function classify_list()
  185. {
  186. return $this->view->fetch();
  187. }
  188. public function scan_code()
  189. {
  190. return $this->view->fetch();
  191. }
  192. /*
  193. * 资源数据列表
  194. */
  195. public function page_block_resource($type)
  196. {
  197. $showWaterBook = WaterBookService::instance()->showBook($this->user->channel_id, $this->user->id, Ip::ip());
  198. if ($type == 'boy') {
  199. if ($showWaterBook) {
  200. $pageId = 3;
  201. } else {
  202. $pageId = 1;
  203. }
  204. } else {
  205. if ($showWaterBook) {
  206. $pageId = 4;
  207. } else {
  208. $pageId = 2;
  209. }
  210. }
  211. $redisKey = 'P:' . $pageId;
  212. if ($value = $this->redis->get($redisKey)) {
  213. $result = json_decode($value, true);
  214. return $result;
  215. } else {
  216. $boydata = [];
  217. $girldata = [];
  218. $boyCleanData = [];
  219. $girlCleanData = [];
  220. $block = collection(model('ManageBlock')
  221. ->order('page_id asc,weigh desc')->select())->toArray();
  222. foreach ($block as $value) {
  223. $where = [
  224. 'manage_block_resource.type' => 1,
  225. 'book.state' => 1
  226. ];
  227. if (in_array($value['page_id'], [3, 4])) {
  228. $where['book.classify_white_list'] = 1;
  229. }
  230. $books = collection(
  231. model('ManageBlockResource')
  232. ->join('book', 'book.id= manage_block_resource.book_id')
  233. ->join('book_category bc', 'bc.id = book.book_category_id', 'LEFT')
  234. ->whereIn('block_id', $value['id'])
  235. ->field('bc.name as bc_name,book.book_category_id,book.name,book.author,book.is_finish, book.description,book.last_chapter_name,book.last_chapter_id,book.read_num,book.tags,manage_block_resource.*')
  236. ->where($where)
  237. ->order('weigh desc')
  238. ->limit(6)
  239. ->select()
  240. )->toArray();
  241. $special = collection(
  242. model('ManageBlockResource')
  243. ->join('special_page', 'special_page.id=manage_block_resource.special_id')
  244. ->field('manage_block_resource.*,special_page.title as name')
  245. ->where('manage_block_resource.type=3')
  246. ->where('block_id', $value['id'])
  247. ->order('weigh desc')
  248. ->limit(6)
  249. ->select()
  250. )->toArray();
  251. if ($books) {
  252. foreach ($books as $k => $v) {
  253. $books[$k]['vip_pay'] = BookService::instance()->showCpVipSubScript($v['book_id']);
  254. }
  255. }
  256. $list = array_merge($books, $special);
  257. usort($list, function ($v1, $v2) {
  258. return $v1['weigh'] < $v2['weigh'];
  259. });
  260. $value['block_resource'] = array_slice($list, 0, 6);
  261. foreach ($value['block_resource'] as &$v2) {
  262. $v2['read_nums'] = empty($v2['read_num']) ? 0 : friend_date($v2['read_num']);
  263. $v2['tags'] = empty($v2['tags']) ? [] : explode(',', $v2['tags']);
  264. }
  265. if ($value['page_id'] == 1) {
  266. $boydata[] = $value;
  267. }
  268. if ($value['page_id'] == 2) {
  269. $girldata[] = $value;
  270. }
  271. if ($value['page_id'] == 3) {
  272. $boyCleanData[] = $value;
  273. }
  274. if ($value['page_id'] == 4) {
  275. $girlCleanData[] = $value;
  276. }
  277. }
  278. if (!empty($boydata)) {
  279. $this->redis->setex('P:1', 900, json_encode($boydata, JSON_UNESCAPED_UNICODE));
  280. }
  281. if (!empty($girldata)) {
  282. $this->redis->setex('P:2', 900, json_encode($girldata, JSON_UNESCAPED_UNICODE));
  283. }
  284. if (!empty($boyCleanData)) {
  285. $this->redis->setex('P:3', 900, json_encode($boyCleanData, JSON_UNESCAPED_UNICODE));
  286. }
  287. if (!empty($girlCleanData)) {
  288. $this->redis->setex('P:4', 900, json_encode($girlCleanData, JSON_UNESCAPED_UNICODE));
  289. }
  290. switch ($pageId){
  291. case 1:
  292. return $boydata;
  293. case 2:
  294. return $girldata;
  295. case 3:
  296. return $boyCleanData;
  297. case 4:
  298. return $girlCleanData;
  299. default:
  300. return [];
  301. }
  302. }
  303. }
  304. /*
  305. * 榜单列表 rank1男频 rank2女频 rank0不区分男女 按照idx排序
  306. */
  307. public function ranklist($type)
  308. {
  309. $channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($this->user->channel_id);
  310. $showWaterBook = WaterBookService::instance()->showBook($channel_id, $this->user->id, Ip::ip());
  311. $where=[];
  312. if($showWaterBook){
  313. $where['book.classify_white_list']=1;
  314. $key0 = 'RANK:0:W';
  315. $key1 = 'RANK:1:W';
  316. $key2 = 'RANK:2:W';
  317. }else{
  318. $key0 = 'RANK:0';
  319. $key1 = 'RANK:1';
  320. $key2 = 'RANK:2';
  321. }
  322. $boydata = [];
  323. $girldata = [];
  324. if ($this->redis->exists($key1) && $this->redis->exists($key2) && $this->redis->exists($key0)) {
  325. $boydata = json_decode($this->redis->get($key1), true);
  326. $girldata = json_decode($this->redis->get($key2), true);
  327. $idxdata = json_decode($this->redis->get($key0), true);
  328. } else {
  329. $boydata['click'] = collection(
  330. model('Book')->join('book_category bc','bc.id = book.book_category_id','LEFT')
  331. ->where(['book.state' => 1, 'book.sex' => 1])
  332. ->where($where)
  333. ->field('book.*,bc.name as bc_name')
  334. ->order('book.read_num desc')
  335. ->limit(3)
  336. ->select()
  337. )->toArray();
  338. foreach ($boydata['click'] as &$value) {
  339. $value['vip_pay'] = BookService::instance()->showCpVipSubScript($value['id']);
  340. $value['read_nums'] = friend_date($value['read_num']);
  341. $value['author'] = $value['bc_name'];
  342. }
  343. $boydata['idx'] = collection(
  344. model('Book')->join('book_category bc','bc.id = book.book_category_id','LEFT')
  345. ->where(['book.state' => 1, 'book.sex' => 1])
  346. ->where($where)
  347. ->field('book.*,bc.name as bc_name')
  348. ->order('book.idx desc')
  349. ->limit(3)
  350. ->select()
  351. )->toArray();
  352. foreach ($boydata['idx'] as &$value) {
  353. $value['vip_pay'] = BookService::instance()->showCpVipSubScript($value['id']);
  354. $value['read_nums'] = friend_date($value['read_num']);
  355. $value['author'] = $value['bc_name'];
  356. }
  357. $girldata['click'] = collection(
  358. model('Book')->join('book_category bc','bc.id = book.book_category_id','LEFT')
  359. ->where(['book.state' => 1, 'book.sex' => 2])
  360. ->where($where)
  361. ->field('book.*,bc.name as bc_name')
  362. ->order('book.read_num desc')
  363. ->limit(3)
  364. ->select()
  365. )->toArray();
  366. foreach ($girldata['click'] as &$value) {
  367. $value['vip_pay'] = BookService::instance()->showCpVipSubScript($value['id']);
  368. $value['read_nums'] = friend_date($value['read_num']);
  369. $value['author'] = $value['bc_name'];
  370. }
  371. $girldata['idx'] = collection(
  372. model('Book')->join('book_category bc','bc.id = book.book_category_id','LEFT')
  373. ->where(['book.state' => 1, 'book.sex' => 2])
  374. ->where($where)
  375. ->field('book.*,bc.name as bc_name')
  376. ->order('book.idx desc')
  377. ->limit(3)
  378. ->select()
  379. )->toArray();
  380. foreach ($girldata['idx'] as &$value) {
  381. $value['vip_pay'] = BookService::instance()->showCpVipSubScript($value['id']);
  382. $value['read_nums'] = friend_date($value['read_num']);
  383. $value['author'] = $value['bc_name'];
  384. }
  385. $idxdata['idx'] = collection(
  386. model('Book')->join('book_category bc','bc.id = book.book_category_id','LEFT')
  387. ->where(['book.state' => 1])
  388. ->where($where)
  389. ->field('book.*,bc.name as bc_name')
  390. ->order('book.idx desc')
  391. ->limit(3)
  392. ->select()
  393. )->toArray();
  394. foreach ($idxdata['idx'] as &$value) {
  395. $value['vip_pay'] = BookService::instance()->showCpVipSubScript($value['id']);
  396. $value['read_nums'] = friend_date($value['read_num']);
  397. $value['author'] = $value['bc_name'];
  398. }
  399. if (!empty($boydata)) {
  400. $this->redis->setex($key1, $this->ranklivetime, json_encode($boydata, JSON_UNESCAPED_UNICODE));
  401. }
  402. if (!empty($girldata)) {
  403. $this->redis->setex($key2, $this->ranklivetime, json_encode($girldata, JSON_UNESCAPED_UNICODE));
  404. }
  405. if (!empty($idxdata)) {
  406. $this->redis->setex($key0, $this->ranklivetime, json_encode($idxdata, JSON_UNESCAPED_UNICODE));
  407. }
  408. }
  409. if ($type == 1) {
  410. return $boydata;
  411. } elseif ($type == 2) {
  412. return $girldata;
  413. } elseif ($type == 'boy') {
  414. return $boydata;
  415. } elseif ($type == 'girl') {
  416. return $girldata;
  417. } else {
  418. return $idxdata;
  419. }
  420. }
  421. /*
  422. * 主编推荐列表
  423. */
  424. public function recommendList($book_id)
  425. {
  426. if($book_id){
  427. $bookInfo = model("book")->BookInfo($book_id);
  428. }else{
  429. return false;
  430. }
  431. $where = [];
  432. $where['state'] = '1';
  433. $where['book_category_id'] = $bookInfo['book_category_id'];
  434. //最近阅读
  435. $recentList = model('UserRecentlyRead')->getRecentlyRead(0);
  436. $recentIds[] = $bookInfo['id'];
  437. if ($recentList['totalNum'] > 0) {
  438. foreach ($recentList['data'] as $v) {
  439. $recentIds[] = $v['book_id'];
  440. }
  441. }
  442. if ($recentIds) {
  443. $where['id'] = ['not in', $recentIds];
  444. }
  445. $pagedata[0]['name'] = "主编推荐";
  446. $pagedata[0]['page_id'] = 1;
  447. $pagedata[0]['second_name'] = "主编推荐";
  448. $pagedata[0]['block_resource'] = collection(model("Book")
  449. ->where($where)
  450. ->order('rand()')
  451. ->limit(4)
  452. ->select())->toArray();
  453. if($pagedata[0]['block_resource']){
  454. foreach ($pagedata[0]['block_resource'] as &$v){
  455. $v['book_id'] = $v['id'];
  456. }
  457. }
  458. return $pagedata;
  459. }
  460. public function recommendAjax(){
  461. $book_id = $this->request->get("book_id");
  462. if($book_id){
  463. $pagedata = $this->recommendList($book_id);
  464. }else{
  465. return false;
  466. }
  467. return json($pagedata);
  468. }
  469. /**
  470. * 搜索页
  471. * @param int $sex 频道标示
  472. */
  473. public function search()
  474. {
  475. $userId = $this->user->id;
  476. $books = model('User')->getLike($userId);
  477. $categoryArr = model("BookCategory")->getCategoryList();
  478. foreach ($books as $k=>$v){
  479. $books[$k]['author'] = $categoryArr[$v['book_category_id']];
  480. }
  481. if($this->request->isAjax()){
  482. return json_encode($books);
  483. }else{
  484. $sex = input('sex');
  485. $this->assign('sex', $sex);
  486. $pagedata['name'] = '精彩推荐';
  487. $pagedata['block_resource'] = $books;
  488. $this->view->assign('value', $pagedata);
  489. return $this->view->fetch();
  490. }
  491. }
  492. /**
  493. * 搜索接口
  494. * @param string $keyword 关键词
  495. * @param int $page 页码
  496. * @return json
  497. */
  498. public function searchapi()
  499. {
  500. $keyword = input('keyword');
  501. $page = input('page', 1);
  502. if (!empty($keyword)) {
  503. $where = array();
  504. //清水
  505. $userObj = UserService::instance()->getUserInfo();
  506. $channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($userObj->channel_id);
  507. $is_water = WaterBookService::instance()->showBook($channel_id, $userObj->id, Ip::ip());
  508. if ($is_water) {
  509. $where['b.classify_white_list'] = 1;
  510. }
  511. $where['b.state'] = 1;
  512. $where['b.name'] = array('like', '%' . $keyword . '%');
  513. $total = model('book')
  514. ->alias('b')
  515. ->join('book_category bc','bc.id=b.book_category_id and bc.status=\'normal\'')
  516. ->where($where)
  517. ->count();
  518. $books = model('book')
  519. ->alias('b')
  520. ->join('book_category bc','bc.id=b.book_category_id and bc.status=\'normal\'')
  521. ->where($where)
  522. ->page($page, 10)
  523. ->field('b.*,bc.name as author')
  524. ->select();
  525. } else {
  526. $total = 0;
  527. $books = array();
  528. }
  529. $result = array(
  530. 'priMap' => array(
  531. 'total' => $total,
  532. 'searchList' => $books,
  533. ),
  534. 'index' => $page,
  535. 'ptype' => 'searchResult',
  536. 'keyword' => $keyword,
  537. );
  538. return json($result);
  539. }
  540. /**
  541. * 查看cookie
  542. */
  543. public function dev()
  544. {
  545. echo '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,user-scalable=no">';
  546. if ($this->urlType != 2) {
  547. echo "<a href='/'>访问首页</a><br><br>";
  548. }
  549. echo "<a href='/index/index/clear'>清除cookie</a><br><br>";
  550. echo '<pre>';
  551. var_dump(Cookie::get());
  552. }
  553. /**
  554. * 清除cookie
  555. */
  556. public function clear()
  557. {
  558. echo '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,user-scalable=no">';
  559. foreach (Cookie::get() as $key => $value) {
  560. Cookie::delete($key);
  561. }
  562. if ($this->urlType != 2) {
  563. echo "<a href='/'>访问首页</a><br><br>";
  564. }
  565. echo "<a href='/index/index/dev'>访问dev</a><br><br>";
  566. echo "cookie已清除!";
  567. }
  568. /**
  569. * 推广链接
  570. * @param $id
  571. */
  572. public function referral($id)
  573. {
  574. $id = intval($id);
  575. $referralinfo = model('referral')->getone($id, false);//获取推广信息
  576. if (isset($referralinfo['source_url']) && $referralinfo['source_url']) {
  577. //确认channel_id
  578. $channel_id = $referralinfo['admin_id'];
  579. $group_id = model("AuthGroupAccess")->getGroupId($referralinfo['admin_id']);
  580. if($group_id == 4){//判断分组
  581. $extends = model("AdminExtend")->getInfo($referralinfo['admin_id']);
  582. if($extends['distribute']==0){
  583. $channel_id = $extends['create_by'];
  584. }
  585. }
  586. $shor_id = $referralinfo['short_id'] ?? null;
  587. if($shor_id && $referralinfo['type'] == 1){
  588. $url = getCurrentDomain($channel_id,$referralinfo['source_url'],['short_id'=>$shor_id]);
  589. }else{
  590. $url = getCurrentDomain($channel_id,$referralinfo['source_url']);
  591. }
  592. //打点信息
  593. $ext = $this->request->get('ext', '');
  594. if (!empty($ext)) {
  595. $url .= '&ext='.$ext;
  596. }
  597. $this->redirect($url);
  598. } else {
  599. $this->redirect($this->request->domain());
  600. }
  601. }
  602. public function activity($id,$rid = null)
  603. {
  604. $id = intval($id);
  605. $rid = intval($rid);
  606. $channel_id = UserService::instance()->getUserInfo()->channel_id;
  607. $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channel_id);
  608. if (empty($id)) {
  609. $rid = $_GET['rid']??'';
  610. $aid = intval($_GET['aid']??'');
  611. if($aid){
  612. $id = $aid;
  613. }
  614. if (empty($rid)) {
  615. $this->error('不存在此活动,正在跳转书城首页', '/index/index/index');
  616. }
  617. } else {
  618. if(!$rid){
  619. list($resource, $isRange) = ActivityService::instance()->getActivityResource($id);
  620. if (empty($resource)) {
  621. $this->error('不存在此活动,正在跳转书城首页', '/index/index/index');
  622. }
  623. $rid = $resource['id'];
  624. }
  625. }
  626. if(!empty($id)){
  627. $params['aid'] = $id;
  628. }
  629. $params['id'] = $rid;
  630. if (!empty($isRange)) {
  631. $params['isRange'] = 1;
  632. }
  633. $params['appid'] = $adminConfig['appid'];
  634. if (UserService::instance()->isLogin()) {
  635. $params['user_id'] = UserService::instance()->getUserInfo()->id;
  636. } elseif (Cookie::has('visitor')) {
  637. $params['visitor'] = Cookie::get('visitor');
  638. }
  639. //打点信息
  640. $ext = $this->request->get('ext', '');
  641. if (!empty($ext)) {
  642. $params['ext'] = $ext;
  643. }
  644. if ($this->request->get('float_id')) {
  645. $params['float_id'] = $this->request->get('float_id');
  646. }
  647. //有菜单支付域名时,跳转菜单支付域名
  648. if ($_SERVER['HTTP_HOST'] != $adminConfig['wxpay_pay_host'] || (isset($adminConfig['menuwxpay_host']) && $_SERVER['HTTP_HOST'] != $adminConfig['menuwxpay_host'])) {
  649. $user_id = UserService::instance()->getUserInfo()->id;
  650. $channel_id = UserService::instance()->getUserChannelId()->data;
  651. $payHost = FufenService::instance()->getPayUrl($user_id, $channel_id)->data;
  652. $url = $payHost . '/index/recharge/activity?' . http_build_query($params);
  653. $this->redirect($url);
  654. // $menuophost = $adminConfig['menuophost'] ?? null;
  655. // $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null;
  656. // if($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()){
  657. // $this->redirect(Config::get('site.scheme') . '://' . $adminConfig['menuwxpay_host'] . '/index/recharge/activity?' . http_build_query($params));
  658. // }else{
  659. // $this->redirect(Config::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host'] . '/index/recharge/activity?' . http_build_query($params));
  660. // }
  661. }
  662. }
  663. public function report()
  664. {
  665. return $this->view->fetch();
  666. }
  667. /**
  668. * vip分流链接入口
  669. * @param $id
  670. */
  671. public function vipreferral($id)
  672. {
  673. $id = intval($id);
  674. if (empty($id)) {
  675. $this->redirect($this->request->domain());
  676. }
  677. //是否禁用
  678. if (!model("Referral")->checkVipReferralValid($id)) {
  679. $this->redirect($this->request->domain());
  680. }
  681. $referralId = model("ReferralSlave")->getReferralId($id);
  682. if (!empty($referralId)) {
  683. $referralinfo = model('referral')->getone($referralId, false);//获取推广信息
  684. if (isset($referralinfo['source_url']) && $referralinfo['source_url']) {
  685. //确认channel_id
  686. $channel_id = $referralinfo['admin_id'];
  687. $group_id = model("AuthGroupAccess")->getGroupId($referralinfo['admin_id']);
  688. if($group_id == 4){//判断分组
  689. $extends = model("AdminExtend")->getInfo($referralinfo['admin_id']);
  690. if($extends['distribute']==0){
  691. $channel_id = $extends['create_by'];
  692. }
  693. }
  694. $shor_id = $referralinfo['short_id'] ?? null;
  695. if($shor_id && $referralinfo['type'] == 1){
  696. $url = getCurrentDomain($channel_id,$referralinfo['source_url'],['short_id'=>$shor_id]);
  697. }else{
  698. $url = getCurrentDomain($channel_id,$referralinfo['source_url']);
  699. }
  700. //打点信息
  701. $ext = $this->request->get('ext', '');
  702. if (!empty($ext)) {
  703. $url .= '&ext='.$ext;
  704. }
  705. $this->redirect($url);
  706. } else {
  707. $this->redirect($this->request->domain());
  708. }
  709. }
  710. $this->redirect($this->request->domain());
  711. }
  712. /**
  713. * 书单
  714. * @param $id
  715. */
  716. public function booklist($id)
  717. {
  718. $id = intval($id);
  719. if (empty($id)) {
  720. $this->error('书单不存在');
  721. die;
  722. }
  723. $result = model('BookList')->getInfo($id);
  724. if (empty($result)) {
  725. $this->error('书单不存在');
  726. die;
  727. }
  728. $result['content'] = json_decode($result['content'], true);
  729. $this->view->assign('result', $result);
  730. return $this->view->fetch();
  731. }
  732. /**
  733. * 渠道自定义书单
  734. * @param $id
  735. */
  736. public function booklistch($id)
  737. {
  738. $id = intval($id);
  739. if (empty($id)) {
  740. $this->error('书单不存在');
  741. die;
  742. }
  743. $adminconfig = $this->adminconfig;
  744. $result = model('BookListCh')->getInfo($id);
  745. if (empty($result)) {
  746. $this->error('书单不存在');
  747. die;
  748. }
  749. if (!in_array($adminconfig['admin_id'], json_decode($result['admin_ids']), true)) {
  750. $this->error('书单不存在');
  751. die;
  752. }
  753. $ext = [
  754. 'mark' => MarkConstants::MARK_BOOKLIST_MSG,
  755. 'push_id' => $id,
  756. 'push_idx' => 0,
  757. 'push_time' => time(),
  758. 'admin_id' => $adminconfig['admin_id'],
  759. ];
  760. $result['content'] = json_decode($result['content'], true);
  761. $this->view->assign('result', $result);
  762. $this->view->assign('ext', $ext);
  763. return $this->view->fetch();
  764. }
  765. /**
  766. * 客服消息 短链
  767. * @param $id
  768. */
  769. public function custom($id)
  770. {
  771. $id = intval($id);
  772. if (empty($id)) {
  773. $this->error('链接地址不存在');
  774. die;
  775. } else {
  776. $shortUrlService = new ShortUrlService();
  777. $url = $shortUrlService->getShortUrl($id);
  778. if (empty($url)) {
  779. $this->error('链接地址不存在');
  780. die;
  781. }
  782. if (strpos($url, '{$ophost}')) {
  783. if (preg_match("/wx\w+/i", $url, $matches)) {
  784. $appId = $matches[0];
  785. $channelData = AdminService::instance()->getAdminConfigModel()->getAdminInfoByAppId($appId); //得到此渠道的配置信息 adminInfoAll
  786. $admin_id = $channelData['admin_id'];
  787. //占位符转换
  788. $url = UrlService::instance()->replaceReferralHost($admin_id, $url, false)->data;
  789. }
  790. }
  791. $this->redirect($url);
  792. }
  793. $this->error('链接地址不存在');
  794. }
  795. public function questionnaire()
  796. {
  797. $endDate = '2020-08-15';
  798. if (time() >= strtotime("{$endDate} + 1 days")) {
  799. $this->redirect($this->request->domain());
  800. }
  801. $adminId = $this->adminconfig['admin_id'];
  802. $userid = UserService::instance()->getUserInfo()->id;
  803. $this->view->assign('admin_id', $adminId);
  804. $this->view->assign('adminconfig', $this->adminconfig);
  805. $this->view->assign('userid', $userid);
  806. $this->view->assign('endDate', $endDate);
  807. return $this->view->fetch();
  808. }
  809. /**
  810. * 专题
  811. * @param $id
  812. * @return string
  813. * @throws \think\Exception
  814. */
  815. public function specialpage($id)
  816. {
  817. $id = intval($id);
  818. if (empty($id)) {
  819. $this->error('链接地址不存在');
  820. die;
  821. }
  822. $result = model('SpecialPage')->getInfo($id);
  823. if (empty($result)) {
  824. $this->error('专题页不存在');
  825. die;
  826. }
  827. $isForbidden = false;
  828. if ($result['status'] == "hidden") {
  829. $isForbidden = true;
  830. }
  831. if (isset($_GET['view']) && $_GET['view'] == 'preview') {
  832. $isForbidden = false;
  833. }
  834. $toUrl = '/';
  835. $this->view->assign('result', $result);
  836. $this->view->assign('isForbidden', $isForbidden);
  837. $this->view->assign('toUrl', $toUrl);
  838. return $this->view->fetch();
  839. }
  840. /**
  841. * 专属链接跳转中转
  842. * @param $id
  843. */
  844. public function rechargeurl($id)
  845. {
  846. $id = intval($id);
  847. if (empty($id)) {
  848. $this->error('链接不存在');
  849. die;
  850. }
  851. $res = model("SpecialRechargeUrl")->checkUrl($id);
  852. if ($res['code'] == 201 || $res['code'] == 202) {
  853. $this->error('链接不存在');
  854. die;
  855. }
  856. $params['id'] = $id;
  857. $params['isRange'] = $res['code'] == 203 ? 1 : 0;
  858. $channel_id = UserService::instance()->getUserInfo()->channel_id;
  859. $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($channel_id);
  860. $params['appid'] = $adminConfig['appid'];
  861. if (UserService::instance()->isLogin()) {
  862. $params['user_id'] = UserService::instance()->getUserInfo()->id;
  863. } elseif (Cookie::has('visitor')) {
  864. $params['visitor'] = Cookie::get('visitor');
  865. }
  866. //打点信息
  867. $ext = $this->request->get('ext', '');
  868. if (!empty($ext)) {
  869. $params['ext'] = $ext;
  870. }
  871. //有菜单支付域名时,跳转菜单支付域名
  872. if ($_SERVER['HTTP_HOST'] != $adminConfig['wxpay_pay_host'] || (isset($adminConfig['menuwxpay_host']) && $_SERVER['HTTP_HOST'] != $adminConfig['menuwxpay_host'])) {
  873. $menuophost = $adminConfig['menuophost'] ?? null;
  874. $menuwxpay_host = $adminConfig['menuwxpay_host'] ?? null;
  875. if($menuophost && $menuwxpay_host && $menuophost == getCurrentOphost()){
  876. $this->redirect(Config::get('site.scheme') . '://' . $adminConfig['menuwxpay_host'] . '/index/recharge/special?' . http_build_query($params));
  877. }else{
  878. $this->redirect(Config::get('site.scheme') . '://' . $adminConfig['wxpay_pay_host'] . '/index/recharge/special?' . http_build_query($params));
  879. }
  880. }
  881. }
  882. }