Linkmange.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wanggb
  5. * Date: 2018/12/21
  6. * Time: 16:04
  7. */
  8. namespace app\admin\controller\auth;
  9. use app\common\controller\Backend;
  10. class Linkmange extends Backend
  11. {
  12. const GROUP_QDS = 3; #渠道商
  13. const GROUP_DLS = 4; #配号代理商
  14. protected $authgroupaccess_model = null;
  15. protected $adminextend_model = null;
  16. protected $book_model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->authgroupaccess_model = model('AuthGroupAccess');
  21. $this->adminextend_model = model('AdminExtend');
  22. $this->book_model = model('Book');
  23. }
  24. public function index()
  25. {
  26. $this->request->filter(['strip_tags']);
  27. if ($this->request->isAjax()) {
  28. $params = $this->request->post("row/a");
  29. $type = $params['type'];
  30. if ($type) {
  31. if(!$this->isQdsOrPhdls($params['qdsid'])){
  32. return $this->error('渠道商或配号代理商ID错误!');
  33. }
  34. // 生成最近阅读
  35. $url = $this->generateRecentReadLink($params['qdsid']);
  36. } else {
  37. if(!$this->isQdsOrPhdls($params['qdsid'])){
  38. return $this->error('渠道商或配号代理商ID错误!');
  39. //return json(['code' => 0, 'data' => '渠道商或配号代理商ID错误!']);
  40. }
  41. if(!$this->isValidBook($params['bookid'])){
  42. return $this->error('书籍ID错误!');
  43. //return json(['code' => 0, 'data' => '书籍ID错误!']);
  44. }
  45. if(!$this->isValidChapter($params['bookid'], $params['chapterid'])){
  46. return $this->error('书籍ID与章节ID不匹配!');
  47. //return json(['code' => 0, 'data' => '书籍与章节不匹配!']);
  48. }
  49. //生成阅读页
  50. $url = $this->generateReadLink($params['qdsid'], $params['bookid'], $params['chapterid']);
  51. }
  52. return json(['code' => 1, 'data' => $url]);
  53. }
  54. return $this->fetch();
  55. }
  56. /**
  57. * 判断是否是渠道商或者是配号代理商
  58. * @param $userid
  59. */
  60. public function isQdsOrPhdls($userid)
  61. {
  62. $user_groupid = $this->authgroupaccess_model->getGroupId($userid);
  63. if ($user_groupid == self::GROUP_QDS) {
  64. return true;
  65. } elseif ($user_groupid == self::GROUP_DLS) {
  66. $data = $this->adminextend_model->getInfo($userid);
  67. return $data['distribute'] ?? 0;
  68. } else {
  69. return false;
  70. }
  71. }
  72. /**
  73. * 判断是否有效的书籍ID
  74. * @param $bookid
  75. * @return bool
  76. */
  77. public function isValidBook($bookid)
  78. {
  79. $bookinfo = $this->book_model->BookInfo($bookid);
  80. if (empty($bookinfo)) {
  81. return false;
  82. } else {
  83. return true;
  84. }
  85. }
  86. /**
  87. * 判断章节是否有效
  88. * @param $bookid
  89. * @param $chapterid
  90. * @return bool
  91. */
  92. public function isValidChapter($bookid, $chapterid)
  93. {
  94. if (!empty($bookid) && !empty($chapterid)) {
  95. if ($this->isValidBook($bookid)) {
  96. $chapterList = $this->book_model->getChapterList($bookid, 0, -1);
  97. $chapterArr = array_column($chapterList['data']['data'], 'id');
  98. if (in_array($chapterid, $chapterArr)) {
  99. return true;
  100. }
  101. }
  102. }
  103. return false;
  104. }
  105. /**
  106. * 按渠道商|配号代理商、 书籍ID、 章节ID 生成链接
  107. * @param $qdsid
  108. * @param $bookid
  109. * @param $chapterid
  110. */
  111. public function generateReadLink($qdsid, $bookid, $chapterid)
  112. {
  113. $url = getCurrentDomain($qdsid);
  114. $url .="index/book/chapter?";
  115. $url .="book_id=$bookid&chapter_id=$chapterid";
  116. return $url;
  117. }
  118. /**
  119. * 按渠道商|配号代理商 生成最近阅读链接
  120. * @param $qdsid
  121. * @return string
  122. */
  123. public function generateRecentReadLink($qdsid)
  124. {
  125. $url = getCurrentDomain($qdsid);
  126. $url .="index/user/recent";
  127. return $url;
  128. }
  129. }