123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- <?php
- namespace Collection\Src;
- use Dever;
- use Collection\Lib\Core;
- class Api extends Core
- {
- public function __construct()
- {
- parent::__construct();
- if (!$this->id) {
- Dever::alert('错误的参数');
- }
- }
- public function data()
- {
- return Dever::db('collection/info')->state();
- }
- # 获取用户信息
- public function getUser()
- {
- $data['user'] = $this->user;
- $data['num'] = array
- (
- array('¥199', '', '钱包'),
- array('200', '', '金币'),
- array('10', '', '好友'),
- array('30', '', '动态'),
- );
- return $data;
- }
- public function qrcode($url, $content_id)
- {
- $file = 'shareDv_' . $this->uid . '_' . $this->id . '_' . $content_id;
- $file = Dever::load('qrcode/api')->qrcode($url, $file, $this->user['avatar']);
- return $file['url'];
- }
- # 获取分享的内容
- public function getShare()
- {
- $url = Dever::input('url');
- $type = Dever::input('type');
- $index = Dever::input('index');
- $content_id = Dever::input('content_id');
- $data = array();
- $info = Dever::db('collection/info')->one($this->id);
- $data['info'] = $data['pic'] = $data['text'] = $data['share'] = array();
- $data['info']['id'] = $content_id;
- $data['info']['platform_name'] = $info['name'];
- $data['info']['qrcode'] = $data['info']['name'] = $data['info']['price'] = $data['info']['s_price'] = '';
- $code = $this->getCode($this->id, $this->parent_page_id, $this->page_id, $index, $this->times, $this->uid);
- $url .= '?code=' . $code;
- $data['info']['qrcode'] = $this->qrcode($url, $content_id);
- $background = array
- (
- '#ffaa00',
- '#bababa'
- );
- if ($type == -1) {
- $page = Dever::db('collection/page')->one($content_id);
- $data['info']['name'] = $page['name'];
- $data['pic'] = explode(',', $page['pic']);
- $data['text'] = array(
- array
- (
- 'background' => $background[0],
- 'content' => $page['desc'],
- )
- );
- $data['share'] = array
- (
- 'title' => $page['name'],
- 'content' => $page['desc'],
- 'pic' => $page['pic'],
- );
- } else {
- $content = Dever::db('collection/content')->one($content_id);
- $data['info']['name'] = $content['share_title'] ? $content['share_title'] : $content['name'];
- if ($content['share_pic']) {
- $data['pic'] = explode(',', $content['share_pic']);
- } else {
- $data['pic'] = explode(',', $content['pic']);
- }
- $content['share_content'] = $content['share_content'] ? $content['share_content'] : $content['name'];
- if ($content['type'] == 70) {
- $content['data'] = Dever::db('content/product')->one(array('content_id' => $content['id'], 'info_id' => $content['info_id']));
- if (isset($content['data']['goods_id']) && $content['data']['goods_id'] > 0) {
- $goods = Dever::load('goods/lib/info')->getInfo($content['data']['goods_id']);
- if ($goods && isset($goods['price']['min']['price'])) {
- $data['info']['price'] = '¥' . $goods['price']['min']['price'];
- $data['info']['s_price'] = '¥' . $goods['price']['min']['s_price'];
- }
- }
- }
-
- if ($content['copy_text']) {
- $text = Dever::array_decode($content['copy_text']);
- $i = 0;
- foreach ($text as $k => $v) {
- if ($v['name']) {
- $back = $background[1];
- if ($i == 0) {
- $back = $background[0];
- }
- $data['text'][$i] = array
- (
- 'background' => $back,
- 'content' => $v['name'],
- );
- $i++;
- }
- }
- }
- if (!$data['text']) {
- $data['text'] = array(
- array
- (
- 'background' => $background[0],
- 'content' => $content['share_content'],
- )
- );
- }
- $data['share'] = array
- (
- 'title' => $data['info']['name'],
- 'content' => $content['share_content'],
- 'pic' => $data['pic'][0],
- );
- }
- return $data;
- }
- # 获取合集内容
- public function getInfo()
- {
- # 是否已经购买
- $data['is_buy'] = false;
- $data['button'] = array(
- 'bgcolor' => 'background: linear-gradient(to right, #000000,#000000) !important;color:#fff;',
- 'color' => 'color:#fff',
- 'name' => array('入口', '排行榜')
- );
- $data['info'] = Dever::db('collection/info')->one($this->id);
- if ($data['info']) {
- $data['info']['user'] = array();
- if ($data['info']['uid'] > 0) {
- $data['info']['user'] = Dever::load('passport/api')->info($data['info']['uid']);
- }
- $data['info']['pic_bg'] = explode(',', $data['info']['pic_bg']);
- if ($data['info']['buy'] == 1) {
- # 收费 从订单中读取是否已经购买
- $data['is_buy'] = false;
- } else {
- # 免费
- $data['is_buy'] = true;
- }
- $data['button']['name'] = explode(',', $data['info']['button']);
- if ($data['info']['button_bgcolor'] && $data['info']['button_bgjcolor']) {
- $data['button']['bgcolor'] = 'background: linear-gradient(to right, '.$data['info']['button_bgcolor'].','.$data['info']['button_bgjcolor'].') !important;';
- }
- if ($data['info']['button_ftcolor']) {
- $data['button']['color'] = 'color:' . $data['info']['button_ftcolor'];
- $data['button']['bgcolor'] .= $data['button']['color'];
- }
- # 获取最新的用户记录
- $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'];
- } else {
- # 获取最新的章节页id
- $page_where['info_id'] = $data['info']['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::alret('内容还没有准备好');
- }
- $times = 0;
- if ($this->times) {
- $times = $this->times;
- }
- $index = 0;
- }
- # 获取code
- $data['code'] = $this->getCode($data['info']['id'], $parent_page_id, $page_id, $index, $times);
- }
- return $data;
- }
- # 获取合集下的内容
- public function getContent()
- {
- $data['info_id'] = $this->id;
- $data['page_id'] = $this->page_id;
- $data['parent_page_id'] = $this->parent_page_id;
- $data['index'] = $this->index;
- $data['times_id'] = $this->times;
- # 获取用户信息
- $data['user'] = $this->user;
- # 获取每个模块
- $data['items'] = Dever::load('collection/lib/content')->getList($this->id, $this->page_id);
- # 滑动到多少时,加载下一页
- $data['total'] = count($data['items']) - 2;
-
- $data['func'] = $this->getFunc();
-
- return $data;
- }
- # 获取合集下的购买内容
- public function getBuy()
- {
- $data['info'] = Dever::db('collection/info')->one($this->id);
- $where['info_id'] = $this->id;
- $data['buy'] = Dever::db('collection/buy')->getAll($where);
- return $data;
- }
- # 获取合集下的榜单列表
- public function getRanking()
- {
- $where['info_id'] = $this->id;
- $data['ranking'] = Dever::db('collection/ranking')->getAll($where);
- return $data;
- }
- # 获取合集下的商品
- public function getProduct()
- {
- $where['info_id'] = $this->id;
- $data['product'] = Dever::db('collection/product')->getAll($where);
- return $data;
- }
- # 获取某一个商品详情
- public function getProductOne()
- {
- $where['id'] = Dever::input('product_id');
- $table = Dever::input('table');
- $data['product'] = Dever::db($table)->one($where);
- if ($data['product'] && isset($data['product']['goods_id']) && $data['product']['goods_id'] > 0) {
- $data['product']['goods'] = Dever::load('goods/lib/info')->getInfo($data['product']['goods_id']);
- $data['product']['goods'] = Dever::load('collection/lib/content')->getContent($data['product']['goods']);
- }
- return $data;
- }
- # 获取榜单数据
- public function getRankingData()
- {
- $where['info_id'] = $this->id;
- $where['ranking_id'] = Dever::input('ranking_id');
- # 获取所有期数
- $data['ranking_periods'] = Dever::db('collection/ranking_periods')->getAll($where);
- if ($data['ranking_periods']) {
- $where['periods_id'] = Dever::input('ranking_periods', $data['ranking_periods'][0]['id']);
- $data['ranking_data'] = Dever::db('collection/ranking_data')->getAll($where);
- if ($data['ranking_data']) {
- foreach ($data['ranking_data'] as $k => $v) {
- $data['ranking_data'][$k]['user'] = Dever::load('passport/api')->info($v['uid']);
- }
- }
- }
- return $data;
- }
- # 获取合集下的分类
- public function getCategory()
- {
- $parent_page_id = $this->parent_page_id;
- $page_id = $this->page_id;
- $where['info_id'] = $this->id;
- $data['cate'] = Dever::db('collection/page')->main($where);
- if ($data['cate']) {
- $content = Dever::db('collection/content')->child($where);
- $page = Dever::db('collection/page')->one($page_id);
- # 步长
- $data['num'] = 0;
- if ($page && $page['desc']) {
- $data['num'] = 1;
- }
- $where = $this->getTimesId($where);
- $data['child'] = Dever::db('collection/page')->child($where);
-
- $data['show'] = array();
- foreach ($data['cate'] as $k => $v) {
- if ($v['id'] == $parent_page_id) {
- $data['show'][$v['id']] = 1;
- } else {
- $data['show'][$v['id']] = 2;
- }
- }
- foreach ($data['child'] as $k => $v) {
-
- if (isset($content[$v['id']])) {
- $data['child'][$k]['content'] = $content[$v['id']];
- }
- }
- }
- return $data;
- }
- # 获取合集下的时光
- public function getTimes()
- {
- $where['info_id'] = $this->id;
- $data['cur'] = $this->times;
- $data['times'] = Dever::db('collection/times')->main($where);
- if ($data['times']) {
- foreach ($data['times'] as $k => $v) {
- $where['times_id'] = $v['id'];
- $data['times'][$k]['child'] = Dever::db('collection/times')->child($where);
- }
- }
- return $data;
- }
- # 根据时光id获取pageid
- public function getPageId()
- {
- $where['info_id'] = $this->id;
- $where['times_id'] = Dever::input('times_id');
- $page = Dever::db('collection/page')->getOne($where);
- if ($page) {
- # 获取code
- $data['code'] = $this->getCode($this->id, $page['page_id'], $page['id'], 0, $page['times_id']);
- return $data;
- }
- Dever::alert('error');
- }
- # 记录用户操作
- public function record()
- {
- $where['info_id'] = $this->id;
- $where['uid'] = $this->uid;
- $record = Dever::db('collection/user_record')->one($where);
- $where['parent_page_id'] = $this->parent_page_id;
- $where['page_id'] = $this->page_id;
- $where['times_id'] = $this->times;
- $where['content_id'] = Dever::input('content_id');
- $where['index'] = Dever::input('index', 0);
- if ($record) {
- $where['where_id'] = $record['id'];
- Dever::db('collection/user_record')->update($where);
- } else {
- Dever::db('collection/user_record')->insert($where);
- }
- return 'yes';
- }
- public function ding($data)
- {
- if (isset($data['num_add_buy']) && isset($data['num_ratio_buy'])) {
- if ($data['buy'] == 1) {
- /*
- if (!$data['num_buy']) {
- $stat = Dever::db('stat/collection')->getNumBycollection(array('collection_id' => $data['id']));
- if (!$stat) {
- $stat['buy_num'] = 0;
- }
- if (!$stat['buy_num']) {
- $stat['buy_num'] = 0;
- }
- $data['num_buy'] = $stat['buy_num'];
- }
- */
- $data['num_up'] = 0;
- } else {
- $data['num_up'] = 0;
- }
- $data['num_buy'] = $data['num_buy'] + $data['num_up'];
- $data['buy_num'] = $data['num_buy'];
- $data['num_buy'] = round(($data['num_buy']+$data['num_add_buy'])*$data['num_ratio_buy']);
- }
- return $data;
- }
- # 获取功能
- private function getFunc()
- {
- $where['info_id'] = $this->id;
- $func = Dever::db('collection/function')->getAll($where);
- $result = array();
- if ($func) {
- foreach ($func as $k => $v) {
- $v['direction'] = strtolower($v['direction']);
- if ($v['direction'] == 'left') {
- $v['width'] = '86';
- } else {
- $v['width'] = '100';
- }
- $result[$v['type']] = array
- (
- 'show' => false,
- 'index' => 5,
- 'top' => 0,
- 'padding' => '0rpx',
- 'width' => $v['width'] . '%',
- 'direction' => strtolower($v['direction']),
- 'param' => array(),
- 'button' => array
- (
- 'bgColor' => $v['bgcolor'],
- 'text' => $v['name'],
- 'fontSize' => 28,
- 'color' => $v['color'],
- ),
- );
- }
- }
- return $result;
- }
- # 获取时光id
- private 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;
- }
- }
|