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.
48 lines
1.3 KiB
48 lines
1.3 KiB
<?php
|
|
|
|
namespace app\admin\validate;
|
|
|
|
use app\admin\model\Ip as IpModel;
|
|
use think\Validate;
|
|
|
|
class IpValidate extends Validate
|
|
{
|
|
|
|
protected $rule = [
|
|
'id|编号' => 'require|number',
|
|
'ip' => 'require|ip',
|
|
'port|端口' => 'require|number',
|
|
'expire_time|到期时间' => 'require|date',
|
|
'city|城市' => 'require',
|
|
'isp|通讯运营商' => 'require',
|
|
'out_ip|退出IP' => 'require|ip',
|
|
'status|状态' => 'require|in:0,1',
|
|
];
|
|
|
|
protected $message = [];
|
|
|
|
protected $scene= [
|
|
'add' => ['ip', 'port', 'expire_time', 'city', 'isp', 'out_ip', 'status'],
|
|
'edit' => ['id', 'ip', 'port', 'expire_time', 'city', 'isp', 'out_ip', 'status']
|
|
];
|
|
|
|
/**
|
|
*
|
|
* @param $ip
|
|
* @param $port
|
|
* @param int $id
|
|
* @return bool|string
|
|
*/
|
|
public static function checkExistsIp($ip, $port, int $id = 0)
|
|
{
|
|
$IpModel = new IpModel();
|
|
$where = [['ip', '=', $ip], ['port', '=', $port]];
|
|
if ($id > 0) $where[] = ['id', '!=', $id];
|
|
try {
|
|
$existsRes = $IpModel->where($where)->find();
|
|
return $existsRes ? 'IP及端口已存在' : true;
|
|
} catch (\Exception $e) {
|
|
return '验证失败';
|
|
}
|
|
}
|
|
}
|
|
|