50 lines
984 B
PHP
50 lines
984 B
PHP
<?php
|
|
|
|
namespace app\store\model;
|
|
|
|
use think\Model;
|
|
|
|
/**
|
|
* 设备模型
|
|
* Class DeviceModel
|
|
* @package app\store\model
|
|
*/
|
|
class DeviceModel extends Model
|
|
{
|
|
// 设置表名
|
|
protected $name = 'device';
|
|
|
|
// 设置主键
|
|
protected $pk = 'id';
|
|
|
|
// 自动时间戳
|
|
protected $autoWriteTimestamp = false;
|
|
|
|
/**
|
|
* 根据设备IMEI获取设备信息
|
|
* @param string $deviceImei 设备IMEI
|
|
* @return array|null
|
|
*/
|
|
public static function getByDeviceImei($deviceImei)
|
|
{
|
|
return self::where('deviceImei', $deviceImei)
|
|
->where('deleteTime', 0)
|
|
->find();
|
|
}
|
|
|
|
/**
|
|
* 检查设备是否在线
|
|
* @param int $deviceId 设备ID
|
|
* @return bool
|
|
*/
|
|
public static function isOnline($deviceId)
|
|
{
|
|
$device = self::where('id', $deviceId)
|
|
->where('deleteTime', 0)
|
|
->find();
|
|
|
|
return $device && $device['alive'] == 1;
|
|
}
|
|
}
|
|
|