cmbYouku_Api/app/model/User.php

36 lines
969 B
PHP
Raw Normal View History

2024-07-01 15:57:07 +08:00
<?php
namespace app\model;
use think\Model;
class User extends Model
{
protected $name = 'users';
public function sign(): \think\model\relation\HasOne
{
return $this->hasOne(Sign::class, 'id', 'user_id');
}
/**
* 根据用户id查询
* @param int $userId
* @return User|array|mixed|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getUserById(int $userId)
{
return self::where('id', $userId)->findOrEmpty();
}
/**
* 根据掌上生活openId获取用户信息
* @param string $openId
* @return User|array|mixed|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getUserByOpenId(string $openId)
{
return self::where('open_id', $openId)->findOrEmpty();
}
}