Api.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. namespace Collection\Src;
  3. use Dever;
  4. use Collection\Lib\Core;
  5. class Api extends Core
  6. {
  7. public function test1()
  8. {
  9. $list = Dever::db('content/news')->state();
  10. return $list;
  11. $test = '😀 😀';
  12. $test = Dever::input('test');
  13. $data['name'] = 'test';
  14. $data['desc'] = $test;
  15. return Dever::db('content/news')->insert($data);
  16. }
  17. public function data()
  18. {
  19. return Dever::db('collection/info')->state();
  20. }
  21. # 获取合集内容
  22. public function getInfo()
  23. {
  24. $id = Dever::input('id');
  25. # 是否已经购买
  26. $data['is_buy'] = false;
  27. $data['button'] = array(
  28. 'style' => 'background: linear-gradient(to right, #000000,#000000) !important;',
  29. 'color' => '#fff',
  30. 'name' => array('入口', '排行榜')
  31. );
  32. $data['info'] = Dever::db('collection/info')->one($id);
  33. if ($data['info']) {
  34. $data['info']['pic_bg'] = explode(',', $data['info']['pic_bg']);
  35. if ($data['info']['buy'] == 1) {
  36. # 收费 从订单中读取是否已经购买
  37. $data['is_buy'] = false;
  38. } else {
  39. # 免费
  40. $data['is_buy'] = true;
  41. }
  42. $data['button']['name'] = explode(',', $data['info']['button']);
  43. if ($data['info']['button_bgcolor'] && $data['info']['button_bgjcolor']) {
  44. $data['button']['style'] = 'background: linear-gradient(to right, '.$data['info']['button_bgcolor'].','.$data['info']['button_bgjcolor'].') !important;';
  45. }
  46. if ($data['info']['button_ftcolor']) {
  47. $data['button']['color'] = 'color:' . $data['info']['button_ftcolor'];
  48. }
  49. }
  50. return $data;
  51. }
  52. # 获取合集下的购买内容
  53. public function getBuy()
  54. {
  55. $id = Dever::input('id');
  56. $where['info_id'] = $id;
  57. $data['buy'] = Dever::db('collection/buy')->getAll($where);
  58. return $data;
  59. }
  60. # 获取合集下的内容
  61. public function getContent()
  62. {
  63. $this->uid = 1;
  64. $id = Dever::input('id');
  65. $page_id = Dever::input('page_id');
  66. $data['items'] = Dever::load('collection/lib/content')->getList($id, $page_id);
  67. $page = Dever::db('collection/page')->one($page_id);
  68. $data['info_id'] = $id;
  69. $data['page_id'] = $page_id;
  70. $data['parent_page_id'] = $page['page_id'];
  71. # 获取用户信息
  72. $data['user'] = Dever::load('passport/api')->info($this->uid);
  73. return $data;
  74. }
  75. # 获取合集下的分类
  76. public function category()
  77. {
  78. $parent_page_id = Dever::input('parent_page_id');
  79. $page_id = Dever::input('page_id');
  80. $where['info_id'] = Dever::input('id');
  81. $data['cate'] = Dever::db('collection/page')->main($where);
  82. if ($data['cate']) {
  83. $data['child'] = Dever::db('collection/page')->child($where);
  84. $content = Dever::db('collection/content')->child($where);
  85. $data['show'] = array();
  86. foreach ($data['cate'] as $k => $v) {
  87. if ($v['id'] == $parent_page_id) {
  88. $data['show'][$v['id']] = 1;
  89. } else {
  90. $data['show'][$v['id']] = 2;
  91. }
  92. }
  93. foreach ($data['child'] as $k => $v) {
  94. if (isset($content[$v['id']])) {
  95. $data['child'][$k]['content'] = $content[$v['id']];
  96. }
  97. }
  98. }
  99. return $data;
  100. }
  101. public function ding($data)
  102. {
  103. if (isset($data['num_add_buy']) && isset($data['num_ratio_buy'])) {
  104. if ($data['buy'] == 1) {
  105. /*
  106. if (!$data['num_buy']) {
  107. $stat = Dever::db('stat/collection')->getNumBycollection(array('collection_id' => $data['id']));
  108. if (!$stat) {
  109. $stat['buy_num'] = 0;
  110. }
  111. if (!$stat['buy_num']) {
  112. $stat['buy_num'] = 0;
  113. }
  114. $data['num_buy'] = $stat['buy_num'];
  115. }
  116. */
  117. $data['num_up'] = 0;
  118. }
  119. $data['num_buy'] = $data['num_buy'] + $data['num_up'];
  120. $data['buy_num'] = $data['num_buy'];
  121. $data['num_buy'] = round(($data['num_buy']+$data['num_add_buy'])*$data['num_ratio_buy']);
  122. }
  123. return $data;
  124. }
  125. # 解析元信息
  126. public function avinfo($data, $url = 'video', $table = 'video/vod')
  127. {
  128. # 解析视频元信息
  129. if (!$data['video_info']) {
  130. $video_info = Dever::curl($data[$url] . '?avinfo');
  131. if ($video_info) {
  132. Dever::db($table)->update(array('where_id' => $data['id'], 'video_info' => $video_info));
  133. }
  134. $video_info = Dever::json_decode($video_info);
  135. } else {
  136. $video_info = Dever::json_decode($data['video_info']);
  137. }
  138. unset($data['video_info']);
  139. $data['video_width'] = 0;
  140. $data['video_height'] = 0;
  141. # 默认横屏
  142. $data['video_type'] = 1;
  143. if (isset($video_info['streams']) && $video_info['streams']) {
  144. foreach ($video_info['streams'] as $k => $v) {
  145. if (isset($v['width']) && isset($v['height'])) {
  146. $data['video_width'] = $v['width'];
  147. $data['video_height'] = $v['height'];
  148. if ($data['video_width'] >= $data['video_height']) {
  149. $data['video_type'] = 1;
  150. } else {
  151. $data['video_type'] = 2;
  152. }
  153. break;
  154. }
  155. }
  156. }
  157. return $data;
  158. }
  159. public function test()
  160. {
  161. $limit = Dever::input('start', 0);
  162. $num = 10000;
  163. $state = true;
  164. while($state) {
  165. $data = $this->tdata($limit, $num);
  166. if ($data) {
  167. $state = true;
  168. foreach ($data as $k => $v) {
  169. if ($v['mobile'] && strstr($v['mobile'], '1')) {
  170. $this->tupdate($v['id'], $v['mobile']);
  171. }
  172. }
  173. } else {
  174. $state = false;
  175. }
  176. }
  177. return 'ok';
  178. }
  179. public function tupdate($id, $mobile)
  180. {
  181. $url = 'https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={mobile}&resource_id=6004&ie=utf8&oe=utf8&format=json';
  182. $url = str_replace('{mobile}', $mobile, $url);
  183. $result = Dever::curl($url);
  184. $result = json_decode($result, true);
  185. if (isset($result['data'][0]['city'])) {
  186. if (!$result['data'][0]['prov']) {
  187. $result['data'][0]['prov'] = $result['data'][0]['city'];
  188. }
  189. $sql = 'update huala_member set mobile_city = "'.$result['data'][0]['city'].'", mobile_prov = "'.$result['data'][0]['prov'].'" where id = ' . $id;
  190. Dever::db('collection/info')->query($sql);
  191. }
  192. }
  193. public function tdata($limit, $num)
  194. {
  195. $sql = 'select * from huala_member where mobile_prov is null order by id asc limit ' . $limit . ',' . $num;
  196. $data = Dever::db('collection/info')->fetchAll($sql);
  197. return $data;
  198. }
  199. }