|  | @@ -0,0 +1,241 @@
 | 
	
		
			
				|  |  | +<?php
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +namespace Collection\Src;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +use Dever;
 | 
	
		
			
				|  |  | +use Collection\Lib\Core;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +class Api extends Core
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    public function __construct()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $this->id = Dever::input('id');
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public function data()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        return Dever::db('collection/info')->state();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    # 获取合集内容
 | 
	
		
			
				|  |  | +    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']['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'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            # 获取最新的章节页id
 | 
	
		
			
				|  |  | +            $page_where['info_id'] = $data['info']['id'];
 | 
	
		
			
				|  |  | +            $page_where['year'] = $this->year;
 | 
	
		
			
				|  |  | +            $data['page'] = Dever::db('collection/page')->child($page_where);
 | 
	
		
			
				|  |  | +            $data['page_id'] = 0;
 | 
	
		
			
				|  |  | +            if ($data['page']) {
 | 
	
		
			
				|  |  | +                $data['page_id'] = $data['page'][0]['id'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        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 getContent()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $page_id = Dever::input('page_id');
 | 
	
		
			
				|  |  | +        $data['items'] = Dever::load('collection/lib/content')->getList($this->id, $page_id);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $page = Dever::db('collection/page')->one($page_id);
 | 
	
		
			
				|  |  | +        $data['info_id'] = $this->id;
 | 
	
		
			
				|  |  | +        $data['page_id'] = $page_id;
 | 
	
		
			
				|  |  | +        $data['parent_page_id'] = $page['page_id'];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        # 获取用户信息
 | 
	
		
			
				|  |  | +        $data['user'] = Dever::load('passport/api')->info($this->uid);
 | 
	
		
			
				|  |  | +        return $data;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    # 获取合集下的分类
 | 
	
		
			
				|  |  | +    public function category()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $parent_page_id = Dever::input('parent_page_id');
 | 
	
		
			
				|  |  | +        $page_id = Dever::input('page_id');
 | 
	
		
			
				|  |  | +        $where['info_id'] = $this->id;
 | 
	
		
			
				|  |  | +        $data['cate'] = Dever::db('collection/page')->main($where);
 | 
	
		
			
				|  |  | +        if ($data['cate']) {
 | 
	
		
			
				|  |  | +            $data['child'] = Dever::db('collection/page')->child($where);
 | 
	
		
			
				|  |  | +            $content = Dever::db('collection/content')->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 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;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $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;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    # 解析元信息
 | 
	
		
			
				|  |  | +    public function avinfo($data, $url = 'video', $table = 'video/vod')
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        # 解析视频元信息
 | 
	
		
			
				|  |  | +        if (!$data['video_info']) {
 | 
	
		
			
				|  |  | +            $video_info = Dever::curl($data[$url] . '?avinfo');
 | 
	
		
			
				|  |  | +            if ($video_info) {
 | 
	
		
			
				|  |  | +                Dever::db($table)->update(array('where_id' => $data['id'], 'video_info' => $video_info));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            $video_info = Dever::json_decode($video_info);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            $video_info = Dever::json_decode($data['video_info']);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        unset($data['video_info']);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $data['video_width'] = 0;
 | 
	
		
			
				|  |  | +        $data['video_height'] = 0;
 | 
	
		
			
				|  |  | +        # 默认横屏
 | 
	
		
			
				|  |  | +        $data['video_type'] = 1;
 | 
	
		
			
				|  |  | +        if (isset($video_info['streams']) && $video_info['streams']) {
 | 
	
		
			
				|  |  | +            foreach ($video_info['streams'] as $k => $v) {
 | 
	
		
			
				|  |  | +                if (isset($v['width']) && isset($v['height'])) {
 | 
	
		
			
				|  |  | +                    $data['video_width'] = $v['width'];
 | 
	
		
			
				|  |  | +                    $data['video_height'] = $v['height'];
 | 
	
		
			
				|  |  | +                    if ($data['video_width'] >= $data['video_height']) {
 | 
	
		
			
				|  |  | +                        $data['video_type'] = 1;
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        $data['video_type'] = 2;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return $data;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public function test()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $limit = Dever::input('start', 0);
 | 
	
		
			
				|  |  | +        $num = 10000;
 | 
	
		
			
				|  |  | +        $state = true;
 | 
	
		
			
				|  |  | +        while($state) {
 | 
	
		
			
				|  |  | +            $data = $this->tdata($limit, $num);
 | 
	
		
			
				|  |  | +            if ($data) {
 | 
	
		
			
				|  |  | +                $state = true;
 | 
	
		
			
				|  |  | +                foreach ($data as $k => $v) {
 | 
	
		
			
				|  |  | +                    if ($v['mobile'] && strstr($v['mobile'], '1')) {
 | 
	
		
			
				|  |  | +                        $this->tupdate($v['id'], $v['mobile']);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                $state = false;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return 'ok';
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public function tupdate($id, $mobile)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $url = 'https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={mobile}&resource_id=6004&ie=utf8&oe=utf8&format=json';
 | 
	
		
			
				|  |  | +        $url = str_replace('{mobile}', $mobile, $url);
 | 
	
		
			
				|  |  | +        $result = Dever::curl($url);
 | 
	
		
			
				|  |  | +        $result = json_decode($result, true);
 | 
	
		
			
				|  |  | +        if (isset($result['data'][0]['city'])) {
 | 
	
		
			
				|  |  | +            if (!$result['data'][0]['prov']) {
 | 
	
		
			
				|  |  | +                $result['data'][0]['prov'] = $result['data'][0]['city'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $sql = 'update huala_member set mobile_city = "'.$result['data'][0]['city'].'", mobile_prov = "'.$result['data'][0]['prov'].'" where id = ' . $id;
 | 
	
		
			
				|  |  | +            Dever::db('collection/info')->query($sql);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public function tdata($limit, $num)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $sql = 'select * from huala_member where mobile_prov is null order by id asc limit ' . $limit . ',' . $num;
 | 
	
		
			
				|  |  | +        $data = Dever::db('collection/info')->fetchAll($sql);
 | 
	
		
			
				|  |  | +        return $data;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |