Files
cycle_api/app/Models/Api/WebSocket/CustomerWsHistoryModel.php
2024-03-08 00:58:23 +08:00

60 lines
1.7 KiB
PHP

<?php
namespace App\Models\Api\WebSocket;
use App\Models\Api\Base\ApiBaseModel;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class CustomerWsHistoryModel 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();
}
}