2023-08-09 03:46:24 +00:00
|
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
import (
|
2023-08-25 02:08:45 +00:00
|
|
|
|
"fmt"
|
2023-08-14 09:56:06 +00:00
|
|
|
|
"fusenapi/service/repositories"
|
2023-08-09 03:46:24 +00:00
|
|
|
|
"fusenapi/utils/auth"
|
|
|
|
|
"fusenapi/utils/basic"
|
|
|
|
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"fusenapi/server/resource/internal/svc"
|
|
|
|
|
"fusenapi/server/resource/internal/types"
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type LogoCombineLogic struct {
|
|
|
|
|
logx.Logger
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewLogoCombineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogoCombineLogic {
|
|
|
|
|
return &LogoCombineLogic{
|
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
|
ctx: ctx,
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理进入前逻辑w,r
|
|
|
|
|
// func (l *LogoCombineLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
|
|
|
// func (l *LogoCombineLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
|
|
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
func (l *LogoCombineLogic) LogoCombine(req *types.LogoCombineReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
|
|
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
|
|
|
// userinfo 传入值时, 一定不为null
|
|
|
|
|
|
|
|
|
|
if userinfo.IsOnlooker() {
|
|
|
|
|
// 如果是,返回未授权的错误码
|
|
|
|
|
return resp.SetStatus(basic.CodeUnAuth)
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-23 03:24:02 +00:00
|
|
|
|
var userId int64
|
|
|
|
|
var guestId int64
|
2023-08-09 03:46:24 +00:00
|
|
|
|
|
2023-08-23 03:24:02 +00:00
|
|
|
|
// 检查用户是否是游客
|
|
|
|
|
if userinfo.IsGuest() {
|
|
|
|
|
// 如果是,使用游客ID和游客键名格式
|
|
|
|
|
guestId = userinfo.GuestId
|
|
|
|
|
} else {
|
|
|
|
|
// 否则,使用用户ID和用户键名格式
|
|
|
|
|
userId = userinfo.UserId
|
|
|
|
|
}
|
2023-08-14 09:56:06 +00:00
|
|
|
|
res, err := l.svcCtx.Repositories.ImageHandle.LogoCombine(l.ctx, &repositories.LogoCombineReq{
|
2023-08-23 03:24:02 +00:00
|
|
|
|
UserId: userId,
|
|
|
|
|
GuestId: guestId,
|
|
|
|
|
TemplateId: req.TemplateId,
|
|
|
|
|
TemplateTag: req.TemplateTag,
|
2023-08-15 02:58:24 +00:00
|
|
|
|
Website: req.Website,
|
|
|
|
|
Slogan: req.Slogan,
|
|
|
|
|
Phone: req.Phone,
|
|
|
|
|
Address: req.Address,
|
2023-08-16 09:33:34 +00:00
|
|
|
|
|
|
|
|
|
Qrcode: req.Qrcode,
|
2023-08-09 03:46:24 +00:00
|
|
|
|
})
|
2023-08-14 09:56:06 +00:00
|
|
|
|
|
2023-08-09 03:46:24 +00:00
|
|
|
|
if err != nil {
|
2023-08-25 02:08:45 +00:00
|
|
|
|
return resp.SetStatus(basic.CodeServiceErr, fmt.Sprintf("算法请求--LOGO信息--错误:%+v", err))
|
2023-08-09 03:46:24 +00:00
|
|
|
|
}
|
2023-08-14 09:56:06 +00:00
|
|
|
|
|
2023-08-09 03:46:24 +00:00
|
|
|
|
// 返回成功的响应和上传URL
|
|
|
|
|
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
2023-08-14 09:56:06 +00:00
|
|
|
|
"resource_id": res.ResourceId,
|
|
|
|
|
"resource_url": res.ResourceUrl,
|
2023-08-09 03:46:24 +00:00
|
|
|
|
"resource_metadata": "",
|
|
|
|
|
})
|
|
|
|
|
}
|