重新初始化项目

This commit is contained in:
2023-04-27 15:56:12 +08:00
parent 10546eb629
commit d6e256ef9e
50 changed files with 1255 additions and 308 deletions

View File

@@ -6,7 +6,6 @@ import (
"Lee-WineList/core"
"Lee-WineList/model/param"
"Lee-WineList/oauth2"
"Lee-WineList/repository"
"context"
"encoding/json"
"fmt"
@@ -30,7 +29,6 @@ func (l loginApi) Login(ctx *gin.Context) {
core.R(ctx).FailWithMessage(err.Error())
return
}
// 获取用户基础账号信息
userId, err := oauth2.OAuthServer.UserAuthorizationHandler(ctx.Writer, ctx.Request)
if err != nil {
@@ -40,10 +38,13 @@ func (l loginApi) Login(ctx *gin.Context) {
}
// 重新组装登录参数
ctx.Request.Form = url.Values{
"username": {userId},
"password": {p.Password},
"scope": {"ALL"},
"grant_type": {"password"},
"username": {userId},
"password": {p.Password},
"scope": {"ALL"},
"grant_type": {"password"},
"invite_code": {p.InviteCode},
"nickName": {p.NickName},
"avatarUrl": {p.AvatarUrl},
}
// 参数解析成功,进行登录
@@ -52,11 +53,7 @@ func (l loginApi) Login(ctx *gin.Context) {
core.R(ctx).FailWithMessage("系统错误,登录失败")
return
}
// 登录成功才更新登录时间
if ctx.Writer.Status() == http.StatusOK {
// 登录成功更新登录时间和IP
go repository.Login().UpdateLastLoginInfo(userId, ctx.ClientIP(), p.UserIdentity)
}
}
// Refresh 刷新登录Token
@@ -107,3 +104,13 @@ func (loginApi) Logout(ctx *gin.Context) {
r.Ok()
}
func (l loginApi) GetWeChatToken(c *gin.Context) {
wechaetToken, err := http.Get("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx3d38ce1103a82225&secret=3c41ca428b4d0f43cfaef6f567a1cc06")
if err != nil {
log.Errorf("获取微信Token失败: %v", err)
core.R(c).FailWithMessage(err.Error())
return
}
core.R(c).OkWithData(wechaetToken)
}

View File

@@ -32,6 +32,7 @@ func (u userApi) GetUser(ctx *gin.Context) {
// 转换为VO
var v vo.UserVO
v.ParseOrdinary(ue)
core.R(ctx).OkWithData(v)
}
@@ -56,11 +57,11 @@ func (u userApi) BindingWeChat(ctx *gin.Context) {
core.R(ctx).FailWithMessage("系统错误,请稍后再试")
return
}
log.Debugf("用户[%v]的UnionId为[%v]OpenId为[%v]", loginUser.Id, unionId, openId)
if repository.User().CheckUnionIdIsExist(unionId, openId) {
core.R(ctx).FailWithMessage("该微信已绑定其他账号")
return
}
//log.Debugf("用户[%v]的UnionId为[%v]OpenId为[%v]", loginUser.Id, unionId, openId)
//if repository.User().CheckUnionIdIsExist(unionId, openId) {
// core.R(ctx).FailWithMessage("该微信已绑定其他账号")
// return
//}
// 解析成功,修改用户信息
loginUser.WechatUnionId = &unionId
loginUser.WechatOpenId = &openId
@@ -100,5 +101,6 @@ func (u userApi) UpdateUser(ctx *gin.Context) {
core.R(ctx).FailWithMessage("修改用户信息失败: " + err.Error())
return
}
// 操作成功,更新头像和昵称
core.R(ctx).Ok()
}

50
api/app/wine.go Normal file
View File

@@ -0,0 +1,50 @@
package app
import (
"Lee-WineList/core"
"Lee-WineList/model/param"
"Lee-WineList/repository"
"github.com/gin-gonic/gin"
)
type wineApi struct {
}
func WineApi() *wineApi {
return &wineApi{}
}
// GetList 获取酒品列表
func (w *wineApi) GetList(ctx *gin.Context) {
var p param.GetWineList
if err := ctx.ShouldBind(&p); err != nil {
core.R(ctx).FailWithMessage(err.Error())
return
}
wines, err := repository.Wine().GetWineList(p)
if err != nil {
core.R(ctx).FailWithMessage(err.Error())
return
}
core.R(ctx).OkWithData(wines)
}
// Add 添加酒单
func (w *wineApi) Add(ctx *gin.Context) {
var p param.AddWine
if err := ctx.ShouldBind(&p); err != nil {
core.R(ctx).FailWithMessage(err.Error())
return
}
if err := repository.Wine().Add(p); err != nil {
core.R(ctx).FailWithMessage(err.Error())
return
}
core.R(ctx).OkWithMessage("添加成功")
}