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
|
||||
|
||||
*.zip
|
||||
*.zip
|
||||
|
||||
vendor
|
|
@ -43,8 +43,8 @@ func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tag
|
|||
err = db.Limit(limit).Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, tagName string, fields ...string) (resp *FsProductTemplateTags, err error) {
|
||||
db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", tagName, 1)
|
||||
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` = ?", templateTagName, 1)
|
||||
if len(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
|
||||
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
|
||||
|
||||
go mod tidy
|
||||
go mod vendor
|
||||
|
||||
# 定义一个函数来在每个服务器目录下运行 go run <server_name>.go
|
||||
run_server() {
|
||||
server_name=$1
|
||||
|
@ -14,8 +17,7 @@ run_server() {
|
|||
|
||||
# 导航到相应的目录
|
||||
cd server/$server_name
|
||||
|
||||
go build -race
|
||||
go build
|
||||
[ -f .gitignore ] || echo $server_name > .gitignore
|
||||
# 使用 screen 运行 go run <server_name>.go
|
||||
screen -dmS $server_name -L ./$server_name
|
||||
|
@ -24,7 +26,8 @@ run_server() {
|
|||
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=() # 初始化一个空数组
|
||||
|
@ -37,7 +40,7 @@ done
|
|||
|
||||
# 在每个服务器目录下运行相应的 go 程序
|
||||
for server_dir in "${server_dirs[@]}"; do
|
||||
run_server $server_dir
|
||||
run_server $server_dir &
|
||||
done
|
||||
|
||||
# 定义目录和screen名称
|
||||
|
@ -46,12 +49,11 @@ screen_name="proxyserver"
|
|||
|
||||
# 进入目录
|
||||
cd $dir_path
|
||||
|
||||
# 检查是否存在screen session
|
||||
if screen -list | grep -q "$screen_name"; then
|
||||
# 结束存在的screen session
|
||||
screen -S $screen_name -X quit
|
||||
fi
|
||||
|
||||
go build
|
||||
# 启动新的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)
|
||||
}
|
||||
if req.LogoSelectedId == 0 {
|
||||
return resp.SetStatus(basic.CodeApiErr, "logo logo_selected_id not null")
|
||||
}
|
||||
if req.TemplateTag == "" {
|
||||
return resp.SetStatus(basic.CodeApiErr, "logo template tag not null")
|
||||
}
|
||||
var userId int64
|
||||
var guestId int64
|
||||
NewFsUserMaterialModel := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
|
||||
NewFsUserMaterialModelRow := NewFsUserMaterialModel.RowSelectBuilder(nil).Where("id = ?", req.LogoSelectedId)
|
||||
|
||||
if userinfo.IsGuest() {
|
||||
// 如果是,使用游客ID和游客键名格式
|
||||
guestId = userinfo.GuestId
|
||||
NewFsUserMaterialModelRow.Where("guest_id = ?", guestId)
|
||||
} else {
|
||||
// 否则,使用用户ID和用户键名格式
|
||||
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()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
err := l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var module = "profile"
|
||||
|
||||
var userInfo = &gmodel.FsUserInfo{}
|
||||
BuilderDB := tx.Model(&gmodel.FsUserInfo{}).Where("module = ?", module)
|
||||
if userId > 0 {
|
||||
|
@ -92,7 +69,7 @@ func (l *UserLogoTemplateTagSetLogic) UserLogoTemplateTagSet(req *types.UserLogo
|
|||
BuilderDB.Where("guest_id=?", guestId)
|
||||
}
|
||||
userInfoFirstRes := BuilderDB.First(userInfo)
|
||||
err = userInfoFirstRes.Error
|
||||
err := userInfoFirstRes.Error
|
||||
if err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
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)
|
||||
|
||||
_, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"]
|
||||
userInfoLogoSelectedData, userInfoLogoSelectedEx := metadataMapOldUserInfo["logo_selected"]
|
||||
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"]
|
||||
if !userMaterialTemplateTagEx {
|
||||
logc.Errorf(l.ctx, "userMaterialInfo Metadata template_tag err:%+v", err)
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
)
|
||||
|
||||
type UserLogoTemplateTagSetReq struct {
|
||||
LogoSelectedId int64 `form:"logo_selected_id"`
|
||||
TemplateTag string `form:"template_tag"`
|
||||
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
||||
}
|
||||
|
@ -230,10 +229,10 @@ type File struct {
|
|||
}
|
||||
|
||||
type Meta struct {
|
||||
TotalCount int64 `json:"totalCount"`
|
||||
PageCount int64 `json:"pageCount"`
|
||||
CurrentPage int `json:"currentPage"`
|
||||
PerPage int `json:"perPage"`
|
||||
TotalCount int64 `json:"total_count"`
|
||||
PageCount int64 `json:"page_count"`
|
||||
CurrentPage int `json:"current_page"`
|
||||
PerPage int `json:"per_page"`
|
||||
}
|
||||
|
||||
// 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",
|
||||
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) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
||||
type logoSelect struct {
|
||||
type LogoSelect struct {
|
||||
LogoSelected struct {
|
||||
LogoSelectedId int `json:"logo_selected_id"`
|
||||
TemplateTagSelected struct {
|
||||
|
@ -73,29 +73,37 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
|
|||
logx.Error(err)
|
||||
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"])
|
||||
if err = json.Unmarshal(b, &mapMaterialTemplateTag); err != nil {
|
||||
if err = json.Unmarshal(b, &mapMaterialTemplateTagColors); err != nil {
|
||||
logx.Error(err)
|
||||
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是选中的索引
|
||||
if logoInfo.UserInfoMetadata != nil && *logoInfo.UserInfoMetadata != "" {
|
||||
//解析用户信息元数据
|
||||
var logoSelectInfo logoSelect
|
||||
var logoSelectInfo LogoSelect
|
||||
if err = json.Unmarshal([]byte(*logoInfo.UserInfoMetadata), &logoSelectInfo); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse user info metadata")
|
||||
}
|
||||
//设置选中
|
||||
key := logoSelectInfo.LogoSelected.TemplateTagSelected.TemplateTag
|
||||
if _, ok := mapMaterialTemplateTag[key]; ok {
|
||||
if _, ok := mapMaterialTemplateTagColors[key]; ok {
|
||||
mapSelectColor[key] = logoSelectInfo.LogoSelected.TemplateTagSelected.SelectedIndex
|
||||
}
|
||||
}
|
||||
var templateTagNameList []string
|
||||
for templateTag, _ := range mapMaterialTemplateTag {
|
||||
for templateTag, _ := range mapMaterialTemplateTagColors {
|
||||
templateTagNameList = append(templateTagNameList, templateTag)
|
||||
}
|
||||
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
|
||||
}
|
||||
//排序
|
||||
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))
|
||||
for _, templateInfo := range productTemplateTags {
|
||||
for _, templateTagInfo := range productTemplateTags {
|
||||
colors := make([][]string, 0, 10)
|
||||
SelectedColorIndex := 0
|
||||
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
|
||||
//标签中选中的索引
|
||||
SelectedColorIndex = selectIndex
|
||||
|
@ -139,19 +155,19 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu
|
|||
colors = colorsSet
|
||||
}
|
||||
var templateTagGroups []interface{}
|
||||
if templateInfo.Groups != nil && *templateInfo.Groups != "" {
|
||||
if err = json.Unmarshal([]byte(*templateInfo.Groups), &templateTagGroups); err != nil {
|
||||
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 groups")
|
||||
}
|
||||
}
|
||||
list = append(list, types.GetProductTemplateTagsRsp{
|
||||
Id: templateInfo.Id,
|
||||
TemplateTag: *templateInfo.TemplateTag,
|
||||
Id: templateTagInfo.Id,
|
||||
TemplateTag: *templateTagInfo.TemplateTag,
|
||||
IsDefaultTemplateTag: isDefaultTemplateTag,
|
||||
TemplateTagGroups: templateTagGroups,
|
||||
Cover: *templateInfo.Cover,
|
||||
CoverMetadata: mapResourceMetadata[*templateInfo.Cover],
|
||||
Cover: *templateTagInfo.Cover,
|
||||
CoverMetadata: mapResourceMetadata[*templateTagInfo.Cover],
|
||||
Colors: colors,
|
||||
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"`
|
||||
}
|
||||
|
||||
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 {
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,22 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
if req.CurrentPage <= 0 {
|
||||
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
|
||||
//获取用户购物车列表
|
||||
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,
|
||||
IsInvalid: false,
|
||||
InvalidDescription: "",
|
||||
IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
|
||||
}
|
||||
//是否有失效的
|
||||
if description, ok := mapCartChange[cart.Id]; ok {
|
||||
|
@ -206,7 +223,8 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
CurrentPage: req.CurrentPage,
|
||||
PerPage: limit,
|
||||
},
|
||||
CartList: list,
|
||||
AllCartIdArray: ids,
|
||||
CartList: list,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -34,22 +34,24 @@ type GetCartsReq struct {
|
|||
}
|
||||
|
||||
type GetCartsRsp struct {
|
||||
Meta Meta `json:"meta"` //分页信息
|
||||
CartList []CartItem `json:"cart_list"`
|
||||
Meta Meta `json:"meta"` //分页信息
|
||||
AllCartIdArray []int64 `json:"all_cartId_array"` //全部购物车id(不分页)
|
||||
CartList []CartItem `json:"cart_list"`
|
||||
}
|
||||
|
||||
type CartItem struct {
|
||||
CartId int64 `json:"cart_id"`
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
}
|
||||
|
||||
type ProductInfo struct {
|
||||
|
|
|
@ -79,7 +79,6 @@ service home-user-auth {
|
|||
|
||||
type (
|
||||
UserLogoTemplateTagSetReq {
|
||||
LogoSelectedId int64 `form:"logo_selected_id"`
|
||||
TemplateTag string `form:"template_tag"`
|
||||
TemplateTagColorIndex int64 `form:"template_tag_color_index"`
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@ service product-template-tag {
|
|||
//获取产品模板标签列表
|
||||
@handler GetProductTemplateTagsHandler
|
||||
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"`
|
||||
Colors [][]string `json:"colors"`
|
||||
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"` //当前页
|
||||
}
|
||||
type GetCartsRsp {
|
||||
Meta Meta `json:"meta"` //分页信息
|
||||
CartList []CartItem `json:"cart_list"`
|
||||
Meta Meta `json:"meta"` //分页信息
|
||||
AllCartIdArray []int64 `json:"all_cartId_array"` //全部购物车id(不分页)
|
||||
CartList []CartItem `json:"cart_list"`
|
||||
}
|
||||
type CartItem {
|
||||
CartId int64 `json:"cart_id"`
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
}
|
||||
type ProductInfo {
|
||||
ProductId int64 `json:"product_id"` //产品id
|
||||
|
|
|
@ -6,8 +6,13 @@ import (
|
|||
)
|
||||
|
||||
// 厘转美元
|
||||
func CentitoDollar(price int64) float64 {
|
||||
str := fmt.Sprintf("%.3f", float64(price)/float64(1000))
|
||||
func CentitoDollar(price int64, remainFloatPoint ...uint) float64 {
|
||||
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)
|
||||
return dollar
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user