|
@@ -26,31 +26,41 @@ class UserOauth extends BaseModel
|
|
|
protected $pk = 'id';
|
|
protected $pk = 'id';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 是否存在第三方用户
|
|
|
|
|
- * @param int $userId 用户ID
|
|
|
|
|
|
|
+ * 根据openid获取用户ID
|
|
|
|
|
+ * @param string $oauthId 第三方用户唯一标识 (openid)
|
|
|
* @param string $oauthType 第三方登陆类型
|
|
* @param string $oauthType 第三方登陆类型
|
|
|
* @return mixed
|
|
* @return mixed
|
|
|
*/
|
|
*/
|
|
|
- public function isExistOauthType(int $userId, string $oauthType)
|
|
|
|
|
|
|
+ public static function getUserIdByOauthId(string $oauthId, string $oauthType)
|
|
|
{
|
|
{
|
|
|
- return $this->where('user_id', '=', $userId)
|
|
|
|
|
|
|
+ return (new static)->where('oauth_id', '=', $oauthId)
|
|
|
->where('oauth_type', '=', $oauthType)
|
|
->where('oauth_type', '=', $oauthType)
|
|
|
->where('is_delete', '=', 0)
|
|
->where('is_delete', '=', 0)
|
|
|
- ->value($this->getPk());
|
|
|
|
|
|
|
+ ->value('user_id');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 根据openid获取用户ID
|
|
|
|
|
- * @param string $oauthId 第三方用户唯一标识 (openid)
|
|
|
|
|
|
|
+ * 根据用户ID获取OpenID
|
|
|
|
|
+ * @param int $userId 用户ID
|
|
|
* @param string $oauthType 第三方登陆类型
|
|
* @param string $oauthType 第三方登陆类型
|
|
|
* @return mixed
|
|
* @return mixed
|
|
|
*/
|
|
*/
|
|
|
- public static function getUserIdByOauthId(string $oauthId, string $oauthType)
|
|
|
|
|
|
|
+ public static function getOauthIdByUserId(int $userId, string $oauthType)
|
|
|
{
|
|
{
|
|
|
- return (new static)->where('oauth_id', '=', $oauthId)
|
|
|
|
|
|
|
+ return (new static)->where('user_id', '=', $userId)
|
|
|
->where('oauth_type', '=', $oauthType)
|
|
->where('oauth_type', '=', $oauthType)
|
|
|
->where('is_delete', '=', 0)
|
|
->where('is_delete', '=', 0)
|
|
|
- ->value('user_id');
|
|
|
|
|
|
|
+ ->value('oauth_id');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据用户ID获取微信小程序OpenID
|
|
|
|
|
+ * @param int $userId 用户ID
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function getMpWeiXinOpenId(int $userId)
|
|
|
|
|
+ {
|
|
|
|
|
+ return static::getOauthIdByUserId($userId, 'MP-WEIXIN');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|