赞助内容修改赞助和删除赞助,内容补丁
This commit is contained in:
parent
c1601e53a2
commit
9c1afa1b18
|
@ -37,4 +37,6 @@ type ISponsorV1 interface {
|
|||
AddSponsor(context.Context, *request.AddSponsorReq) (*request.AddSponsorRes, error)
|
||||
GetCheckSponsor(context.Context, *request.GetCheckSponsorReq) (*request.GetCheckSponsorRes, error)
|
||||
CheckSponsor(context.Context, *request.CheckSponsorReq) (*request.CheckSponsorRes, error)
|
||||
EditSponsor(context.Context, *request.EditSponsorReq) (*request.EditSponsorRes, error)
|
||||
DeleteSponsor(context.Context, *request.DeleteSponsorReq) (*request.DeleteSponsorRes, error)
|
||||
}
|
||||
|
|
|
@ -14,8 +14,16 @@ type GetCheckSponsorReq struct {
|
|||
type CheckSponsorReq struct {
|
||||
g.Meta `path:"/" tags:"检查赞助" method:"patch" summary:"检查赞助"`
|
||||
}
|
||||
type EditSponsorReq struct {
|
||||
g.Meta `path:"/edit" tags:"编辑赞助" method:"put" summary:"编辑赞助"`
|
||||
}
|
||||
type DeleteSponsorReq struct {
|
||||
g.Meta `path:"/delete" tags:"删除赞助" method:"delete" summary:"删除赞助"`
|
||||
}
|
||||
|
||||
type GetSponsorRes struct{}
|
||||
type AddSponsorRes struct{}
|
||||
type GetCheckSponsorRes struct{}
|
||||
type CheckSponsorRes struct{}
|
||||
type EditSponsorRes struct{}
|
||||
type DeleteSponsorRes struct{}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"PersonalMain/internal/controller/auth/link/custom/friend"
|
||||
"PersonalMain/internal/controller/auth/link/custom/sponsor"
|
||||
authUser "PersonalMain/internal/controller/auth"
|
||||
"PersonalMain/internal/controller/auth/token"
|
||||
authUser "PersonalMain/internal/controller/auth/user"
|
||||
"PersonalMain/internal/controller/link/custom/friend"
|
||||
"PersonalMain/internal/controller/link/custom/sponsor"
|
||||
"PersonalMain/internal/controller/user"
|
||||
"PersonalMain/internal/middleware"
|
||||
"context"
|
||||
|
@ -56,6 +56,8 @@ var (
|
|||
group.Bind(
|
||||
sponsor.NewSponsorV1().AddSponsor,
|
||||
sponsor.NewSponsorV1().GetSponsor,
|
||||
sponsor.NewSponsorV1().EditSponsor,
|
||||
sponsor.NewSponsorV1().DeleteSponsor,
|
||||
)
|
||||
group.Group("/check", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(middleware.VerifyTokenMiddleware)
|
||||
|
@ -65,12 +67,6 @@ var (
|
|||
)
|
||||
})
|
||||
})
|
||||
group.Group("/location", func(group *ghttp.RouterGroup) {
|
||||
//location.NewLinkCustomLocationV1()
|
||||
})
|
||||
group.Group("/color", func(group *ghttp.RouterGroup) {
|
||||
//color.NewLinkCustomColorV1()
|
||||
})
|
||||
})
|
||||
// 管理员访问
|
||||
//group.Group("/admin", func(group *ghttp.RouterGroup) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package user
|
||||
package auth
|
||||
|
||||
import (
|
||||
"PersonalMain/api"
|
|
@ -32,16 +32,16 @@ func (*ControllerV1) TokenCreate(ctx context.Context, _ *request.TokenCreateReq)
|
|||
token = tokenService.GetToken(req)
|
||||
if tokenService.VerifyToken(token) {
|
||||
// 有效则输出Token依然有效
|
||||
ResultUtil.Success(req, "TokenServiceImpl 依然有效", nil)
|
||||
ResultUtil.Success(req, "Token 依然有效", nil)
|
||||
} else {
|
||||
// 生成新的 Session
|
||||
token = tokenService.CreateToken()
|
||||
ResultUtil.Success(req, "TokenServiceImpl 已重新生成", g.Map{"token": token.Token})
|
||||
ResultUtil.Success(req, "Token 已重新生成", g.Map{"token": token.Token})
|
||||
}
|
||||
} else {
|
||||
// 生成新的 Session
|
||||
token = tokenService.CreateToken()
|
||||
ResultUtil.Success(req, "TokenServiceImpl 已生成", g.Map{"token": token.Token})
|
||||
ResultUtil.Success(req, "Token 已生成", g.Map{"token": token.Token})
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func (*ControllerV1) TokenVerify(ctx context.Context, _ *request.TokenVerifyReq)
|
|||
// 检查 Session 是否有效
|
||||
token = tokenService.GetToken(req)
|
||||
if tokenService.VerifyToken(token) {
|
||||
ResultUtil.SuccessNoData(req, "TokenServiceImpl 有效")
|
||||
ResultUtil.SuccessNoData(req, "Token 有效")
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.TokenVerifyFailed)
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package hello
|
|
@ -1,15 +0,0 @@
|
|||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package hello
|
||||
|
||||
import (
|
||||
"PersonalMain/api"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
func NewV1() api.IHelloV1 {
|
||||
return &ControllerV1{}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package hello
|
||||
|
||||
import (
|
||||
"PersonalMain/api/request"
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Hello(ctx context.Context, _ *request.HelloReq) (res *request.HelloRes, err error) {
|
||||
g.RequestFromCtx(ctx).Response.Writeln("Hello World!")
|
||||
return
|
||||
}
|
|
@ -66,3 +66,31 @@ func (*ControllerV1) CheckSponsor(ctx context.Context, _ *request.CheckSponsorRe
|
|||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
// EditSponsor
|
||||
//
|
||||
// 编辑赞助
|
||||
func (*ControllerV1) EditSponsor(ctx context.Context, _ *request.EditSponsorReq) (res *request.EditSponsorRes, err error) {
|
||||
req := ghttp.RequestFromCtx(ctx)
|
||||
// 获取业务
|
||||
editSponsorVO := entity.SponsorEditVO{}
|
||||
err = req.GetRequestStruct(&editSponsorVO)
|
||||
if err == nil {
|
||||
sponorService().EditSponsor(req, editSponsorVO)
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
// DeleteSponsor
|
||||
//
|
||||
// 删除赞助
|
||||
func (*ControllerV1) DeleteSponsor(ctx context.Context, _ *request.DeleteSponsorReq) (res *request.DeleteSponsorRes, err error) {
|
||||
req := ghttp.RequestFromCtx(ctx)
|
||||
// 获取业务
|
||||
deleteSponsorVO := entity.SponsorDelVO{}
|
||||
err = req.GetRequestStruct(&deleteSponsorVO)
|
||||
if err == nil {
|
||||
sponorService().DeleteSponsor(req, deleteSponsorVO)
|
||||
}
|
||||
return res, err
|
||||
}
|
|
@ -2,6 +2,7 @@ package sponsorDAO
|
|||
|
||||
import (
|
||||
"PersonalMain/internal/model/do"
|
||||
"PersonalMain/internal/model/entity"
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
@ -137,3 +138,52 @@ func DeleteSponsor(id uint64) bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// EditSponsorNoRegisterUser
|
||||
//
|
||||
// 编辑赞助
|
||||
func EditSponsorNoRegisterUser(entity entity.SponsorEditVO) bool {
|
||||
// 获取相应id数据信息
|
||||
_, err := g.Model("xf_sponsor").Data(
|
||||
g.Map{
|
||||
"name": entity.Name,
|
||||
"type": entity.Type,
|
||||
"url": entity.Url,
|
||||
"money": entity.Money,
|
||||
"statement_of_account": entity.StatementOfAccount,
|
||||
"created_at": entity.CreatedAt,
|
||||
"check": 1,
|
||||
}).Where("id", entity.Id).Update()
|
||||
if err == nil {
|
||||
g.Log().Cat("Database").Cat("Sponor").Notice(context.Background(), "xf_sponor 数据表", entity.Id, "数据更新成功")
|
||||
return true
|
||||
} else {
|
||||
g.Log().Cat("Database").Cat("Sponor").Error(context.Background(), err.Error())
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// EditSponsorRegisterUser
|
||||
//
|
||||
// 编辑赞助
|
||||
func EditSponsorRegisterUser(entity entity.SponsorEditVO) bool {
|
||||
// 获取相应id数据信息
|
||||
_, err := g.Model("xf_sponsor").Data(
|
||||
g.Map{
|
||||
"name": entity.Name,
|
||||
"type": entity.Type,
|
||||
"user_id": entity.UserId,
|
||||
"url": entity.UserId,
|
||||
"money": entity.Money,
|
||||
"statement_of_account": entity.StatementOfAccount,
|
||||
"created_at": entity.CreatedAt,
|
||||
"check": 0,
|
||||
}).Where("id", entity.Id).Update()
|
||||
if err == nil {
|
||||
g.Log().Cat("Database").Cat("Sponor").Notice(context.Background(), "xf_sponor 数据表", entity.Id, "数据更新成功")
|
||||
return true
|
||||
} else {
|
||||
g.Log().Cat("Database").Cat("Sponor").Error(context.Background(), err.Error())
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,3 +89,29 @@ func GetUserByToken(token string) *do.UserDO {
|
|||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetUserById
|
||||
//
|
||||
// 通过ID获取用户信息
|
||||
func GetUserById(u uint64) *do.UserDO {
|
||||
userDO := do.UserDO{}
|
||||
result, err := g.Model("xf_user").Where("id = ?", u).One()
|
||||
if err == nil {
|
||||
if result.IsEmpty() {
|
||||
g.Log().Cat("Database").Cat("User").Notice(context.Background(), "无法获取ID为", u, "用户。原因:不存在此用户")
|
||||
return nil
|
||||
} else {
|
||||
err := result.Struct(&userDO)
|
||||
if err != nil {
|
||||
g.Log().Cat("Database").Cat("User").Error(context.Background(), err.Error())
|
||||
return nil
|
||||
} else {
|
||||
g.Log().Cat("Database").Cat("User").Notice(context.Background(), "获取ID为", u, "用户成功")
|
||||
return &userDO
|
||||
}
|
||||
}
|
||||
} else {
|
||||
g.Log().Cat("Database").Cat("User").Error(context.Background(), err.Error())
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,27 +108,27 @@ func (*SponsorServiceImpl) GetCheckSponsor(req *ghttp.Request) {
|
|||
// CheckSponsor
|
||||
//
|
||||
// 检查赞助
|
||||
func (*SponsorServiceImpl) CheckSponsor(req *ghttp.Request, vo entity.CheckSponsorVO) {
|
||||
func (*SponsorServiceImpl) CheckSponsor(req *ghttp.Request, entity entity.CheckSponsorVO) {
|
||||
// 检查用户是否是管理员
|
||||
if userService().CheckAdministrator(req) {
|
||||
// 获取此单位注册信息
|
||||
getSponsorDO := sponsorDAO.GetSponsorById(vo.Id)
|
||||
getSponsorDO := sponsorDAO.GetSponsorById(entity.Id)
|
||||
if getSponsorDO != nil {
|
||||
// 检查是否已经审核过
|
||||
if getSponsorDO.Check {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.SponsorAlreadyCheck)
|
||||
} else {
|
||||
// 对内容内容进行审核管理
|
||||
if vo.Check {
|
||||
if entity.Check {
|
||||
// 更新数据
|
||||
if sponsorDAO.CheckSponsorSuccess(vo.Id, true) {
|
||||
if sponsorDAO.CheckSponsorSuccess(entity.Id, true) {
|
||||
ResultUtil.SuccessOther(req, "CheckSuccess", "审核通过,内容已处理")
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.ServerDatabaseInteriorError)
|
||||
}
|
||||
} else {
|
||||
// 删除数据
|
||||
if sponsorDAO.DeleteSponsor(vo.Id) {
|
||||
if sponsorDAO.DeleteSponsor(entity.Id) {
|
||||
ResultUtil.SuccessOther(req, "CheckDenied", "审核不通过,内容已处理")
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.ServerDatabaseInteriorError)
|
||||
|
@ -142,3 +142,68 @@ func (*SponsorServiceImpl) CheckSponsor(req *ghttp.Request, vo entity.CheckSpons
|
|||
ResultUtil.ErrorNoData(req, ErrorCode.NoPermission)
|
||||
}
|
||||
}
|
||||
|
||||
// EditSponsor
|
||||
//
|
||||
// 编辑赞助
|
||||
func (*SponsorServiceImpl) EditSponsor(req *ghttp.Request, entity entity.SponsorEditVO) {
|
||||
// 检查用户是否是管理员
|
||||
if userService().CheckAdministrator(req) {
|
||||
// 获取此单位注册信息
|
||||
getSponsorDO := sponsorDAO.GetSponsorById(entity.Id)
|
||||
if getSponsorDO != nil {
|
||||
// 检查类型是否存在
|
||||
if sponsorDAO.GetSponsorType(entity.Type) != nil {
|
||||
// 检查为注册用户或非注册用户
|
||||
if entity.UserId == nil {
|
||||
// 对数据进行上传(NoRegisterUser)
|
||||
if sponsorDAO.EditSponsorNoRegisterUser(entity) {
|
||||
ResultUtil.SuccessNoData(req, "编辑成功")
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.ServerDatabaseInteriorError)
|
||||
}
|
||||
} else {
|
||||
// 检查用户是否存在
|
||||
getUserDO := userService().GetUserById(*entity.UserId)
|
||||
if getUserDO != nil {
|
||||
// 对数据进行上传(RegisterUser)
|
||||
if sponsorDAO.EditSponsorRegisterUser(entity) {
|
||||
ResultUtil.SuccessNoData(req, "编辑成功")
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.ServerDatabaseInteriorError)
|
||||
}
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.UserNotExist)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.NoSponsorType)
|
||||
}
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.NoSponsor)
|
||||
}
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.NoPermission)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteSponsor
|
||||
//
|
||||
// 删除赞助
|
||||
func (*SponsorServiceImpl) DeleteSponsor(req *ghttp.Request, entity entity.SponsorDelVO) {
|
||||
// 检查用户是否是管理员
|
||||
if userService().CheckAdministrator(req) {
|
||||
// 获取此单位注册信息
|
||||
getSponsorDO := sponsorDAO.GetSponsorById(entity.Id)
|
||||
if getSponsorDO != nil {
|
||||
// 删除数据
|
||||
if sponsorDAO.DeleteSponsor(entity.Id) {
|
||||
ResultUtil.SuccessNoData(req, "删除成功")
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.ServerDatabaseInteriorError)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ResultUtil.ErrorNoData(req, ErrorCode.NoPermission)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ func tokenService() TokenService.TokenService {
|
|||
// UserRegister
|
||||
//
|
||||
// 用户注册
|
||||
func (_ *DefaultUserImpl) UserRegister(req *ghttp.Request, userVO *entity.UserRegisterVO) {
|
||||
func (*DefaultUserImpl) UserRegister(req *ghttp.Request, userVO *entity.UserRegisterVO) {
|
||||
// 密码加密
|
||||
enPassword, err := bcrypt.GenerateFromPassword([]byte(userVO.Password), bcrypt.DefaultCost)
|
||||
if err == nil {
|
||||
|
@ -62,7 +62,7 @@ func (_ *DefaultUserImpl) UserRegister(req *ghttp.Request, userVO *entity.UserRe
|
|||
// UserLogin
|
||||
//
|
||||
// 用户登录
|
||||
func (_ *DefaultUserImpl) UserLogin(req *ghttp.Request, userVO *entity.UserLoginVO) {
|
||||
func (*DefaultUserImpl) UserLogin(req *ghttp.Request, userVO *entity.UserLoginVO) {
|
||||
// 获取数据库中用户信息
|
||||
getUserDO := userDAO.GetUser(userVO.User)
|
||||
if getUserDO != nil {
|
||||
|
@ -142,3 +142,10 @@ func (*DefaultUserImpl) CheckAdministrator(req *ghttp.Request) bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// GetUserById
|
||||
//
|
||||
// 通过id获取用户信息
|
||||
func (*DefaultUserImpl) GetUserById(u uint64) *do.UserDO {
|
||||
return userDAO.GetUserById(u)
|
||||
}
|
||||
|
|
5
internal/model/entity/sponsorDelVO.go
Normal file
5
internal/model/entity/sponsorDelVO.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package entity
|
||||
|
||||
type SponsorDelVO struct {
|
||||
Id uint64 `json:"id" v:"required#id不能为空"`
|
||||
}
|
14
internal/model/entity/sponsorEditVO.go
Normal file
14
internal/model/entity/sponsorEditVO.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package entity
|
||||
|
||||
import "time"
|
||||
|
||||
type SponsorEditVO struct {
|
||||
Id uint64 `json:"id" v:"required|between:1,18446744073709551615#请输入赞助id|赞助id只能为:1到18446744073709551615"`
|
||||
Name string `json:"name" v:"required|length:1,50#请输入赞助名称|赞助名称长度为:1到:50位"`
|
||||
UserId *uint64 `json:"user_id"`
|
||||
Url *string `json:"url" v:"url#请输入正确的赞助链接"`
|
||||
Type uint8 `json:"type" v:"required|between:1,255#请选择赞助类型|赞助类型参考列表内容"`
|
||||
Money uint64 `json:"money" v:"required|between:1,18446744073709551615#请输入赞助金额|赞助金额只能为:1到18446744073709551615"`
|
||||
StatementOfAccount *string `json:"statement_of_account"`
|
||||
CreatedAt time.Time `json:"created_at" v:"required#请输入赞助时间"`
|
||||
}
|
|
@ -15,4 +15,6 @@ type SponsorService interface {
|
|||
AddSponsor(*ghttp.Request, entity.SponsorAddVO)
|
||||
GetCheckSponsor(*ghttp.Request)
|
||||
CheckSponsor(*ghttp.Request, entity.CheckSponsorVO)
|
||||
EditSponsor(*ghttp.Request, entity.SponsorEditVO)
|
||||
DeleteSponsor(*ghttp.Request, entity.SponsorDelVO)
|
||||
}
|
||||
|
|
|
@ -18,4 +18,5 @@ type UserService interface {
|
|||
UserLogout(*ghttp.Request)
|
||||
UserCurrent(*ghttp.Request) *do.UserDO
|
||||
CheckAdministrator(*ghttp.Request) bool
|
||||
GetUserById(uint64) *do.UserDO
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user