83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Model;
|
||
|
||
|
||
|
||
use Hyperf\Database\Model\Collection;
|
||
use Hyperf\Snowflake\Concern\Snowflake;
|
||
|
||
/**
|
||
* @property int $user_location_id 主键id
|
||
* @property int $user_id 用户id
|
||
* @property string $lon 经度,范围为 -180~180,负数表示西经
|
||
* @property string $lat 纬度,范围为 -90~90,负数表示南纬
|
||
* @property string $province 省份
|
||
* @property string $city 城市
|
||
* @property string $county 区县
|
||
* @property string $address 详细地址
|
||
* @property string $create_time 创建时间
|
||
* @property string $update_time 更新时间
|
||
*/
|
||
class UserLocation extends Model
|
||
{
|
||
use Snowflake;
|
||
|
||
/**
|
||
* The table associated with the model.
|
||
*/
|
||
protected ?string $table = 'user_location';
|
||
|
||
/**
|
||
* The attributes that are mass assignable.
|
||
*/
|
||
protected array $fillable = ['user_location_id', 'user_id', 'lon', 'lat', 'province', 'city', 'county', 'address', 'create_time', 'update_time'];
|
||
|
||
protected string $primaryKey = "user_location_id";
|
||
|
||
/**
|
||
* 获取信息-单条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->first($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取数据-多
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return Collection|array
|
||
*/
|
||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||
{
|
||
return self::where($params)->get($fields);
|
||
}
|
||
|
||
/**
|
||
* 新增-批量
|
||
* @param array $data 新增数据
|
||
* @return \Hyperf\Database\Model\Model|UserLocation
|
||
*/
|
||
public static function addUserLocation(array $data): \Hyperf\Database\Model\Model|UserLocation
|
||
{
|
||
return self::create($data);
|
||
}
|
||
|
||
/**
|
||
* 修改-批量
|
||
* @param array $params
|
||
* @param array $data
|
||
* @return int
|
||
*/
|
||
public static function editUserLocation(array $params = [], array $data = []): int
|
||
{
|
||
return self::where($params)->update($data);
|
||
}
|
||
}
|