Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson
2023-10-07 16:59:56 +08:00
35 changed files with 293 additions and 671 deletions

View File

@@ -1,6 +1,7 @@
package logic
import (
"fmt"
"fusenapi/constants"
"fusenapi/service/repositories"
"fusenapi/utils/auth"
@@ -55,9 +56,25 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth
}
// 延时任务
l.svcCtx.DelayQueue.AddTask(time.Now().Add(time.Minute*30), constants.QUEUE_NAME_ORDER, func(args ...interface{}) {
// l.svcCtx.DelayQueue.AddTask(time.Now().Add(time.Minute*30), constants.QUEUE_NAME_ORDER, func(args ...interface{}) {
// ctx := context.Background()
// orderSn := args[0].(string)
// svcCtx := svc.ServiceContext{
// Config: l.svcCtx.Config,
// Repositories: l.svcCtx.Repositories,
// }
// svcCtx.Repositories.NewOrder.Close(ctx, &repositories.CloseReq{
// OrderSn: orderSn,
// Type: 1,
// })
// }, []interface{}{res.OrderSn})
// 延时任务
time.AfterFunc(time.Minute*30, func() {
orderSn := res.OrderSn
fmt.Println("延时任务: OrderSn--", orderSn)
ctx := context.Background()
orderSn := args[0].(string)
svcCtx := svc.ServiceContext{
Config: l.svcCtx.Config,
Repositories: l.svcCtx.Repositories,
@@ -66,7 +83,7 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth
OrderSn: orderSn,
Type: 1,
})
}, []interface{}{res.OrderSn})
})
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
"order_sn": res.OrderSn,

View File

@@ -21,10 +21,10 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext {
conn := initalize.InitMysql(c.SourceMysql)
delayQueue := initalize.InitDelayMessage()
// delayQueue := initalize.InitDelayMessage()
repositories := initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
GormDB: conn,
DelayQueue: delayQueue,
GormDB: conn,
// DelayQueue: delayQueue,
})
return &ServiceContext{
@@ -32,6 +32,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
MysqlConn: conn,
AllModels: gmodel.NewAllModels(conn),
Repositories: repositories,
DelayQueue: delayQueue,
// DelayQueue: delayQueue,
}
}

View File

@@ -30,10 +30,10 @@ type CreatePrePaymentByBalanceReq struct {
}
type OrderListReq struct {
DeliveryMethod int64 `json:"delivery_method,options=[0,1,2],optional"`
OrderCycle string `json:"order_cycle,optional,options=[within_one_month,within_three_month,within_six_month,within_one_year]"`
CurrentPage int64 `json:"current_page,optional,default=1"`
PerPage int64 `json:"per_page,optional,default=10"`
DeliveryMethod int64 `form:"delivery_method,options=[0,1,2],optional"`
OrderCycle string `form:"order_cycle,optional,options=[within_one_month,within_three_month,within_six_month,within_one_year]"`
CurrentPage int64 `form:"current_page,optional,default=1"`
PerPage int64 `form:"per_page,optional,default=10"`
}
type Request struct {

View File

@@ -1,35 +0,0 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/product/internal/logic"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
)
func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetProductListReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewGetProductListLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.GetProductList(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@@ -1,35 +0,0 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/product/internal/logic"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
)
func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetSuccessRecommandReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.GetSuccessRecommand(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@@ -12,16 +12,6 @@ import (
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/api/product/list",
Handler: GetProductListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/product/success-recommand",
Handler: GetSuccessRecommandHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/product/get-size-by-product",

View File

@@ -3,6 +3,7 @@ package logic
import (
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
@@ -83,15 +84,38 @@ func (l *CalculateProductPriceLogic) CalculateProductPrice(req *types.CalculateP
}
fittingPrice = *fittingInfo.Price
}
rangeLen := len(stepPrice.PriceRange)
stepRange := make([]interface{}, 0, rangeLen)
for rIndex, rangeInfo := range stepPrice.PriceRange {
//最后一个
if rIndex+1 == rangeLen {
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
stepRange = append(stepRange, map[string]interface{}{
"start": rangeInfo.StartQuantity,
"end": rangeInfo.EndQuantity,
"range_description": fmt.Sprintf(">=%s Units", begin),
"item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3),
})
break
}
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
end := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.EndQuantity))
stepRange = append(stepRange, map[string]interface{}{
"start": rangeInfo.StartQuantity,
"end": rangeInfo.EndQuantity,
"range_description": fmt.Sprintf("%s-%s Units", begin, end),
"item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3),
})
}
totalPrice, itemPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(req.PurchaseQuantity, stepPrice, fittingPrice)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to calculate product price ")
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateProductPriceRsp{
ItemPrice: format.CentitoDollar(itemPrice, 3),
TotalPrice: format.CentitoDollarWithNoHalfAdjust(totalPrice, 2),
PurchaseQuantity: req.PurchaseQuantity,
ItemPrice: format.CentitoDollar(itemPrice, 3),
TotalPrice: format.CentitoDollarWithNoHalfAdjust(totalPrice, 2),
StepRange: stepRange,
})
}

View File

@@ -1,188 +0,0 @@
package logic
import (
"context"
"encoding/json"
"errors"
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image"
"math"
"sort"
"strings"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"gorm.io/gorm"
)
type GetProductListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductListLogic {
return &GetProductListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 获取产品列表
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
//如果是demo
if req.IsDemo == 1 {
var demo types.GetProductListRsp
if err := json.Unmarshal([]byte(constants.PRODUCT_LIST_DEMO), &demo); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "demo data format err")
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", demo)
}
if req.Page <= 0 {
req.Page = constants.DEFAULT_PAGE
}
//获取合适尺寸
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
pageSize := constants.DEFAULT_PAGE_SIZE
//查询用户信息(不用判断存在)
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
user, err := userModel.FindUserById(l.ctx, userinfo.UserId)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
}
//查询符合的产品列表
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
productList, total, err := productModel.GetProductListByTypeIds(l.ctx, []int64{req.Cid}, int(req.Page), pageSize, "sort-desc")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
}
productLen := len(productList)
if productLen == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
//提取产品ids
productIds := make([]int64, 0, productLen)
for _, v := range productList {
productIds = append(productIds, v.Id)
}
productPriceModel := gmodel.NewFsProductPriceModel(l.svcCtx.MysqlConn)
productPriceList, err := productPriceModel.GetSimplePriceListByProductIds(l.ctx, productIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list")
}
//存储产品最小价格
mapProductMinPrice := make(map[int64]int64)
for _, v := range productPriceList {
priceStrSlic := strings.Split(v.Price, ",")
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
}
if len(priceSlice) == 0 {
continue
}
sort.Ints(priceSlice)
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
//获取模板
productTemplateModel := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds, "")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
}
mapProductTemplate := make(map[int64]struct{})
for _, v := range productTemplatesV2 {
mapProductTemplate[*v.ProductId] = struct{}{}
}
//获取分类
tagsModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn)
tagInfo, err := tagsModel.FindOne(l.ctx, req.Cid)
if err != nil && !errors.Is(err, sqlc.ErrNotFound) {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "tag is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get tag err")
}
//获取产品尺寸数量
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
productSizeCountList, err := productSizeModel.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product size count err")
}
mapProductSizeCount := make(map[int64]int64)
for _, v := range productSizeCountList {
mapProductSizeCount[v.ProductId] = v.Num
}
//拼接返回
itemList := make([]types.Items, 0, productLen)
for _, v := range productList {
minPrice, ok := mapProductMinPrice[v.Id]
_, tmpOk := mapProductTemplate[v.Id]
//无最小价格则不显示 || 没有模板也不显示
if !ok || !tmpOk {
continue
}
sizeNum := int64(0)
if mapSizeNum, ok := mapProductSizeCount[v.Id]; ok {
sizeNum = mapSizeNum
}
item := types.Items{
Id: v.Id,
Sn: *v.Sn,
Title: *v.Title,
Intro: *v.Intro,
IsEnv: *v.IsProtection,
IsMicro: *v.IsMicrowave,
SizeNum: uint32(sizeNum),
MinPrice: minPrice,
}
//千人千面处理
r := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: 0,
Cover: *v.Cover,
CoverImg: *v.CoverImg,
CoverDefault: *v.CoverImg,
ProductId: v.Id,
UserId: user.Id,
}
if user.Id != 0 {
r.IsThousandFace = 1
}
image.ThousandFaceImageFormat(&r)
item.Cover = r.Cover
item.CoverImg = r.CoverImg
item.CoverDefault = r.CoverDefault
itemList = append(itemList, item)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductListRsp{
Ob: types.Ob{
Items: itemList,
Meta: types.Meta{
TotalCount: total,
PageCount: int64(math.Ceil(float64(total) / float64(pageSize))),
CurrentPage: int(req.Page),
PerPage: pageSize,
},
},
TypeName: *tagInfo.Title,
Description: *tagInfo.Description,
})
}

View File

@@ -11,6 +11,7 @@ import (
"fusenapi/utils/basic"
"fusenapi/utils/format"
"gorm.io/gorm"
"strings"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
@@ -50,15 +51,21 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
//查询产品价格
modelPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdTag(l.ctx, req.ProductId, constants.TAG_MODEL, "id,size_id,part_id,step_price,packed_unit")
modelPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdTag(l.ctx, req.ProductId, constants.TAG_MODEL, "id,size_id,part_list,part_id,step_price,packed_unit")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model price list")
}
fittingIds := make([]int64, 0, len(modelPriceList))
for _, v := range modelPriceList {
if *v.PartId > 0 {
fittingIds = append(fittingIds, *v.PartId)
*v.PartList = strings.Trim(*v.PartList, ",")
if *v.PartList != "" {
tmpPartIds, err := format.StrSlicToInt64Slice(strings.Split(*v.PartList, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse model part list ")
}
fittingIds = append(fittingIds, tmpPartIds...)
}
}
//查询配件价格列表
@@ -73,77 +80,38 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
}
//遍历处理模型价格
mapRsp := make(map[string]interface{})
for _, modelPriceInfo := range modelPriceList {
for _, modelInfo := range modelPriceList {
var stepPrice gmodel.StepPriceJsonStruct
if err = json.Unmarshal(*modelPriceInfo.StepPrice, &stepPrice); err != nil {
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price json")
}
rangeLen := len(stepPrice.PriceRange)
if rangeLen == 0 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price is not set:%d", modelPriceInfo.Id))
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price is not set:%d", modelInfo.Id))
}
//最小单价
minPrice := stepPrice.PriceRange[rangeLen-1].Price
//最大单价
maxPrice := stepPrice.PriceRange[0].Price
//购买数步进基数
stepPurchaseQuantity := *modelPriceInfo.PackedUnit
//购买数步进基数描述
stepPurchaseQuantityDescription := "主体装箱数为步进基数"
//配件价格
fittingPrice := int64(0)
if *modelPriceInfo.PartId > 0 {
fittingPriceInfo, ok := mapFitting[*modelPriceInfo.PartId]
if !ok {
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("fitting price is not exists:%d", *modelPriceInfo.PartId))
*modelInfo.PartList = strings.Trim(*modelInfo.PartList, ",")
mapFittingUnit := make(map[string]interface{})
if *modelInfo.PartList != "" {
tmpPartIds, err := format.StrSlicToInt64Slice(strings.Split(*modelInfo.PartList, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse model part list!! ")
}
//最小/最大价格要加配件
fittingPrice = *fittingPriceInfo.Price
minPrice += fittingPrice
maxPrice += fittingPrice
//如果配件装箱基数比主体大,则基数以配件为主
if *fittingPriceInfo.PackedUnit > stepPurchaseQuantity {
stepPurchaseQuantity = *fittingPriceInfo.PackedUnit
stepPurchaseQuantityDescription = "配件装箱数为步进基数"
for _, partId := range tmpPartIds {
fittingInfo, ok := mapFitting[*modelInfo.PartId]
if !ok {
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("fitting price is not exists:%d", *modelInfo.PartId))
}
mapFittingUnit[fmt.Sprintf("_%d", partId)] = map[string]interface{}{
"packed_unit": *fittingInfo.PackedUnit, //装箱个数
}
}
}
stepRange := make([]interface{}, 0, rangeLen)
for rIndex, rangeInfo := range stepPrice.PriceRange {
//最后一个
if rIndex+1 == rangeLen {
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
stepRange = append(stepRange, map[string]interface{}{
"start": rangeInfo.StartQuantity,
"end": rangeInfo.EndQuantity,
"range_description": fmt.Sprintf(">=%s Units", begin),
"item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3),
})
break
}
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
end := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.EndQuantity))
stepRange = append(stepRange, map[string]interface{}{
"start": rangeInfo.StartQuantity,
"end": rangeInfo.EndQuantity,
"range_description": fmt.Sprintf("%s-%s Units", begin, end),
"item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3),
})
}
//计算起购数量的单价
_, minBuyUnitsQuantityPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(stepPrice.MinBuyUnitsNum, stepPrice, fittingPrice)
if err != nil {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get min buy quantity item price")
}
mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{
"step_purchase_quantity": stepPurchaseQuantity,
"step_purchase_quantity_description": stepPurchaseQuantityDescription,
"min_price": minPrice,
"max_price": maxPrice,
"step_range": stepRange,
"min_buy_units_quantity": stepPrice.MinBuyUnitsNum,
"min_buy_units_quantity_total_price": format.CentitoDollarWithNoHalfAdjust(minBuyUnitsQuantityPrice*stepPrice.MinBuyUnitsNum, 2),
"min_buy_units_quantity_item_price": format.CentitoDollar(minBuyUnitsQuantityPrice, 3),
mapRsp[fmt.Sprintf("_%d", *modelInfo.SizeId)] = map[string]interface{}{
"min_buy_units_quantity": stepPrice.MinBuyUnitsNum, //起购数量
"main_packed_unit": *modelInfo.PackedUnit, //主体装箱数
"fitting": mapFittingUnit,
}
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)

View File

@@ -1,88 +0,0 @@
package logic
import (
"context"
"errors"
"fusenapi/model/gmodel"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/image"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type GetSuccessRecommandLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSuccessRecommandLogic {
return &GetSuccessRecommandLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 获取推荐的产品列表
func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, userInfo *auth.UserInfo) (resp *basic.Response) {
if userInfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in first")
}
//获取用户信息
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
user, err := userModel.FindUserById(l.ctx, userInfo.UserId)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
}
if req.Num == 0 || req.Num > 500 {
req.Num = 8
}
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
//随机取8个产品
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
productList, err := productModel.GetRandomProductList(l.ctx, int(req.Num))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
}
//没有推荐产品就返回
if len(productList) == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
list := make([]types.GetSuccessRecommandRsp, 0, len(productList))
for _, v := range productList {
data := types.GetSuccessRecommandRsp{
Title: *v.Title,
Sn: *v.Sn,
Id: v.Id,
SkuId: 0, //???????
}
//千人千面处理
r := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: 0,
Cover: *v.Cover,
CoverImg: *v.CoverImg,
CoverDefault: *v.CoverImg,
ProductId: v.Id,
UserId: user.Id,
}
if user.Id > 0 {
r.IsThousandFace = int(1)
}
image.ThousandFaceImageFormat(&r)
data.Cover = r.Cover
data.CoverImg = r.CoverImg
data.CoverDefault = r.CoverDefault
list = append(list, data)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
}

View File

@@ -5,54 +5,6 @@ import (
"fusenapi/utils/basic"
)
type GetProductListReq struct {
Cid int64 `form:"cid"`
Size uint32 `form:"size"`
Page uint32 `form:"page,optional"`
IsDemo uint32 `form:"is_demo,optional"`
}
type GetProductListRsp struct {
Ob Ob `json:"ob"`
TypeName string `json:"typeName"`
Description string `json:"description"`
}
type Ob struct {
Items []Items `json:"items"`
Meta Meta `json:"_meta"`
}
type Items struct {
Id int64 `json:"id"`
Sn string `json:"sn"`
Title string `json:"title"`
Cover string `json:"cover"`
Intro string `json:"intro"`
CoverImg string `json:"cover_img"`
IsEnv int64 `json:"isEnv"`
IsMicro int64 `json:"isMicro"`
SizeNum uint32 `json:"sizeNum"`
MinPrice int64 `json:"minPrice"`
CoverDefault string `json:"coverDefault"`
}
type GetSuccessRecommandReq struct {
Num uint32 `form:"num"`
Size uint32 `form:"size"`
Sn string `form:"sn"`
}
type GetSuccessRecommandRsp struct {
Title string `json:"title"`
Cover string `json:"cover"`
CoverImg string `json:"coverImg"`
Sn string `json:"sn"`
Id int64 `json:"id"`
SkuId int64 `json:"skuId"`
CoverDefault string `json:"coverDefault"`
}
type GetSizeByProductRsp struct {
Id int64 `json:"id"`
Name string `json:"name"`
@@ -343,9 +295,9 @@ type CalculateProductPriceReq struct {
}
type CalculateProductPriceRsp struct {
ItemPrice string `json:"item_price"`
TotalPrice string `json:"total_price"`
PurchaseQuantity int64 `json:"purchase_quantity"`
ItemPrice string `json:"item_price"`
TotalPrice string `json:"total_price"`
StepRange interface{} `json:"step_range"`
}
type GetSizeByPidReq struct {

View File

@@ -28,6 +28,9 @@ type ResourceInfoReq struct {
}
type LogoCombineReq struct {
LogoUrl string `json:"logo_url"` // 合图参数
TemplateTagColor TemplateTagColor `json:"template_tag_color"`
TemplateTagGroups []TemplateTagGroups `json:"template_tag_groups"`
TemplateId int64 `json:"template_id"` // 合图参数
TemplateTag string `json:"template_tag"` // 合图参数
Website string `json:"website,optional"` // 合图参数
@@ -35,9 +38,6 @@ type LogoCombineReq struct {
Address string `json:"address,optional"` // 合图参数
Phone string `json:"phone,optional"` // 合图参数
Qrcode string `json:"qrcode,optional"` // 合图参数
LogoUrl string `json:"logo_url"` // 合图参数
TemplateTagColor TemplateTagColor `json:"template_tag_color"`
TemplateTagGroups []TemplateTagGroups `json:"template_tag_groups"`
}
type TemplateTagColor struct {

View File

@@ -13,6 +13,7 @@ import (
"fusenapi/utils/file"
"fusenapi/utils/hash"
"gorm.io/gorm"
"strings"
"time"
"github.com/zeromicro/go-zero/core/logx"
@@ -53,9 +54,9 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
if cartCount >= 100 {
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "sorry,the count of your carts can`t greater than 100")
}
if req.RenderImage != "" {
//不是传路径则就是传base64
if !strings.Contains(req.RenderImage, "https://") {
//上传base64文件
// 上传文件
var upload = file.Upload{
Ctx: l.ctx,
MysqlConn: l.svcCtx.MysqlConn,
@@ -270,6 +271,10 @@ func (l *AddToCartLogic) AddToCartParamVerify(req *types.AddToCartReq) error {
if req.PurchaseQuantity <= 0 {
return errors.New("purchase quantity can not less than 0 or equal 0")
}
req.RenderImage = strings.Trim(req.RenderImage, " ")
if req.RenderImage == "" {
return errors.New("render image is required")
}
return nil
}

View File

@@ -19,6 +19,7 @@ AWS:
Secret: sjCEv0JxATnPCxno2KNLm0X8oDc7srUR+4vkYhvm
Token:
BLMService:
Version: "2"
Url: "http://18.119.109.254:8999"
# Url: "http://192.168.1.9:8999"
ImageProcess:

View File

@@ -22,6 +22,7 @@ type Config struct {
}
}
BLMService struct {
Version string
Url string
ImageProcess struct {
Url string

View File

@@ -171,12 +171,9 @@ func (l *UploadLogoLogic) UploadLogo(req *types.UploadLogoReq, userinfo *auth.Us
logoHeight = 200
}
var resultStr string
var postMap = make(map[string]string, 1)
postMap["logo_url"] = logoUrl
resLogoStandard, err := l.svcCtx.Repositories.ImageHandle.LogoInfoSet(l.ctx, &repositories.LogoInfoSetReq{
LogoUrl: logoUrl,
Version: l.svcCtx.Config.BLMService.Version,
})
if err != nil {

View File

@@ -81,12 +81,12 @@ var (
// 用户标识的连接增删操作队列传输的值的结构
type userConnPoolCtlChanItem struct {
userId int64 //必须两个用户id任意一个不为0
guestId int64 //必须两个用户id任意一个不为0
uniqueId string //主连接池唯一标识(添加/删除时候必须)
message []byte //消息(发送消息传的,格式是经过标准输出序列化后的数据)
messageType constants.Websocket //消息类型(发送消息传的)
option int64 //操作 2发消息 1增加 0删除
userId int64 //必须两个用户id任意一个不为0
guestId int64 //必须两个用户id任意一个不为0
uniqueId string //主连接池唯一标识(添加/删除时候必须)
message []byte //消息(发送消息传的,格式是经过标准输出序列化后的数据)
//messageType constants.Websocket //消息类型(发送消息传的)
option int64 //操作 2发消息 1增加 0删除
}
// 每个连接的连接基本属性

View File

@@ -40,7 +40,7 @@ func ConsumeWebsocketConnectCountCtlChanData(ctx context.Context) {
select {
case num = <-websocketConnectCountCtlChan:
currentWebsocketConnectCount += num
logx.Info("当前websocket连接总数:", currentWebsocketConnectCount)
//logx.Info("当前websocket连接总数:", currentWebsocketConnectCount)
}
}
}

View File

@@ -24,7 +24,7 @@ var (
//每个websocket渲染任务缓冲队列长度默认值
renderChanLen = 500
//每个websocket渲染并发数
renderChanConcurrency = 500
renderChanConcurrency = 10
)
// 渲染处理器
@@ -55,7 +55,6 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
w.extendRenderProperty.selectColorIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex
//让之前的失效
w.extendRenderProperty.renderCtxCancelFunc()
logx.Info("模板标签/颜色更换上下文取消")
//重新赋值
w.extendRenderProperty.renderCtx, w.extendRenderProperty.renderCtxCancelFunc = context.WithCancel(w.logic.ctx)
}
@@ -85,18 +84,42 @@ func (w *wsConnectItem) consumeRenderImageData() {
case <-w.closeChan: //已关闭
return
case data := <-w.extendRenderProperty.renderChan: //消费数据
logx.Info("准备执行任务。。。。。")
//标签不一样
if data.RenderData.TemplateTag != w.extendRenderProperty.templateTag {
//logx.Info("标签不一致,丢弃消息")
continue
}
//颜色不一致
if data.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.selectColorIndex {
//logx.Info("颜色不一致,丢弃消息")
continue
}
limitChan <- struct{}{}
logx.Info("执行任务中。。。。。")
go func(d websocket_data.RenderImageReqMsg) {
defer func() {
if err := recover(); err != nil {
logx.Error("func renderImage panic:", err)
logx.Error("func renderImage main panic:", err)
}
}()
//临时chan用select io多路复用去判断携程退出
tmpChan := make(chan struct{}, 1)
defer close(tmpChan)
defer func() {
<-limitChan
}()
go func() {
defer func() {
if err := recover(); err != nil {
logx.Error("func renderImage panic:", err)
}
}()
select {
case <-w.extendRenderProperty.renderCtx.Done():
panic("=========渲染取消旧的上下文=======")
case <-tmpChan:
return
}
}()
w.renderImage(d)
}(data)
}
@@ -159,25 +182,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
logx.Error("failed to get element ,", err)
return
}
//获取模板开关信息并且对于没有默认值的给赋值默认值(但凡DIY有一个是空的就要请求默认数据)
/*if renderImageData.RenderData.Website == "" || renderImageData.RenderData.Phone == "" || renderImageData.RenderData.Address == "" || renderImageData.RenderData.Qrcode == "" || renderImageData.RenderData.Slogan == "" {
templateSwitchInfo := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, productTemplate.TemplateInfo, *productTemplate.MaterialImg)
if renderImageData.RenderData.Website == "" && templateSwitchInfo.MaterialData.Website.IfShow {
renderImageData.RenderData.Website = templateSwitchInfo.MaterialData.Website.DefaultValue
}
if renderImageData.RenderData.Phone == "" && templateSwitchInfo.MaterialData.Phone.IfShow {
renderImageData.RenderData.Phone = templateSwitchInfo.MaterialData.Phone.DefaultValue
}
if renderImageData.RenderData.Address == "" && templateSwitchInfo.MaterialData.Address.IfShow {
renderImageData.RenderData.Address = templateSwitchInfo.MaterialData.Address.DefaultValue
}
if renderImageData.RenderData.Qrcode == "" && templateSwitchInfo.MaterialData.QRcode.IfShow {
renderImageData.RenderData.Qrcode = templateSwitchInfo.MaterialData.QRcode.DefaultValue
}
if renderImageData.RenderData.Slogan == "" && templateSwitchInfo.MaterialData.Slogan.IfShow {
renderImageData.RenderData.Slogan = templateSwitchInfo.MaterialData.Slogan.DefaultValue
}
}*/
//获取刀版图
combineReq := repositories.LogoCombineReq{
UserId: renderImageData.RenderData.UserId,

View File

@@ -70,7 +70,7 @@ func (r *reuseConnProcessor) allocationMessage(w *wsConnectItem, data []byte) {
createUserConnPoolElement(w.userId, w.guestId, wid)
rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, wid)
w.sendToOutChan(rsp)
logx.Info("重新绑定websocket连接标识成功")
//logx.Info("重新绑定websocket连接标识成功")
}
// 获取用户拼接部分(复用标识用到)

View File

@@ -19,12 +19,11 @@ func createUserConnPoolElement(userId, guestId int64, uniqueId string) {
return
}
data := userConnPoolCtlChanItem{
userId: userId,
guestId: guestId,
uniqueId: uniqueId,
message: nil,
messageType: "",
option: 1,
userId: userId,
guestId: guestId,
uniqueId: uniqueId,
message: nil,
option: 1,
}
select {
case userConnPoolCtlChan <- data:
@@ -38,17 +37,13 @@ func deleteUserConnPoolElement(userId, guestId int64, uniqueId string) {
return
}
data := userConnPoolCtlChanItem{
userId: userId,
guestId: guestId,
uniqueId: uniqueId,
message: nil,
messageType: "",
option: 0,
}
select {
case userConnPoolCtlChan <- data:
return
userId: userId,
guestId: guestId,
uniqueId: uniqueId,
message: nil,
option: 0,
}
userConnPoolCtlChan <- data
}
// 根据用户索引发现链接并发送(广播)消息到出口队列
@@ -89,7 +84,7 @@ func ConsumeUserConnPoolCtlChanData(ctx context.Context) {
userKey = getmapUserConnPoolUniqueId(data.userId, data.guestId)
switch data.option {
case 2: //发送消息
logx.Info("通过用户id索引发送消息")
//logx.Info("通过用户id索引发送消息")
mapUserUniqueId, ok := mapUserConnPool[userKey]
if !ok {
logx.Info("通过用户id索引发送消息,连接不存在用户索引key:", userKey)
@@ -110,7 +105,7 @@ func ConsumeUserConnPoolCtlChanData(ctx context.Context) {
originConn.sendToOutChan(data.message)
}
case 1: //添加
logx.Info("添加用户id索引标识", data.uniqueId)
//logx.Info("添加用户id索引标识", data.uniqueId)
//存在这个用户的map池子
if mapUserUniqueId, ok := mapUserConnPool[userKey]; ok {
mapUserUniqueId[data.uniqueId] = struct{}{}
@@ -119,7 +114,7 @@ func ConsumeUserConnPoolCtlChanData(ctx context.Context) {
mapUserConnPool[userKey][data.uniqueId] = struct{}{}
}
case 0: //删除
logx.Info("删除用户id索引标识", data.uniqueId)
//logx.Info("删除用户id索引标识", data.uniqueId)
if mapUserUniqueId, ok := mapUserConnPool[userKey]; ok {
delete(mapUserUniqueId, data.uniqueId)
}