Merge branch 'develop' into feature/mhw-v1.01
This commit is contained in:
commit
37fc648025
4
.gitignore
vendored
4
.gitignore
vendored
@ -42,4 +42,6 @@ proxyserver/proxyserver
|
|||||||
|
|
||||||
shared-state
|
shared-state
|
||||||
|
|
||||||
*.zip
|
*.zip
|
||||||
|
|
||||||
|
vendor
|
@ -43,8 +43,8 @@ func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tag
|
|||||||
err = db.Limit(limit).Find(&resp).Error
|
err = db.Limit(limit).Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, tagName string, fields ...string) (resp *FsProductTemplateTags, err error) {
|
func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, templateTagName string, fields ...string) (resp *FsProductTemplateTags, err error) {
|
||||||
db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", tagName, 1)
|
db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", templateTagName, 1)
|
||||||
if len(fields) != 0 {
|
if len(fields) != 0 {
|
||||||
db = db.Select(fields[0])
|
db = db.Select(fields[0])
|
||||||
}
|
}
|
||||||
|
@ -142,3 +142,7 @@ func (m *FsUserMaterialModel) GetListByUser(ctx context.Context, userId, guestId
|
|||||||
Where(cond).Order("id DESC").Limit(limit).Find(&resp).Error
|
Where(cond).Order("id DESC").Limit(limit).Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
func (m *FsUserMaterialModel) FindOneByLogoResourceId(ctx context.Context, logoResourceId string) (resp *FsUserMaterial, err error) {
|
||||||
|
err = m.db.WithContext(ctx).Model(&FsUserMaterial{}).Where("`resource_id` = ?", logoResourceId).Take(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
2
proxyserver/.gitignore
vendored
Normal file
2
proxyserver/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
main
|
||||||
|
proxyserver
|
@ -1,5 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
go mod tidy
|
||||||
|
go mod vendor
|
||||||
|
|
||||||
# 定义一个函数来在每个服务器目录下运行 go run <server_name>.go
|
# 定义一个函数来在每个服务器目录下运行 go run <server_name>.go
|
||||||
run_server() {
|
run_server() {
|
||||||
server_name=$1
|
server_name=$1
|
||||||
@ -14,8 +17,7 @@ run_server() {
|
|||||||
|
|
||||||
# 导航到相应的目录
|
# 导航到相应的目录
|
||||||
cd server/$server_name
|
cd server/$server_name
|
||||||
|
go build
|
||||||
go build -race
|
|
||||||
[ -f .gitignore ] || echo $server_name > .gitignore
|
[ -f .gitignore ] || echo $server_name > .gitignore
|
||||||
# 使用 screen 运行 go run <server_name>.go
|
# 使用 screen 运行 go run <server_name>.go
|
||||||
screen -dmS $server_name -L ./$server_name
|
screen -dmS $server_name -L ./$server_name
|
||||||
@ -24,7 +26,8 @@ run_server() {
|
|||||||
cd - > /dev/null
|
cd - > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
find /tmp/go-build* -mmin +5 -delete
|
find /tmp/go-build* -mmin +5 -exec rm -rf {} +
|
||||||
|
find /tmp/go-link* -mmin +5 -exec rm -rf {} +
|
||||||
|
|
||||||
# 列出所有服务器目录
|
# 列出所有服务器目录
|
||||||
server_dirs=() # 初始化一个空数组
|
server_dirs=() # 初始化一个空数组
|
||||||
@ -37,7 +40,7 @@ done
|
|||||||
|
|
||||||
# 在每个服务器目录下运行相应的 go 程序
|
# 在每个服务器目录下运行相应的 go 程序
|
||||||
for server_dir in "${server_dirs[@]}"; do
|
for server_dir in "${server_dirs[@]}"; do
|
||||||
run_server $server_dir
|
run_server $server_dir &
|
||||||
done
|
done
|
||||||
|
|
||||||
# 定义目录和screen名称
|
# 定义目录和screen名称
|
||||||
@ -46,12 +49,11 @@ screen_name="proxyserver"
|
|||||||
|
|
||||||
# 进入目录
|
# 进入目录
|
||||||
cd $dir_path
|
cd $dir_path
|
||||||
|
|
||||||
# 检查是否存在screen session
|
# 检查是否存在screen session
|
||||||
if screen -list | grep -q "$screen_name"; then
|
if screen -list | grep -q "$screen_name"; then
|
||||||
# 结束存在的screen session
|
# 结束存在的screen session
|
||||||
screen -S $screen_name -X quit
|
screen -S $screen_name -X quit
|
||||||
fi
|
fi
|
||||||
|
go build
|
||||||
# 启动新的screen session并运行go程序
|
# 启动新的screen session并运行go程序
|
||||||
screen -dmS $screen_name -L go run main.go
|
screen -dmS $screen_name -L ./$screen_name
|
@ -44,46 +44,23 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo
|
|||||||
// 如果是,返回未授权的错误码
|
// 如果是,返回未授权的错误码
|
||||||
return resp.SetStatus(basic.CodeUnAuth)
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
}
|
}
|
||||||
if req.LogoSelectedId == 0 {
|
|
||||||
return resp.SetStatus(basic.CodeApiErr, "logo logo_selected_id not null")
|
|
||||||
}
|
|
||||||
if req.TemplateTag == "" {
|
if req.TemplateTag == "" {
|
||||||
return resp.SetStatus(basic.CodeApiErr, "logo template tag not null")
|
return resp.SetStatus(basic.CodeApiErr, "logo template tag not null")
|
||||||
}
|
}
|
||||||
var userId int64
|
var userId int64
|
||||||
var guestId int64
|
var guestId int64
|
||||||
NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
|
||||||
NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", req.LogoSelectedId)
|
|
||||||
|
|
||||||
if userinfo.IsGuest() {
|
if userinfo.IsGuest() {
|
||||||
// 如果是,使用游客ID和游客键名格式
|
// 如果是,使用游客ID和游客键名格式
|
||||||
guestId = userinfo.GuestId
|
guestId = userinfo.GuestId
|
||||||
NewFsUserMaterialModelRow.Where("guest_id = ?", guestId)
|
|
||||||
} else {
|
} else {
|
||||||
// 否则,使用用户ID和用户键名格式
|
// 否则,使用用户ID和用户键名格式
|
||||||
userId = userinfo.UserId
|
userId = userinfo.UserId
|
||||||
NewFsUserMaterialModelRow.Where("user_id = ?", userId)
|
|
||||||
}
|
|
||||||
|
|
||||||
userMaterialInfo, err := NewFsUserMaterialModel.FindOne(l.ctx, NewFsUserMaterialModelRow.Model(&gmodel.FsUserMaterial{}))
|
|
||||||
if err != nil {
|
|
||||||
logc.Errorf(l.ctx, "FsUserMaterial FindOne err:%+v", err)
|
|
||||||
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var nowTime = time.Now().UTC()
|
var nowTime = time.Now().UTC()
|
||||||
err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
|
err := l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
var metadataMapOldUserMaterial map[string]interface{}
|
|
||||||
if userMaterialInfo.Metadata != nil {
|
|
||||||
err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial)
|
|
||||||
if err != nil {
|
|
||||||
logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var module = "profile"
|
var module = "profile"
|
||||||
|
|
||||||
var userInfo = &gmodel.FsUserInfo{}
|
var userInfo = &gmodel.FsUserInfo{}
|
||||||
BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module)
|
BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module)
|
||||||
if userId > 0 {
|
if userId > 0 {
|
||||||
@ -92,7 +69,7 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo
|
|||||||
BuilderDB.Where("guest_id=?", guestId)
|
BuilderDB.Where("guest_id=?", guestId)
|
||||||
}
|
}
|
||||||
userInfoFirstRes := BuilderDB.First(userInfo)
|
userInfoFirstRes := BuilderDB.First(userInfo)
|
||||||
err = userInfoFirstRes.Error
|
err := userInfoFirstRes.Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logc.Errorf(l.ctx, "userInfo First err:%+v", err)
|
logc.Errorf(l.ctx, "userInfo First err:%+v", err)
|
||||||
@ -110,8 +87,25 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo
|
|||||||
|
|
||||||
var metadataChildUserInfo = make(map[string]interface{}, 1)
|
var metadataChildUserInfo = make(map[string]interface{}, 1)
|
||||||
|
|
||||||
_, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"]
|
userInfoLogoSelectedData, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"]
|
||||||
if userInfoLogoSelectedEx {
|
if userInfoLogoSelectedEx {
|
||||||
|
logoSelectedId := int64(userInfoLogoSelectedData.(map[string]interface{})["logo_selected_id"].(float64))
|
||||||
|
NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
||||||
|
NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", logoSelectedId)
|
||||||
|
userMaterialInfo, err := NewFsUserMaterialModel.FindOne(l.ctx, NewFsUserMaterialModelRow.Model(&gmodel.FsUserMaterial{}))
|
||||||
|
if err != nil {
|
||||||
|
logc.Errorf(l.ctx, "FsUserMaterial FindOne err:%+v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var metadataMapOldUserMaterial map[string]interface{}
|
||||||
|
if userMaterialInfo.Metadata != nil {
|
||||||
|
err = json.Unmarshal(*userMaterialInfo.Metadata, &metadataMapOldUserMaterial)
|
||||||
|
if err != nil {
|
||||||
|
logc.Errorf(l.ctx, "userMaterialInfo Metadata Unmarshal err:%+v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"]
|
userMaterialTemplateTagData, userMaterialTemplateTagEx := metadataMapOldUserMaterial["template_tag"]
|
||||||
if !userMaterialTemplateTagEx {
|
if !userMaterialTemplateTagEx {
|
||||||
logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err)
|
logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err)
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UserLogoTemplateTagSetReq struct {
|
type UserLogoTemplateTagSetReq struct {
|
||||||
LogoSelectedId int64 `form:"logo_selected_id"`
|
|
||||||
TemplateTag string `form:"template_tag"`
|
TemplateTag string `form:"template_tag"`
|
||||||
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
||||||
}
|
}
|
||||||
@ -230,10 +229,10 @@ type File struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
TotalCount int64 `json:"totalCount"`
|
TotalCount int64 `json:"total_count"`
|
||||||
PageCount int64 `json:"pageCount"`
|
PageCount int64 `json:"page_count"`
|
||||||
CurrentPage int `json:"currentPage"`
|
CurrentPage int `json:"current_page"`
|
||||||
PerPage int `json:"perPage"`
|
PerPage int `json:"per_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set 设置Response的Code和Message值
|
// Set 设置Response的Code和Message值
|
||||||
|
1
server/order/.gitignore
vendored
Normal file
1
server/order/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
order
|
@ -0,0 +1,35 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/product-template-tag/internal/logic"
|
||||||
|
"fusenapi/server/product-template-tag/internal/svc"
|
||||||
|
"fusenapi/server/product-template-tag/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetTemplateTagColorHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.GetTemplateTagColorReq
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewGetTemplateTagColorLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.GetTemplateTagColor(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/api/product-template-tag/get_product_template_tags",
|
Path: "/api/product-template-tag/get_product_template_tags",
|
||||||
Handler: GetProductTemplateTagsHandler(serverCtx),
|
Handler: GetProductTemplateTagsHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/api/product-template-tag/get_template_tag_color",
|
||||||
|
Handler: GetTemplateTagColorHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func NewGetProductTemplateTagsLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
|||||||
// func (l *GetProductTemplateTagsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
// func (l *GetProductTemplateTagsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
// }
|
// }
|
||||||
type logoSelect struct {
|
type LogoSelect struct {
|
||||||
LogoSelected struct {
|
LogoSelected struct {
|
||||||
LogoSelectedId int `json:"logo_selected_id"`
|
LogoSelectedId int `json:"logo_selected_id"`
|
||||||
TemplateTagSelected struct {
|
TemplateTagSelected struct {
|
||||||
@ -73,29 +73,37 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
|
|||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
|
||||||
}
|
}
|
||||||
var mapMaterialTemplateTag map[string][][]string
|
//解析模板标签颜色
|
||||||
|
var mapMaterialTemplateTagColors map[string][][]string
|
||||||
b, _ := json.Marshal(metaData["template_tag"])
|
b, _ := json.Marshal(metaData["template_tag"])
|
||||||
if err = json.Unmarshal(b, &mapMaterialTemplateTag); err != nil {
|
if err = json.Unmarshal(b, &mapMaterialTemplateTagColors); err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag")
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag")
|
||||||
}
|
}
|
||||||
|
//解析单纯的模板标签用于排序
|
||||||
|
var simpleTemplateTags []string
|
||||||
|
b, _ = json.Marshal(metaData["template_tag_id"])
|
||||||
|
if err = json.Unmarshal(b, &simpleTemplateTags); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag_id")
|
||||||
|
}
|
||||||
//从用户元数据获取选中的颜色数据
|
//从用户元数据获取选中的颜色数据
|
||||||
mapSelectColor := make(map[string]int) //key是模板标签val是选中的索引
|
mapSelectColor := make(map[string]int) //key是模板标签val是选中的索引
|
||||||
if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" {
|
if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" {
|
||||||
//解析用户信息元数据
|
//解析用户信息元数据
|
||||||
var logoSelectInfo logoSelect
|
var logoSelectInfo LogoSelect
|
||||||
if err = json.Unmarshal([]byte(*logoInfo.UserInfoMetadata), &logoSelectInfo); err != nil {
|
if err = json.Unmarshal([]byte(*logoInfo.UserInfoMetadata), &logoSelectInfo); err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user info metadata")
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user info metadata")
|
||||||
}
|
}
|
||||||
//设置选中
|
//设置选中
|
||||||
key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag
|
key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag
|
||||||
if _, ok := mapMaterialTemplateTag[key]; ok {
|
if _, ok := mapMaterialTemplateTagColors[key]; ok {
|
||||||
mapSelectColor[key] = logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex
|
mapSelectColor[key] = logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var templateTagNameList []string
|
var templateTagNameList []string
|
||||||
for templateTag, _ := range mapMaterialTemplateTag {
|
for templateTag, _ := range mapMaterialTemplateTagColors {
|
||||||
templateTagNameList = append(templateTagNameList, templateTag)
|
templateTagNameList = append(templateTagNameList, templateTag)
|
||||||
}
|
}
|
||||||
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC")
|
productTemplateTags, err = l.svcCtx.AllModels.FsProductTemplateTags.GetListByTagNames(l.ctx, templateTagNameList, req.Limit, 1, "id DESC")
|
||||||
@ -122,15 +130,23 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
|
|||||||
}
|
}
|
||||||
mapResourceMetadata[*v.ResourceUrl] = metadata
|
mapResourceMetadata[*v.ResourceUrl] = metadata
|
||||||
}
|
}
|
||||||
|
//排序
|
||||||
|
for index, templateTagStr := range simpleTemplateTags {
|
||||||
|
for k, v := range productTemplateTags {
|
||||||
|
if templateTagStr == *v.TemplateTag {
|
||||||
|
productTemplateTags[k], productTemplateTags[index] = productTemplateTags[index], productTemplateTags[k]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags))
|
list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags))
|
||||||
for _, templateInfo := range productTemplateTags {
|
for _, templateTagInfo := range productTemplateTags {
|
||||||
colors := make([][]string, 0, 10)
|
colors := make([][]string, 0, 10)
|
||||||
SelectedColorIndex := 0
|
SelectedColorIndex := 0
|
||||||
isDefaultTemplateTag := false
|
isDefaultTemplateTag := false
|
||||||
//查看用户素材中标签对应的颜色
|
//查看用户素材中标签对应的颜色
|
||||||
if colorsSet, ok := mapMaterialTemplateTag[*templateInfo.TemplateTag]; ok {
|
if colorsSet, ok := mapMaterialTemplateTagColors[*templateTagInfo.TemplateTag]; ok {
|
||||||
//是不是选中的标签
|
//是不是选中的标签
|
||||||
if selectIndex, ok := mapSelectColor[*templateInfo.TemplateTag]; ok {
|
if selectIndex, ok := mapSelectColor[*templateTagInfo.TemplateTag]; ok {
|
||||||
isDefaultTemplateTag = true
|
isDefaultTemplateTag = true
|
||||||
//标签中选中的索引
|
//标签中选中的索引
|
||||||
SelectedColorIndex = selectIndex
|
SelectedColorIndex = selectIndex
|
||||||
@ -139,19 +155,19 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
|
|||||||
colors = colorsSet
|
colors = colorsSet
|
||||||
}
|
}
|
||||||
var templateTagGroups []interface{}
|
var templateTagGroups []interface{}
|
||||||
if templateInfo.Groups != nil && *templateInfo.Groups != "" {
|
if templateTagInfo.Groups != nil && *templateTagInfo.Groups != "" {
|
||||||
if err = json.Unmarshal([]byte(*templateInfo.Groups), &templateTagGroups); err != nil {
|
if err = json.Unmarshal([]byte(*templateTagInfo.Groups), &templateTagGroups); err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse groups")
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse groups")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list = append(list, types.GetProductTemplateTagsRsp{
|
list = append(list, types.GetProductTemplateTagsRsp{
|
||||||
Id: templateInfo.Id,
|
Id: templateTagInfo.Id,
|
||||||
TemplateTag: *templateInfo.TemplateTag,
|
TemplateTag: *templateTagInfo.TemplateTag,
|
||||||
IsDefaultTemplateTag: isDefaultTemplateTag,
|
IsDefaultTemplateTag: isDefaultTemplateTag,
|
||||||
TemplateTagGroups: templateTagGroups,
|
TemplateTagGroups: templateTagGroups,
|
||||||
Cover: *templateInfo.Cover,
|
Cover: *templateTagInfo.Cover,
|
||||||
CoverMetadata: mapResourceMetadata[*templateInfo.Cover],
|
CoverMetadata: mapResourceMetadata[*templateTagInfo.Cover],
|
||||||
Colors: colors,
|
Colors: colors,
|
||||||
SelectedColorIndex: SelectedColorIndex,
|
SelectedColorIndex: SelectedColorIndex,
|
||||||
})
|
})
|
||||||
|
@ -0,0 +1,109 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/product-template-tag/internal/svc"
|
||||||
|
"fusenapi/server/product-template-tag/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetTemplateTagColorLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetTemplateTagColorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTemplateTagColorLogic {
|
||||||
|
return &GetTemplateTagColorLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *GetTemplateTagColorLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *GetTemplateTagColorLogic) GetTemplateTagColor(req *types.GetTemplateTagColorReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if req.SelectedColorIndex < 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param selected_color_index is invalid")
|
||||||
|
}
|
||||||
|
//根据logo查询素材资源
|
||||||
|
s := strings.Split(req.Logo, "/")
|
||||||
|
if len(s) <= 1 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid logo")
|
||||||
|
}
|
||||||
|
resourceId := s[len(s)-1]
|
||||||
|
var (
|
||||||
|
userMaterial *gmodel.FsUserMaterial
|
||||||
|
templateTagInfo *gmodel.FsProductTemplateTags
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
//获取模板标签信息
|
||||||
|
templateTagInfo, err = l.svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(l.ctx, req.TemplateTag)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the template tag is not exists")
|
||||||
|
}
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template tag info")
|
||||||
|
}
|
||||||
|
userMaterial, err = l.svcCtx.AllModels.FsUserMaterial.FindOneByLogoResourceId(l.ctx, resourceId)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the logo is not found")
|
||||||
|
}
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user material")
|
||||||
|
}
|
||||||
|
if userMaterial.Metadata == nil || len(*userMaterial.Metadata) == 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "the user material is empty")
|
||||||
|
}
|
||||||
|
//解析用户素材元数据
|
||||||
|
var metaData map[string]interface{}
|
||||||
|
if err = json.Unmarshal(*userMaterial.Metadata, &metaData); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user metadata")
|
||||||
|
}
|
||||||
|
var mapMaterialTemplateTag map[string][][]string
|
||||||
|
b, _ := json.Marshal(metaData["template_tag"])
|
||||||
|
if err = json.Unmarshal(b, &mapMaterialTemplateTag); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "invalid format of metadata`s template_tag")
|
||||||
|
}
|
||||||
|
colors, ok := mapMaterialTemplateTag[req.TemplateTag]
|
||||||
|
if !ok {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "the template tag is not found from this logo material`s metadata")
|
||||||
|
}
|
||||||
|
if req.SelectedColorIndex >= len(colors) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "select color index is out of range !!")
|
||||||
|
}
|
||||||
|
var templateTagGroups interface{}
|
||||||
|
if templateTagInfo.Groups != nil && *templateTagInfo.Groups != "" {
|
||||||
|
if err = json.Unmarshal([]byte(*templateTagInfo.Groups), &templateTagGroups); err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse template tag`s groups info")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTemplateTagColorRsp{
|
||||||
|
Colors: colors,
|
||||||
|
SelectedColorIndex: req.SelectedColorIndex,
|
||||||
|
TemplateTagGroups: templateTagGroups,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *GetTemplateTagColorLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
@ -20,6 +20,18 @@ type GetProductTemplateTagsRsp struct {
|
|||||||
SelectedColorIndex int `json:"selected_color_index"`
|
SelectedColorIndex int `json:"selected_color_index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetTemplateTagColorReq struct {
|
||||||
|
Logo string `form:"logo"`
|
||||||
|
TemplateTag string `form:"template_tag"`
|
||||||
|
SelectedColorIndex int `form:"selected_color_index"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetTemplateTagColorRsp struct {
|
||||||
|
Colors [][]string `json:"colors"`
|
||||||
|
SelectedColorIndex int `json:"selected_color_index"`
|
||||||
|
TemplateTagGroups interface{} `json:"template_tag_groups"`
|
||||||
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,22 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||||||
if req.CurrentPage <= 0 {
|
if req.CurrentPage <= 0 {
|
||||||
req.CurrentPage = constants.DEFAULT_PAGE
|
req.CurrentPage = constants.DEFAULT_PAGE
|
||||||
}
|
}
|
||||||
|
//获取全部购物车id
|
||||||
|
allCratIds, count, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
||||||
|
UserId: userinfo.UserId,
|
||||||
|
Fields: "id",
|
||||||
|
Sort: "id DESC",
|
||||||
|
Page: 1,
|
||||||
|
Limit: 1000,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get your shopping carts")
|
||||||
|
}
|
||||||
|
ids := make([]int64, 0, count)
|
||||||
|
for _, v := range allCratIds {
|
||||||
|
ids = append(ids, v.Id)
|
||||||
|
}
|
||||||
limit := 10
|
limit := 10
|
||||||
//获取用户购物车列表
|
//获取用户购物车列表
|
||||||
carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
||||||
@ -191,6 +207,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||||||
StepNum: stepQuantityList,
|
StepNum: stepQuantityList,
|
||||||
IsInvalid: false,
|
IsInvalid: false,
|
||||||
InvalidDescription: "",
|
InvalidDescription: "",
|
||||||
|
IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
|
||||||
}
|
}
|
||||||
//是否有失效的
|
//是否有失效的
|
||||||
if description, ok := mapCartChange[cart.Id]; ok {
|
if description, ok := mapCartChange[cart.Id]; ok {
|
||||||
@ -206,7 +223,8 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||||||
CurrentPage: req.CurrentPage,
|
CurrentPage: req.CurrentPage,
|
||||||
PerPage: limit,
|
PerPage: limit,
|
||||||
},
|
},
|
||||||
CartList: list,
|
AllCartIdArray: ids,
|
||||||
|
CartList: list,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,22 +34,24 @@ type GetCartsReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetCartsRsp struct {
|
type GetCartsRsp struct {
|
||||||
Meta Meta `json:"meta"` //分页信息
|
Meta Meta `json:"meta"` //分页信息
|
||||||
CartList []CartItem `json:"cart_list"`
|
AllCartIdArray []int64 `json:"all_cartId_array"` //全部购物车id(不分页)
|
||||||
|
CartList []CartItem `json:"cart_list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CartItem struct {
|
type CartItem struct {
|
||||||
CartId int64 `json:"cart_id"`
|
CartId int64 `json:"cart_id"`
|
||||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||||
ItemPrice string `json:"item_price"` //单价
|
ItemPrice string `json:"item_price"` //单价
|
||||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||||
|
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductInfo struct {
|
type ProductInfo struct {
|
||||||
|
@ -79,7 +79,6 @@ service home-user-auth {
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
UserLogoTemplateTagSetReq {
|
UserLogoTemplateTagSetReq {
|
||||||
LogoSelectedId int64 `form:"logo_selected_id"`
|
|
||||||
TemplateTag string `form:"template_tag"`
|
TemplateTag string `form:"template_tag"`
|
||||||
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,9 @@ service product-template-tag {
|
|||||||
//获取产品模板标签列表
|
//获取产品模板标签列表
|
||||||
@handler GetProductTemplateTagsHandler
|
@handler GetProductTemplateTagsHandler
|
||||||
get /api/product-template-tag/get_product_template_tags(GetProductTemplateTagsReq) returns (response);
|
get /api/product-template-tag/get_product_template_tags(GetProductTemplateTagsReq) returns (response);
|
||||||
|
//根据模板标签跟logo还有选择颜色的索引获取颜色
|
||||||
|
@handler GetTemplateTagColorHandler
|
||||||
|
get /api/product-template-tag/get_template_tag_color(GetTemplateTagColorReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取产品模板标签列表
|
//获取产品模板标签列表
|
||||||
@ -28,4 +31,15 @@ type GetProductTemplateTagsRsp {
|
|||||||
CoverMetadata interface{} `json:"cover_metadata"`
|
CoverMetadata interface{} `json:"cover_metadata"`
|
||||||
Colors [][]string `json:"colors"`
|
Colors [][]string `json:"colors"`
|
||||||
SelectedColorIndex int `json:"selected_color_index"`
|
SelectedColorIndex int `json:"selected_color_index"`
|
||||||
|
}
|
||||||
|
//根据模板标签跟logo还有选择颜色的索引获取颜色
|
||||||
|
type GetTemplateTagColorReq {
|
||||||
|
Logo string `form:"logo"`
|
||||||
|
TemplateTag string `form:"template_tag"`
|
||||||
|
SelectedColorIndex int `form:"selected_color_index"`
|
||||||
|
}
|
||||||
|
type GetTemplateTagColorRsp {
|
||||||
|
Colors [][]string `json:"colors"`
|
||||||
|
SelectedColorIndex int `json:"selected_color_index"`
|
||||||
|
TemplateTagGroups interface{} `json:"template_tag_groups"`
|
||||||
}
|
}
|
@ -52,21 +52,23 @@ type GetCartsReq {
|
|||||||
CurrentPage int `form:"current_page"` //当前页
|
CurrentPage int `form:"current_page"` //当前页
|
||||||
}
|
}
|
||||||
type GetCartsRsp {
|
type GetCartsRsp {
|
||||||
Meta Meta `json:"meta"` //分页信息
|
Meta Meta `json:"meta"` //分页信息
|
||||||
CartList []CartItem `json:"cart_list"`
|
AllCartIdArray []int64 `json:"all_cartId_array"` //全部购物车id(不分页)
|
||||||
|
CartList []CartItem `json:"cart_list"`
|
||||||
}
|
}
|
||||||
type CartItem {
|
type CartItem {
|
||||||
CartId int64 `json:"cart_id"`
|
CartId int64 `json:"cart_id"`
|
||||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||||
ItemPrice string `json:"item_price"` //单价
|
ItemPrice string `json:"item_price"` //单价
|
||||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||||
|
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||||
}
|
}
|
||||||
type ProductInfo {
|
type ProductInfo {
|
||||||
ProductId int64 `json:"product_id"` //产品id
|
ProductId int64 `json:"product_id"` //产品id
|
||||||
|
@ -6,8 +6,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// 厘转美元
|
// 厘转美元
|
||||||
func CentitoDollar(price int64) float64 {
|
func CentitoDollar(price int64, remainFloatPoint ...uint) float64 {
|
||||||
str := fmt.Sprintf("%.3f", float64(price)/float64(1000))
|
s := "%.3f"
|
||||||
|
if len(remainFloatPoint) > 0 {
|
||||||
|
s = fmt.Sprintf("%%.%df", remainFloatPoint[0])
|
||||||
|
}
|
||||||
|
fmt.Println(s)
|
||||||
|
str := fmt.Sprintf(s, float64(price)/float64(1000))
|
||||||
dollar, _ := strconv.ParseFloat(str, 64)
|
dollar, _ := strconv.ParseFloat(str, 64)
|
||||||
return dollar
|
return dollar
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user