123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wanggb
- * Date: 2018/12/21
- * Time: 16:04
- */
- namespace app\admin\controller\auth;
- use app\common\controller\Backend;
- class Linkmange extends Backend
- {
- const GROUP_QDS = 3; #渠道商
- const GROUP_DLS = 4; #配号代理商
- protected $authgroupaccess_model = null;
- protected $adminextend_model = null;
- protected $book_model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->authgroupaccess_model = model('AuthGroupAccess');
- $this->adminextend_model = model('AdminExtend');
- $this->book_model = model('Book');
- }
- public function index()
- {
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- $params = $this->request->post("row/a");
- $type = $params['type'];
- if ($type) {
- if(!$this->isQdsOrPhdls($params['qdsid'])){
- return $this->error('渠道商或配号代理商ID错误!');
- }
- // 生成最近阅读
- $url = $this->generateRecentReadLink($params['qdsid']);
- } else {
- if(!$this->isQdsOrPhdls($params['qdsid'])){
- return $this->error('渠道商或配号代理商ID错误!');
- //return json(['code' => 0, 'data' => '渠道商或配号代理商ID错误!']);
- }
- if(!$this->isValidBook($params['bookid'])){
- return $this->error('书籍ID错误!');
- //return json(['code' => 0, 'data' => '书籍ID错误!']);
- }
- if(!$this->isValidChapter($params['bookid'], $params['chapterid'])){
- return $this->error('书籍ID与章节ID不匹配!');
- //return json(['code' => 0, 'data' => '书籍与章节不匹配!']);
- }
- //生成阅读页
- $url = $this->generateReadLink($params['qdsid'], $params['bookid'], $params['chapterid']);
- }
- return json(['code' => 1, 'data' => $url]);
- }
- return $this->fetch();
- }
- /**
- * 判断是否是渠道商或者是配号代理商
- * @param $userid
- */
- public function isQdsOrPhdls($userid)
- {
- $user_groupid = $this->authgroupaccess_model->getGroupId($userid);
- if ($user_groupid == self::GROUP_QDS) {
- return true;
- } elseif ($user_groupid == self::GROUP_DLS) {
- $data = $this->adminextend_model->getInfo($userid);
- return $data['distribute'] ?? 0;
- } else {
- return false;
- }
- }
- /**
- * 判断是否有效的书籍ID
- * @param $bookid
- * @return bool
- */
- public function isValidBook($bookid)
- {
- $bookinfo = $this->book_model->BookInfo($bookid);
- if (empty($bookinfo)) {
- return false;
- } else {
- return true;
- }
- }
- /**
- * 判断章节是否有效
- * @param $bookid
- * @param $chapterid
- * @return bool
- */
- public function isValidChapter($bookid, $chapterid)
- {
- if (!empty($bookid) && !empty($chapterid)) {
- if ($this->isValidBook($bookid)) {
- $chapterList = $this->book_model->getChapterList($bookid, 0, -1);
- $chapterArr = array_column($chapterList['data']['data'], 'id');
- if (in_array($chapterid, $chapterArr)) {
- return true;
- }
- }
- }
- return false;
- }
- /**
- * 按渠道商|配号代理商、 书籍ID、 章节ID 生成链接
- * @param $qdsid
- * @param $bookid
- * @param $chapterid
- */
- public function generateReadLink($qdsid, $bookid, $chapterid)
- {
- $url = getCurrentDomain($qdsid);
- $url .="index/book/chapter?";
- $url .="book_id=$bookid&chapter_id=$chapterid";
- return $url;
- }
- /**
- * 按渠道商|配号代理商 生成最近阅读链接
- * @param $qdsid
- * @return string
- */
- public function generateRecentReadLink($qdsid)
- {
- $url = getCurrentDomain($qdsid);
- $url .="index/user/recent";
- return $url;
- }
- }
|