| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 | <?phpnamespace Collection\Lib;use Dever;class Core{	protected $token;	protected $uid;    protected $id;    protected $id_code;    protected $share_uid = 0;    protected $user;	protected $year;    protected $times;    protected $day = 0;    protected $parent_page_id;    protected $page_id;    protected $info;    protected $key = 'dreamland1985';    /*    # 定义全局的系统类型    'system_source' => array    (        1 => 'H5',        2 => '安卓',        3 => 'ios',        4 => 'pc',        5 => '微信小程序',        6 => '微信公众号',    ),    */    protected $system_source = 1;    public function __construct()    {        $this->checkCode();    	# 获取当前的用户信息        $this->token = Dever::input('token');        $this->uid = 1;        $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);    }    # 检查内容    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')->num($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_id']);        unset($info['score_type']);        unset($info['score_name']);        $info['id_code'] = Dever::encode($info['id'], $this->key);    }    # 检查是否可以查看    protected function checkView()    {        if (!$this->info) {            $this->checkInfo();        }        if ($this->info['buy'] == 1) {            # 收费 从订单中读取是否已经购买            $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::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_code = Dever::input('id');            if ($this->id_code == -1) {                $this->id = $this->id_code;            } else {                $this->id = Dever::decode($this->id_code, $this->key);            }        }    }    # 获取邀请码    protected function getCode($id, $parent_page_id, $page_id, $index, $times_id, $day = 0, $uid = 0)    {        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;        }        $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('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, $this->uid);        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;    }}
 |