更换model目录
This commit is contained in:
59
app/Models/Api/WebSocket/ApiWsHistoryModel.php
Normal file
59
app/Models/Api/WebSocket/ApiWsHistoryModel.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Api\WebSocket;
|
||||
|
||||
use App\Models\Api\Base\ApiBaseModel;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ApiWsHistoryModel extends ApiBaseModel
|
||||
{
|
||||
protected $table = 'customer_ws_history';
|
||||
protected $primaryKey = 'id';
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'event',
|
||||
'status',
|
||||
'uid',
|
||||
'device',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
const EVENT_ON_CONNECT = 1;
|
||||
const EVENT = [
|
||||
self::EVENT_ON_CONNECT => 'onConnect',
|
||||
];
|
||||
|
||||
const STATUS_SUCCESS = 1;
|
||||
const STATUS_FAIL = 2;
|
||||
const STATUS = [
|
||||
self::STATUS_SUCCESS => '成功',
|
||||
self::STATUS_FAIL => '失败',
|
||||
];
|
||||
|
||||
function getActiveUserIdList($date, $days = 3): array
|
||||
{
|
||||
return $this->newQuery()
|
||||
->where('event', self::EVENT_ON_CONNECT)
|
||||
->where('status', self::STATUS_SUCCESS)
|
||||
->whereBetween(DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d')"), [Carbon::parse($date)->subDays($days - 1)->toDateString(), Carbon::parse($date)->toDateString()])
|
||||
->distinct(['uid'])
|
||||
->get()
|
||||
->pluck('uid')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
//获取判断用户是否活跃
|
||||
//@需要加入缓存-缓存时间为3天
|
||||
function findActiveUserId($uid, $date, $days = 3): array
|
||||
{
|
||||
return $this->newQuery()
|
||||
->where('uid', $uid)
|
||||
->where('event', self::EVENT_ON_CONNECT)
|
||||
->where('status', self::STATUS_SUCCESS)
|
||||
->whereBetween(DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d')"), [Carbon::parse($date)->subDays($days - 1)->toDateString(), Carbon::parse($date)->toDateString()])
|
||||
->first(['uid'])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user