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

This commit is contained in:
eson 2023-09-27 11:30:22 +08:00
commit 899db716f1
11 changed files with 212 additions and 109 deletions

View File

@ -23,8 +23,8 @@ type ExchangeRateUnit interface{}
type PayMethods string type PayMethods string
const ( const (
PAYMETHODCARD PayMethods = "CARD" PAY_METHOD_CARD PayMethods = "CARD"
PayMethodVISA PayMethods = "VISA" PayMethodVISA PayMethods = "VISA"
) )
// 支付状态 // 支付状态
@ -56,20 +56,21 @@ const (
type OrderStatusCode int64 type OrderStatusCode int64
const ( const (
ORDERSTATUSUNPAIDDEPOSIT OrderStatusCode = 0 // 0,未支付定金 ORDER_STATUS_UNPAIDDEPOSIT OrderStatusCode = 0 // 0,未支付定金
ORDERSTATUSDIRECTMAILORDERED OrderStatusCode = 10100 // 10100,直邮单--已下单 ORDER_STATUS_DIRECTMAIL_ORDERED OrderStatusCode = 10100 // 10100,直邮单--已下单
ORDERSTATUSDIRECTMAILORDEREDMAINING OrderStatusCode = 10100001 // 10100001,直邮单--已下单--尾款 ORDER_STATUS_DIRECTMAIL_ORDEREDMAINING OrderStatusCode = 10100001 // 10100001,直邮单--已下单--尾款
ORDERSTATUSDIRECTMAILCANCEL OrderStatusCode = 10101 // 10101,直邮单--已取消 ORDER_STATUS_DIRECTMAIL_CANCEL OrderStatusCode = 10101 // 10101,直邮单--已取消
ORDERSTATUSDIRECTMAILSTARTPRODUCTION OrderStatusCode = 10200 // 10200,直邮单--开始生产 ORDER_STATUS_DIRECTMAIL_STARTPRODUCTION OrderStatusCode = 10200 // 10200,直邮单--开始生产
ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION OrderStatusCode = 10300 // 10300,直邮单--生产完成 ORDER_STATUS_DIRECTMAIL_COMPLETEPRODUCTION OrderStatusCode = 10300 // 10300,直邮单--生产完成
ORDERSTATUSDIRECTMAILSHIPPED OrderStatusCode = 10400 // 10400,直邮单--已发货 ORDER_STATUS_DIRECTMAIL_SHIPPED OrderStatusCode = 10400 // 10400,直邮单--已发货
ORDERSTATUSDIRECTMAILARRIVED OrderStatusCode = 10500 // 10500,直邮单--已到达 ORDER_STATUS_DIRECTMAIL_ARRIVED OrderStatusCode = 10500 // 10500,直邮单--已到达
ORDERSTATUSCLOUDSTOREORDERED OrderStatusCode = 20100 // 20100,云仓单--已下单 ORDER_STATUS_CLOUDSTORE_ORDERED OrderStatusCode = 20100 // 20100,云仓单--已下单
ORDERSTATUSCLOUDSTOREORDEREDMAINING OrderStatusCode = 20100001 // 20100001,云仓单--已下单-尾款 ORDER_STATUS_CLOUDSTORE_ORDEREDMAINING OrderStatusCode = 20100001 // 20100001,云仓单--已下单-尾款
ORDERSTATUSCLOUDSTORECANCEL OrderStatusCode = 20101 // 20101,云仓单--已取消 ORDER_STATUS_CLOUDSTORE_CANCEL OrderStatusCode = 20101 // 20101,云仓单--已取消
ORDERSTATUSCLOUDSTORESTARTPRODUCTION OrderStatusCode = 20200 // 20200,云仓单--开始生产 ORDER_STATUS_CLOUDSTORE_STARTPRODUCTION OrderStatusCode = 20200 // 20200,云仓单--开始生产
ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION OrderStatusCode = 20300 // 20300,云仓单--生产完成 ORDER_STATUS_CLOUDSTORE_COMPLETEPRODUCTION OrderStatusCode = 20300 // 20300,云仓单--生产完成
ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE OrderStatusCode = 20400 // 20400,云仓单--直达仓库 ORDER_STATUS_CLOUDSTORE_ARRIVEDWAREHOUSE OrderStatusCode = 20400 // 20400,云仓单--直达仓库
ORDER_STATUS_COMPLETE OrderStatusCode = 30000 // 30000,订单完成
) )
// 订单状态名称 // 订单状态名称
@ -93,27 +94,29 @@ func init() {
// 订单状态名称 // 订单状态名称
OrderStatusMessage = make(map[OrderStatusCode]string) OrderStatusMessage = make(map[OrderStatusCode]string)
OrderStatusMessage[ORDERSTATUSUNPAIDDEPOSIT] = "未支付定金" OrderStatusMessage[ORDER_STATUS_UNPAIDDEPOSIT] = "未支付定金"
OrderStatusMessage[ORDERSTATUSDIRECTMAILORDERED] = "直邮单--已下单" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_ORDERED] = "直邮单--已下单"
OrderStatusMessage[ORDERSTATUSDIRECTMAILSTARTPRODUCTION] = "直邮单--开始生产" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_STARTPRODUCTION] = "直邮单--开始生产"
OrderStatusMessage[ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION] = "直邮单--生产完成" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_COMPLETEPRODUCTION] = "直邮单--生产完成"
OrderStatusMessage[ORDERSTATUSDIRECTMAILSHIPPED] = "直邮单--已发货" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_SHIPPED] = "直邮单--已发货"
OrderStatusMessage[ORDERSTATUSDIRECTMAILARRIVED] = "直邮单--已到达" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_ARRIVED] = "直邮单--已到达"
OrderStatusMessage[ORDERSTATUSCLOUDSTOREORDERED] = "云仓单--已下单" OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_ORDERED] = "云仓单--已下单"
OrderStatusMessage[ORDERSTATUSCLOUDSTORESTARTPRODUCTION] = "云仓单--开始生产" OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_STARTPRODUCTION] = "云仓单--开始生产"
OrderStatusMessage[ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION] = "云仓单--生产完成" OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_COMPLETEPRODUCTION] = "云仓单--生产完成"
OrderStatusMessage[ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE] = "云仓单--直达仓库" OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_ARRIVEDWAREHOUSE] = "云仓单--直达仓库"
OrderStatusMessage[ORDER_STATUS_COMPLETE] = "订单完成"
// 订单状态--用户可见--直邮 // 订单状态--用户可见--直邮
OrderStatusUserDIRECTMAIL = []OrderStatusCode{ OrderStatusUserDIRECTMAIL = []OrderStatusCode{
ORDERSTATUSUNPAIDDEPOSIT, ORDER_STATUS_UNPAIDDEPOSIT, ORDER_STATUS_COMPLETE,
ORDERSTATUSDIRECTMAILORDERED, ORDERSTATUSDIRECTMAILSTARTPRODUCTION, ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION, ORDERSTATUSDIRECTMAILSHIPPED, ORDERSTATUSDIRECTMAILARRIVED, ORDER_STATUS_DIRECTMAIL_ORDERED, ORDER_STATUS_DIRECTMAIL_STARTPRODUCTION, ORDER_STATUS_DIRECTMAIL_COMPLETEPRODUCTION, ORDER_STATUS_DIRECTMAIL_SHIPPED, ORDER_STATUS_DIRECTMAIL_ARRIVED,
} }
// 订单状态--用户可见--云仓 // 订单状态--用户可见--云仓
OrderStatusUserCLOUDSTORE = []OrderStatusCode{ OrderStatusUserCLOUDSTORE = []OrderStatusCode{
ORDERSTATUSUNPAIDDEPOSIT, ORDER_STATUS_UNPAIDDEPOSIT, ORDER_STATUS_COMPLETE,
ORDERSTATUSCLOUDSTOREORDERED, ORDERSTATUSCLOUDSTORESTARTPRODUCTION, ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION, ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE, ORDER_STATUS_CLOUDSTORE_ORDERED, ORDER_STATUS_CLOUDSTORE_STARTPRODUCTION, ORDER_STATUS_CLOUDSTORE_COMPLETEPRODUCTION, ORDER_STATUS_CLOUDSTORE_ARRIVEDWAREHOUSE,
} }
} }

View File

@ -95,12 +95,12 @@ type OrderStatus struct {
// 订单商品 // 订单商品
type OrderProduct struct { type OrderProduct struct {
TotalPrice AmountInfo `json:"amount"` // 商品总价 TotalPrice AmountInfo `json:"total_price"` // 商品总价
ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间 ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间
PurchaseQuantity PurchaseQuantity `json:"purchase_quantity"` // 购买数量 PurchaseQuantity PurchaseQuantity `json:"purchase_quantity"` // 购买数量
ProductID int64 `json:"product_id"` // 商品ID ProductID int64 `json:"product_id"` // 商品ID
ProductName string `json:"product_name"` // 商品名称 ProductName string `json:"product_name"` // 商品名称
ItemPrice AmountInfo `json:"product_price"` // 商品单价 ItemPrice AmountInfo `json:"item_price"` // 商品单价
ProductSnapshot interface{} `json:"product_snapshot"` // 商品快照 ProductSnapshot interface{} `json:"product_snapshot"` // 商品快照
ShoppingCartSnapshot *FsShoppingCartData `json:"shopping_cart_snapshot"` // 购物车快照 ShoppingCartSnapshot *FsShoppingCartData `json:"shopping_cart_snapshot"` // 购物车快照
ProductCover string `json:"product_cover"` // 商品封面 ProductCover string `json:"product_cover"` // 商品封面

View File

@ -4,7 +4,7 @@ import "context"
type RelaFsProduct struct { type RelaFsProduct struct {
FsProduct FsProduct
CoverResource *FsResource `json:"cover_resource" gorm:"foreignkey:cover;references:resource_id"` CoverResource *FsResource `json:"cover_resource" gorm:"foreignkey:cover;references:resource_url"`
} }
func (m *FsProductModel) TableName() string { func (m *FsProductModel) TableName() string {

View File

@ -152,3 +152,17 @@ func (d *FsProductModel3dModel) FindOneByProductIdSizeIdTag(ctx context.Context,
err = db.Take(&resp).Error err = db.Take(&resp).Error
return resp, err return resp, err
} }
func (d *FsProductModel3dModel) GetAllByProductIdsTags(ctx context.Context, productIds []int64, tags []int, fields ...string) (resp []FsProductModel3d, err error) {
if len(productIds) == 0 || len(tags) == 0 {
return
}
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).
Where("`product_id` in (?) and `tag` in (?) and `status` = ?", productIds, tags, 1).
Order("sort DESC")
if len(fields) != 0 {
db = db.Select(fields[0])
}
err = db.Find(&resp).Error
return resp, err
}

View File

@ -45,8 +45,31 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
// 如果是,返回未授权的错误码 // 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth) return resp.SetStatus(basic.CodeUnAuth)
} }
var nowTime = time.Now().UTC()
if req.LogoSelectedId == 0 { if req.LogoSelectedId == 0 {
return resp.SetStatus(basic.CodeLogoSetCategory, "logo logo_selected_id not null") NewFsUserMaterialModel1 := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
NewFsUserMaterialModelRow1 := NewFsUserMaterialModel1.RowSelectBuilder(nil).Where("id = ?", 0)
defaultMaterialInfo, err := NewFsUserMaterialModel1.FindOne(l.ctx, NewFsUserMaterialModelRow1.Model(&gmodel.FsUserMaterial{}))
if err != nil {
logc.Errorf(l.ctx, "defaultMaterialInfo FindOne err%+v", err)
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find")
}
var defaultMaterial = gmodel.FsUserMaterial{
Module: defaultMaterialInfo.Module,
UserId: &userinfo.UserId,
GuestId: &userinfo.GuestId,
ResourceId: defaultMaterialInfo.ResourceId,
ResourceUrl: defaultMaterialInfo.ResourceUrl,
Ctime: &nowTime,
}
MaterialCreateRes := l.svcCtx.MysqlConn.Create(&defaultMaterial)
err = MaterialCreateRes.Error
if err != nil {
logc.Errorf(l.ctx, "defaultMaterialInfo Create err%+v", err)
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find")
}
req.LogoSelectedId = defaultMaterial.Id
} }
if req.SetLogoCategory == 1 && req.CategoryId == 0 { if req.SetLogoCategory == 1 && req.CategoryId == 0 {
return resp.SetStatus(basic.CodeLogoSetCategory, "logo category_id not null") return resp.SetStatus(basic.CodeLogoSetCategory, "logo category_id not null")
@ -73,7 +96,6 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find") 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 { err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
var metadataMapOldUserMaterial map[string]interface{} var metadataMapOldUserMaterial map[string]interface{}
if userMaterialInfo.Metadata != nil { if userMaterialInfo.Metadata != nil {

View File

@ -105,11 +105,18 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
} }
} }
stepRange := make([]interface{}, 0, rangeLen) stepRange := make([]interface{}, 0, rangeLen)
for _, rangeInfo := range stepPrice.PriceRange { for rIndex, rangeInfo := range stepPrice.PriceRange {
//最后一个
if rIndex+1 == rangeLen {
stepRange = append(stepRange, map[string]interface{}{
"range_description": fmt.Sprintf(">=%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity)),
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
})
break
}
stepRange = append(stepRange, map[string]interface{}{ stepRange = append(stepRange, map[string]interface{}{
"start_quantity": rangeInfo.StartQuantity, "range_description": fmt.Sprintf("%s-%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity), format.NumToStringWithThousandthPercentile(rangeInfo.EndQuantity)),
"end_quantity": rangeInfo.EndQuantity, "item_price": format.CentitoDollar(rangeInfo.Price, 3),
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
}) })
} }
mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{ mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{

View File

@ -3,10 +3,11 @@ package logic
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel" "fusenapi/model/gmodel"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image" "fusenapi/utils/image"
"fusenapi/utils/s3url_to_s3id" "fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm" "gorm.io/gorm"
@ -228,32 +229,52 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
CoverMetadata: req.MapResourceMetadata[*v.Cover], CoverMetadata: req.MapResourceMetadata[*v.Cover],
}) })
} }
//获取产品价格列表 //获取产品模型价格列表
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price")
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return nil, errors.New("failed to get product min price list") return nil, errors.New("failed to get model list")
} }
//存储产品最小价格 mapModelMinPrice := make(map[int64]int64)
for _, v := range productPriceList { //每个模型/配件存储最小价格
priceStrSlic := strings.Split(v.Price, ",") for _, modelInfo := range modelList {
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic) switch *modelInfo.Tag {
if err != nil { case constants.TAG_MODEL: //模型
logx.Error(err) if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
return nil, errors.New("parse price err") return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id))
}
var stepPrice gmodel.StepPriceJsonStruct
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
logx.Error(err)
return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id))
}
lenRange := len(stepPrice.PriceRange)
if lenRange == 0 {
return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id))
}
mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price
case constants.TAG_PARTS: //配件
mapModelMinPrice[modelInfo.Id] = *modelInfo.Price
} }
if len(priceSlice) == 0 { }
//给产品存储最小价格
for _, v := range modelList {
if *v.Tag != constants.TAG_MODEL {
continue continue
} }
//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算) itemPrice := mapModelMinPrice[v.Id]
sort.Ints(priceSlice) if *v.PartId > 0 {
if min, ok := req.MapProductMinPrice[v.ProductId]; ok { if fittingPrice, ok := mapModelMinPrice[*v.PartId]; ok {
if min > int64(priceSlice[0]) { itemPrice += fittingPrice
req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0])
} }
} else {
req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0])
} }
if minPrice, ok := req.MapProductMinPrice[*v.ProductId]; ok {
if itemPrice < minPrice {
req.MapProductMinPrice[*v.ProductId] = itemPrice
}
continue
}
req.MapProductMinPrice[*v.ProductId] = itemPrice
} }
//获取模板 //获取模板
productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag") productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag")

View File

@ -23,7 +23,7 @@ var (
//每个websocket渲染任务缓冲队列长度默认值 //每个websocket渲染任务缓冲队列长度默认值
renderChanLen = 500 renderChanLen = 500
//每个websocket渲染并发数 //每个websocket渲染并发数
renderChanConcurrency = 1 renderChanConcurrency = 500
) )
// 渲染处理器 // 渲染处理器
@ -369,7 +369,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
} }
//发送运行阶段消息 //发送运行阶段消息
w.sendRenderDataToUnityStepResponseMessage(info.RenderId) w.sendRenderDataToUnityStepResponseMessage(info.RenderId)
logx.Info("发送到unity成功,刀版图:", combineImage , " 请求unity的数据:", string(postDataBytes)) logx.Info("发送到unity成功,刀版图:", combineImage /*, " 请求unity的数据:", string(postDataBytes)*/)
return nil return nil
} }

View File

@ -17,7 +17,6 @@ import (
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
"github.com/stripe/stripe-go/v75" "github.com/stripe/stripe-go/v75"
"github.com/zeromicro/go-zero/core/logc" "github.com/zeromicro/go-zero/core/logc"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -226,12 +225,12 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
result := tx.Where("is_del = ?", 0).Where("order_sn = ?", orderSn).Take(&orderInfo) result := tx.Where("is_del = ?", 0).Where("order_sn = ?", orderSn).Take(&orderInfo)
err = result.Error err = result.Error
if err != nil { if err != nil {
logx.Errorf("PaymentSuccessful failed order Take, eventId:%s,err: %v", in.EventId, err) logc.Errorf(ctx, "PaymentSuccessful failed order Take, eventId:%s,err: %v", in.EventId, err)
return err return err
} }
ress, err := d.OrderDetailHandler(ctx, &orderInfo, 0) ress, err := d.OrderDetailHandler(ctx, &orderInfo, 0)
if err != nil { if err != nil {
logx.Errorf("PaymentSuccessful failed DetailOrderDetailHandler,eventId:%s, err: %v", in.EventId, err) logc.Errorf(ctx, "PaymentSuccessful failed DetailOrderDetailHandler,eventId:%s, err: %v", in.EventId, err)
return err return err
} }
var ntime = time.Now().UTC() var ntime = time.Now().UTC()
@ -253,11 +252,11 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
if payStage == "deposit" { if payStage == "deposit" {
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
// 直邮 // 直邮
statusCode = constants.ORDERSTATUSDIRECTMAILORDERED statusCode = constants.ORDER_STATUS_DIRECTMAIL_ORDERED
} }
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE { if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE {
// 云仓 // 云仓
statusCode = constants.ORDERSTATUSCLOUDSTOREORDERED statusCode = constants.ORDER_STATUS_CLOUDSTORE_ORDERED
} }
payStageInt = 1 payStageInt = 1
orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDEPOSIT orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDEPOSIT
@ -287,13 +286,13 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
if payStage == "remaining_balance" { if payStage == "remaining_balance" {
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
// 直邮 // 直邮
statusCodePre = constants.ORDERSTATUSDIRECTMAILORDERED statusCodePre = constants.ORDER_STATUS_DIRECTMAIL_ORDERED
statusCode = constants.ORDERSTATUSDIRECTMAILORDEREDMAINING statusCode = constants.ORDER_STATUS_DIRECTMAIL_ORDEREDMAINING
} }
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE { if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE {
// 云仓 // 云仓
statusCodePre = constants.ORDERSTATUSCLOUDSTOREORDERED statusCodePre = constants.ORDER_STATUS_CLOUDSTORE_ORDERED
statusCode = constants.ORDERSTATUSCLOUDSTOREORDEREDMAINING statusCode = constants.ORDER_STATUS_CLOUDSTORE_ORDEREDMAINING
} }
payStageInt = 2 payStageInt = 2
orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDREMAINING orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDREMAINING
@ -313,7 +312,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
} }
statusLink = ress.OrderDetail.OrderInfo.StatusLink statusLink = ress.OrderDetail.OrderInfo.StatusLink
if ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDERSTATUSDIRECTMAILORDERED || ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDERSTATUSCLOUDSTOREORDERED { if ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDER_STATUS_DIRECTMAIL_ORDERED || ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDER_STATUS_CLOUDSTORE_ORDERED {
status = ress.OrderDetail.OrderInfo.Status status = ress.OrderDetail.OrderInfo.Status
status.Children = statusChildren status.Children = statusChildren
} }
@ -349,7 +348,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
PayTitle: &payTitle, PayTitle: &payTitle,
}) })
var sql string var sql string
if *orderInfo.Status == int64(constants.ORDERSTATUSUNPAIDDEPOSIT) { if *orderInfo.Status == int64(constants.ORDER_STATUS_UNPAIDDEPOSIT) {
sql = fmt.Sprintf(", `utime` = '%s', `pay_status` = %d, `status` = %d ", ntime, orderPayStatusCode, statusCode) sql = fmt.Sprintf(", `utime` = '%s', `pay_status` = %d, `status` = %d ", ntime, orderPayStatusCode, statusCode)
} else { } else {
sql = fmt.Sprintf(", `utime` = '%s', `pay_status` = %d", ntime, orderPayStatusCode) sql = fmt.Sprintf(", `utime` = '%s', `pay_status` = %d", ntime, orderPayStatusCode)
@ -370,7 +369,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
if len(uOrderDetail) > 0 { if len(uOrderDetail) > 0 {
err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, orderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", orderInfo.Id) err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, orderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", orderInfo.Id)
if err != nil { if err != nil {
logx.Errorf("PaymentSuccessful failed MetadataOrderPATCH,eventId:%s, err: %v", in.EventId, err) logc.Errorf(ctx, "PaymentSuccessful failed MetadataOrderPATCH,eventId:%s, err: %v", in.EventId, err)
return err return err
} }
} }
@ -399,7 +398,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
} else { } else {
errorCode = *basic.CodeServiceErr errorCode = *basic.CodeServiceErr
} }
logx.Errorf("create prePayment balance failed, err: %v", err) logc.Errorf(ctx, "create prePayment balance failed, err: %v", err)
return &CreatePrePaymentByBalanceRes{ return &CreatePrePaymentByBalanceRes{
ErrorCode: errorCode, ErrorCode: errorCode,
}, result.Error }, result.Error
@ -408,7 +407,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
if *order.PayStatus != int64(constants.ORDERPAYSTATUSPAIDDEPOSIT) { if *order.PayStatus != int64(constants.ORDERPAYSTATUSPAIDDEPOSIT) {
errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid
err = errors.New("order balance pay status is not unPaid") err = errors.New("order balance pay status is not unPaid")
logx.Errorf("create prePayment balance failed, err: %v", err) logc.Errorf(ctx, "create prePayment balance failed, err: %v", err)
return &CreatePrePaymentByBalanceRes{ return &CreatePrePaymentByBalanceRes{
ErrorCode: errorCode, ErrorCode: errorCode,
}, err }, err
@ -416,7 +415,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
ress, err := d.OrderDetailHandler(ctx, &order, 1) ress, err := d.OrderDetailHandler(ctx, &order, 1)
if err != nil { if err != nil {
logx.Errorf("create prePayment balance failed DetailOrderDetailHandler, err: %v", err) logc.Errorf(ctx, "create prePayment balance failed DetailOrderDetailHandler, err: %v", err)
errorCode = *basic.CodeServiceErr errorCode = *basic.CodeServiceErr
return &CreatePrePaymentByBalanceRes{ return &CreatePrePaymentByBalanceRes{
ErrorCode: errorCode, ErrorCode: errorCode,
@ -444,7 +443,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
prepaymentRes, err := payDriver.GeneratePrepayment(generatePrepaymentReq) prepaymentRes, err := payDriver.GeneratePrepayment(generatePrepaymentReq)
if err != nil { if err != nil {
logx.Errorf("create prePayment balance failed GeneratePrepayment, err: %v", err) logc.Errorf(ctx, "create prePayment balance failed GeneratePrepayment, err: %v", err)
errorCode = *basic.CodeServiceErr errorCode = *basic.CodeServiceErr
return &CreatePrePaymentByBalanceRes{ return &CreatePrePaymentByBalanceRes{
ErrorCode: errorCode, ErrorCode: errorCode,
@ -485,7 +484,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
} else { } else {
errorCode = *basic.CodeServiceErr errorCode = *basic.CodeServiceErr
} }
logx.Errorf("create prePayment deposit failed, err: %v", err) logc.Errorf(ctx, "create prePayment deposit failed, err: %v", err)
return &CreatePrePaymentByDepositRes{ return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode, ErrorCode: errorCode,
}, result.Error }, result.Error
@ -495,7 +494,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
if *order.PayStatus != int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT) { if *order.PayStatus != int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT) {
errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid
err = errors.New("order pay status is not unPaidDeposit") err = errors.New("order pay status is not unPaidDeposit")
logx.Errorf("create prePayment deposit failed, err: %v", err) logc.Errorf(ctx, "create prePayment deposit failed, err: %v", err)
return &CreatePrePaymentByDepositRes{ return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode, ErrorCode: errorCode,
}, err }, err
@ -511,7 +510,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
if ctimeTimeOut == ntimeTimeOut { if ctimeTimeOut == ntimeTimeOut {
errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout
err = errors.New("order pay timeout") err = errors.New("order pay timeout")
logx.Errorf("create prePayment deposit failed, err: %v", err) logc.Errorf(ctx, "create prePayment deposit failed, err: %v", err)
return &CreatePrePaymentByDepositRes{ return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode, ErrorCode: errorCode,
}, err }, err
@ -519,7 +518,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
ress, err := d.OrderDetailHandler(ctx, &order, 0) ress, err := d.OrderDetailHandler(ctx, &order, 0)
if err != nil { if err != nil {
logx.Errorf("create prePayment deposit failed DetailOrderDetailHandler, err: %v", err) logc.Errorf(ctx, "create prePayment deposit failed DetailOrderDetailHandler, err: %v", err)
errorCode = *basic.CodeServiceErr errorCode = *basic.CodeServiceErr
return &CreatePrePaymentByDepositRes{ return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode, ErrorCode: errorCode,
@ -573,7 +572,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, in.OrderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", order.Id) err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, in.OrderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", order.Id)
if err != nil { if err != nil {
errorCode = *basic.CodeServiceErr errorCode = *basic.CodeServiceErr
logx.Errorf("create prePayment deposit failed MetadataOrderPATCH, err: %v", err) logc.Errorf(ctx, "create prePayment deposit failed MetadataOrderPATCH, err: %v", err)
return &CreatePrePaymentByDepositRes{ return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode, ErrorCode: errorCode,
}, result.Error }, result.Error
@ -606,7 +605,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
prepaymentRes, err := payDriver.GeneratePrepayment(generatePrepaymentReq) prepaymentRes, err := payDriver.GeneratePrepayment(generatePrepaymentReq)
if err != nil { if err != nil {
logx.Errorf("create prePayment deposit failed GeneratePrepayment, err: %v", err) logc.Errorf(ctx, "create prePayment deposit failed GeneratePrepayment, err: %v", err)
errorCode = *basic.CodeServiceErr errorCode = *basic.CodeServiceErr
return &CreatePrePaymentByDepositRes{ return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode, ErrorCode: errorCode,
@ -657,7 +656,7 @@ func (d *defaultOrder) List(ctx context.Context, in *ListReq) (res *ListRes, err
var count int64 var count int64
resultCount := model.Count(&count) resultCount := model.Count(&count)
if resultCount.Error != nil { if resultCount.Error != nil {
logx.Errorf("order count failed, err: %v", err) logc.Errorf(ctx, "order count failed, err: %v", err)
return nil, resultCount.Error return nil, resultCount.Error
} }
var orderDetailList []gmodel.OrderDetail var orderDetailList []gmodel.OrderDetail
@ -665,7 +664,7 @@ func (d *defaultOrder) List(ctx context.Context, in *ListReq) (res *ListRes, err
m := model.Scopes(handlers.Paginate(&in.CurrentPage, &in.PerPage)) m := model.Scopes(handlers.Paginate(&in.CurrentPage, &in.PerPage))
result := m.Find(&orderList) result := m.Find(&orderList)
if result.Error != nil { if result.Error != nil {
logx.Errorf("order list failed, err: %v", err) logc.Errorf(ctx, "order list failed, err: %v", err)
return nil, result.Error return nil, result.Error
} }
for _, order := range orderList { for _, order := range orderList {
@ -707,28 +706,30 @@ func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRe
} else { } else {
errorCode = *basic.CodeServiceErr errorCode = *basic.CodeServiceErr
} }
logx.Errorf("order detail failed, err: %v", err) logc.Errorf(ctx, "order detail failed, err: %v", err)
return &DetailRes{ return &DetailRes{
ErrorCode: errorCode, ErrorCode: errorCode,
}, result.Error }, result.Error
} }
// 是否超时支付 // 是否超时支付
ctime := *order.Ctime // if *order.Status == int64(constants.ORDER_STATUS_UNPAIDDEPOSIT) {
ctimeTimeOut := ctime.Add(30 * time.Minute).UTC().Unix() // ctime := *order.Ctime
ntimeTimeOut := time.Now().UTC().Unix() // ctimeTimeOut := ctime.Add(30 * time.Minute).UTC().Unix()
if ctimeTimeOut < ntimeTimeOut { // ntimeTimeOut := time.Now().UTC().Unix()
errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout // if ctimeTimeOut < ntimeTimeOut {
err = errors.New("order pay timeout") // errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout
logx.Errorf("order detail failed, err: %v", err) // err = errors.New("order pay timeout")
return &DetailRes{ // logc.Errorf(ctx, "order detail failed, err: %v", err)
ErrorCode: errorCode, // return &DetailRes{
}, err // ErrorCode: errorCode,
} // }, err
// }
// }
ress, err := d.OrderDetailHandler(ctx, &order, 1) ress, err := d.OrderDetailHandler(ctx, &order, 1)
if err != nil { if err != nil {
logx.Errorf("order detail failed, err: %v", err) logc.Errorf(ctx, "order detail failed, err: %v", err)
errorCode = *basic.CodeServiceErr errorCode = *basic.CodeServiceErr
return &DetailRes{ return &DetailRes{
ErrorCode: errorCode, ErrorCode: errorCode,
@ -983,8 +984,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
var status = gmodel.OrderStatus{ var status = gmodel.OrderStatus{
Ctime: &nowTime, Ctime: &nowTime,
Utime: &nowTime, Utime: &nowTime,
StatusCode: constants.ORDERSTATUSUNPAIDDEPOSIT, StatusCode: constants.ORDER_STATUS_UNPAIDDEPOSIT,
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSUNPAIDDEPOSIT], StatusTitle: constants.OrderStatusMessage[constants.ORDER_STATUS_UNPAIDDEPOSIT],
} }
// 订单状态--链路 // 订单状态--链路
var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime, in.ExpectedDeliveryTime) var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime, in.ExpectedDeliveryTime)
@ -1004,8 +1005,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
PayStatus: payStatus, PayStatus: payStatus,
PayTimeout: 30 * time.Minute, PayTimeout: 30 * time.Minute,
} }
// 数据库操作
// 数据库操作
orderDetailByte, err := json.Marshal(orderDetail) orderDetailByte, err := json.Marshal(orderDetail)
if err != nil { if err != nil {
return err return err
@ -1019,14 +1020,21 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
Ctime: &nowTime, Ctime: &nowTime,
Metadata: &orderDetailByte, Metadata: &orderDetailByte,
} }
result := tx.Create(&order) // 创建订单
if result.Error != nil { resultCreate := tx.Create(&order)
return result.Error if resultCreate.Error != nil {
return resultCreate.Error
} }
// 删除购物车
resultDelete := tx.Delete(&gmodel.FsShoppingCart{}, in.CartIds)
if resultDelete.Error != nil {
return resultDelete.Error
}
return nil return nil
}) })
if err != nil { if err != nil {
logx.Errorf("order create order failed, err: %v", err) logc.Errorf(ctx, "order create order failed, err: %v", err)
if errorCode.Code == 0 { if errorCode.Code == 0 {
errorCode.Code = basic.CodeApiErr.Code errorCode.Code = basic.CodeApiErr.Code
@ -1109,7 +1117,7 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel
err = json.Unmarshal(*orderInfo.Metadata, &orderDetail) err = json.Unmarshal(*orderInfo.Metadata, &orderDetail)
if err != nil { if err != nil {
logx.Errorf("order detail handler unmarshal metadata failed, err: %v", err) logc.Errorf(ctx, "order detail handler unmarshal metadata failed, err: %v", err)
return nil, err return nil, err
} }
orderDetailOriginal := orderDetail orderDetailOriginal := orderDetail

25
utils/format/number.go Normal file
View File

@ -0,0 +1,25 @@
package format
import (
"fmt"
"strings"
)
// 数字变成带千分位的字符串
func NumToStringWithThousandthPercentile(number int64) string {
s := fmt.Sprintf("%d", number)
l := len(s)
if l <= 3 {
return s
}
r := l % 3 //前面第几位开始加入千分位
b := strings.Builder{}
for i := 0; i < l; i++ {
b.WriteString(string(s[i]))
if i+1 == r && i != l-1 {
b.WriteString(",")
r += 3
}
}
return b.String()
}

View File

@ -6,9 +6,10 @@ import (
) )
type GetTemplateSwitchInfoRsp struct { type GetTemplateSwitchInfoRsp struct {
Id int64 `json:"id"` Id int64 `json:"id"`
Material string `json:"material"` Material string `json:"material"`
MaterialData MaterialData `json:"material_data"` MaterialData MaterialData `json:"material_data"`
CombineIsVisible bool `json:"combine_is_visible"` //合图总开关是否开启
} }
type MaterialData struct { type MaterialData struct {
QRcode QRcode `json:"QRcode"` QRcode QRcode `json:"QRcode"`
@ -68,6 +69,7 @@ func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMa
Material: "/image/logo/aHnT1_rzubdwax_scale.png", Material: "/image/logo/aHnT1_rzubdwax_scale.png",
}, },
}, },
CombineIsVisible: false,
} }
if templateJsonStr == nil || *templateJsonStr == "" { if templateJsonStr == nil || *templateJsonStr == "" {
return returnData return returnData
@ -78,7 +80,7 @@ func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMa
return returnData return returnData
} }
for _, v := range templateJsonInfo.MaterialList { for _, v := range templateJsonInfo.MaterialList {
if v.Type == "combine" && !v.Visible { if v.Type == "combine" {
return GetTemplateSwitchInfoRsp{ return GetTemplateSwitchInfoRsp{
Id: templateId, Id: templateId,
Material: templateMaterialImg, Material: templateMaterialImg,
@ -87,6 +89,7 @@ func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMa
Material: "/image/logo/aHnT1_rzubdwax_scale.png", Material: "/image/logo/aHnT1_rzubdwax_scale.png",
}, },
}, },
CombineIsVisible: v.Visible,
} }
} }
switch v.Tag { switch v.Tag {