添加用户赞助模块(带校验检查与登陆自动填写有关信息)
This commit is contained in:
parent
35f0243616
commit
18b5d94a4d
@ -34,4 +34,5 @@ type IUserV1 interface {
|
||||
|
||||
type ISponsorV1 interface {
|
||||
GetSponsor(context.Context, *request.GetSponsorReq) (*request.GetSponsorRes, error)
|
||||
AddSponsor(context.Context, *request.AddSponsorReq) (*request.AddSponsorRes, error)
|
||||
}
|
||||
|
@ -5,5 +5,9 @@ import "github.com/gogf/gf/v2/frame/g"
|
||||
type GetSponsorReq struct {
|
||||
g.Meta `path:"/list" tags:"获取赞助" method:"get" summary:"获取赞助"`
|
||||
}
|
||||
type AddSponsorReq struct {
|
||||
g.Meta `path:"/add" tags:"添加赞助" method:"post" summary:"添加赞助"`
|
||||
}
|
||||
|
||||
type GetSponsorRes struct{}
|
||||
type AddSponsorRes struct{}
|
||||
|
@ -3,6 +3,7 @@ package sponsor
|
||||
import (
|
||||
"PersonalMain/api"
|
||||
"PersonalMain/api/request"
|
||||
"PersonalMain/internal/model/entity"
|
||||
"PersonalMain/internal/service/SponsorService"
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
@ -27,3 +28,17 @@ func (*ControllerV1) GetSponsor(ctx context.Context, _ *request.GetSponsorReq) (
|
||||
sponorService().GetSponsor(req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// AddSponsor
|
||||
//
|
||||
// 添加赞助
|
||||
func (*ControllerV1) AddSponsor(ctx context.Context, _ *request.AddSponsorReq) (res *request.AddSponsorRes, err error) {
|
||||
req := ghttp.RequestFromCtx(ctx)
|
||||
// 获取业务
|
||||
sponsorAddVO := entity.SponsorAddVO{}
|
||||
err = req.GetRequestStruct(&sponsorAddVO)
|
||||
if err == nil {
|
||||
sponorService().AddSponsor(req, sponsorAddVO)
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
@ -27,3 +27,37 @@ func GetSponsor() *[]do.SponsorDO {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// AddSponsor
|
||||
//
|
||||
// 添加赞助
|
||||
func AddSponsor(getSponsorDO do.SponsorDO) bool {
|
||||
//
|
||||
_, err := g.Model("xf_sponsor").Data(getSponsorDO).Insert()
|
||||
if err == nil {
|
||||
g.Log().Cat("Database").Cat("Sponor").Notice(context.Background(), "xf_sponor 数据表数据添加成功")
|
||||
return true
|
||||
} else {
|
||||
g.Log().Cat("Database").Cat("Sponor").Error(context.Background(), err.Error())
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func GetSponsorType(t uint8) *do.SponsorTypeDO {
|
||||
var getSponsorTypeDO do.SponsorTypeDO
|
||||
result, err := g.Model("xf_sponsor_type").Where("id", t).One()
|
||||
if err == nil {
|
||||
if !result.IsEmpty() {
|
||||
_ = result.Struct(&getSponsorTypeDO)
|
||||
g.Log().Cat("Database").Cat("Sponor").Notice(context.Background(), "xf_sponsor_type 数据表数据提取成功")
|
||||
return &getSponsorTypeDO
|
||||
} else {
|
||||
g.Log().Cat("Database").Cat("Sponor").Notice(context.Background(), "xf_sponsor_type 数据表中没有赞助类型相关信息")
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
g.Log().Cat("Database").Cat("Sponor").Error(context.Background(), err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,77 @@ package SponsorServiceImpl
|
||||
|
||||
import (
|
||||
"PersonalMain/internal/dao/sponsorDAO"
|
||||
"PersonalMain/internal/model/do"
|
||||
"PersonalMain/internal/model/entity"
|
||||
"PersonalMain/internal/service/TokenService"
|
||||
"PersonalMain/internal/service/UserService"
|
||||
"PersonalMain/utility/ErrorCode"
|
||||
"PersonalMain/utility/ResultUtil"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SponsorServiceImpl struct{}
|
||||
|
||||
func tokenService() TokenService.TokenService {
|
||||
return TokenService.NewTokenService()
|
||||
}
|
||||
|
||||
func userService() UserService.UserService {
|
||||
return UserService.NewUserService()
|
||||
}
|
||||
|
||||
// AddSponsor
|
||||
//
|
||||
// 添加赞助
|
||||
func (*SponsorServiceImpl) AddSponsor(req *ghttp.Request, entity entity.SponsorAddVO) {
|
||||
// 检查用户是否登陆
|
||||
getTokenDO := tokenService().GetToken(req)
|
||||
var getUserDO *do.UserDO
|
||||
var check = false
|
||||
if getTokenDO != nil {
|
||||
// 检查token是否有效
|
||||
if tokenService().VerifyToken(getTokenDO) {
|
||||
// 配置用户信息
|
||||
getUserDO = userService().UserCurrent(req)
|
||||
if getUserDO.Permission {
|
||||
check = true
|
||||
}
|
||||
} else {
|
||||
// token无效
|
||||
tokenService().DeleteToken(req)
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.TokenVerifyFailed)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
getUserDO = new(do.UserDO)
|
||||
getUserDO.UserName = entity.Name
|
||||
}
|
||||
// 数据检查
|
||||
getSponsorTypeInfo := sponsorDAO.GetSponsorType(entity.Type)
|
||||
if getSponsorTypeInfo == nil {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.NoSponsorType)
|
||||
return
|
||||
}
|
||||
// 数据处理
|
||||
newSponsorDO := do.SponsorDO{
|
||||
Name: getUserDO.UserName,
|
||||
UserId: getUserDO.Id,
|
||||
Url: entity.Url,
|
||||
Type: entity.Type,
|
||||
Money: entity.Money,
|
||||
CreatedAt: time.Time{},
|
||||
Check: check,
|
||||
}
|
||||
if sponsorDAO.AddSponsor(newSponsorDO) {
|
||||
//TODO:发送邮件
|
||||
ResultUtil.SuccessNoData(req, "添加成功")
|
||||
} else {
|
||||
//TODO:发送邮件
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.AddSponsorFailed)
|
||||
}
|
||||
}
|
||||
|
||||
// GetSponsor
|
||||
//
|
||||
// 获取赞助
|
||||
|
@ -8,7 +8,7 @@ type SponsorDO struct {
|
||||
UserId *uint64 `json:"user_id"`
|
||||
Url *string `json:"url"`
|
||||
Type uint8 `json:"type"`
|
||||
Amount uint64 `json:"amount"`
|
||||
Money uint64 `json:"money"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Check uint8 `json:"check"`
|
||||
Check bool `json:"check"`
|
||||
}
|
||||
|
13
internal/model/do/sponsorTypeDO.go
Normal file
13
internal/model/do/sponsorTypeDO.go
Normal file
@ -0,0 +1,13 @@
|
||||
package do
|
||||
|
||||
import "time"
|
||||
|
||||
type SponsorTypeDO struct {
|
||||
Id *uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
Include bool `json:"include"`
|
||||
Link bool `json:"link"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at"`
|
||||
}
|
@ -10,6 +10,7 @@ type UserDO struct {
|
||||
Qq *string `json:"qq"`
|
||||
Password string `json:"password"`
|
||||
OldPassword *string `json:"old_password"`
|
||||
Permission bool `json:"permission"`
|
||||
EmailVerify bool `json:"email_verify"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt *time.Time `json:"updated_at"`
|
||||
|
9
internal/model/entity/sponsorAddVO.go
Normal file
9
internal/model/entity/sponsorAddVO.go
Normal file
@ -0,0 +1,9 @@
|
||||
package entity
|
||||
|
||||
type SponsorAddVO struct {
|
||||
Name string `json:"name" v:"required|length:1,50#请输入赞助名称|赞助名称长度为:1到:50位"`
|
||||
Url *string `json:"url" v:"url#请输入正确的赞助链接"`
|
||||
Type uint8 `json:"type" v:"required|between:1,4#请选择赞助类型|赞助类型只能为:1或:2"`
|
||||
Money uint64 `json:"money" v:"required|between:1,1000000#请输入赞助金额|赞助金额只能为:1到1000000"`
|
||||
StatementOfAccount *string `json:"statement_of_account" v:"required#请输入流水号,以便博主可以查明账单来源"`
|
||||
}
|
@ -2,6 +2,7 @@ package SponsorService
|
||||
|
||||
import (
|
||||
"PersonalMain/internal/logic/SponsorServiceImpl"
|
||||
"PersonalMain/internal/model/entity"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
@ -11,4 +12,5 @@ func NewSponsorService() SponsorService {
|
||||
|
||||
type SponsorService interface {
|
||||
GetSponsor(*ghttp.Request)
|
||||
AddSponsor(*ghttp.Request, entity.SponsorAddVO)
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ var (
|
||||
LinkAcceptDenied = ErrorCode{output: "LinkAcceptDenied", code: 40305, message: "链接接受协议拒绝"}
|
||||
FriendLinkDoesNotExist = ErrorCode{output: "FriendLinkDoesNotExist", code: 40306, message: "友链不存在"}
|
||||
NoSponsor = ErrorCode{output: "NoSponsor", code: 40307, message: "没有赞助"}
|
||||
AddSponsorFailed = ErrorCode{output: "AddSponsorFailed", code: 40308, message: "添加赞助失败"}
|
||||
NoSponsorType = ErrorCode{output: "NoSponsorType", code: 40309, message: "没有此赞助类型"}
|
||||
ServerUnknownError = ErrorCode{output: "ServerUnknownError", code: 50000, message: "服务器未知错误"}
|
||||
ServerDatabaseInteriorError = ErrorCode{output: "ServerDatabaseInteriorError", code: 50001, message: "服务器数据库内部错误"}
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user