123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- namespace Collection\Lib;
- use Dever;
- class Core
- {
- protected $token;
- protected $uid;
- protected $share_uid = 0;
- protected $user;
- protected $year;
- protected $times;
- protected $day = 0;
- protected $parent_page_id;
- protected $page_id;
- protected $key = 'dreamland1985';
- public function __construct()
- {
- $this->checkCode();
- # 获取当前的用户信息
- $this->token = Dever::input('token');
- $this->uid = 1;
- $this->user = Dever::load('passport/api')->info($this->uid);
- }
- protected function checkInfo()
- {
- return Dever::db('collection/info')->one($this->id);
- }
- protected function checkCode()
- {
- $this->code = Dever::input('code');
- if ($this->code) {
- $code = Dever::decode($this->code, $this->key);
- $code = explode('_', $code);
- $this->id = $code[1];
- $this->parent_page_id = $code[2];
- $this->page_id = $code[3];
- $this->index = $code[4];
- $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];
- }
-
- } else {
- $this->id = Dever::input('id');
- }
- }
- protected function getCode($id, $parent_page_id, $page_id, $index, $times_id, $day = 0, $uid = 0)
- {
- if (Dever::project('invite')) {
- $invite = Dever::input('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;
- }
- $key = 'dlv1_' . $id. '_' . $parent_page_id . '_' . $page_id . '_' . $index . '_' . $times_id . '_' . $day . '_' . $uid;
- $code = Dever::encode($key, $this->key);
- return $code;
- }
- protected function getInfoCode()
- {
- # 获取最新的用户记录
- $where['info_id'] = $this->id;
- $where['uid'] = $this->uid;
- $record = Dever::db('collection/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;
- }
- # 获取code
- $code = $this->getCode($this->id, $parent_page_id, $page_id, $index, $times, $day);
- 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)
- {
- $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;
- }
- }
|