Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
8fe6e8be74
|
@ -2,24 +2,28 @@ package gmodel
|
|||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// fs_address 用户地址表
|
||||
type FsAddress struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID
|
||||
Name *string `gorm:"default:'';" json:"name"` // 地址名称
|
||||
FirstName *string `gorm:"default:'';" json:"first_name"` // FirstName
|
||||
LastName *string `gorm:"default:'';" json:"last_name"` // LastName
|
||||
Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码
|
||||
Street *string `gorm:"default:'';" json:"street"` // 街道
|
||||
Suite *string `gorm:"default:'';" json:"suite"` // 房号
|
||||
City *string `gorm:"default:'';" json:"city"` // 城市
|
||||
State *string `gorm:"default:'';" json:"state"` //
|
||||
Country *string `gorm:"default:'';" json:"country"` //
|
||||
ZipCode *string `gorm:"default:'';" json:"zip_code"` //
|
||||
Status *int64 `gorm:"default:0;" json:"status"` // 1正常 0异常
|
||||
IsDefault *int64 `gorm:"index;default:0;" json:"is_default"` // 1默认地址,0非默认地址
|
||||
AddressId int64 `gorm:"primary_key;default:0;auto_increment;" json:"address_id"` //
|
||||
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID
|
||||
AddressName *string `gorm:"default:'';" json:"address_name"` //
|
||||
FirstName *string `gorm:"default:'';" json:"first_name"` // FirstName
|
||||
LastName *string `gorm:"default:'';" json:"last_name"` // LastName
|
||||
Mobile *string `gorm:"default:'';" json:"mobile"` // 手机号码
|
||||
Street *string `gorm:"default:'';" json:"street"` // 街道
|
||||
Suite *string `gorm:"default:'';" json:"suite"` // 房号
|
||||
City *string `gorm:"default:'';" json:"city"` // 城市
|
||||
State *string `gorm:"default:'';" json:"state"` //
|
||||
Country *string `gorm:"default:'';" json:"country"` //
|
||||
ZipCode *string `gorm:"default:'';" json:"zip_code"` //
|
||||
Status *int64 `gorm:"default:0;" json:"status"` // 1正常 0异常
|
||||
IsDefault *int64 `gorm:"index;default:0;" json:"is_default"` // 1默认地址,0非默认地址
|
||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // 创建时间
|
||||
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // 更新时间
|
||||
Ltime *time.Time `gorm:"index;default:'0000-00-00 00:00:00';" json:"ltime"` // 上次被使用的时间
|
||||
}
|
||||
type FsAddressModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -24,19 +24,19 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
|
|||
err = a.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
// now := time.Now().UTC().Unix()
|
||||
result = &FsAddress{
|
||||
UserId: address.UserId,
|
||||
Name: address.Name,
|
||||
FirstName: address.FirstName,
|
||||
LastName: address.LastName,
|
||||
Mobile: address.Mobile,
|
||||
Street: address.Street,
|
||||
Suite: address.Suite,
|
||||
City: address.City,
|
||||
State: address.State,
|
||||
Country: address.Country,
|
||||
ZipCode: address.ZipCode,
|
||||
Status: address.Status,
|
||||
IsDefault: address.IsDefault,
|
||||
UserId: address.UserId,
|
||||
AddressName: address.AddressName,
|
||||
FirstName: address.FirstName,
|
||||
LastName: address.LastName,
|
||||
Mobile: address.Mobile,
|
||||
Street: address.Street,
|
||||
Suite: address.Suite,
|
||||
City: address.City,
|
||||
State: address.State,
|
||||
Country: address.Country,
|
||||
ZipCode: address.ZipCode,
|
||||
Status: address.Status,
|
||||
IsDefault: address.IsDefault,
|
||||
}
|
||||
|
||||
return tx.Create(result).Error
|
||||
|
@ -57,7 +57,7 @@ func (a *FsAddressModel) UpdateAddAddress(ctx context.Context, address *FsAddres
|
|||
return err
|
||||
}
|
||||
}
|
||||
return tx.Model(&FsAddress{}).Where("id = ? and user_id = ?", address.Id, address.UserId).Omit("id", "user_id").Updates(address).Error
|
||||
return tx.Model(&FsAddress{}).Where("id = ? and user_id = ?", address.AddressId, address.UserId).Omit("id", "user_id").Updates(address).Error
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,17 +2,18 @@ package gmodel
|
|||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// fs_change_code 忘记密码code表
|
||||
type FsChangeCode struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id
|
||||
Email *string `gorm:"default:'';" json:"email"` //
|
||||
Code *string `gorm:"default:'';" json:"code"` //
|
||||
CreatedAt *int64 `gorm:"default:0;" json:"created_at"` // 创建时间
|
||||
IsUse *int64 `gorm:"default:0;" json:"is_use"` // 是否使用 1已使用 0未使用
|
||||
Metadata *[]byte `gorm:"default:'';" json:"metadata"` //
|
||||
Module *string `gorm:"default:'logo';" json:"module"` //
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id
|
||||
Email *string `gorm:"default:'';" json:"email"` //
|
||||
Code *string `gorm:"default:'';" json:"code"` //
|
||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||
IsUse *int64 `gorm:"default:0;" json:"is_use"` // 是否使用 1已使用 0未使用
|
||||
Metadata *[]byte `gorm:"default:'';" json:"metadata"` //
|
||||
Module *string `gorm:"default:'logo';" json:"module"` //
|
||||
}
|
||||
type FsChangeCodeModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -40,7 +40,7 @@ type PayInfo struct {
|
|||
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
||||
PayAmount AmountInfo `json:"pay_amount"` // 金额明细
|
||||
PayMethod string `json:"pay_method"` // 交易方式
|
||||
PayTime **time.Time `json:"pay_time"` // 支付时间
|
||||
PayTime *time.Time `json:"pay_time"` // 支付时间
|
||||
Status PayStatus `json:"status"` // 当前状态
|
||||
StatusLink []PayStatus `json:"status_link"` // 状态链路
|
||||
TradeNo string `json:"trade_no"` // 支付交易号
|
||||
|
@ -97,7 +97,7 @@ type OrderStatus struct {
|
|||
type OrderProduct struct {
|
||||
TotalPrice AmountInfo `json:"amount"` // 商品总价
|
||||
ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` // 购买数量
|
||||
PurchaseQuantity PurchaseQuantity `json:"purchase_quantity"` // 购买数量
|
||||
ProductID int64 `json:"product_id"` // 商品ID
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
ItemPrice AmountInfo `json:"product_price"` // 商品单价
|
||||
|
@ -112,6 +112,10 @@ type OrderProduct struct {
|
|||
StepNum []int `json:"step_num"` // 阶梯数量
|
||||
IsHighlyCustomized int64 `json:"is_highly_customized"`
|
||||
}
|
||||
type PurchaseQuantity struct {
|
||||
Current interface{} `json:"current"`
|
||||
Initiate interface{} `json:"initiate"`
|
||||
}
|
||||
|
||||
type OrderProductSizeInfo struct {
|
||||
SizeID int64 `json:"size_id"`
|
||||
|
|
|
@ -36,6 +36,7 @@ type FsProduct struct {
|
|||
RecommendProductSort *string `gorm:"default:'';" json:"recommend_product_sort"` //
|
||||
SceneIds *string `gorm:"default:'';" json:"scene_ids"` //
|
||||
IsCustomization *int64 `gorm:"default:0;" json:"is_customization"` // 是否可定制
|
||||
Unit *string `gorm:"default:'';" json:"unit"` //
|
||||
}
|
||||
type FsProductModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -2,30 +2,34 @@ package gmodel
|
|||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// fs_product_model3d 产品模型表
|
||||
type FsProductModel3d struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||
ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID
|
||||
Tag *int64 `gorm:"default:1;" json:"tag"` // 类别(1:模型,2:配件,3:场景)
|
||||
Title *string `gorm:"default:'';" json:"title"` // 标题
|
||||
Name *string `gorm:"default:'';" json:"name"` // 详情页展示名称
|
||||
ModelInfo *string `gorm:"default:'';" json:"model_info"` // 模型详情
|
||||
MaterialId *int64 `gorm:"default:0;" json:"material_id"` // 材质ID
|
||||
SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸ID
|
||||
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
|
||||
Light *int64 `gorm:"default:0;" json:"light"` // 灯光组
|
||||
LightList *string `gorm:"default:'';" json:"light_list"` // 灯光备选项
|
||||
PartId *int64 `gorm:"default:0;" json:"part_id"` // 配件选项id(配件就是模型的id)
|
||||
PartList *string `gorm:"default:'';" json:"part_list"` //
|
||||
Status *int64 `gorm:"default:0;" json:"status"` // 状态位 显示 删除
|
||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
||||
OptionTemplate *int64 `gorm:"default:0;" json:"option_template"` // 配件绑定的公共模板
|
||||
Price *int64 `gorm:"default:0;" json:"price"` // 仅配件用,配件的价格, 单位:美分
|
||||
Sku *string `gorm:"default:'';" json:"sku"` // sku
|
||||
IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门
|
||||
IsCloudRender *int64 `gorm:"default:0;" json:"is_cloud_render"` // 是否设置为云渲染模型
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||
ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID
|
||||
Tag *int64 `gorm:"default:1;" json:"tag"` // 类别(1:模型,2:配件,3:场景)
|
||||
Title *string `gorm:"default:'';" json:"title"` // 标题
|
||||
Name *string `gorm:"default:'';" json:"name"` // 详情页展示名称
|
||||
ModelInfo *string `gorm:"default:'';" json:"model_info"` // 模型详情
|
||||
MaterialId *int64 `gorm:"default:0;" json:"material_id"` // 材质ID
|
||||
SizeId *int64 `gorm:"default:0;" json:"size_id"` // 尺寸ID
|
||||
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
|
||||
Light *int64 `gorm:"default:0;" json:"light"` // 灯光组
|
||||
LightList *string `gorm:"default:'';" json:"light_list"` // 灯光备选项
|
||||
PartId *int64 `gorm:"default:0;" json:"part_id"` // 配件选项id(配件就是模型的id)
|
||||
PartList *string `gorm:"default:'';" json:"part_list"` //
|
||||
Status *int64 `gorm:"default:0;" json:"status"` // 状态位 显示 删除
|
||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||
OptionTemplate *int64 `gorm:"default:0;" json:"option_template"` // 配件绑定的公共模板
|
||||
Price *int64 `gorm:"default:0;" json:"price"` //
|
||||
Sku *string `gorm:"default:'';" json:"sku"` // sku
|
||||
IsHot *int64 `gorm:"default:0;" json:"is_hot"` // 是否热门
|
||||
IsCloudRender *int64 `gorm:"default:0;" json:"is_cloud_render"` // 是否设置为云渲染模型
|
||||
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||
StepPrice *[]byte `gorm:"default:'';" json:"step_price"` //
|
||||
PackedUnit *int64 `gorm:"default:0;" json:"packed_unit"` //
|
||||
}
|
||||
type FsProductModel3dModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -3,8 +3,10 @@ package logic
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"time"
|
||||
|
@ -52,7 +54,7 @@ func (l *StripeWebhookLogic) StripeWebhook(req *types.StripeWebhookReq, userinfo
|
|||
event := stripe.Event{}
|
||||
|
||||
if err := json.Unmarshal(req.Payload, &event); err != nil {
|
||||
logc.Errorf(l.ctx, "StripeWebhookLogic StripeWebhook Unmarshal err:", err)
|
||||
logc.Errorf(l.ctx, "StripeWebhookLogic StripeWebhook Unmarshal err:%v", err)
|
||||
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail")
|
||||
}
|
||||
|
||||
|
@ -106,7 +108,7 @@ func (l *StripeWebhookLogic) StripeWebhook(req *types.StripeWebhookReq, userinfo
|
|||
logx.Errorf("err:%+v,desc:%s", err, "pay notify Unmarshal fail event.Type payment_intent.succeeded")
|
||||
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_intent.succeeded")
|
||||
}
|
||||
err = l.HandlePaymentIntentSucceeded(&paymentIntent)
|
||||
err = l.HandlePaymentIntentSucceeded(&paymentIntent, event.ID)
|
||||
if err != nil {
|
||||
logx.Errorf("err:%+v,desc:%s", err, "pay notify handle payment_intent.succeeded")
|
||||
return resp.SetStatusWithMessage(basic.CodePaybackNotOk, "pay notify handle payment_intent.succeeded")
|
||||
|
@ -230,119 +232,27 @@ func (l *StripeWebhookLogic) handlePaymentSessionCompleted(sessionId string, tra
|
|||
}
|
||||
|
||||
// 付款成功
|
||||
func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.PaymentIntent) error {
|
||||
orderSn, ok := paymentIntent.Metadata["order_sn"]
|
||||
if !ok || orderSn == "" {
|
||||
return errors.New("order_sn not found")
|
||||
func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.PaymentIntent, eventId string) error {
|
||||
// 支付成功
|
||||
if paymentIntent.Status == "succeeded" {
|
||||
model, ok := paymentIntent.Metadata["model"]
|
||||
if !ok {
|
||||
err := errors.New("model is empty")
|
||||
logc.Errorf(l.ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", eventId, err)
|
||||
return err
|
||||
}
|
||||
switch model {
|
||||
case "product_order":
|
||||
res, err := l.svcCtx.Repositories.NewOrder.PaymentSuccessful(l.ctx, &repositories.PaymentSuccessfulReq{
|
||||
EventId: eventId,
|
||||
PaymentMethod: 1,
|
||||
PaymentIntent: paymentIntent,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(res)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
// 查询订单
|
||||
|
||||
// 支付成功
|
||||
// if paymentIntent.Status == "succeeded" {
|
||||
// var card string
|
||||
// var brand string
|
||||
// if paymentIntent.LatestCharge.PaymentMethodDetails != nil {
|
||||
// if paymentIntent.LatestCharge.PaymentMethodDetails.Card != nil {
|
||||
// if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4 != "" {
|
||||
// card = paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4
|
||||
// }
|
||||
// if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand != "" {
|
||||
// brand = string(paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// ctx := l.ctx
|
||||
// err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error {
|
||||
// // 更新支付信息
|
||||
// payModelT := gmodel.NewFsPayModel(connGorm)
|
||||
// *payInfo.PayStatus = 1
|
||||
// *payInfo.PayTime = nowTime
|
||||
// *payInfo.CardNo = card
|
||||
// *payInfo.Brand = brand
|
||||
// *payInfo.TradeNo = paymentIntent.ID
|
||||
// _, err = payModelT.RBCreateOrUpdate(ctx, payInfo)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// // 更新设计数据
|
||||
// productDesignModelT := gmodel.NewFsProductDesignModel(connGorm)
|
||||
// productDesignModelTRSB := productDesignModelT.BuilderTrans(ctx, nil)
|
||||
// var isPay int64 = 1
|
||||
// err = productDesignModelT.RBUpdateByIds(productDesignModelTRSB, designIds, &gmodel.FsProductDesign{IsPay: &isPay})
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// var orderInfo = &gmodel.FsOrder{}
|
||||
// var orderStatus int64
|
||||
// var orderIsPartPay int64
|
||||
// var orderPayedAmount int64
|
||||
// var orderIsPayCompleted int64
|
||||
// // 支付记录是首款
|
||||
// if *payInfo.PayStage == int64(constants.PAYSTAGE_DEPOSIT) {
|
||||
// orderStatus = int64(constants.STATUS_NEW_PART_PAY)
|
||||
// orderIsPartPay = 1
|
||||
// orderInfo.IsPartPay = &orderIsPartPay
|
||||
// orderPayedAmount = paymentIntent.Amount
|
||||
|
||||
// // 删除购物车
|
||||
// cartModelT := gmodel.NewFsCartModel(connGorm)
|
||||
// cartModelTRSB := cartModelT.BuilderTrans(ctx, nil)
|
||||
// err = cartModelT.RBDeleteCartsByIds(cartModelTRSB, cartIds)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 支付记录是尾款
|
||||
// if *payInfo.PayStage == int64(constants.PAYSTAGE_REMAINING) {
|
||||
// if *fsOrderRelInfo.Status < int64(constants.STATUS_NEW_PAY_COMPLETED) {
|
||||
// orderStatus = int64(constants.STATUS_NEW_PAY_COMPLETED)
|
||||
// }
|
||||
// orderIsPayCompleted = 1
|
||||
// orderInfo.IsPayCompleted = &orderIsPayCompleted
|
||||
// orderPayedAmount = *fsOrderRelInfo.PayedAmount + paymentIntent.Amount
|
||||
// }
|
||||
|
||||
// // 更新订单信息
|
||||
// orderInfo.Id = fsOrderRelInfo.Id
|
||||
// orderInfo.Status = &orderStatus
|
||||
// orderInfo.Ptime = &nowTime
|
||||
// orderInfo.PayedAmount = &orderPayedAmount
|
||||
// orderModelT := gmodel.NewFsOrderModel(connGorm)
|
||||
// err = orderModelT.RBUpdate(ctx, orderInfo)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return err
|
||||
// })
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
//千人千面的处理
|
||||
// $renderServer = (new RenderService());
|
||||
// $renderServer->thousandsFacesV2($order->id);
|
||||
// //清除用户最新的设计
|
||||
// $cache = \Yii::$app->cache;
|
||||
// $cache->delete(CacheConfigHelper::LAST_DESIGN . $order->user_id);
|
||||
// //缓存最新订单编号
|
||||
// $cache->set(CacheConfigHelper::USER_ORDERNO . $order->user_id, $order->sn);
|
||||
|
||||
// //查询用户邮箱信息
|
||||
// $user = \api\models\User::find()->where(['id' => $order->user_id])->one();
|
||||
// $redisData = [
|
||||
// 'key' => 'receipt_download',
|
||||
// 'param' => [
|
||||
// 'email' => $user->email,
|
||||
// 'order_id' => $order->id,
|
||||
// 'pay_id' => $pay->id,
|
||||
// 'type' => 1,//付款成功为1
|
||||
// ]
|
||||
// ];
|
||||
// Email::timely($redisData);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,9 @@ type ServiceContext struct {
|
|||
Config config.Config
|
||||
SharedState *shared.SharedState
|
||||
|
||||
MysqlConn *gorm.DB
|
||||
AllModels *gmodel.AllModelsGen
|
||||
MysqlConn *gorm.DB
|
||||
AllModels *gmodel.AllModelsGen
|
||||
Repositories *initalize.Repositories
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
@ -31,6 +32,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||
MysqlConn: conn,
|
||||
SharedState: nil,
|
||||
AllModels: gmodel.NewAllModels(initalize.InitMysql(c.SourceMysql)),
|
||||
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
|
||||
GormDB: conn,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,32 +41,24 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
if !userinfo.IsUser() {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in")
|
||||
}
|
||||
if req.CurrentPage <= 0 {
|
||||
req.CurrentPage = constants.DEFAULT_PAGE
|
||||
}
|
||||
currentPage := constants.DEFAULT_PAGE
|
||||
limit := 300
|
||||
//获取用户购物车列表
|
||||
var cartIds []int64
|
||||
if req.CartId > 0 {
|
||||
cartIds = append(cartIds, req.CartId)
|
||||
}
|
||||
carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
||||
Ids: cartIds,
|
||||
UserId: userinfo.UserId,
|
||||
Sort: "id DESC",
|
||||
Page: req.CurrentPage,
|
||||
Page: currentPage,
|
||||
Limit: limit,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get your shopping carts")
|
||||
}
|
||||
if len(carts) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCartsRsp{
|
||||
Meta: types.Meta{
|
||||
TotalCount: total,
|
||||
PageCount: int64(math.Ceil(float64(total) / float64(limit))),
|
||||
CurrentPage: req.CurrentPage,
|
||||
PerPage: limit,
|
||||
},
|
||||
CartList: nil,
|
||||
})
|
||||
}
|
||||
var (
|
||||
mapSize = make(map[int64]gmodel.FsProductSize)
|
||||
mapModel = make(map[int64]gmodel.FsProductModel3d)
|
||||
|
@ -201,7 +193,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
Meta: types.Meta{
|
||||
TotalCount: total,
|
||||
PageCount: int64(math.Ceil(float64(total) / float64(limit))),
|
||||
CurrentPage: req.CurrentPage,
|
||||
CurrentPage: currentPage,
|
||||
PerPage: limit,
|
||||
},
|
||||
CartList: list,
|
||||
|
|
|
@ -30,7 +30,7 @@ type DeleteCartReq struct {
|
|||
}
|
||||
|
||||
type GetCartsReq struct {
|
||||
CurrentPage int `form:"current_page"` //当前页
|
||||
CartId int64 `form:"cart_id,optional"` //购物车ids可选
|
||||
}
|
||||
|
||||
type GetCartsRsp struct {
|
||||
|
|
|
@ -49,7 +49,7 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
|||
return
|
||||
case w.extendRenderProperty.renderChan <- renderImageData: //发入到缓冲队列
|
||||
return
|
||||
case <- time.After(time.Millisecond * 50)://超过50毫秒丢弃
|
||||
case <-time.After(time.Millisecond * 50): //超过50毫秒丢弃
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染队列溢出,请稍后再发", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return
|
||||
}
|
||||
|
@ -70,7 +70,9 @@ func (w *wsConnectItem) consumeRenderImageData() {
|
|||
case <-w.closeChan: //已关闭
|
||||
return
|
||||
case data := <-w.extendRenderProperty.renderChan: //消费数据
|
||||
logx.Info("准备执行任务。。。。。")
|
||||
limitChan <- struct{}{}
|
||||
logx.Info("执行任务中。。。。。")
|
||||
go func(d websocket_data.RenderImageReqMsg) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
|
@ -179,17 +181,11 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
|||
Index: renderImageData.RenderData.TemplateTagColor.SelectedColorIndex,
|
||||
},
|
||||
}
|
||||
res := &repositories.LogoCombineRes{}
|
||||
if w.userId == 127{
|
||||
u := "https://s3.us-west-1.amazonaws.com/storage.fusenpack.com/1c4549bea75f9247f8aee5f7f6f3909a551cef97dc7acb0d01568b8bad042a01"
|
||||
res.ResourceUrl = &u
|
||||
}else{
|
||||
res, err = w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq)
|
||||
if err != nil {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "合成刀版图失败:"+err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
|
||||
logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err)
|
||||
return
|
||||
}
|
||||
res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq)
|
||||
if err != nil {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "合成刀版图失败:"+err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId)
|
||||
logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err)
|
||||
return
|
||||
}
|
||||
combineImage := "" //刀版图
|
||||
if res != nil && res.ResourceUrl != nil {
|
||||
|
|
|
@ -49,7 +49,7 @@ type DeleteCartReq {
|
|||
|
||||
//获取购物车列表
|
||||
type GetCartsReq {
|
||||
CurrentPage int `form:"current_page"` //当前页
|
||||
CartId int64 `form:"cart_id,optional"` //购物车ids可选
|
||||
}
|
||||
type GetCartsRsp {
|
||||
Meta Meta `json:"meta"` //分页信息
|
||||
|
|
|
@ -15,6 +15,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/stripe/stripe-go/v74"
|
||||
"github.com/zeromicro/go-zero/core/logc"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
@ -40,6 +42,16 @@ type (
|
|||
List(ctx context.Context, in *ListReq) (res *ListRes, err error)
|
||||
// 详情
|
||||
Detail(ctx context.Context, in *DetailReq) (res *DetailRes, err error)
|
||||
// 支付成功
|
||||
PaymentSuccessful(ctx context.Context, in *PaymentSuccessfulReq) (res *PaymentSuccessfulRes, err error)
|
||||
}
|
||||
|
||||
PayInfo struct {
|
||||
PayMethod int64 `json:"pay_method"` // 交易方式
|
||||
PayTime time.Time `json:"pay_time"` // 支付时间
|
||||
Status gmodel.PayStatus `json:"status"` // 当前状态
|
||||
StatusLink []gmodel.PayStatus `json:"status_link"` // 状态链路
|
||||
TradeNo string `json:"trade_no"` // 支付交易号
|
||||
}
|
||||
|
||||
OrderAddress struct {
|
||||
|
@ -63,6 +75,16 @@ type (
|
|||
Amount int64 `json:"amount"` // 金额
|
||||
Label string `json:"label"` // 标签
|
||||
}
|
||||
|
||||
/* 支付成功 */
|
||||
PaymentSuccessfulReq struct {
|
||||
EventId string
|
||||
PaymentMethod int64
|
||||
PaymentIntent *stripe.PaymentIntent
|
||||
}
|
||||
PaymentSuccessfulRes struct{}
|
||||
/* 支付成功 */
|
||||
|
||||
/* 预支付--定金 */
|
||||
CreatePrePaymentByDepositReq struct {
|
||||
StripeKey string `json:"stripe_key"`
|
||||
|
@ -139,6 +161,175 @@ type (
|
|||
/* 列表 */
|
||||
)
|
||||
|
||||
// 支付成功
|
||||
func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccessfulReq) (res *PaymentSuccessfulRes, err error) {
|
||||
var orderSn string
|
||||
var payStage string
|
||||
var ok bool
|
||||
var card string
|
||||
var brand string
|
||||
var country string
|
||||
var currency string
|
||||
var tradeSn string
|
||||
var payAmount int64
|
||||
var payTitle string
|
||||
var payTime time.Time
|
||||
if in.PaymentIntent != nil {
|
||||
paymentIntent := in.PaymentIntent
|
||||
orderSn, ok = paymentIntent.Metadata["order_sn"]
|
||||
if !ok || orderSn == "" {
|
||||
err = errors.New("order_sn is empty")
|
||||
logc.Errorf(ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", in.EventId, err)
|
||||
return &PaymentSuccessfulRes{}, err
|
||||
}
|
||||
payStage, ok = paymentIntent.Metadata["pay_stage"]
|
||||
if !ok || payStage == "" {
|
||||
err = errors.New("pay_stage is empty")
|
||||
logc.Errorf(ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", in.EventId, err)
|
||||
return &PaymentSuccessfulRes{}, err
|
||||
}
|
||||
country, ok = paymentIntent.Metadata["country"]
|
||||
if !ok || country == "" {
|
||||
err = errors.New("country is empty")
|
||||
logc.Errorf(ctx, "PaymentSuccessful failed param, eventId:%s,err:%v", in.EventId, err)
|
||||
return &PaymentSuccessfulRes{}, err
|
||||
}
|
||||
if paymentIntent.LatestCharge.PaymentMethodDetails != nil {
|
||||
if paymentIntent.LatestCharge.PaymentMethodDetails.Card != nil {
|
||||
if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4 != "" {
|
||||
card = paymentIntent.LatestCharge.PaymentMethodDetails.Card.Last4
|
||||
}
|
||||
if paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand != "" {
|
||||
brand = string(paymentIntent.LatestCharge.PaymentMethodDetails.Card.Brand)
|
||||
}
|
||||
}
|
||||
}
|
||||
if paymentIntent.Currency != "" {
|
||||
currency = string(paymentIntent.Currency)
|
||||
}
|
||||
tradeSn = paymentIntent.ID
|
||||
payAmount = paymentIntent.Amount
|
||||
payTitle = paymentIntent.Description
|
||||
payTime = time.Unix(paymentIntent.Created, 0)
|
||||
}
|
||||
err = d.MysqlConn.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var orderInfo gmodel.FsOrder
|
||||
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)
|
||||
return err
|
||||
}
|
||||
ress, err := d.OrderDetailHandler(ctx, &orderInfo, 0)
|
||||
if err != nil {
|
||||
logx.Errorf("PaymentSuccessful failed DetailOrderDetailHandler,eventId:%s, err: %v", in.EventId, err)
|
||||
return err
|
||||
}
|
||||
var ntime = time.Now().UTC()
|
||||
if (payStage == "deposit" && *orderInfo.PayStatus == int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT)) || (payStage == "remaining_balance" && *orderInfo.PayStatus == int64(constants.ORDERPAYSTATUSPAIDDEPOSIT)) {
|
||||
var payStatus = int64(constants.PAYSTATUSPAID)
|
||||
var payStageInt int64
|
||||
var orderPayStatusCode constants.OrderPayStatusCode
|
||||
// 订单状态--当前
|
||||
var status gmodel.OrderStatus
|
||||
var statusLink []gmodel.OrderStatus
|
||||
var uOrderDetail = make(map[string]interface{})
|
||||
var payInfo PayInfo
|
||||
payInfo.PayMethod = in.PaymentMethod
|
||||
payInfo.PayTime = payTime
|
||||
payInfo.TradeNo = tradeSn
|
||||
|
||||
if payStage == "deposit" {
|
||||
payStageInt = 1
|
||||
orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDEPOSIT
|
||||
status = gmodel.OrderStatus{
|
||||
Ctime: &ntime,
|
||||
Utime: &ntime,
|
||||
StatusCode: constants.ORDERSTATUSDIRECTMAILORDERED,
|
||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSDIRECTMAILORDERED],
|
||||
}
|
||||
statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{
|
||||
Utime: &ntime,
|
||||
StatusCode: constants.ORDERSTATUSDIRECTMAILORDERED,
|
||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSDIRECTMAILORDERED],
|
||||
})
|
||||
payInfo.Status = gmodel.PayStatus{
|
||||
StatusCode: int64(constants.PAYSTATUSPAID),
|
||||
StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSPAID],
|
||||
}
|
||||
payInfo.StatusLink = append(ress.OrderDetail.OrderAmount.Deposit.StatusLink, payInfo.Status)
|
||||
uOrderDetail["order_amount"] = struct {
|
||||
Deposit PayInfo `json:"deposit"`
|
||||
}{
|
||||
Deposit: payInfo,
|
||||
}
|
||||
}
|
||||
if payStage == "remaining_balance" {
|
||||
payStageInt = 2
|
||||
orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDREMAINING
|
||||
status = gmodel.OrderStatus{
|
||||
Ctime: &ntime,
|
||||
Utime: &ntime,
|
||||
StatusCode: constants.ORDERSTATUSCLOUDSTOREORDERED,
|
||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSCLOUDSTOREORDERED],
|
||||
}
|
||||
statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{
|
||||
Utime: &ntime,
|
||||
StatusCode: constants.ORDERSTATUSCLOUDSTOREORDERED,
|
||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSCLOUDSTOREORDERED],
|
||||
})
|
||||
payInfo.StatusLink = append(ress.OrderDetail.OrderAmount.RemainingBalance.StatusLink, payInfo.Status)
|
||||
uOrderDetail["order_amount"] = struct {
|
||||
RemainingBalance PayInfo `json:"remaining_balance"`
|
||||
}{
|
||||
RemainingBalance: payInfo,
|
||||
}
|
||||
}
|
||||
|
||||
// 新增交易信息
|
||||
tx.Create(&gmodel.FsOrderTrade{
|
||||
UserId: orderInfo.UserId,
|
||||
OrderSn: &orderSn,
|
||||
OrderSource: orderInfo.OrderSource,
|
||||
TradeSn: &tradeSn,
|
||||
PayAmount: &payAmount,
|
||||
PayStatus: &payStatus,
|
||||
PaymentMethod: &in.PaymentMethod,
|
||||
PayStage: &payStageInt,
|
||||
CardSn: &card,
|
||||
CardBrand: &brand,
|
||||
Country: &country,
|
||||
Currency: ¤cy,
|
||||
Ctime: &ntime,
|
||||
Utime: &ntime,
|
||||
PayTitle: &payTitle,
|
||||
})
|
||||
// 更新订单信息
|
||||
var sql string = fmt.Sprintf(", `utime` = '%s'", ntime)
|
||||
uOrderDetail["pay_status"] = orderPayStatusCode
|
||||
uOrderDetail["order_info"] = struct {
|
||||
Utime *time.Time `json:"utime"`
|
||||
Status gmodel.OrderStatus `json:"status"`
|
||||
StatusLink []gmodel.OrderStatus `json:"status_link"`
|
||||
}{
|
||||
Utime: &ntime,
|
||||
Status: status,
|
||||
StatusLink: statusLink,
|
||||
}
|
||||
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)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return &PaymentSuccessfulRes{}, nil
|
||||
}
|
||||
|
||||
// 预支付--尾款
|
||||
func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error) {
|
||||
var errorCode basic.StatusResponse
|
||||
|
@ -172,7 +363,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
|
|||
}, err
|
||||
}
|
||||
|
||||
ress, err := d.OrderDetailHandler(ctx, &order)
|
||||
ress, err := d.OrderDetailHandler(ctx, &order, 1)
|
||||
if err != nil {
|
||||
logx.Errorf("create prePayment balance failed DetailOrderDetailHandler, err: %v", err)
|
||||
errorCode = *basic.CodeServiceErr
|
||||
|
@ -185,8 +376,13 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create
|
|||
payConfig := &pay.Config{}
|
||||
payConfig.Stripe.PayType = "intent"
|
||||
payConfig.Stripe.Key = in.StripeKey
|
||||
var metadata = make(map[string]string, 2)
|
||||
metadata["model"] = "product_order"
|
||||
metadata["order_sn"] = in.OrderSn
|
||||
metadata["pay_stage"] = "remaining_balance"
|
||||
metadata["country"] = in.Country
|
||||
var generatePrepaymentReq = &pay.GeneratePrepaymentReq{
|
||||
OrderSn: in.OrderSn,
|
||||
Metadata: metadata,
|
||||
ProductName: "支付尾款后期统一调整",
|
||||
Amount: amount,
|
||||
Currency: "usd",
|
||||
|
@ -270,7 +466,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
|
|||
}, err
|
||||
}
|
||||
|
||||
ress, err := d.OrderDetailHandler(ctx, &order)
|
||||
ress, err := d.OrderDetailHandler(ctx, &order, 0)
|
||||
if err != nil {
|
||||
logx.Errorf("create prePayment deposit failed DetailOrderDetailHandler, err: %v", err)
|
||||
errorCode = *basic.CodeServiceErr
|
||||
|
@ -342,8 +538,13 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
|
|||
payConfig := &pay.Config{}
|
||||
payConfig.Stripe.PayType = "intent"
|
||||
payConfig.Stripe.Key = in.StripeKey
|
||||
var metadata = make(map[string]string, 2)
|
||||
metadata["model"] = "product_order"
|
||||
metadata["order_sn"] = in.OrderSn
|
||||
metadata["pay_stage"] = "deposit"
|
||||
metadata["country"] = in.Country
|
||||
var generatePrepaymentReq = &pay.GeneratePrepaymentReq{
|
||||
OrderSn: in.OrderSn,
|
||||
Metadata: metadata,
|
||||
ProductName: "支付首款",
|
||||
Amount: amount,
|
||||
Currency: "usd",
|
||||
|
@ -417,7 +618,7 @@ func (d *defaultOrder) List(ctx context.Context, in *ListReq) (res *ListRes, err
|
|||
return nil, result.Error
|
||||
}
|
||||
for _, order := range orderList {
|
||||
ress, err := d.OrderDetailHandler(ctx, &order)
|
||||
ress, err := d.OrderDetailHandler(ctx, &order, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -474,7 +675,7 @@ func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRe
|
|||
}, err
|
||||
}
|
||||
|
||||
ress, err := d.OrderDetailHandler(ctx, &order)
|
||||
ress, err := d.OrderDetailHandler(ctx, &order, 1)
|
||||
if err != nil {
|
||||
logx.Errorf("order detail failed, err: %v", err)
|
||||
errorCode = *basic.CodeServiceErr
|
||||
|
@ -662,7 +863,10 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
OriginalCurrency: in.OriginalCurrency,
|
||||
}),
|
||||
ExpectedDeliveryTime: &in.ExpectedDeliveryTime,
|
||||
PurchaseQuantity: *shoppingCart.PurchaseQuantity,
|
||||
PurchaseQuantity: gmodel.PurchaseQuantity{
|
||||
Current: *shoppingCart.PurchaseQuantity,
|
||||
Initiate: *shoppingCart.PurchaseQuantity,
|
||||
},
|
||||
ProductID: *shoppingCart.ProductId,
|
||||
ProductCover: *shoppingCart.ShoppingCartProduct.Cover,
|
||||
ProductCoverMetadata: productCoverMetadata,
|
||||
|
@ -718,6 +922,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
StatusCode: int64(constants.PAYSTATUSUNPAID),
|
||||
StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSUNPAID],
|
||||
},
|
||||
StatusLink: make([]gmodel.PayStatus, 0),
|
||||
PayAmount: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||
ExchangeRate: in.ExchangeRate,
|
||||
Initiate: depositInt,
|
||||
|
@ -734,6 +939,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
StatusCode: int64(constants.PAYSTATUSUNPAID),
|
||||
StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSUNPAID],
|
||||
},
|
||||
StatusLink: make([]gmodel.PayStatus, 0),
|
||||
PayAmount: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||
ExchangeRate: in.ExchangeRate,
|
||||
Initiate: remainingBalanceInt,
|
||||
|
@ -817,7 +1023,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
}
|
||||
|
||||
// 详情处理
|
||||
func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel.FsOrder) (res *DetailRes, err error) {
|
||||
func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel.FsOrder, original int64) (res *DetailRes, err error) {
|
||||
var orderDetail gmodel.OrderDetail
|
||||
|
||||
err = json.Unmarshal(*orderInfo.Metadata, &orderDetail)
|
||||
|
@ -826,18 +1032,22 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel
|
|||
return nil, err
|
||||
}
|
||||
orderDetailOriginal := orderDetail
|
||||
for orderProductKey, orderProduct := range orderDetail.OrderProduct {
|
||||
orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice)
|
||||
orderDetail.OrderProduct[orderProductKey].ItemPrice = order.GetAmountInfoFormat(&orderProduct.ItemPrice)
|
||||
orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot = nil
|
||||
orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil
|
||||
if original == 1 {
|
||||
for orderProductKey, orderProduct := range orderDetail.OrderProduct {
|
||||
orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice)
|
||||
orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice)
|
||||
orderDetail.OrderProduct[orderProductKey].PurchaseQuantity = order.GetPurchaseQuantity(&orderProduct.PurchaseQuantity)
|
||||
orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot = nil
|
||||
orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil
|
||||
}
|
||||
orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink)
|
||||
orderDetail.OrderAmount.Deposit.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Deposit.PayAmount)
|
||||
orderDetail.OrderAmount.RemainingBalance.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.RemainingBalance.PayAmount)
|
||||
orderDetail.OrderAmount.Subtotal = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Subtotal)
|
||||
orderDetail.OrderAmount.Total = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Total)
|
||||
orderDetail.PayTimeout = time.Duration(orderDetail.OrderInfo.Ctime.Add(orderDetail.PayTimeout).UTC().Unix() - time.Now().UTC().Unix())
|
||||
|
||||
}
|
||||
orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink)
|
||||
orderDetail.OrderAmount.Deposit.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Deposit.PayAmount)
|
||||
orderDetail.OrderAmount.RemainingBalance.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.RemainingBalance.PayAmount)
|
||||
orderDetail.OrderAmount.Subtotal = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Subtotal)
|
||||
orderDetail.OrderAmount.Total = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Total)
|
||||
orderDetail.PayTimeout = time.Duration(orderDetail.OrderInfo.Ctime.Add(orderDetail.PayTimeout).UTC().Unix() - time.Now().UTC().Unix())
|
||||
|
||||
return &DetailRes{
|
||||
OrderDetail: orderDetail,
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/format"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -112,6 +113,14 @@ func GetAmountInfoFormat(req *gmodel.AmountInfo) gmodel.AmountInfo {
|
|||
}
|
||||
}
|
||||
|
||||
// 处理商品数量
|
||||
func GetPurchaseQuantity(req *gmodel.PurchaseQuantity) gmodel.PurchaseQuantity {
|
||||
return gmodel.PurchaseQuantity{
|
||||
Initiate: strconv.FormatInt(int64(req.Initiate.(float64)), 10),
|
||||
Current: strconv.FormatInt(int64(req.Current.(float64)), 10),
|
||||
}
|
||||
}
|
||||
|
||||
// 生成订单编号
|
||||
func GenerateOrderNumber() string {
|
||||
t := time.Now()
|
||||
|
@ -120,7 +129,7 @@ func GenerateOrderNumber() string {
|
|||
return orderNumber
|
||||
}
|
||||
|
||||
// 初始化订单状态
|
||||
// 初始化订单状态--链路
|
||||
func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time, expectedTime time.Time) []gmodel.OrderStatus {
|
||||
var list []gmodel.OrderStatus
|
||||
|
||||
|
@ -142,6 +151,39 @@ func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time, expectedTim
|
|||
return list
|
||||
}
|
||||
|
||||
// 更新订单状态--链路
|
||||
func UpdateOrderStatusLink(statusLink []gmodel.OrderStatus, status gmodel.OrderStatus) []gmodel.OrderStatus {
|
||||
var list []gmodel.OrderStatus
|
||||
for _, v := range statusLink {
|
||||
if v.StatusCode == status.StatusCode {
|
||||
item := v
|
||||
if status.StatusTitle != "" {
|
||||
item.StatusTitle = status.StatusTitle
|
||||
}
|
||||
if status.StatusCode != 0 {
|
||||
item.StatusCode = status.StatusCode
|
||||
}
|
||||
if status.Utime != nil {
|
||||
item.Utime = status.Utime
|
||||
}
|
||||
if status.Metadata != nil {
|
||||
item.Metadata = status.Metadata
|
||||
}
|
||||
if status.ExpectedTime != nil {
|
||||
item.ExpectedTime = status.ExpectedTime
|
||||
}
|
||||
if status.Children != nil || len(status.Children) > 0 {
|
||||
item.Children = status.Children
|
||||
}
|
||||
|
||||
list = append(list, item)
|
||||
} else {
|
||||
list = append(list, v)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// 获取订单状态
|
||||
func GetOrderStatusLinkUser(deliveryMethod int64, statusLink []gmodel.OrderStatus) []gmodel.OrderStatus {
|
||||
var list []gmodel.OrderStatus
|
||||
|
|
|
@ -29,15 +29,15 @@ type Pay interface {
|
|||
}
|
||||
|
||||
type GeneratePrepaymentReq struct {
|
||||
OrderSn string `json:"order_sn"` // 订单编号
|
||||
Amount int64 `json:"amount"` // 支付金额
|
||||
Currency string `json:"currency"` // 支付货币
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
ProductDescription string `json:"product_description"` // 商品描述
|
||||
ProductImages []*string `json:"product_imageso"` // 商品照片
|
||||
Quantity int64 `json:"quantity"` //数量
|
||||
SuccessURL string `json:"success_url"` // 支付成功回调
|
||||
CancelURL string `json:"cancel_url"` // 支付取消回调
|
||||
Metadata map[string]string `json:"metadata"` // 元数据
|
||||
Amount int64 `json:"amount"` // 支付金额
|
||||
Currency string `json:"currency"` // 支付货币
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
ProductDescription string `json:"product_description"` // 商品描述
|
||||
ProductImages []*string `json:"product_imageso"` // 商品照片
|
||||
Quantity int64 `json:"quantity"` //数量
|
||||
SuccessURL string `json:"success_url"` // 支付成功回调
|
||||
CancelURL string `json:"cancel_url"` // 支付取消回调
|
||||
}
|
||||
|
||||
type GeneratePrepaymentRes struct {
|
||||
|
|
|
@ -50,7 +50,7 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge
|
|||
case "session":
|
||||
// session 方式
|
||||
params := &stripe.CheckoutSessionParams{
|
||||
PaymentIntentData: &stripe.CheckoutSessionPaymentIntentDataParams{Metadata: map[string]string{"order_sn": req.OrderSn}},
|
||||
PaymentIntentData: &stripe.CheckoutSessionPaymentIntentDataParams{Metadata: req.Metadata},
|
||||
// Params: stripe.Params{Metadata: map[string]string{"order_id": "1111111111111"}},
|
||||
PaymentMethodTypes: stripe.StringSlice([]string{
|
||||
"card",
|
||||
|
@ -79,7 +79,6 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge
|
|||
case "intent":
|
||||
// 密钥方式
|
||||
params := &stripe.PaymentIntentParams{
|
||||
Params: stripe.Params{Metadata: map[string]string{"order_sn": req.OrderSn}},
|
||||
Amount: stripe.Int64(req.Amount),
|
||||
Currency: stripe.String(string(req.Currency)),
|
||||
PaymentMethodTypes: stripe.StringSlice([]string{
|
||||
|
@ -87,6 +86,9 @@ func (stripePay *Stripe) GeneratePrepayment(req *GeneratePrepaymentReq) (res *Ge
|
|||
// "ideal",
|
||||
}),
|
||||
}
|
||||
for key, item := range req.Metadata {
|
||||
params.AddMetadata(key, item)
|
||||
}
|
||||
resPaymentintent, err := paymentintent.New(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue
Block a user