www_fpvone_cn/application/index/controller/Live.php

83 lines
2.3 KiB
PHP

<?php
/**
* @Created by PhpStorm.
* @Author:Soar
* @Time:2023/12/18 13:42
*/
namespace app\index\controller;
use app\common\controller\Frontend;
use app\common\library\Auth;
use app\index\service\ScreenService;
use think\Session;
class Live extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedLoginLive = '*';
protected $noNeedRight = '*';
protected $layout = '';
protected $match_id;
public function _initialize()
{
$auth = Auth::instance();
parent::_initialize();
$this->screemService = new ScreenService();
}
public function live()
{
$id = $this->request->param("id");
if (empty($id)) {
$this->error("非法请求");
}
$this->auth->setMatchId($id);
if (!$this->screemService->verifyScreen(['match_id' => $id, 'type' => "ranking"])) {
// 判断是否登陆
if (!Session::has("screen_ranking{$id}")) {
$this->match_id = $id;
$this->error("请先登录!", url('live/login', ['match_id' => $id]));
}
}
$screen_info = $this->screemService->getScreenInfo([
'match_id' => $id,
'type' => "ranking"
]);
$this->view->assign("match_id", $id);
$this->view->assign('screeninfo', $screen_info);
return $this->view->fetch();
}
public function login()
{
if ($this->request->isPost()) {
$data['look_pwd'] = $this->request->post("password");
if (empty($data['look_pwd'])) {
$this->error("密码不能为空!");
} elseif (empty($this->request->param("match_id"))) {
$this->error("非法请求");
}
$data['match_id'] = $this->request->param("match_id");
$data['type'] = 'ranking';
if ($this->screemService->verifyScreen($data)) {
Session::set("screen_ranking{$data['match_id']}", true);
$this->success("登陆成功!", url('live/live?id='.$data['match_id']));
} else {
$this->error("密码错误!");
}
}
$id = $this->request->param("match_id");
if (empty($id)) {
$this->error("非法请求");
}
return $this->view->fetch();
}
}