You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.9 KiB
77 lines
2.9 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\web\model\live;
|
|
|
|
use basic\ModelBasic;
|
|
use traits\ModelTrait;
|
|
|
|
/**直播间用户表
|
|
* Class LiveUser
|
|
* @package app\web\model\live
|
|
*/
|
|
class LiveUser extends ModelBasic
|
|
{
|
|
use ModelTrait;
|
|
|
|
/**用户进入直播间
|
|
* @param $uid
|
|
* @param $live_id
|
|
* @param int $lastCd
|
|
* @return array|bool|false|object|\PDOStatement|string|\think\Model
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public static function setLiveUser($uid, $live_id, $lastCd = 3600)
|
|
{
|
|
$liveUser = self::where(['uid' => $uid, 'live_id' => $live_id])->find();
|
|
$ip = \think\Request::instance()->ip();
|
|
if ($liveUser) {
|
|
if ($liveUser->is_open_ben && $liveUser->open_ben_time > time()) return self::setErrorInfo('您已被禁止访问此直播间!');
|
|
$liveUser->last_ip = $ip;
|
|
$liveUser->visit_num = ($liveUser->last_time + $lastCd) < time() ? $liveUser->visit_num++ : $liveUser->visit_num;
|
|
$liveUser->last_time = time();
|
|
if ($liveUser->is_ban && $liveUser->ban_time && $liveUser->ban_time < time()) {
|
|
$liveUser->is_ban = 0;
|
|
$liveUser->ban_time = 0;
|
|
}
|
|
$liveUser->save();
|
|
return $liveUser;
|
|
} else {
|
|
$data = [
|
|
'uid' => $uid,
|
|
'live_id' => $live_id,
|
|
'add_time' => time(),
|
|
'last_time' => time(),
|
|
'visit_num' => 1,
|
|
'last_ip' => $ip,
|
|
'add_ip' => $ip,
|
|
'is_ban' => 0,
|
|
];
|
|
return self::set($data);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 设置用户上下线
|
|
* @param int $live_id 直播间号
|
|
* @param int $uid 用户id
|
|
* @param int $is_online 上下线
|
|
* @return object
|
|
* */
|
|
public static function setLiveUserOnline($live_id, $uid, $is_online = 1)
|
|
{
|
|
if (self::be(['live_id' => $live_id, 'uid' => $uid, 'is_online' => $is_online])) return true;
|
|
return self::where(['live_id' => $live_id, 'uid' => $uid])->update(['is_online' => $is_online]);
|
|
}
|
|
|
|
}
|
|
|