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
const (
PAYMETHODCARD PayMethods = "CARD"
PayMethodVISA PayMethods = "VISA"
PAY_METHOD_CARD PayMethods = "CARD"
PayMethodVISA PayMethods = "VISA"
)
// 支付状态
@ -56,20 +56,21 @@ const (
type OrderStatusCode int64
const (
ORDERSTATUSUNPAIDDEPOSIT OrderStatusCode = 0 // 0,未支付定金
ORDERSTATUSDIRECTMAILORDERED OrderStatusCode = 10100 // 10100,直邮单--已下单
ORDERSTATUSDIRECTMAILORDEREDMAINING OrderStatusCode = 10100001 // 10100001,直邮单--已下单--尾款
ORDERSTATUSDIRECTMAILCANCEL OrderStatusCode = 10101 // 10101,直邮单--已取消
ORDERSTATUSDIRECTMAILSTARTPRODUCTION OrderStatusCode = 10200 // 10200,直邮单--开始生产
ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION OrderStatusCode = 10300 // 10300,直邮单--生产完成
ORDERSTATUSDIRECTMAILSHIPPED OrderStatusCode = 10400 // 10400,直邮单--已发货
ORDERSTATUSDIRECTMAILARRIVED OrderStatusCode = 10500 // 10500,直邮单--已到达
ORDERSTATUSCLOUDSTOREORDERED OrderStatusCode = 20100 // 20100,云仓单--已下单
ORDERSTATUSCLOUDSTOREORDEREDMAINING OrderStatusCode = 20100001 // 20100001,云仓单--已下单-尾款
ORDERSTATUSCLOUDSTORECANCEL OrderStatusCode = 20101 // 20101,云仓单--已取消
ORDERSTATUSCLOUDSTORESTARTPRODUCTION OrderStatusCode = 20200 // 20200,云仓单--开始生产
ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION OrderStatusCode = 20300 // 20300,云仓单--生产完成
ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE OrderStatusCode = 20400 // 20400,云仓单--直达仓库
ORDER_STATUS_UNPAIDDEPOSIT OrderStatusCode = 0 // 0,未支付定金
ORDER_STATUS_DIRECTMAIL_ORDERED OrderStatusCode = 10100 // 10100,直邮单--已下单
ORDER_STATUS_DIRECTMAIL_ORDEREDMAINING OrderStatusCode = 10100001 // 10100001,直邮单--已下单--尾款
ORDER_STATUS_DIRECTMAIL_CANCEL OrderStatusCode = 10101 // 10101,直邮单--已取消
ORDER_STATUS_DIRECTMAIL_STARTPRODUCTION OrderStatusCode = 10200 // 10200,直邮单--开始生产
ORDER_STATUS_DIRECTMAIL_COMPLETEPRODUCTION OrderStatusCode = 10300 // 10300,直邮单--生产完成
ORDER_STATUS_DIRECTMAIL_SHIPPED OrderStatusCode = 10400 // 10400,直邮单--已发货
ORDER_STATUS_DIRECTMAIL_ARRIVED OrderStatusCode = 10500 // 10500,直邮单--已到达
ORDER_STATUS_CLOUDSTORE_ORDERED OrderStatusCode = 20100 // 20100,云仓单--已下单
ORDER_STATUS_CLOUDSTORE_ORDEREDMAINING OrderStatusCode = 20100001 // 20100001,云仓单--已下单-尾款
ORDER_STATUS_CLOUDSTORE_CANCEL OrderStatusCode = 20101 // 20101,云仓单--已取消
ORDER_STATUS_CLOUDSTORE_STARTPRODUCTION OrderStatusCode = 20200 // 20200,云仓单--开始生产
ORDER_STATUS_CLOUDSTORE_COMPLETEPRODUCTION OrderStatusCode = 20300 // 20300,云仓单--生产完成
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[ORDERSTATUSUNPAIDDEPOSIT] = "未支付定金"
OrderStatusMessage[ORDER_STATUS_UNPAIDDEPOSIT] = "未支付定金"
OrderStatusMessage[ORDERSTATUSDIRECTMAILORDERED] = "直邮单--已下单"
OrderStatusMessage[ORDERSTATUSDIRECTMAILSTARTPRODUCTION] = "直邮单--开始生产"
OrderStatusMessage[ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION] = "直邮单--生产完成"
OrderStatusMessage[ORDERSTATUSDIRECTMAILSHIPPED] = "直邮单--已发货"
OrderStatusMessage[ORDERSTATUSDIRECTMAILARRIVED] = "直邮单--已到达"
OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_ORDERED] = "直邮单--已下单"
OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_STARTPRODUCTION] = "直邮单--开始生产"
OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_COMPLETEPRODUCTION] = "直邮单--生产完成"
OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_SHIPPED] = "直邮单--已发货"
OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_ARRIVED] = "直邮单--已到达"
OrderStatusMessage[ORDERSTATUSCLOUDSTOREORDERED] = "云仓单--已下单"
OrderStatusMessage[ORDERSTATUSCLOUDSTORESTARTPRODUCTION] = "云仓单--开始生产"
OrderStatusMessage[ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION] = "云仓单--生产完成"
OrderStatusMessage[ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE] = "云仓单--直达仓库"
OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_ORDERED] = "云仓单--已下单"
OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_STARTPRODUCTION] = "云仓单--开始生产"
OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_COMPLETEPRODUCTION] = "云仓单--生产完成"
OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_ARRIVEDWAREHOUSE] = "云仓单--直达仓库"
OrderStatusMessage[ORDER_STATUS_COMPLETE] = "订单完成"
// 订单状态--用户可见--直邮
OrderStatusUserDIRECTMAIL = []OrderStatusCode{
ORDERSTATUSUNPAIDDEPOSIT,
ORDERSTATUSDIRECTMAILORDERED, ORDERSTATUSDIRECTMAILSTARTPRODUCTION, ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION, ORDERSTATUSDIRECTMAILSHIPPED, ORDERSTATUSDIRECTMAILARRIVED,
ORDER_STATUS_UNPAIDDEPOSIT, ORDER_STATUS_COMPLETE,
ORDER_STATUS_DIRECTMAIL_ORDERED, ORDER_STATUS_DIRECTMAIL_STARTPRODUCTION, ORDER_STATUS_DIRECTMAIL_COMPLETEPRODUCTION, ORDER_STATUS_DIRECTMAIL_SHIPPED, ORDER_STATUS_DIRECTMAIL_ARRIVED,
}
// 订单状态--用户可见--云仓
OrderStatusUserCLOUDSTORE = []OrderStatusCode{
ORDERSTATUSUNPAIDDEPOSIT,
ORDERSTATUSCLOUDSTOREORDERED, ORDERSTATUSCLOUDSTORESTARTPRODUCTION, ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION, ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE,
ORDER_STATUS_UNPAIDDEPOSIT, ORDER_STATUS_COMPLETE,
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 {
TotalPrice AmountInfo `json:"amount"` // 商品总价
TotalPrice AmountInfo `json:"total_price"` // 商品总价
ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间
PurchaseQuantity PurchaseQuantity `json:"purchase_quantity"` // 购买数量
ProductID int64 `json:"product_id"` // 商品ID
ProductName string `json:"product_name"` // 商品名称
ItemPrice AmountInfo `json:"product_price"` // 商品单价
ItemPrice AmountInfo `json:"item_price"` // 商品单价
ProductSnapshot interface{} `json:"product_snapshot"` // 商品快照
ShoppingCartSnapshot *FsShoppingCartData `json:"shopping_cart_snapshot"` // 购物车快照
ProductCover string `json:"product_cover"` // 商品封面

View File

@ -4,7 +4,7 @@ import "context"
type RelaFsProduct struct {
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 {

View File

@ -152,3 +152,17 @@ func (d *FsProductModel3dModel) FindOneByProductIdSizeIdTag(ctx context.Context,
err = db.Take(&resp).Error
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)
}
var nowTime = time.Now().UTC()
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 {
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")
}
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 {

View File

@ -105,11 +105,18 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
}
}
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{}{
"start_quantity": rangeInfo.StartQuantity,
"end_quantity": rangeInfo.EndQuantity,
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
"range_description": fmt.Sprintf("%s-%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity), format.NumToStringWithThousandthPercentile(rangeInfo.EndQuantity)),
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
})
}
mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{

View File

@ -3,10 +3,11 @@ package logic
import (
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
@ -228,32 +229,52 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
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 {
logx.Error(err)
return nil, errors.New("failed to get product min price list")
return nil, errors.New("failed to get model list")
}
//存储产品最小价格
for _, v := range productPriceList {
priceStrSlic := strings.Split(v.Price, ",")
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
if err != nil {
logx.Error(err)
return nil, errors.New("parse price err")
mapModelMinPrice := make(map[int64]int64)
//每个模型/配件存储最小价格
for _, modelInfo := range modelList {
switch *modelInfo.Tag {
case constants.TAG_MODEL: //模型
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
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
}
//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算)
sort.Ints(priceSlice)
if min, ok := req.MapProductMinPrice[v.ProductId]; ok {
if min > int64(priceSlice[0]) {
req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0])
itemPrice := mapModelMinPrice[v.Id]
if *v.PartId > 0 {
if fittingPrice, ok := mapModelMinPrice[*v.PartId]; ok {
itemPrice += fittingPrice
}
} 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")

View File

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

View File

@ -17,7 +17,6 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/stripe/stripe-go/v75"
"github.com/zeromicro/go-zero/core/logc"
"github.com/zeromicro/go-zero/core/logx"
"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)
err = result.Error
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
}
ress, err := d.OrderDetailHandler(ctx, &orderInfo, 0)
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
}
var ntime = time.Now().UTC()
@ -253,11 +252,11 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
if payStage == "deposit" {
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
// 直邮
statusCode = constants.ORDERSTATUSDIRECTMAILORDERED
statusCode = constants.ORDER_STATUS_DIRECTMAIL_ORDERED
}
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE {
// 云仓
statusCode = constants.ORDERSTATUSCLOUDSTOREORDERED
statusCode = constants.ORDER_STATUS_CLOUDSTORE_ORDERED
}
payStageInt = 1
orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDEPOSIT
@ -287,13 +286,13 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
if payStage == "remaining_balance" {
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
// 直邮
statusCodePre = constants.ORDERSTATUSDIRECTMAILORDERED
statusCode = constants.ORDERSTATUSDIRECTMAILORDEREDMAINING
statusCodePre = constants.ORDER_STATUS_DIRECTMAIL_ORDERED
statusCode = constants.ORDER_STATUS_DIRECTMAIL_ORDEREDMAINING
}
if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDSCLOUDSTORE {
// 云仓
statusCodePre = constants.ORDERSTATUSCLOUDSTOREORDERED
statusCode = constants.ORDERSTATUSCLOUDSTOREORDEREDMAINING
statusCodePre = constants.ORDER_STATUS_CLOUDSTORE_ORDERED
statusCode = constants.ORDER_STATUS_CLOUDSTORE_ORDEREDMAINING
}
payStageInt = 2
orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDREMAINING
@ -313,7 +312,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
}
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.Children = statusChildren
}
@ -349,7 +348,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess
PayTitle: &payTitle,
})
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)
} else {
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 {
err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, orderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", orderInfo.Id)
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
}
}
@ -399,7 +398,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
} else {
errorCode = *basic.CodeServiceErr
}
logx.Errorf("create prePayment balance failed, err: %v", err)
logc.Errorf(ctx, "create prePayment balance failed, err: %v", err)
return &CreatePrePaymentByBalanceRes{
ErrorCode: errorCode,
}, result.Error
@ -408,7 +407,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
if *order.PayStatus != int64(constants.ORDERPAYSTATUSPAIDDEPOSIT) {
errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid
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{
ErrorCode: errorCode,
}, err
@ -416,7 +415,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
ress, err := d.OrderDetailHandler(ctx, &order, 1)
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
return &CreatePrePaymentByBalanceRes{
ErrorCode: errorCode,
@ -444,7 +443,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
prepaymentRes, err := payDriver.GeneratePrepayment(generatePrepaymentReq)
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
return &CreatePrePaymentByBalanceRes{
ErrorCode: errorCode,
@ -485,7 +484,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
} else {
errorCode = *basic.CodeServiceErr
}
logx.Errorf("create prePayment deposit failed, err: %v", err)
logc.Errorf(ctx, "create prePayment deposit failed, err: %v", err)
return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode,
}, result.Error
@ -495,7 +494,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
if *order.PayStatus != int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT) {
errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid
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{
ErrorCode: errorCode,
}, err
@ -511,7 +510,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
if ctimeTimeOut == ntimeTimeOut {
errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout
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{
ErrorCode: errorCode,
}, err
@ -519,7 +518,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
ress, err := d.OrderDetailHandler(ctx, &order, 0)
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
return &CreatePrePaymentByDepositRes{
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)
if err != nil {
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{
ErrorCode: errorCode,
}, result.Error
@ -606,7 +605,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
prepaymentRes, err := payDriver.GeneratePrepayment(generatePrepaymentReq)
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
return &CreatePrePaymentByDepositRes{
ErrorCode: errorCode,
@ -657,7 +656,7 @@ func (d *defaultOrder) List(ctx context.Context, in *ListReq) (res *ListRes, err
var count int64
resultCount := model.Count(&count)
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
}
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))
result := m.Find(&orderList)
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
}
for _, order := range orderList {
@ -707,28 +706,30 @@ func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRe
} else {
errorCode = *basic.CodeServiceErr
}
logx.Errorf("order detail failed, err: %v", err)
logc.Errorf(ctx, "order detail failed, err: %v", err)
return &DetailRes{
ErrorCode: errorCode,
}, result.Error
}
// 是否超时支付
ctime := *order.Ctime
ctimeTimeOut := ctime.Add(30 * time.Minute).UTC().Unix()
ntimeTimeOut := time.Now().UTC().Unix()
if ctimeTimeOut < ntimeTimeOut {
errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout
err = errors.New("order pay timeout")
logx.Errorf("order detail failed, err: %v", err)
return &DetailRes{
ErrorCode: errorCode,
}, err
}
// if *order.Status == int64(constants.ORDER_STATUS_UNPAIDDEPOSIT) {
// ctime := *order.Ctime
// ctimeTimeOut := ctime.Add(30 * time.Minute).UTC().Unix()
// ntimeTimeOut := time.Now().UTC().Unix()
// if ctimeTimeOut < ntimeTimeOut {
// errorCode = *basic.CodeErrOrderCreatePrePaymentTimeout
// err = errors.New("order pay timeout")
// logc.Errorf(ctx, "order detail failed, err: %v", err)
// return &DetailRes{
// ErrorCode: errorCode,
// }, err
// }
// }
ress, err := d.OrderDetailHandler(ctx, &order, 1)
if err != nil {
logx.Errorf("order detail failed, err: %v", err)
logc.Errorf(ctx, "order detail failed, err: %v", err)
errorCode = *basic.CodeServiceErr
return &DetailRes{
ErrorCode: errorCode,
@ -983,8 +984,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
var status = gmodel.OrderStatus{
Ctime: &nowTime,
Utime: &nowTime,
StatusCode: constants.ORDERSTATUSUNPAIDDEPOSIT,
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSUNPAIDDEPOSIT],
StatusCode: constants.ORDER_STATUS_UNPAIDDEPOSIT,
StatusTitle: constants.OrderStatusMessage[constants.ORDER_STATUS_UNPAIDDEPOSIT],
}
// 订单状态--链路
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,
PayTimeout: 30 * time.Minute,
}
// 数据库操作
// 数据库操作
orderDetailByte, err := json.Marshal(orderDetail)
if err != nil {
return err
@ -1019,14 +1020,21 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
Ctime: &nowTime,
Metadata: &orderDetailByte,
}
result := tx.Create(&order)
if result.Error != nil {
return result.Error
// 创建订单
resultCreate := tx.Create(&order)
if resultCreate.Error != nil {
return resultCreate.Error
}
// 删除购物车
resultDelete := tx.Delete(&gmodel.FsShoppingCart{}, in.CartIds)
if resultDelete.Error != nil {
return resultDelete.Error
}
return 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 {
errorCode.Code = basic.CodeApiErr.Code
@ -1109,7 +1117,7 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel
err = json.Unmarshal(*orderInfo.Metadata, &orderDetail)
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
}
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 {
Id int64 `json:"id"`
Material string `json:"material"`
MaterialData MaterialData `json:"material_data"`
Id int64 `json:"id"`
Material string `json:"material"`
MaterialData MaterialData `json:"material_data"`
CombineIsVisible bool `json:"combine_is_visible"` //合图总开关是否开启
}
type MaterialData struct {
QRcode QRcode `json:"QRcode"`
@ -68,6 +69,7 @@ func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMa
Material: "/image/logo/aHnT1_rzubdwax_scale.png",
},
},
CombineIsVisible: false,
}
if templateJsonStr == nil || *templateJsonStr == "" {
return returnData
@ -78,7 +80,7 @@ func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMa
return returnData
}
for _, v := range templateJsonInfo.MaterialList {
if v.Type == "combine" && !v.Visible {
if v.Type == "combine" {
return GetTemplateSwitchInfoRsp{
Id: templateId,
Material: templateMaterialImg,
@ -87,6 +89,7 @@ func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMa
Material: "/image/logo/aHnT1_rzubdwax_scale.png",
},
},
CombineIsVisible: v.Visible,
}
}
switch v.Tag {