97 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
use Hyperf\Snowflake\Concern\Snowflake;
/**
* @property int $user_id 主键
* @property string $user_name 用户名称
* @property string $user_account 账号
* @property string $mobile 手机号
* @property string $wx_mobile 微信手机号
* @property string $user_password 密码
* @property string $salt 密码混淆码
* @property int $user_type 用户类型1:患者 2:医师 3:药师)
* @property int $user_status 状态0:禁用 1:正常 2:删除)
* @property int $register_method 注册方式1:微信小程序 2:后台添加
* @property int $age 年龄
* @property int $sex 性别0:未知 1:男 2:女)
* @property string $email 邮箱
* @property string $avatar 头像
* @property int $is_online 是否在线0:不在线 1:在线)
* @property string $login_at 小程序登陆时间
* @property string $im_login_at im登陆时间
* @property string $login_ip 登陆ip
* @property string $created_by 创建者id后台用户表id前台用户表id
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
*/
class User extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'user';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['user_id', 'user_name', 'user_account', 'mobile', 'wx_mobile', 'user_password', 'salt', 'user_type', 'user_status', 'register_method', 'age', 'sex', 'email', 'avatar', 'is_online', 'login_at', 'im_login_at', 'login_ip', 'created_by', 'created_at', 'updated_at'];
protected string $primaryKey = "user_id";
/**
* 获取用户信息-单条
* @param array $params
* @param array $fields
* @return object|null
*/
public static function getOne(array $params, array $fields = ['*']): object|null
{
$result = self::where($params)->first($fields);
unset($result->user_password);
unset($result->salt);
return $result;
}
/**
* 获取用户信息-多条
* @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 User|\Hyperf\Database\Model\Model
*/
public static function addUser(array $data): User|\Hyperf\Database\Model\Model
{
return self::create($data);
}
/**
* 修改用户-批量
* @param array $params
* @param array $data
* @return int
*/
public static function editUser(array $params = [], array $data = []) : int
{
return self::where($params)->update($data);
}
}