123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Http\Validator\LiveValidator;
- use App\Services\Api\TaskService;
- use App\Services\LiveService;
- use App\Services\RedisService;
- /**
- * 在线直播
- * @package App\Http\Controllers\Api\v1
- */
- class LiveController extends webApp
- {
- /**
- * 列表
- * @return array
- */
- public function index()
- {
- try {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 0);
- $params['is_recommend'] = 1;
- $datas = LiveService::make()->getDataList($params, $pageSize,'', $this->userId);
- return showJson(1010, true, $datas);
- } catch (\Exception $exception){
- RedisService::set("caches:request:error_live_index", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
- return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
- }
- }
- /**
- * 在线用户数据
- * @return array
- */
- public function users()
- {
- $params =request()->post();
- $pageSize = request()->post('pageSize', 15);
- $datas = LiveService::make()->getUserList($params, $pageSize, $this->userId);
- return showJson(1010, true, $datas);
- }
- /**
- * 礼物列表
- * @return array
- */
- public function giftList()
- {
- $params =request()->post();
- $pageSize = request()->post('pageSize', 15);
- $datas = LiveService::make()->getGiftList($params, $pageSize, $this->userId);
- return showJson(1010, true, $datas);
- }
- /**
- * 播放与浏览
- * @return array
- */
- public function updatePlay()
- {
- $id = request()->post('id',0);
- if(!$result = LiveService::make()->updatePlay($this->userId, $id)){
- return showJson(LiveService::make()->getError(), false);
- }else{
- return showJson(LiveService::make()->getError(), true, $result);
- }
- }
- /**
- * 获取流地址
- * @return array
- */
- public function getUrl()
- {
- $urls = LiveService::make()->getLiveUrl($this->userId);
- return showJson(1010, true, $urls);
- }
- /**
- * 直播详情
- * @param LiveValidator $validator
- * @return array
- */
- public function getInfo(LiveValidator $validator)
- {
- $params = request()->all();
- $params = $validator->check($params, 'info');
- if (!is_array($params)) {
- return showJson($params, false);
- }
- if(!$info = LiveService::make()->getInfo($params['id'], $this->userId)){
- return showJson(LiveService::make()->getError(),false);
- }else{
- return showJson(1010,true, $info);
- }
- }
- /**
- * 更新观看时长任务
- * @return array
- */
- public function updatePlayTask()
- {
- // 观看直播任务
- $id = request()->post('id',0);
- $time = request()->post('time',0);
- TaskService::make()->updateTask($this->userId,1, $id, $time);
- return showJson(1010,true, []);
- }
- /**
- * 状态
- * @return array|mixed
- */
- public function status()
- {
- if(!$result = LiveService::make()->status()){
- return showJson(LiveService::make()->getError(), false);
- }else{
- return showJson(LiveService::make()->getError(), true, $result);
- }
- }
- /**
- * 点赞
- * @return array|mixed
- */
- public function like()
- {
- $params = request()->post();
- if(!$result = LiveService::make()->like($this->userId, $params)){
- return showJson(LiveService::make()->getError(), false);
- }else{
- return showJson(LiveService::make()->getError(), true, $result);
- }
- }
- /**
- * 创建直播间(开启直播)
- * @return array
- */
- public function create(LiveValidator $validator)
- {
- $params = request()->all();
- $params = $validator->check($params, 'create');
- if (!is_array($params)) {
- return showJson($params, false);
- }
- if(!$result = LiveService::make()->create($this->userId, $params)){
- return showJson(LiveService::make()->getError(),false);
- }else{
- return showJson(LiveService::make()->getError(),true, $result);
- }
- }
- /**
- * 礼物打赏
- * @return array
- */
- public function reward()
- {
- $params = request()->all();
- if(!$result = LiveService::make()->reward($this->userId, $params)){
- return showJson(LiveService::make()->getError(),false);
- }else{
- return showJson(LiveService::make()->getError(),true, $result);
- }
- }
- }
|