title;//标题 $poster = $Request->poster;//海报 $introduction = $Request->introduction;//介绍 $merchant_id = $Request->account_id;//商户id $status = 0;//直播状态 $is_show = $Request->is_show;//是否展示 $start_time = $Request->start_time;//直播开始时间 $end_time = $Request->end_time;//直播结束时间 $channel_id = 0;//推流信息id $chat_room_id = 0; //聊天室信息id $merchant_live = new MerchantLive(); $merchant_live['title'] = $title; $merchant_live['poster'] = $poster; $merchant_live['introduction'] = $introduction; $merchant_live['merchant_id'] = $merchant_id; $merchant_live['status'] = $status; $merchant_live['is_show'] = $is_show; $merchant_live['start_time'] = $start_time; $merchant_live['end_time'] = $end_time; $merchant_live['channel_id'] = $channel_id; $merchant_live['chat_room_id'] = $chat_room_id; $merchant_live->save(); $result = $merchant_live->layout(); return $this->success('ok', $result); }catch (\Exception $e){ $this->getError($e); return $this->failure('服务器休息了,请稍后再试'); } } /** * 更新直播 * * * @param Request $Request * @param $id * @return JsonResponse|string */ public function UpdateLive(Request $Request, $id) { try { $MerchantLive = MerchantLive::where('id', $id)->first(); if (!$MerchantLive) return $this->failure('直播数据不存在'); if ($Request->has('title')) { $MerchantLive->title = $Request->title; } if ($Request->has('poster')) { $MerchantLive->poster = $Request->poster; } if ($Request->has('introduction')) { $MerchantLive->introduction = $Request->introduction; } if ($Request->has('is_show')) { $MerchantLive->is_show = $Request->is_show; } if ($Request->has('start_time')) { $MerchantLive->start_time = $Request->start_time; } if ($Request->has('end_time')) { $MerchantLive->end_time = $Request->end_time; } if ($Request->has('is_top')) { $MerchantLive->is_top = $Request->is_top; } if ($Request->has('top_time')) { $MerchantLive->top_time = $Request->top_time; } if ($Request->has('status')) { $MerchantLive->status = $Request->status; } $MerchantLive->save(); return $this->success('ok'); }catch (\Exception $e){ $this->getError($e); return $this->failure('服务器休息了,请稍后再试'); } } /** * 删除直播 * * * @param Request $Request * @param $id * @return JsonResponse|string */ public function DelLive(Request $Request, $id) { try { $merchant_id = $Request->account_id;//商户id $MerchantLive = MerchantLive::where('id', $id)->where('merchant_id', $merchant_id)->first(); if (!$MerchantLive) return $this->failure('直播数据不存在'); $MerchantLive->delete(); return $this->success('ok'); }catch (\Exception $e){ $this->getError($e); return $this->failure('服务器休息了,请稍后再试'); } } /** * 直播列表 * @param Request $request * @return JsonResponse|string */ public function LiveList(Request $request) { try { $merchant_id = $request->account_id;//商户id $keyword = $request->keyword; $lives = MerchantLive::where('merchant_id', $merchant_id); if ($request->has('keyword')) { $lives = $lives->where('title', 'like', '%' . $keyword . '%'); } $lives = $lives->orderBy('is_top', 'desc') ->orderBy('top_time', 'desc') ->orderBy('id', 'desc') ->paginate(); foreach ($lives as $key => $value) { $value->pv = Redis::zscore('merchantLive', $value->id) ?: 0; } return $this->success('ok', $lives); }catch (\Exception $e){ $this->getError($e); return $this->failure('服务器休息了,请稍后再试'); } } /** * 直播详情 * @param Request $Request * @param $id * @return JsonResponse|string */ public function LiveDetail(Request $Request, $id) { try { $merchant_id = $Request->account_id;//商户id $MerchantLive = MerchantLive::where('id', $id)->where('merchant_id', $merchant_id)->first(); $MerchantLive->pv = Redis::zscore('merchantLive', $id) ?? 0; return $this->success('ok', $MerchantLive); }catch (\Exception $e){ $this->getError($e); return $this->failure('服务器休息了,请稍后再试'); } } }