array ( 1 => 'H5', 2 => '安卓', 3 => 'ios', 4 => 'pc', 5 => '微信小程序', 6 => '微信公众号', ), */ protected $system_source = 1; public function __construct() { # 获取当前的用户信息 $this->token = Dever::input('token'); $this->uid = Dever::load('passport/user')->check(false); $this->checkCode(); $this->user = $this->getUser($this->uid, $this->id); $this->user['id'] = $this->uid; $this->system_source = Dever::input('system_source', 1); } # 获取用户信息 protected function getUser($uid, $collection_id) { return Dever::load('user/lib/info')->get($uid, $collection_id, true); } # 获取上级信息 protected function getParent() { if (!$this->share_uid) { $info = Dever::load('user/lib/collection')->check($this->uid, $this->id); if ($info && $info['source_uid']) { $this->share_uid = $info['source_uid']; } } } # 检查内容 protected function checkInfo() { $this->info = $this->getOne($this->id); if (!$this->info) { Dever::alert('内容还没有准备好'); } return $this->info; } # 获取内容 protected function getOne($id) { $info = Dever::load('collection/lib/info')->one($id); if ($info) { $this->handle($info); } return $info; } protected function handle(&$info) { # 过滤一些不用的信息 unset($info['num_buy']); unset($info['num_ratio_buy']); unset($info['num_add_buy']); unset($info['num_add_view']); unset($info['num_view']); unset($info['buy_price']); unset($info['audit']); unset($info['status']); unset($info['reorder']); unset($info['admin_founder']); unset($info['admin_editor']); unset($info['udate']); unset($info['state']); unset($info['cdate']); unset($info['score_type']); unset($info['score_name']); $this->id_code = $info['id_code'] = Dever::load('collection/lib/common')->encode($info['id']); } # 检查是否可以查看 protected function checkView() { if ($this->uid < 1) { return false; } if (!$this->info) { $this->checkInfo(); } if ($this->info['buy'] == 1 || $this->info['password']) { # 是否已经拥有 $this->info['buy_data'] = Dever::load('user/lib/collection')->check($this->uid, $this->info['id']); return $this->info['buy_data'] ? true : false; } else { # 免费 return true; } } # 检测邀请码 protected function checkCode() { $this->code = Dever::input('code'); if ($this->code) { $code = Dever::load('collection/lib/common')->decode($this->code); $code = explode('_', $code); $this->id = $code[1]; $this->parent_page_id = $code[2]; $this->page_id = $code[3]; $this->index = $code[4] ? $code[4] : 0; $this->times = $code[5]; if (isset($code[6]) && $code[6]) { # 用户设置时间 $this->day = $code[6]; } else { $this->day = 0; } if (isset($code[7]) && $code[7] && $code[7] != $this->uid) { $this->share_uid = $code[7]; if (isset($code[8]) && $code[8]) { $this->ticket_id = $code[8]; } } } else { $this->id_code = Dever::input('id'); if ($this->id_code == -1) { $this->id = $this->id_code; } else { $this->id = Dever::load('collection/lib/common')->decode($this->id_code); } } if ($this->share_uid == $this->uid) { $this->share_uid = 0; } } # 获取邀请码 protected function getCode($id, $parent_page_id, $page_id, $index, $times_id, $day = 0, $uid = 0, $ticket_id = 0, $encode = true) { if (Dever::project('invite')) { $invite = Dever::input('invite'); if ($invite) { $uid = Dever::load('invite/api')->getUid($invite); } } if (!$day) { $day = $this->day; } if ($day) { if (strstr($day, '-')) { $day = str_replace('-', '', $day); } } else { $day = 0; } $code = 'dlv1_' . $id. '_' . $parent_page_id . '_' . $page_id . '_' . $index . '_' . $times_id . '_' . $day . '_' . $uid . '_' . $ticket_id; if ($encode) { $code = Dever::load('collection/lib/common')->encode($code); } return $code; } #获取短域名 public function getUrl($url, $param = array()) { if (Dever::project('short')) { # 转成短域名 if (isset($param['code']) && $param['code']) { $param['code'] .= '|collection/lib/common.encode'; } $url = Dever::load('short/lib/handle')->get(1, $url, $param); } elseif ($param) { if (isset($param['code']) && $param['code']) { $param['code'] = Dever::load('collection/lib/common')->encode($param['code']); } $url .= '?' . http_build_query($param); } return $url; } protected function getInfoCode() { # 获取最新的用户记录 $where['info_id'] = $this->id; $where['uid'] = $this->uid; $record = Dever::db('user/record')->one($where); if ($record) { $parent_page_id = $record['parent_page_id']; $page_id = $record['page_id']; $times = $record['times_id']; $index = $record['index']; $day = $record['day']; } else { # 获取最新的章节页id $page_where['info_id'] = $this->id; $page_where = $this->getTimesId($page_where); $page = Dever::db('collection/page')->child($page_where); $parent_page_id = $page_id = 0; if ($page) { $parent_page_id = $page[0]['page_id']; $page_id = $page[0]['id']; } else { Dever::alert('内容还没有准备好'); } $times = 0; if ($this->times) { $times = $this->times; } $index = 0; $day = 0; } if (!$day) { # 从用户的时光获取 $my_times = Dever::load('user/lib/times')->getData($this->uid, $this->id); if ($my_times && $my_times['day']) { $day = str_replace('-', '', $my_times['day']); } } # 获取门票 $ticket = Dever::load('user/lib/ticket')->check($this->uid, $this->id); if ($ticket) { $this->ticket_id = $ticket['id']; } # 获取code $code = $this->getCode($this->id, $parent_page_id, $page_id, $index, $times, $day, $this->uid, $this->ticket_id); return $code; } # 获取时光id protected function getTimesId($where) { # 获取当前年份的最新的时光 if (!$this->times) { $where['year'] = date('Y'); $times = Dever::db('collection/times')->getNew($where); if ($times) { $this->times = $times['id']; } } if ($this->times) { $where['times_id'] = $this->times; } return $where; } # 获取按钮的样式 protected function button($info) { if (isset($info['button'])) { $button = array( 'bgcolor' => 'background: linear-gradient(to right, #000000,#000000) !important;color:#fff;', 'color' => 'color:#fff', 'name' => array('入口', '排行榜') ); $button['name'] = explode(',', $info['button']); if ($info['button_bgcolor'] && $info['button_bgjcolor']) { $button['bgcolor'] = 'background: linear-gradient(to right, '.$info['button_bgcolor'].','.$info['button_bgjcolor'].') !important;'; } if ($info['button_ftcolor']) { $button['color'] = 'color:' . $info['button_ftcolor']; $button['bgcolor'] .= $button['color']; } return $button; } else { return array(); } } # 获取其他页面的分享 protected function getConfigShare($config = array()) { $config = $config ? $config : Dever::db('main/config')->one(); $config['desc'] = $config['info']; $config['pic_cover'] = $config['logo']; return $this->getInfoShare($config); } # 获取合集的分享 protected function getInfoShare($info, $code = false) { if ($this->uid && $this->uid > 0) { $data['title'] = $info['share_title'] ? $info['share_title'] : '{username}邀请你看{name}'; $data['title'] = str_replace('{username}', $this->user['username'], $data['title']); $data['title'] = str_replace('{name}', $info['name'], $data['title']); } else { $data['title'] = $info['name']; } $data['content'] = $info['share_content'] ? $info['share_content'] : $info['desc']; $data['pic'] = $info['share_pic'] ? $info['share_pic'] : $info['pic_cover']; $url = Dever::input('url'); $data['source_link'] = ''; $url = $this->getUrl($url); $data['link'] = $url; return $data; } }