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.
67 lines
1.8 KiB
67 lines
1.8 KiB
<?php
|
|
|
|
namespace app\admin\model;
|
|
|
|
use app\admin\validate\IpValidate;
|
|
use app\common\model\TimeModel;
|
|
|
|
class Ip extends TimeModel
|
|
{
|
|
protected $deleteTime = 'delete_time';
|
|
|
|
protected $defaultSoftDelete = '0';
|
|
|
|
public static $saveField = ['ip', 'port', 'expire_time', 'city', 'isp', 'out_ip', 'status'];
|
|
|
|
public static function getPageList($param = [])
|
|
{
|
|
$page = $param['page'] ?? 1;
|
|
$limit = $param['limit'] ?? 10;
|
|
$where = [['status', '=', 1]];
|
|
if (isset($param['keyword'])) {
|
|
$where[] = ['ip', 'like', '%'.$param['keyword'].'%'];
|
|
}
|
|
$field = 'id, ip';
|
|
$order = 'id desc';
|
|
$count = self::where($where)->count();
|
|
$list = self::where($where)->field($field)->order($order)->page($page, $limit)->select();
|
|
return ['data' => $list, 'count' => $count];
|
|
}
|
|
|
|
/**
|
|
* 更新IP
|
|
* @param $params
|
|
* @return bool
|
|
*/
|
|
public static function updateIp($params): bool
|
|
{
|
|
if (empty($params) || !is_array($params)) return false;
|
|
|
|
$is_true = false;
|
|
|
|
|
|
foreach ($params as $item) {
|
|
|
|
foreach ($item as $key => $value) {
|
|
if (!in_array($key, self::$saveField)) {
|
|
unset($item[$key]);
|
|
}
|
|
}
|
|
|
|
if (isset($item['expire_time'])) {
|
|
$item['expire_time'] = strtotime($item['expire_time']) ?: 0;
|
|
}
|
|
|
|
if (!isset($item['ip']) && !isset($item['port'])) continue;
|
|
|
|
$existsValidate = IpValidate::checkExistsIp($item['ip'], $item['port']);
|
|
|
|
if ($existsValidate === true) {
|
|
$model = new self();
|
|
$model->save($item);
|
|
$is_true = true;
|
|
}
|
|
}
|
|
return $is_true;
|
|
}
|
|
}
|
|
|