fix:前台从logo数据库存储为用户素材
This commit is contained in:
parent
b9e35bba6c
commit
639e9f8d4a
|
@ -72,6 +72,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/user/logo-templatetag-set",
|
||||
Handler: UserLogoTemplateTagSetHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/user/logo-data-set",
|
||||
Handler: UserLogoDataSetHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/logic"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
)
|
||||
|
||||
func UserLogoDataSetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.UserLogoDataSetReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewUserLogoDataSetLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.UserLogoDataSet(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
97
server/home-user-auth/internal/logic/userlogodatasetlogic.go
Normal file
97
server/home-user-auth/internal/logic/userlogodatasetlogic.go
Normal file
|
@ -0,0 +1,97 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/s3url_to_s3id"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logc"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserLogoDataSetLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserLogoDataSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogoDataSetLogic {
|
||||
return &UserLogoDataSetLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *UserLogoDataSetLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *UserLogoDataSetLogic) UserLogoDataSet(req *types.UserLogoDataSetReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
if userinfo.IsOnlooker() {
|
||||
// 如果是,返回未授权的错误码
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
var userId int64
|
||||
var guestId int64
|
||||
|
||||
// 检查用户是否是游客
|
||||
if userinfo.IsGuest() {
|
||||
// 如果是,使用游客ID和游客键名格式
|
||||
guestId = userinfo.GuestId
|
||||
} else {
|
||||
// 否则,使用用户ID和用户键名格式
|
||||
userId = userinfo.UserId
|
||||
}
|
||||
var logoData = gmodel.FsPreprocessLogo{}
|
||||
result := l.svcCtx.MysqlConn.Model(&gmodel.FsPreprocessLogo{}).Where("id = ?", req.LogoDataId).Take(&logoData)
|
||||
err := result.Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logc.Errorf(l.ctx, "UserLogoDataSet logoData find err:%+v", err)
|
||||
basic.CodeApiErr.Message = "logo data not find"
|
||||
return resp.SetStatus(basic.CodeApiErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeApiErr)
|
||||
}
|
||||
// 新增素材
|
||||
var module = "logo"
|
||||
var nowTime = time.Now().UTC()
|
||||
var resourceId = s3url_to_s3id.GetS3ResourceIdFormUrl(*logoData.ResourceUrl)
|
||||
// 新增素材记录
|
||||
materialInfo := gmodel.FsUserMaterial{
|
||||
Module: &module,
|
||||
UserId: &userId,
|
||||
GuestId: &guestId,
|
||||
ResourceId: &resourceId,
|
||||
ResourceUrl: logoData.ResourceUrl,
|
||||
Ctime: &nowTime,
|
||||
}
|
||||
resCreate := l.svcCtx.MysqlConn.Create(&materialInfo)
|
||||
err = resCreate.Error
|
||||
if err != nil {
|
||||
logc.Errorf(l.ctx, "UserLogoDataSet logoData find err:%+v", err)
|
||||
return resp.SetStatus(basic.CodeApiErr)
|
||||
}
|
||||
|
||||
// 返回成功的响应和上传URL
|
||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||
"user_material_id": materialInfo.Id,
|
||||
})
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *UserLogoDataSetLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
|
@ -5,6 +5,10 @@ import (
|
|||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type UserLogoDataSetReq struct {
|
||||
LogoDataId int64 `form:"logo_data_id"`
|
||||
}
|
||||
|
||||
type UserLogoTemplateTagSetReq struct {
|
||||
TemplateTag string `form:"template_tag"`
|
||||
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
||||
|
|
|
@ -10,60 +10,70 @@ info (
|
|||
import "basic.api"
|
||||
|
||||
service home-user-auth {
|
||||
|
||||
|
||||
// @handler UserRegisterHandler
|
||||
// post /api/user/register(RequestUserRegister) returns (response);
|
||||
//用户字体
|
||||
@handler UserFontsHandler
|
||||
get /api/user/fonts(request) returns (response);
|
||||
|
||||
|
||||
//状态配置
|
||||
@handler UserStatusConfigHandler
|
||||
get /api/user/status-config(request) returns (response);
|
||||
|
||||
|
||||
//联系服务
|
||||
@handler UserContactServiceHandler
|
||||
post /api/user/contact-service (RequestContactService) returns (response);
|
||||
|
||||
|
||||
// @handler UserOderListHandler
|
||||
// get /api/user/order-list(RequestOrderId) returns (response);
|
||||
//删除订单
|
||||
@handler UserOderDeleteHandler
|
||||
post /api/user/order-delete(RequestOrderId) returns (response);
|
||||
|
||||
|
||||
//订单列表
|
||||
@handler UserOrderListHandler
|
||||
get /api/user/order-list (UserOrderListReq) returns (response);
|
||||
|
||||
|
||||
//删除订单
|
||||
@handler UserOrderDeleteHandler
|
||||
get /api/user/order-delete (UserOrderDeleteReq) returns (response);
|
||||
|
||||
|
||||
//取消订单
|
||||
@handler UserOrderCancelHandler
|
||||
get /api/user/order-cancel (UserOrderCancelReq) returns (response);
|
||||
|
||||
|
||||
// 用户logo列表
|
||||
@handler UserLogoListHandler
|
||||
get /api/user/logo-list (UserLogoListReq) returns (response);
|
||||
|
||||
|
||||
// 再来一单
|
||||
@handler UserAgainOrderHandler
|
||||
get /api/user/one-more-order (UserAgainOrderReq) returns (response);
|
||||
|
||||
|
||||
// 保存商户信息
|
||||
@handler UserInfoSetHandler
|
||||
post /api/user/set_user_info (UserInfoSetReq) returns (response);
|
||||
|
||||
|
||||
// 用户logo设置当前
|
||||
@handler UserLogoSetHandler
|
||||
post /api/user/logo-set (UserLogoSetReq) returns (response);
|
||||
|
||||
|
||||
// 用户logo模版信息
|
||||
@handler UserLogoTemplateTagSetHandler
|
||||
post /api/user/logo-templatetag-set (UserLogoTemplateTagSetReq) returns (response);
|
||||
|
||||
// 用户logo数据设置用户logo素材
|
||||
@handler UserLogoDataSetHandler
|
||||
post /api/user/logo-data-set (UserLogoDataSetReq) returns (response);
|
||||
}
|
||||
|
||||
type (
|
||||
UserLogoDataSetReq {
|
||||
LogoDataId int64 `form:"logo_data_id"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
UserLogoTemplateTagSetReq {
|
||||
TemplateTag string `form:"template_tag"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user