love_php/app/Http/Controllers/App/InteractLiveController.php
2026-04-02 09:20:51 +08:00

936 lines
30 KiB
PHP

<?php
namespace App\Http\Controllers\App;
use App\Services\IMService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Response\ResponseJson;
use Illuminate\Support\Facades\Cache;
//Model
use App\Models\User;
use App\Models\InteractLive;
use App\Models\Live\LiveBanner;
use App\Models\InteractApplyLog;
use App\Models\InteractLiveGift;
use App\Models\InteractLiveComment;
//Service
use App\Contracts\LiveContract;
use App\Contracts\UserContract;
use App\Models\InteractLiveJoinLog;
use App\Models\Live\GiftOrder;
use App\Models\Live\Live;
use Illuminate\Support\Facades\Redis;
class InteractLiveController extends Controller
{
use ResponseJson;
protected $liveCon;
protected $userCon;
public function __construct(LiveContract $liveCon, UserContract $userCon)
{
$this->liveCon = $liveCon;
$this->userCon = $userCon;
}
/**
* 直播首页
* @return [type] [description]
*/
public function liveHome(Request $request)
{
try {
$lives = $this->liveCon->liveList();
if (empty($lives)) throw new \Exception("获取直播列表失败", 1);
$carousel = $this->liveCon->liveCarousel();
return $this->success('ok', compact('lives', 'carousel'));
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取直播首页失败,请稍后再试');
}
}
/**
* 直播首页
* @return [type] [description]
*/
public function liveHomeV2(Request $request)
{
try {
$lives = $this->liveCon->liveListV2();
if (empty($lives)) throw new \Exception("获取直播列表失败", 1);
foreach ($lives as $key => $value) {
$user = User::where('id',$value->user_id)->first();
$value['name'] = $user->nickname;
$value['age'] = \CommonUtilsService::getAge($user->profileCourtship->birthday);
$value['city'] = $user->profileCourtship->city??'';
$value['avatar'] = $user->avatar;
$rtmp_pull_url[0] = $value->channels[0]['rtmp_pull_url']??'';
$hls_pull_url[0] = $value->channels[0]['hls_pull_url']??'';
$value['rtmp_pull_url'] = $rtmp_pull_url;
$value['hls_pull_url'] = $hls_pull_url;
unset($value->channels);
//用户城市.用户年龄
}
return $this->success('ok', compact('lives'));
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取直播首页失败,请稍后再试');
}
}
/**
* 直播详情
* @param Request $request [description]
* @param int $live_id 直播详情
* @return [type] [description]
*/
public function live(Request $request, $live_id)
{
try {
//是否被禁止
$result = auth()->user()->isBanBylives($live_id);
if (is_array($result)) return $this->failure('已被禁止进入该直播间至'.$result['msg']);
//直播间信息
$live =$this->liveCon->live($live_id, $mk=true);
//是否有密码
if (empty($request->input('is_invited')) && $live->password && $live->password != $request->input('password')) {
return $this->failure('请输入正确的直播间密码');
}
$tasks = $live->getRtmpTask();
if ($tasks) {
$tasks['layoutPara'] = json_decode($tasks['layoutPara']);
}
$live->tasks = $tasks;
if (empty($live)) throw new \Exception("获取直播详情失败", 1);
//主播信息
$maker = $live->matchMaker;
//获取主播详细信息
$anchor = User::where('id',$maker->id)->first();
$match_maker = [];
$match_maker['sex'] = $anchor->sex;
$match_maker['is_real_approved'] = $anchor->is_real_approved??0;
$match_maker['stature'] = $anchor->profileCourtship->stature??'未知';
$match_maker['age'] = \CommonUtilsService::getAge($anchor->profileCourtship->birthday);
$match_maker['city'] = $anchor->profileCourtship->city??'未知';
$match_maker['isSuperRank'] = $anchor->isSuperRank($anchor->id)??0;
$match_maker['avatar'] = $anchor->avatar;
$match_maker['app_avatar'] = $anchor->avatar;
$match_maker['id'] = $anchor->id;
$match_maker['nickname'] = $anchor->nickname;
unset($live->matchMaker);
//是否关注
$match_maker['is_followed'] = auth()->user()->isFollowing($maker)?1:0;
//在线用户
// $chatroom_members = $this->liveCon->liveMembers($live, $nopage = 1, $limit=15);
// if ($chatroom_members === false) throw new \Exception("获取直播间在线用户失败", 1);
//获取NERTC Token
$im_service= new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET'));
$request->merge(['channel_name'=>$live->name]);
$curl_result = $im_service->getToken($request);
$live->token = '';
if($curl_result['code'] == 200 && !empty($curl_result['token'])){
$live->token = $curl_result['token'];
}
//赠送详情卡
$result = $this->liveCon->daliySendLiveCard(auth()->id());
$live->channels;
//上线房间用户
$this->liveCon->addLiveMember($live, auth()->user());
if (empty($result)) throw new \Exception("赠送相亲卡失败", 1);
return $this->success('ok', compact('live', 'match_maker'));
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('进入直播失败,请稍后再试');
}
}
public function liveByChatroom(Request $request)
{
try {
$room_id = $request->input('room_id');
if (empty($room_id)) return $this->failure('没有聊天室id');
$result = $this->liveCon->liveByChatroom($room_id);
if (empty($result)) throw new \Exception("获取直播间信息失败", 1);
if ($result && is_array($result) && $result['code']) return $this->failure($result['msg']);
return $this->success('ok',$result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取直播间信息失败,请稍后再试');
}
}
/**
* 创建直播间:红娘
* @param Request $request [description]
* @return [type] [description]
*/
public function storeLive(Request $request)
{
try {
$user = auth()->user();
//查看权限
$result = $user->checkStoreLive();
if (empty($result)) return $this->failure('没有创建直播权限');
//创建直播
$result = $this->liveCon->storeInteractLive();
if (empty($result)) throw new \Exception("创建直播间失败", 1);
return $this->success('ok', $result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('创建直播间失败,请稍后再试');
}
}
// 查看直播间信息
public function livedebug(Request $request)
{
// // $im = new IMService();
// $user = auth()->user();
// //直播间参数
// //创建福恋直播
// $live = InteractLive::where('user_id',$user->id)->first();
// $im = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET'));
// $result = $im->liveRoom($request->channel_id);
// $result = $im->createChannelV2($live->name, $user->id);
// return $this->success('ok',$result);
}
/**
* 创建直播间:真人认证后即可直播
* @param Request $request [description]
* @return [type] [description]
*/
public function startLive(Request $request)
{
try {
return $this->failure('直播模块正在维护中~');
$user = auth()->user();
//查看权限
if ($user->is_real_approved!=1)
return $this->failure('您尚未真人认证~');
//创建直播
$result = $this->liveCon->storeInteractLiveV2();
//获取NERTC Token
$im_service= new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET'));
$request->merge(['channel_name'=>$result->name]);
$curl_result = $im_service->getToken($request);
$token = '';
if($curl_result['code'] == 200 && !empty($curl_result['token'])){
$token = $curl_result['token'];
}
$live = Live::where('user_id',$user->id)->orderBy('id','desc')->first();
$result->share_qrcode = '';
$result['share_url'] = '';
if($live){
$live->status = 1;
$live->chat_room_id = $result->chat_room_id;
$live->channel_id = $result->channel_id;
$result->share_qrcode = $live->share_qrcode;
$result->live_id = $live->id;
$live->save();
$result['share_url'] = env('APP_URL').'/pu/#/ordinaryWatchLive/'.$live->id;
}
$result['token'] = $token??'';
if (empty($result)) throw new \Exception("创建直播间失败", 1);
$result['avatar'] = $user->avatar??'';
$result['nickname'] = $user->nickname??'';
return $this->success('ok', $result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('创建直播间失败,请稍后再试');
}
}
// 直播间信息
public function liveInfo(Request $request){
$id = $request->live_id;
$live = Live::where('id',$id)->orderBy('id','desc')->first();
$data['like_count'] =$live->like_count??0;
$data['gift_count'] = GiftOrder::where('live_id',$id)->where('pay_status',1)->count()??0;
$data['pv'] = Redis::zscore('page_pv', $id);
return $this->success('ok', $data);
}
// 申请连麦
public function joinChat(Request $request)
{
$user = auth()->user();
$live_id = $request->live_id;
$result = InteractLiveJoinLog::where('user_id',$user->id)->where('live_id',$live_id)->first();
if($result&&($result->status==0||$result->status==1))
return $this->failure('您已经在连麦过程中。');
$JoinLog = new InteractLiveJoinLog ;
$JoinLog->user_id = $user->id;
$JoinLog->live_id = $live_id;
$JoinLog->save();
return $this->success('申请成功');
}
// 连麦列表
public function joinChatList(Request $request)
{
$live_id = $request->live_id;
$result = InteractLiveJoinLog::select('id','user_id','status')->where('live_id',$live_id)->wherein('status',[0,1])
->orderBy('status','desc')
->orderBy('id','desc')
->get();
foreach ($result as $key => $value) {
$value->nickname = $value->user->nickname;
$value->avatar = $value->user->avatar;
$value->user_id = $value->user->id;
unset($value->user);
}
return $this->success('ok',$result);
}
// 更改连麦状态
public function changejoinChat(Request $request)
{
$user = auth()->user();
$id = $request->id;
$status = $request->status;
$result = InteractLiveJoinLog::where('id',$id)->first();
if(!$result)
return $this->failure('该记录不存在');
if($result->status==2||$result->status==3)
return $this->failure('连线已结束或已取消');
$result->status = $status;
$result->Operator = $user->id;
if($status==1)
$result->join_start_time = now();
if($status==2||$status==3)
$result->join_end_time = now();
$result->save();
return $this->success('操作成功');
}
/**
* 创建直播间:返回是否真人认证
*/
public function checkLive(Request $request)
{
try {
$user = auth()->user();
//查看权限
$data['status'] = $user->is_real_approved;
return $this->success('ok',$data);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取信息失败,请稍后再试');
}
}
/**
* 轮播图
*/
public function banner(Request $result)
{
$key = 'live_banner';
$result = cache::remember($key,30,function(){
$result = LiveBanner::select('icon','link','desc')->where('status',1)->where('class','live')->orderBy('sort','desc')->get();
return $result;
});
return $this->success('ok', $result);
}
/**
* 推荐直播
* @param Request $request [description]
* @return [type] [description]
*/
public function recommendLive(Request $request)
{
try {
$lives = $this->liveCon->recommendLive();
if (empty($lives)) return $this->failure('推荐直播间失败');
return $this->success('ok', $lives);
} catch (\Exception $e) {
$this->getError($e);
// return $this->success('ok', null);
return $this->failure('推荐直播间失败,请稍后再试');
}
}
/**
* 申请互动直播相亲
* @param Request $request [description]
* @param int $live_id [直播间id]
* @return [type] [description]
*/
public function applyLive(Request $request, $live_id)
{
try {
$user = auth()->user();
//检查直播间状态
$live = $this->liveCon->live($live_id, $match_maker=false);
if (empty($live->in_live)) {
return $this->failure('主播未开播');
}
//检查用户权限
$result = $user->checkInteractApply($live_id);
if (empty($result)) throw new \Exception("权限检查失败", 1);
if ($result && is_array($result) && $result['code']) return $this->failure($result['msg']);
//创建申请记录
$result = $this->liveCon->applyInteractLive($live_id);
if (empty($result)) throw new \Exception("创建申请记录失败", 1);
//提醒当前直播间红娘
return $this->success('ok');
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('申请直播相亲失败,请稍后再试');
}
}
/**
* 互动直播相亲申请列表
* @param Request $request [description]
* @param int $live_id [直播间id]
* @return [type] [description]
*/
public function liveApplyLogs(Request $request, $live_id)
{
try {
//是否是直播间红娘
$live = $this->liveCon->live($live_id);
if (empty($live) || $live->user_id != auth()->id()) return $this->failure('暂无权限访问');
$logs = $this->liveCon->liveApplyLogs($live_id, $is_audited=0);
return $this->success('ok', $logs);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取直播间申请相亲列表失败,请稍后再试');
}
}
/**
* 审核直播申请
* @param Request $request [description]
* @param [type] $log_id [description]
* @return [type] [description]
*/
public function auditedApplyLog(Request $request, $log_id)
{
try {
$log = InteractApplyLog::find($log_id);
$result = $this->liveCon->auditedApplyLog($log);
if (empty($result)) throw new \Exception("审核报错", 1);
if ($result && is_array($result) && $result['code']) return $this->failure($result['msg']);
$is_audited = $request->input('is_audited');
if ($is_audited == 1) {
$live = $log->live;
$apply_user = $log->user()->select('id', 'app_avatar', 'nickname', 'sex')->first();
return $this->success('ok', compact('live', 'apply_user'));
}else{
return $this->success('ok');
}
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('审核申请详情记录失败,请稍后再试');
}
}
/**
* 审核直播详情记录 根据用户和房间
* @param Request $request [description]
* @param [type] $live_id [description]
* @param [type] $user_id [description]
* @return [type] [description]
*/
public function auditedApplyLogV2(Request $request, $live_id, $user_id)
{
try {
$log = InteractApplyLog::where('user_id', $user_id)->where('live_id', $live_id)->where('is_audited', 0)->first();
if (empty($log)) throw new \Exception("申请记录不存在", 1);
$result = $this->liveCon->auditedApplyLog($log);
if (empty($result)) throw new \Exception("审核报错", 1);
if ($result && is_array($result) && $result['code']) return $this->failure($result['msg']);
$is_audited = $request->input('is_audited');
if ($is_audited == 1) {
$live = $log->live;
$apply_user = $log->user()->select('id', 'app_avatar', 'nickname', 'sex')->first();
return $this->success('ok', compact('live', 'apply_user'));
}else{
return $this->success('ok');
}
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('审核申请详情记录失败,请稍后再试');
}
}
/**
* 举报用户
* @param Request $request [description]
* @param [type] $user_id [description]
* @return [type] [description]
*/
public function complaintUser(Request $request, $user_id)
{
try {
$request->type = 'interact_live';
$photos = $request->input('photos', []);
$label = $request->input('label');
if(empty($label)){
return $this->failure('请选择举报类型');
}else if($photos == []){
return $this->failure('请提供举报截图');
}
$this->userCon->complaint($request, auth()->id(), $user_id);
return $this->success('ok');
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('举报用户失败,请稍后再试');
}
}
/**
* 举报标签
*/
public function complaintLabels(Request $request)
{
try {
$type = $request->input('type');
$labels = [
'小号相亲','引导去其他平台','在其他平台直播','账号非本人使用','广告','强迫刷礼物','恶意刷好评','辱骂攻击','色情骚扰','欺诈骗钱','涉政涉恐','其他'
];
if ($type =='user') {
array_unshift($labels, '信息虚假');
}elseif ($type =='mk_user') {
array_unshift($labels, '服务态度差');
}
return $this->success('ok', $labels);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取信息失败');
}
}
/**
* 直播间只用用户信息
* 红娘+男女嘉宾
* @param Request $request [description]
* @param [type] $live_id [description]
* @return [type] [description]
*/
public function liveUsersInfo(Request $request, $live_id)
{
try {
//当前直播记录
$result = $this->liveCon->liveUsersInfo($live_id);
if (empty($result)) return $this->failure('直播用户信息关闭');
$match_maker = $result->matchMaker;
$male = $result->male;
$female = $result->female;
$channels = $result->channels;
$live = $result->live;
return $this->success('ok', compact('match_maker', 'male', 'female', 'channels', 'live'));
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取当前直播用户信息失败');
}
}
/**
* 修改用户在线状态
* @param Request $request [description]
* @param [type] $user_id [description]
* @return [type] [description]
*/
public function updateUserOnline(Request $request)
{
try {
$result = $this->userCon->updateUser($request);
return $this->success('ok', $result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('修改用户在线状态失败,请稍后再试');
}
}
/**
* 直播间踢人
* @param Request $request [description]
* @param [type] $live_id [description]
* @param [type] $user_id [description]
* @return [type] [description]
*/
public function banLiveUser(Request $request, $live_id, $user_id)
{
try {
$result = $this->liveCon->banLiveUser($live_id, $user_id);
if (empty($result)) throw new \Exception("踢人失败", 1);
if ($result && is_array($result) && $result['code']) return $this->failure($result['msg']);
return $this->success('ok');
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('踢出用户失败,请稍后再试');
}
}
/**
* 主动退出互动直播
* @param Request $request [description]
* @param [type] $live_id [description]
* @return [type] [description]
*/
public function leaveInteractLive(Request $request, $live_id)
{
try {
$result = $this->liveCon->leaveInteractLive($live_id);
if (empty($result)) throw new \Exception("退出互动直播失败", 1);
return $this->success('ok', $result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('退出互动直播失败,请稍后再试');
}
}
/**
* 被动退出互动直播
* 红娘权限
* @param Request $request [description]
* @param [type] $live_id [description]
* @return [type] [description]
*/
public function askLeaveInteractLive(Request $request, $user_id, $live_id)
{
try {
$result = $this->liveCon->askLeaveInteractLive($live_id, $user_id);
if (empty($result)) throw new \Exception("请出互动直播失败", 1);
if ($result && is_array($result) && $result['msg'] == 'check') return $this->failure('暂无权限');
return $this->success('ok', $result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('请出互动直播失败,请稍后再试');
}
}
/**
* 加入互动直播
* @param Request $request [description]
* @param [type] $live_id [description]
* @return [type] [description]
*/
public function joinInteractLive(Request $request, $live_id)
{
try {
$result = $this->liveCon->joinInteractLive($live_id);
if (empty($result)) throw new \Exception("加入直播失败", 1);
if ($result && is_array($result) && $result['code']) return $this->failure($result['msg']);
return $this->success('ok', $result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('加入互动直播失败,请稍后再试');
}
}
/**
* 主播开播
* @param Request $request [description]
* @return [type] [description]
*/
public function onLive(Request $request)
{
try {
$result = $this->liveCon->onLive();
if (empty($result)) throw new \Exception("开播失败", 1);
if ($result && is_array($result) && $result['code']) return $this->failure($result['msg']);
return $this->success('ok', $result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('开播失败,请稍后再试');
}
}
/**
* 下播
* @param Request $request [description]
* @return [type] [description]
*/
public function offLive(Request $request)
{
try {
$result = $this->liveCon->offLive();
if (empty($result)) throw new \Exception("下播失败", 1);
if ($result && is_array($result) && $result['code']) return $this->failure($result['msg']);
return $this->success('ok', $result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('下播失败,请稍后再试');
}
}
/**
* 直播卡列表
* @param Request $request [description]
* @return [type] [description]
*/
public function userLiveCards(Request $request)
{
try {
$is_used = $request->input('is_used');
$result = $this->liveCon->liveCards($is_used);
if (empty($result)) throw new \Exception("获取直播卡列表失败", 1);
return $this->success('ok', $result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取直播卡列表失败,请稍后再试');
}
}
/**
* 邀请用户参加直播
* @param Request $request [description]
* @param [type] $live_id [description]
* @param [type] $user_id [description]
* @return [type] [description]
*/
public function inviteJoinLive(Request $request, $user_id, $live_id)
{
try {
$result = $this->liveCon->inviteJoinLive($live_id, $user_id);
if (empty($result)) throw new \Exception("邀请失败", 1);
return $this->success('ok');
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('邀请用户参加直播失败,请稍后再试');
}
}
/**
* 直播间提示语
* @return [type] [description]
*/
public function livePromptWorld()
{
$prompt_word = "请各位会员自觉遵守法律法规,遇到转账切勿相信,谨防上当受骗,对未实名认证的会员保持警惕,交友期保持必要的界线以及顾及自身安全,请勿轻易委身于人和用户产生借贷关系,否则后果自己承担";
return $this->success('ok', compact('prompt_word'));
}
/**
* 用户福币记录
* @return [type] [description]
*/
public function userCoinLogs(Request $request)
{
try {
$logs = $this->liveCon->userCoinLogs();
return $this->success('ok', $logs);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('用户福币记录失败,请稍后再试');
}
}
/**
* 比例福币列表
* @return [type] [description]
*/
public function ratioCoins(Request $request)
{
try {
$result = $this->liveCon->ratioCoins();
if (empty($result)) throw new \Exception("获取福币充值信息失败", 1);
$coin = $result['coin'];
$coin->remain_amount = $coin->remain_amount+$coin->amount_from_other;
$ratio_coins = $result['ratio_coins'];
return $this->success('ok', compact('coin', 'ratio_coins'));
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取充值福币列表失败,请稍后再试');
}
}
//礼物列表
public function liveGifts(Request $request)
{
try {
$result = $this->liveCon->liveGifts();
if (empty($result)) throw new \Exception("获取礼物信息失败", 1);
$coin = $result['coin'];
$gifts = $result['gifts'];
return $this->success('ok', compact('coin', 'gifts'));
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取直播礼物列表失败,请稍后再试');
}
}
/**
* 赠送礼物
* @param Request $request [description]
* @param [type] $user_id 被赠送用户id
* @param [type] $gift_id 礼物id
* @return [type] [description]
*/
public function sendLiveGift(Request $request, $user_id, $gift_id)
{
try {
$result = $this->liveCon->sendLiveGift($user_id, $gift_id);
if (empty($result)) throw new \Exception("赠送礼物失败", 1);
if ($result && is_array($result) && $result['code'] == 1) return $this->failure($result['msg']);
return $this->success('ok');
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('赠送礼物失败,请稍后再试');
}
}
/**
* 在线用户列表
* @return [type] [description]
*/
public function liveOnlineUsers(Request $request)
{
try {
$users = $this->liveCon->liveOnlineUsers();
if (empty($users)) throw new \Exception("列表错误", 1);
return $this->success('ok', $users);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('在线用户列表失败,请稍后再试');
}
}
/**
* 房间用户列表
* @param Request $request [description]
* @param [type] $Live_id [description]
* @return [type] [description]
*/
public function liveMembers(Request $request, $live_id)
{
try {
$live = InteractLive::find($live_id);
$members = $this->liveCon->liveMembers($live);
return $this->success('ok', $members);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取直播间成员列表失败');
}
}
/**
* 离开观看直播
* @param Request $request [description]
* @param [type] $live_id [description]
* @return [type] [description]
*/
public function leaveViewLive(Request $request, $live_id)
{
try {
$live = InteractLive::find($live_id);
$this->liveCon->leaveLiveMember($live, auth()->user());
return $this->success('ok');
} catch (Exception $e) {
$this->getError($e);
return $this->failure('离开观看直播失败');
}
}
/**
* 直播观众用户信息
* @return [type] [description]
*/
public function liveUserInfo(Request $request, $user_id)
{
try {
$user = User::where('id', $user_id)->with('profileCourtship:user_id,birthday,stature,city,introduction')->select('id','app_avatar','sex','is_approved','nickname')->first();
$user = $this->liveCon->liveUserInfo($user);
if (empty($user)) throw new \Exception("获取观众用户信息失败", 1);
return $this->success('ok',$user);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('获取观众用户信息失败,请稍后再试');
}
}
public function payLive(Request $request, $live_id)
{
try {
$result = $this->liveCon->payLive($live_id);
if (empty($result)) throw new \Exception("付费失败", 1);
return $this->success('ok',$result);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('付费失败,请稍后再试');
}
}
/**
* 评价直播间
* @return [type] [description]
*/
public function commentLive(Request $request, $live_id)
{
try {
$live = InteractLive::find($live_id);
$user = auth()->user();
$option = $request->input('option');
if (empty($option)) return $this->failure('请选择评价选项');
$comment = InteractLiveComment::where('user_id', $user->id)->where('live_id', $live_id)->where('num',$live->num)->first();
if ($comment) return $this->failure('此次直播已经评论过');
$user->commentLive($live);
return $this->success('ok');
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('评价失败,请稍后再试');
}
}
/**
* 正在直播的直播间数
* @param Request $request [description]
* @return [type] [description]
*/
public function inLiveNum(Request $request)
{
try {
//正在直播数
$count = $this->liveCon->inLiveNum();
$count = 0 ;
if (empty($count) && !is_numeric($count)) throw new \Exception("获取正在直播数失败", 1);
//直播用戶頭像
$photos = $this->liveCon->inLivePhotos();
return $this->success('ok', compact('count', 'photos'));
} catch (\Exception $e) {
$this->getError($e);
$count = 0;
return $this->success('ok', compact('count'));
}
}
public function anchorInfo(Request $request,$anhcor_id){
$user = auth()->user();
$anchor = User::with('profileCourtship:id,user_id,stature,city,birthday,introduction')->where('id',$anhcor_id)->select('id','sex','is_approved','is_real_approved','app_avatar','circle_avatar','nickname','name')->first();
$anchor->fans_count = $anchor->cacheUserProperty('fans_count');//主播粉丝数
$anchor->follow_count = $anchor->cacheUserProperty('follow_count');
$anchor->is_follow = $user->isFollowing($anchor)?1:0;
$anchor->is_superRank = $anchor->isSuperRank($anchor->id);
$anchor->age = $anchor->profileCourtship ? \CommonUtilsService::getAge($anchor->profileCourtship->birthday) : $anchor->age;
return $this->success('ok',$anchor);
}
}