2023-02-17 17:10:16 +08:00

83 lines
2.4 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\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:微信小程序
* @property string $login_ip 登陆ip
* @property string $last_login_at 最后登陆时间
* @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', 'login_ip', 'last_login_at', 'created_at', 'updated_at'];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['user_id' => 'integer', 'user_type' => 'integer', 'user_status' => 'integer', 'register_method' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
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 $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);
}
}