12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/6
- * Time: 18:05
- */
- namespace App\Traits;
- use Illuminate\Support\Facades\Redis;
- trait PostTrait
- {
- //预计可获得U米数
- public function availableBean()
- {
- $bean = Redis::get('yesterday_post_create_bean');
- $count = Redis::get('yesterday_post_count');
- $num = 1000;
- if($bean && $count){
- $num = $bean / $count;
- }
- $h = date('h');
- $H = date('H');
- $t = $h * 60 / 720 + 2;
- if(in_array(intval($H), [9,10,11,12,17.18,19,20,21])){
- $t += 0.5;
- }
- return intval($num * $t);
- }
- //获取内容话题
- public function getTopic($topic_ids, $type = 0)
- {
- $ids = explode(',', $topic_ids);
- $topic = [];
- foreach($ids as $id){
- $name = Redis::ZRANGEBYSCORE('topic.name', $id, $id);
- if($name && isset($name[0])){
- if($type){
- $topic[] = [
- 'id' => intval($id),
- 'name' => $name[0],
- ];
- }else{
- $topic[] = $name[0];
- }
- }
- }
- return $topic;
- }
- public function getAcFunList($page = 1, $size = 10, $categoryId = 25) {
- $client = new \GuzzleHttp\Client();
- $response = $client->request('get', "https://webapi.acfun.cn/query/article/list?pageNo={$page}&size={$size}&realmIds={$categoryId}", []);
- $result = json_decode($response->getBody()->getContents(), true);
- if(isset($result['data']['articleList'])){
- return $result['data']['articleList'];
- }else{
- return [];
- }
- }
- }
|