123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <?php
- namespace Collection\Src;
- use Dever;
- use Collection\Lib\Core;
- class Api extends Core
- {
- public function test1()
- {
- $list = Dever::db('content/news')->state();
- return $list;
- $test = '😀 😀';
- $test = Dever::input('test');
- $data['name'] = 'test';
- $data['desc'] = $test;
- return Dever::db('content/news')->insert($data);
- }
- public function data()
- {
- return Dever::db('collection/info')->state();
- }
- # 获取合集内容
- public function getInfo()
- {
- $id = Dever::input('id');
- # 是否已经购买
- $data['is_buy'] = false;
- $data['button'] = array(
- 'style' => 'background: linear-gradient(to right, #000000,#000000) !important;',
- 'color' => '#fff',
- 'name' => array('入口', '排行榜')
- );
- $data['info'] = Dever::db('collection/info')->one($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']['style'] = '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'];
- }
- }
- return $data;
- }
- # 获取合集下的购买内容
- public function getBuy()
- {
- $id = Dever::input('id');
- $where['info_id'] = $id;
- $data['buy'] = Dever::db('collection/buy')->getAll($where);
- return $data;
- }
- # 获取合集下的内容
- public function getContent()
- {
- $this->uid = 1;
- $id = Dever::input('id');
- $page_id = Dever::input('page_id');
- $data['items'] = Dever::load('collection/lib/content')->getList($id, $page_id);
- $page = Dever::db('collection/page')->one($page_id);
- $data['info_id'] = $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'] = Dever::input('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;
- }
- }
|