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

This commit is contained in:
laodaming 2023-09-22 12:15:23 +08:00
commit 9753920595
11 changed files with 196 additions and 450 deletions

View File

@ -6,6 +6,7 @@ import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/check"
"log"
"strings"
"context"
@ -82,6 +83,26 @@ func (mquery *ModuleQuery) EncodeEmpty() map[string]any {
return qstr
}
func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string) map[string]any {
qname := strings.Split(moduleQuery, ".")
queryAsName := qname[len(qname)-1]
sqlstr := fmt.Sprintf(
"select JSON_EXTRACT(metadata,'$.%s') as %s from %s where module = '%s' and user_id = 0 and guest_id = 0 order by ctime DESC limit 1",
moduleQuery, // logo_selected
queryAsName, // logo_selected
tname, // fs_user_info
module, // profile
)
raw := conn.Raw(sqlstr)
var info map[string]any
err := raw.Scan(&info).Error
if err == gorm.ErrRecordNotFound {
logx.Error(err)
}
return info
}
func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
@ -178,6 +199,29 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
}
}
// 隐含白板用户逻辑
if v, ok := metadict["userinfo.profile"]; ok {
if v == nil {
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
log.Println(info)
metadict["userinfo.profile"] = info
// log.Println(metadict)
} else {
profileDict := v.(map[string]any)
if _, ok := profileDict["logo_selected"]; !ok {
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
profileDict["logo_selected"] = info["logo_selected"]
}
}
} else if v, ok := metadict["userinfo.profile.logo_selected"]; ok {
if v == nil {
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
metadict["userinfo.profile.logo_selected"] = info
}
}
return resp.SetStatus(basic.CodeOK, metadict)
}

View File

@ -115,9 +115,7 @@ func TestMain(t *testing.T) {
if v, ok := metadict["userinfo.profile"]; ok {
if v == nil {
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
log.Println(info)
metadict["userinfo.profile"] = info
// log.Println(metadict)
} else {
@ -126,19 +124,15 @@ func TestMain(t *testing.T) {
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
profileDict["logo_selected"] = info["logo_selected"]
}
}
} else if v, ok := metadict["userinfo.profile.logo_selected"]; ok {
if v == nil {
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
metadict["userinfo.profile.logo_selected"] = info
}
}
log.Println(metadict)
return
}
func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string) map[string]any {

View File

@ -15,7 +15,7 @@ type CreateOrderReq struct {
type CreatePrePaymentByDepositReq struct {
OrderSn string `json:"order_sn"`
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
DeliveryAddress *DeliveryAddress `json:"delivery_address,optional"`
}

View File

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

View File

@ -12,11 +12,6 @@ import (
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/api/pay/payment-intent",
Handler: OrderPaymentIntentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/pay/refund",

View File

@ -1,181 +0,0 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/pay/internal/svc"
"fusenapi/server/pay/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type OrderPaymentIntentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewOrderPaymentIntentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderPaymentIntentLogic {
return &OrderPaymentIntentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *OrderPaymentIntentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *OrderPaymentIntentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }
func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentIntentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
// if userinfo == nil || userinfo.UserId == 0 {
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
// }
// // 查询订单数据
// orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
// orderInfo, err := orderModel.FindOneBySn(l.ctx, userinfo.UserId, req.Sn)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
// }
// logx.Error(err)
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get order info")
// }
// // 校验订单状态
// if *orderInfo.IsCancel == 1 {
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "order cancelled")
// }
// // 校验地址信息
// addressModel := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn)
// _, err = addressModel.GetOne(l.ctx, req.AddressId, userinfo.UserId)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "address not found")
// }
// logx.Error(err)
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get address info")
// }
// // 校验订单支付信息
// if *orderInfo.IsPayCompleted == 1 {
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "order is pay completed")
// }
// // 判断订单状态以及该支付金额
// var nowAt int64 = time.Now().UTC().Unix()
// var payAmount int64
// if *orderInfo.Status == int64(constants.STATUS_NEW_NOT_PAY) {
// payAmount = *orderInfo.TotalAmount / 2
// *orderInfo.DeliveryMethod = req.DeliveryMethod
// *orderInfo.AddressId = req.AddressId
// *orderInfo.PayMethod = req.PayMethod
// } else {
// payAmount = *orderInfo.TotalAmount - *orderInfo.TotalAmount/2
// }
// payConfig := &pay.Config{}
// var generatePrepaymentReq = &pay.GeneratePrepaymentReq{
// OrderSn: req.Sn,
// ProductName: "支付标题",
// Amount: payAmount,
// Currency: "eur",
// Quantity: 1,
// ProductDescription: "支付描述",
// }
// var resData types.OrderPaymentIntentRes
// // 事务处理
// ctx := l.ctx
// err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error {
// // 支付记录--处理 //支付记录改为一条订单多条,分首款尾款
// var payStatus int64 = 0
// var orderSource int64 = 1
// var payStage int64
// var fspay *gmodel.FsPay
// newFsPayModel := gmodel.NewFsPayModel(connGorm)
// if *orderInfo.Status == int64(constants.STATUS_NEW_NOT_PAY) {
// fspay, err = newFsPayModel.RBGetListByOrderNumberStage(ctx, *orderInfo.Sn, 1)
// if err != nil {
// if !errors.Is(err, gorm.ErrRecordNotFound) {
// return err
// }
// }
// payStage = 1
// } else {
// fspay, err = newFsPayModel.RBGetListByOrderNumberStage(ctx, *orderInfo.Sn, 2)
// if err != nil {
// if !errors.Is(err, gorm.ErrRecordNotFound) {
// return err
// }
// }
// payStage = 2
// }
// // 支付预付--生成
// if constants.PayMethod(req.PayMethod) == constants.PAYMETHOD_STRIPE {
// payConfig.Stripe.Key = l.svcCtx.Config.PayConfig.Stripe.Key
// generatePrepaymentReq.SuccessURL = l.svcCtx.Config.PayConfig.Stripe.SuccessURL
// generatePrepaymentReq.CancelURL = l.svcCtx.Config.PayConfig.Stripe.CancelURL
// }
// payDriver := pay.NewPayDriver(req.PayMethod, payConfig)
// prepaymentRes, err := payDriver.GeneratePrepayment(generatePrepaymentReq)
// if err != nil {
// return err
// }
// // 订单信息--修改
// err = gmodel.NewFsOrderModel(connGorm).RBUpdate(ctx, orderInfo)
// if err != nil {
// return err
// }
// if fspay == nil {
// fspay = &gmodel.FsPay{
// UserId: orderInfo.UserId,
// OrderNumber: orderInfo.Sn,
// CreatedAt: &nowAt,
// }
// } else {
// fspay.UpdatedAt = &nowAt
// }
// fspay.PayAmount = &payAmount
// fspay.PayStage = &payStage
// //fspay.TradeNo = &prepaymentRes.TradeNo
// fspay.PaymentMethod = &req.PayMethod
// fspay.OrderSource = &orderSource
// fspay.PayStatus = &payStatus
// _, err = newFsPayModel.RBCreateOrUpdate(ctx, fspay)
// if err != nil {
// return err
// }
// resData.RedirectUrl = prepaymentRes.URL
// resData.ClientSecret = prepaymentRes.ClientSecret
// return nil
// })
// if err != nil {
// logx.Error(err)
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to make payment")
// }
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}

View File

@ -1,9 +1,13 @@
package logic
import (
"encoding/json"
"errors"
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"time"
"context"
@ -11,6 +15,8 @@ import (
"fusenapi/server/pay/internal/types"
"github.com/stripe/stripe-go/v74"
"github.com/stripe/stripe-go/v74/webhook"
"github.com/zeromicro/go-zero/core/logc"
"github.com/zeromicro/go-zero/core/logx"
)
@ -42,110 +48,107 @@ func (l *StripeWebhookLogic) StripeWebhook(req *types.StripeWebhookReq, userinfo
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
// stripe.Key = l.svcCtx.Config.PayConfig.Stripe.Key
// event := stripe.Event{}
stripe.Key = l.svcCtx.Config.PayConfig.Stripe.Key
event := stripe.Event{}
// if err := json.Unmarshal(req.Payload, &event); err != nil {
// logx.Error(err)
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail")
// }
if err := json.Unmarshal(req.Payload, &event); err != nil {
logc.Errorf(l.ctx, "StripeWebhookLogic StripeWebhook Unmarshal err:", err)
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail")
}
// endpointSecret := l.svcCtx.Config.PayConfig.Stripe.EndpointSecret
// signatureHeader := req.StripeSignature
// event, err := webhook.ConstructEvent(req.Payload, signatureHeader, endpointSecret)
endpointSecret := l.svcCtx.Config.PayConfig.Stripe.EndpointSecret
signatureHeader := req.StripeSignature
event, err := webhook.ConstructEvent(req.Payload, signatureHeader, endpointSecret)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "Webhook signature verification failed")
}
// 支付回调事件日志
var payMethod = int64(constants.PAYMETHOD_STRIPE)
var nowTime = time.Now().UTC()
var eventData = []byte(event.Data.Raw)
l.HandlePayEventCreate(&gmodel.FsOrderTradeEvent{
PayMethod: &payMethod,
EventId: &event.ID,
EventType: &event.Type,
EventData: &eventData,
Ctime: &nowTime,
})
// Unmarshal the event data into an appropriate struct depending on its Type
switch event.Type {
case "charge.succeeded":
// var charge stripe.Charge
// err := json.Unmarshal(event.Data.Raw, &charge)
// if err != nil {
// logx.Error(err)
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "Webhook signature verification failed")
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type charge.succeeded")
// }
// // 新增支付回调事件日志
// var payMethod = int64(constants.PAYMETHOD_STRIPE)
// var nowTime = time.Now().UTC().Unix()
// var eventData = string(event.Data.Raw)
// var fsPayEvent = &gmodel.FsPayEvent{
// PayMethod: &payMethod,
// EventId: &event.ID,
// EventType: &event.Type,
// EventData: &eventData,
// EventCreated: &event.Created,
// Ip: &req.RemoteAddr,
// CreatedAt: &nowTime,
// }
// l.HandlePayEventCreate(fsPayEvent)
// // Unmarshal the event data into an appropriate struct depending on its Type
// switch event.Type {
// case "charge.succeeded":
// // var charge stripe.Charge
// // err := json.Unmarshal(event.Data.Raw, &charge)
// // if err != nil {
// // logx.Error(err)
// // return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type charge.succeeded")
// // }
// case "checkout.session.completed":
// // checkout checkout.session.completed 处理逻辑
// // var session stripe.CheckoutSession
// // err := json.Unmarshal(event.Data.Raw, &session)
// // if err != nil {
// // logx.Error(err)
// // return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_intent.succeeded")
// // }
// // fmt.Println("checkout.session.completed")
// // err = l.handlePaymentSessionCompleted(session.ID, session.PaymentIntent.ID)
// // if err != nil {
// // return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "checkout.session.completed fail")
// // }
// case "payment_intent.succeeded":
// var paymentIntent stripe.PaymentIntent
// err := json.Unmarshal(event.Data.Raw, &paymentIntent)
case "checkout.session.completed":
// checkout checkout.session.completed 处理逻辑
// var session stripe.CheckoutSession
// err := json.Unmarshal(event.Data.Raw, &session)
// if err != nil {
// logx.Errorf("err%+vdesc%s", err, "pay notify Unmarshal fail event.Type payment_intent.succeeded")
// logx.Error(err)
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_intent.succeeded")
// }
// err = l.HandlePaymentIntentSucceeded(&paymentIntent)
// fmt.Println("checkout.session.completed")
// err = l.handlePaymentSessionCompleted(session.ID, session.PaymentIntent.ID)
// if err != nil {
// logx.Errorf("err%+vdesc%s", err, "pay notify handle payment_intent.succeeded")
// return resp.SetStatusWithMessage(basic.CodePaybackNotOk, "pay notify handle payment_intent.succeeded")
// }
// case "payment_method.attached":
// var paymentMethod stripe.PaymentMethod
// err := json.Unmarshal(event.Data.Raw, &paymentMethod)
// if err != nil {
// logx.Error(err)
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_method.attached")
// }
// case "charge.refunded":
// var chargeRefunded stripe.Charge
// err := json.Unmarshal(event.Data.Raw, &chargeRefunded)
// if err != nil {
// logx.Errorf("err%+vdesc%s", err, "pay notify Unmarshal fail event.Type charge.refunded")
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type charge.refunded")
// }
// err = l.HandleChargeRefunded(&chargeRefunded)
// if err != nil {
// logx.Errorf("err%+vdesc%s", err, "pay notify handle charge.refunded")
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify handle charge.refunded")
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "checkout.session.completed fail")
// }
case "payment_intent.succeeded":
var paymentIntent stripe.PaymentIntent
err := json.Unmarshal(event.Data.Raw, &paymentIntent)
if err != nil {
logx.Errorf("err%+vdesc%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)
if err != nil {
logx.Errorf("err%+vdesc%s", err, "pay notify handle payment_intent.succeeded")
return resp.SetStatusWithMessage(basic.CodePaybackNotOk, "pay notify handle payment_intent.succeeded")
}
case "payment_method.attached":
var paymentMethod stripe.PaymentMethod
err := json.Unmarshal(event.Data.Raw, &paymentMethod)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type payment_method.attached")
}
case "charge.refunded":
var chargeRefunded stripe.Charge
err := json.Unmarshal(event.Data.Raw, &chargeRefunded)
if err != nil {
logx.Errorf("err%+vdesc%s", err, "pay notify Unmarshal fail event.Type charge.refunded")
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type charge.refunded")
}
err = l.HandleChargeRefunded(&chargeRefunded)
if err != nil {
logx.Errorf("err%+vdesc%s", err, "pay notify handle charge.refunded")
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify handle charge.refunded")
}
// // ... handle other event types
// default:
// logx.Error("Unhandled event")
// return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type Unhandled")
// }
// ... handle other event types
default:
logx.Error("Unhandled event")
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify Unmarshal fail event.Type Unhandled")
}
return resp.SetStatus(basic.CodeOK)
}
// 回调事件日志
func (l *StripeWebhookLogic) HandlePayEventCreate(fsPayEvent *gmodel.FsPayEvent) error {
_, err := gmodel.NewFsPayEventModel(l.svcCtx.MysqlConn).CreateOrUpdate(l.ctx, fsPayEvent)
return err
func (l *StripeWebhookLogic) HandlePayEventCreate(fsPayEvent *gmodel.FsOrderTradeEvent) error {
result := l.svcCtx.MysqlConn.Create(fsPayEvent)
return result.Error
}
// 退款成功
func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge) (err error) {
// // 退款成功
// 退款成功
// if chargeRefunded.Status == "succeeded" {
// ctx := l.ctx
// err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error {
@ -205,77 +208,37 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge)
}
// session完成
// func (l *StripeWebhookLogic) handlePaymentSessionCompleted(sessionId string, tradeNo string) (err error) {
// // 查询支付记录
// payModel := gmodel.NewFsPayModel(l.svcCtx.MysqlConn)
// rsbPay := payModel.RowSelectBuilder(nil)
// rsbPay = rsbPay.Where("session_id = ?", sessionId)
// payInfo, err := payModel.FindOneByQuery(l.ctx, rsbPay, nil)
// if err != nil {
// return err
// }
// if *payInfo.PayStatus == 0 {
// *payInfo.TradeNo = tradeNo
// _, err = payModel.CreateOrUpdate(l.ctx, payInfo)
// if err != nil {
// return err
// }
// } else {
// return errors.New("pay status 1")
// }
// return err
// }
func (l *StripeWebhookLogic) handlePaymentSessionCompleted(sessionId string, tradeNo string) (err error) {
// 查询支付记录
payModel := gmodel.NewFsPayModel(l.svcCtx.MysqlConn)
rsbPay := payModel.RowSelectBuilder(nil)
rsbPay = rsbPay.Where("session_id = ?", sessionId)
payInfo, err := payModel.FindOneByQuery(l.ctx, rsbPay, nil)
if err != nil {
return err
}
if *payInfo.PayStatus == 0 {
*payInfo.TradeNo = tradeNo
_, err = payModel.CreateOrUpdate(l.ctx, payInfo)
if err != nil {
return err
}
} else {
return errors.New("pay status 1")
}
return err
}
// 付款成功
func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.PaymentIntent) error {
// orderSn, ok := paymentIntent.Metadata["order_sn"]
// if !ok || orderSn == "" {
// return errors.New("order_sn not found")
// }
orderSn, ok := paymentIntent.Metadata["order_sn"]
if !ok || orderSn == "" {
return errors.New("order_sn not found")
}
return nil
// 查询订单
// // 查询支付记录
// payModel := gmodel.NewFsPayModel(l.svcCtx.MysqlConn)
// rsbPay := payModel.RowSelectBuilder(nil)
// rsbPay = rsbPay.Where("order_number = ?", orderSn).Where("pay_status = ?", constants.PAYSTATUS_UNSUCCESS)
// payInfo, err := payModel.FindOneByQuery(l.ctx, rsbPay, nil)
// if err != nil {
// return err
// }
// //订单信息
// orderDetailTemplateModel := gmodel.NewFsOrderDetailTemplateModel(l.svcCtx.MysqlConn)
// orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
// fsOrderDetailModel := gmodel.NewFsOrderDetailModel(l.svcCtx.MysqlConn)
// fsProductDesignModel := gmodel.NewFsProductDesignModel(l.svcCtx.MysqlConn)
// rsbOrder := orderModel.RowSelectBuilder(nil)
// rsbOrder = rsbOrder.Where("sn =?", orderSn).Preload("FsOrderDetails")
// rsbOrder = rsbOrder.Preload("FsOrderDetails", func(dbPreload *gorm.DB) *gorm.DB {
// return dbPreload.Table(fsOrderDetailModel.TableName()).Preload("FsOrderDetailTemplateInfo", func(dbPreload *gorm.DB) *gorm.DB {
// return dbPreload.Table(orderDetailTemplateModel.TableName()).Preload("FsProductDesignInfo", func(dbPreload *gorm.DB) *gorm.DB {
// return dbPreload.Table(fsProductDesignModel.TableName())
// })
// })
// })
// fsOrderRelInfo, err := orderModel.FindOneByQuery(l.ctx, rsbOrder, nil)
// if err != nil {
// return err
// }
// var designIds []int64
// var cartIds []int64
// if len(fsOrderRelInfo.FsOrderDetails) > 0 {
// for _, fsOrderDetail := range fsOrderRelInfo.FsOrderDetails {
// if fsOrderDetail.FsOrderDetailTemplateInfo.FsProductDesignInfo.Id != 0 {
// designIds = append(designIds, fsOrderDetail.FsOrderDetailTemplateInfo.FsProductDesignInfo.Id)
// }
// cartIds = append(cartIds, *fsOrderDetail.CartId)
// }
// }
// var nowTime int64 = time.Now().UTC().Unix()
// // 支付成功
// 支付成功
// if paymentIntent.Status == "succeeded" {
// var card string
// var brand string
@ -360,29 +323,26 @@ func (l *StripeWebhookLogic) HandlePaymentIntentSucceeded(paymentIntent *stripe.
// 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);
//千人千面的处理
// $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);
// }
// //查询用户邮箱信息
// $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);
// 订单记录
return nil
}

View File

@ -11,18 +11,6 @@ type OrderRefundReq struct {
type OrderRefundRes struct {
}
type OrderPaymentIntentReq struct {
Sn string `form:"sn"` //订单编号
DeliveryMethod int64 `form:"delivery_method"` //发货方式
AddressId int64 `form:"address_id"` //地址id
PayMethod int64 `form:"pay_method"` //支付方式
}
type OrderPaymentIntentRes struct {
RedirectUrl string `json:"redirect_url"`
ClientSecret string `json:"clientSecret"`
}
type StripeWebhookReq struct {
Payload []byte `json:"base_byte_slice,optional"`
StripeSignature string `json:"Stripe-Signature"`
@ -52,10 +40,10 @@ type File struct {
}
type Meta struct {
TotalCount int64 `json:"totalCount"`
PageCount int64 `json:"pageCount"`
CurrentPage int `json:"currentPage"`
PerPage int `json:"perPage"`
TotalCount int64 `json:"total_count"`
PageCount int64 `json:"page_count"`
CurrentPage int `json:"current_page"`
PerPage int `json:"per_page"`
}
// Set 设置Response的Code和Message值

View File

@ -39,7 +39,7 @@ type CreateOrderReq {
type CreatePrePaymentByDepositReq {
OrderSn string `json:"order_sn"`
DeliveryMethod int64 `json:"delivery_method,optional,options=[1,2],default=2"`
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
DeliveryAddress *DeliveryAddress `json:"delivery_address,optional"`
}

View File

@ -11,9 +11,6 @@ import "basic.api"
service pay {
@handler OrderPaymentIntentHandler
post /api/pay/payment-intent(OrderPaymentIntentReq) returns (response);
@handler OrderRefundHandler
post /api/pay/refund(OrderRefundReq) returns (response);
@ -28,20 +25,6 @@ type (
OrderRefundRes struct{}
)
// 生成预付款
type (
OrderPaymentIntentReq {
Sn string `form:"sn"` //订单编号
DeliveryMethod int64 `form:"delivery_method"` //发货方式
AddressId int64 `form:"address_id"` //地址id
PayMethod int64 `form:"pay_method"` //支付方式
}
OrderPaymentIntentRes {
RedirectUrl string `json:"redirect_url"`
ClientSecret string `json:"clientSecret"`
}
)
// StripeWebhook支付通知
type (
StripeWebhookReq {

View File

@ -282,15 +282,13 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create
var uOrderDetail = make(map[string]interface{})
var orderAddress *gmodel.OrderAddress
if in.DeliveryAddress != nil {
if in.DeliveryAddress.Name != ress.OrderDetailOriginal.DeliveryAddress.Name || in.DeliveryAddress.Address != ress.OrderDetail.DeliveryAddress.Address || in.DeliveryAddress.Mobile != ress.OrderDetail.DeliveryAddress.Mobile {
if in.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
orderAddress = &gmodel.OrderAddress{
Name: in.DeliveryAddress.Name,
Mobile: in.DeliveryAddress.Mobile,
Address: in.DeliveryAddress.Address,
}
}
}
var sql string = fmt.Sprintf(", `utime` = '%s'", ntime)
// 是否更新