// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\common\model; /** * 模型类:第三方用户信息 * Class UserOauth * @package app\common\model */ class UserOauth extends BaseModel { // 定义表名 protected $name = 'user_oauth'; // 定义主键 protected $pk = 'id'; /** * 是否存在第三方用户 * @param int $userId 用户ID * @param string $oauthType 第三方登陆类型 * @return mixed */ public function isExistOauthType(int $userId, string $oauthType) { return $this->where('user_id', '=', $userId) ->where('oauth_type', '=', $oauthType) ->value($this->getPk()); } /** * 获取第三方用户信息 * @param int $userId 用户ID * @param string $oauthType 第三方登陆类型 * @return array|\think\Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function getOauth(int $userId, string $oauthType) { return (new static)->where('user_id', '=', $userId) ->where('oauth_type', '=', $oauthType) ->find(); } }