mirror of https://gitee.com/karson/fastadmin.git
'添加直播流'
parent
b69b0022af
commit
85adc4f880
|
|
@ -3,6 +3,9 @@
|
|||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\Log;
|
||||
|
||||
/**
|
||||
* 直播接口
|
||||
|
|
@ -26,7 +29,7 @@ class Live extends Api
|
|||
}
|
||||
|
||||
/**
|
||||
* 读取产品信息
|
||||
* 读取直播流信息
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
|
@ -44,14 +47,56 @@ class Live extends Api
|
|||
|
||||
// $pagesize = $this->request->request("per_page");
|
||||
|
||||
// print_r($this->request->request("status"));
|
||||
// exit();
|
||||
if ($this->request->request("status")) {
|
||||
$where = array(
|
||||
'status' => $this->request->request("status"),
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->request->request("username")) {
|
||||
$username = $this->request->request("username");
|
||||
// $username = 'qq';
|
||||
$sql = "select b.*
|
||||
from fa_user as a,fa_live as b
|
||||
where a.id=b.user_id and a.username = '$username'";
|
||||
|
||||
$list = Db::query($sql);
|
||||
if (!empty($list)) {
|
||||
return true;
|
||||
} else {
|
||||
//创建直播流
|
||||
$sql = "select id
|
||||
from fa_user
|
||||
where username = '$username'";
|
||||
|
||||
$list = Db::query($sql);
|
||||
$user_id = $list[0]['id'];
|
||||
|
||||
$code = time();
|
||||
$base_url = "rtmp://47.104.165.49:1935/live/";
|
||||
$push_url = $base_url . $code;
|
||||
$pull_url = $push_url;
|
||||
$sql = "INSERT INTO fa_live(push_url,pull_url,user_id,status) VALUES ('$push_url','$pull_url','$user_id','1')";
|
||||
|
||||
// echo $sql;
|
||||
// exit();
|
||||
$rs = Db::execute($sql);
|
||||
if ($rs === false) {
|
||||
echo '添加直播流失败';
|
||||
} else {
|
||||
echo '添加直播流成功';
|
||||
}
|
||||
|
||||
$list = array(
|
||||
'base_url'=>$base_url,
|
||||
'code'=>$code,
|
||||
);
|
||||
|
||||
$result = array( "rows" => $list);
|
||||
return json($result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$total = $this->model
|
||||
->where($where)
|
||||
|
|
@ -67,7 +112,6 @@ class Live extends Api
|
|||
$result = array("total" => $total, "rows" => $list);
|
||||
|
||||
return json($result);
|
||||
// return ($where);
|
||||
|
||||
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
|
||||
// 表名
|
||||
protected $name = 'user';
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'prevtime_text',
|
||||
'logintime_text',
|
||||
'jointime_text'
|
||||
];
|
||||
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeUpdate(function ($row) {
|
||||
$changed = $row->getChangedData();
|
||||
//如果有修改密码
|
||||
if (isset($changed['password']))
|
||||
{
|
||||
$salt = \fast\Random::alnum();
|
||||
$row->password = \app\common\library\Auth::instance()->getEncryptPassword($changed['password'], $salt);
|
||||
$row->salt = $salt;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function getGenderList()
|
||||
{
|
||||
return ['1' => __('Male'), '0' => __('Female')];
|
||||
}
|
||||
|
||||
public function getStatusList()
|
||||
{
|
||||
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
|
||||
}
|
||||
|
||||
public function getPrevtimeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : $data['prevtime'];
|
||||
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
||||
}
|
||||
|
||||
public function getLogintimeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : $data['logintime'];
|
||||
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
||||
}
|
||||
|
||||
public function getJointimeTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : $data['jointime'];
|
||||
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
||||
}
|
||||
|
||||
protected function setPrevtimeAttr($value)
|
||||
{
|
||||
return $value && !is_numeric($value) ? strtotime($value) : $value;
|
||||
}
|
||||
|
||||
protected function setLogintimeAttr($value)
|
||||
{
|
||||
return $value && !is_numeric($value) ? strtotime($value) : $value;
|
||||
}
|
||||
|
||||
protected function setJointimeAttr($value)
|
||||
{
|
||||
return $value && !is_numeric($value) ? strtotime($value) : $value;
|
||||
}
|
||||
|
||||
public function group()
|
||||
{
|
||||
return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class UserGroup extends Model
|
||||
{
|
||||
|
||||
// 表名
|
||||
protected $name = 'user_group';
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status_text'
|
||||
];
|
||||
|
||||
public function getStatusList()
|
||||
{
|
||||
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
|
||||
}
|
||||
|
||||
public function getStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : $data['status'];
|
||||
$list = $this->getStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class UserRule extends Model
|
||||
{
|
||||
|
||||
// 表名
|
||||
protected $name = 'user_rule';
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'int';
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = 'createtime';
|
||||
protected $updateTime = 'updatetime';
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'status_text'
|
||||
];
|
||||
|
||||
protected static function init()
|
||||
{
|
||||
self::afterInsert(function ($row) {
|
||||
$pk = $row->getPk();
|
||||
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
|
||||
});
|
||||
}
|
||||
|
||||
public function getStatusList()
|
||||
{
|
||||
return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
|
||||
}
|
||||
|
||||
public function getStatusTextAttr($value, $data)
|
||||
{
|
||||
$value = $value ? $value : $data['status'];
|
||||
$list = $this->getStatusList();
|
||||
return isset($list[$value]) ? $list[$value] : '';
|
||||
}
|
||||
|
||||
public static function getTreeList($selected = [])
|
||||
{
|
||||
$ruleList = collection(self::where('status', 'normal')->select())->toArray();
|
||||
$nodeList = [];
|
||||
foreach ($ruleList as $k => $v)
|
||||
{
|
||||
$state = array('selected' => $v['ismenu'] ? false : in_array($v['id'], $selected));
|
||||
$nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state);
|
||||
}
|
||||
return $nodeList;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue