feat:新增api
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/collect"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -12,7 +10,6 @@ import (
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserContactServiceLogic struct {
|
||||
@@ -33,36 +30,36 @@ func (l *UserContactServiceLogic) UserContactService(req *types.RequestContactSe
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
// if !userinfo.IsUser() {
|
||||
// return resp.SetStatus(basic.CodeUnAuth)
|
||||
// }
|
||||
|
||||
cs := gmodel.FsContactService{
|
||||
UserId: &userinfo.UserId,
|
||||
}
|
||||
collect.LoadJsonTag(&cs, &req)
|
||||
// cs := gmodel.FsContactService{
|
||||
// UserId: &userinfo.UserId,
|
||||
// }
|
||||
// collect.LoadJsonTag(&cs, &req)
|
||||
|
||||
switch req.Type {
|
||||
case "order":
|
||||
_, err := l.svcCtx.AllModels.FsOrder.FindOneAndCreateServiceContact(l.ctx, userinfo.UserId, req.RelationID, &cs)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return resp.SetStatus(basic.CodeOrderNotFoundErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
case "cloud":
|
||||
_, err := l.svcCtx.AllModels.FsCloudPickUp.GetCloudPickUpByIDAndUserID(l.ctx, userinfo.UserId, req.RelationID, &cs)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return resp.SetStatus(basic.CodeCloudOrderNotFoundErr)
|
||||
}
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
return
|
||||
default:
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "type is unknown")
|
||||
}
|
||||
// switch req.Type {
|
||||
// case "order":
|
||||
// _, err := l.svcCtx.AllModels.FsOrder.FindOneAndCreateServiceContact(l.ctx, userinfo.UserId, req.RelationID, &cs)
|
||||
// if err != nil {
|
||||
// if err == gorm.ErrRecordNotFound {
|
||||
// return resp.SetStatus(basic.CodeOrderNotFoundErr)
|
||||
// }
|
||||
// return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
// }
|
||||
// case "cloud":
|
||||
// _, err := l.svcCtx.AllModels.FsCloudPickUp.GetCloudPickUpByIDAndUserID(l.ctx, userinfo.UserId, req.RelationID, &cs)
|
||||
// if err != nil {
|
||||
// if err == gorm.ErrRecordNotFound {
|
||||
// return resp.SetStatus(basic.CodeCloudOrderNotFoundErr)
|
||||
// }
|
||||
// return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
// }
|
||||
// return
|
||||
// default:
|
||||
// return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "type is unknown")
|
||||
// }
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, cs)
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/stripe/stripe-go/v74"
|
||||
"github.com/stripe/stripe-go/v74/client"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserOderDeleteLogic struct {
|
||||
@@ -38,109 +30,109 @@ func (l *UserOderDeleteLogic) UserOderDelete(req *types.RequestOrderId, userinfo
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误
|
||||
}
|
||||
// if !userinfo.IsUser() {
|
||||
// return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误
|
||||
// }
|
||||
|
||||
//订单id
|
||||
orderId := req.OrderId
|
||||
if orderId < 1 {
|
||||
return resp.SetStatus(basic.CodeRequestParamsErr)
|
||||
}
|
||||
// //订单id
|
||||
// orderId := req.OrderId
|
||||
// if orderId < 1 {
|
||||
// return resp.SetStatus(basic.CodeRequestParamsErr)
|
||||
// }
|
||||
|
||||
m := l.svcCtx.AllModels.FsOrder
|
||||
order, err := m.FindOne(l.ctx, userinfo.UserId, orderId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatus(basic.CodeOrderNotFoundErr)
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
// m := l.svcCtx.AllModels.FsOrder
|
||||
// order, err := m.FindOne(l.ctx, userinfo.UserId, orderId)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return resp.SetStatus(basic.CodeOrderNotFoundErr)
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
// }
|
||||
|
||||
if auth.CheckValueRange[constants.Order](
|
||||
constants.Order(*order.Status),
|
||||
constants.STATUS_NEW_NOT_PAY,
|
||||
constants.STATUS_NEW_PAY_COMPLETED,
|
||||
constants.STATUS_NEW_PART_PAY,
|
||||
) {
|
||||
return resp.SetStatus(basic.CodeOrderNotCancelledErr)
|
||||
}
|
||||
// if auth.CheckValueRange[constants.Order](
|
||||
// constants.Order(*order.Status),
|
||||
// constants.STATUS_NEW_NOT_PAY,
|
||||
// constants.STATUS_NEW_PAY_COMPLETED,
|
||||
// constants.STATUS_NEW_PART_PAY,
|
||||
// ) {
|
||||
// return resp.SetStatus(basic.CodeOrderNotCancelledErr)
|
||||
// }
|
||||
|
||||
if *order.IsPayCompleted == 1 &&
|
||||
time.Now().After(time.Unix(*order.Ctime, 0).Add(48*time.Hour)) {
|
||||
return resp.SetStatus(basic.CodeOrderNotCancelledErr)
|
||||
}
|
||||
// if *order.IsPayCompleted == 1 &&
|
||||
// time.Now().After(time.Unix(*order.Ctime, 0).Add(48*time.Hour)) {
|
||||
// return resp.SetStatus(basic.CodeOrderNotCancelledErr)
|
||||
// }
|
||||
|
||||
uOrder := &gmodel.FsOrder{
|
||||
Id: orderId,
|
||||
}
|
||||
// uOrder := &gmodel.FsOrder{
|
||||
// Id: orderId,
|
||||
// }
|
||||
|
||||
var (
|
||||
isCancel int64 = 1
|
||||
ustatus int64 = int64(constants.STATUS_NEW_CANCEL)
|
||||
)
|
||||
// 修改取消状态和取消原因
|
||||
uOrder.Status = &ustatus
|
||||
uOrder.IsCancel = &isCancel
|
||||
uOrder.RefundReasonId = &req.RefundReasonId
|
||||
uOrder.RefundReason = &req.RefundReason
|
||||
// var (
|
||||
// isCancel int64 = 1
|
||||
// ustatus int64 = int64(constants.STATUS_NEW_CANCEL)
|
||||
// )
|
||||
// // 修改取消状态和取消原因
|
||||
// uOrder.Status = &ustatus
|
||||
// uOrder.IsCancel = &isCancel
|
||||
// uOrder.RefundReasonId = &req.RefundReasonId
|
||||
// uOrder.RefundReason = &req.RefundReason
|
||||
|
||||
err = m.Update(l.ctx, uOrder)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbUpdateErr)
|
||||
}
|
||||
// err = m.Update(l.ctx, uOrder)
|
||||
// if err != nil {
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatus(basic.CodeDbUpdateErr)
|
||||
// }
|
||||
|
||||
var (
|
||||
IsRefund int64 = 0
|
||||
CreatedAt = time.Now().UTC().Unix()
|
||||
)
|
||||
// var (
|
||||
// IsRefund int64 = 0
|
||||
// CreatedAt = time.Now().UTC().Unix()
|
||||
// )
|
||||
|
||||
refund := &gmodel.FsRefundReason{
|
||||
IsRefund: &IsRefund,
|
||||
RefundReasonId: &req.RefundReasonId,
|
||||
RefundReason: &req.RefundReason,
|
||||
OrderId: &order.Id,
|
||||
CreatedAt: &CreatedAt,
|
||||
}
|
||||
// refund := &gmodel.FsRefundReason{
|
||||
// IsRefund: &IsRefund,
|
||||
// RefundReasonId: &req.RefundReasonId,
|
||||
// RefundReason: &req.RefundReason,
|
||||
// OrderId: &order.Id,
|
||||
// CreatedAt: &CreatedAt,
|
||||
// }
|
||||
|
||||
mFsRefundReason := gmodel.NewFsRefundReasonModel(l.svcCtx.MysqlConn)
|
||||
err = mFsRefundReason.Create(l.ctx, refund)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
}
|
||||
// mFsRefundReason := gmodel.NewFsRefundReasonModel(l.svcCtx.MysqlConn)
|
||||
// err = mFsRefundReason.Create(l.ctx, refund)
|
||||
// if err != nil {
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatus(basic.CodeDbSqlErr)
|
||||
// }
|
||||
|
||||
// 退款
|
||||
// 调用第三方接口发起退款
|
||||
// // 退款
|
||||
// // 调用第三方接口发起退款
|
||||
|
||||
config := &stripe.BackendConfig{
|
||||
MaxNetworkRetries: stripe.Int64(0), // Zero retries
|
||||
}
|
||||
// config := &stripe.BackendConfig{
|
||||
// MaxNetworkRetries: stripe.Int64(0), // Zero retries
|
||||
// }
|
||||
|
||||
sc := &client.API{}
|
||||
sc.Init(l.svcCtx.Config.Stripe.SK, &stripe.Backends{
|
||||
API: stripe.GetBackendWithConfig(stripe.APIBackend, config),
|
||||
Uploads: stripe.GetBackendWithConfig(stripe.UploadsBackend, config),
|
||||
})
|
||||
// ['order_number' => $order->sn, 'is_refund' => 0, 'pay_status' => 1]
|
||||
payM := l.svcCtx.AllModels.FsPay
|
||||
// sc := &client.API{}
|
||||
// sc.Init(l.svcCtx.Config.Stripe.SK, &stripe.Backends{
|
||||
// API: stripe.GetBackendWithConfig(stripe.APIBackend, config),
|
||||
// Uploads: stripe.GetBackendWithConfig(stripe.UploadsBackend, config),
|
||||
// })
|
||||
// // ['order_number' => $order->sn, 'is_refund' => 0, 'pay_status' => 1]
|
||||
// payM := l.svcCtx.AllModels.FsPay
|
||||
|
||||
// 查询支付信息
|
||||
pays, err := payM.GetOrderPayList(l.ctx, *order.Sn, 1, 0)
|
||||
for _, pay := range pays {
|
||||
sc.Refunds.New(&stripe.RefundParams{
|
||||
PaymentIntent: pay.TradeNo,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatus(basic.CodeApiErr)
|
||||
}
|
||||
}
|
||||
// // 查询支付信息
|
||||
// pays, err := payM.GetOrderPayList(l.ctx, *order.Sn, 1, 0)
|
||||
// for _, pay := range pays {
|
||||
// sc.Refunds.New(&stripe.RefundParams{
|
||||
// PaymentIntent: pay.TradeNo,
|
||||
// })
|
||||
// }
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return resp.SetStatus(basic.CodeApiErr)
|
||||
// }
|
||||
// }
|
||||
|
||||
return resp.SetStatus(basic.CodePayCancelOk, uOrder)
|
||||
return resp.SetStatus(basic.CodePayCancelOk)
|
||||
|
||||
// return ResponseError(500, "Cancellation failure")
|
||||
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/handlers"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -15,7 +10,6 @@ import (
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserOrderCancelLogic struct {
|
||||
@@ -36,93 +30,93 @@ func (l *UserOrderCancelLogic) UserOrderCancel(req *types.UserOrderCancelReq, us
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if userinfo == nil || userinfo.UserId == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
}
|
||||
// if userinfo == nil || userinfo.UserId == 0 {
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
// }
|
||||
|
||||
//查询订单信息
|
||||
orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
orderInfo, err := orderModel.FindOne(l.ctx, userinfo.UserId, req.ID)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the order is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeServiceErr, "failed to get order info")
|
||||
}
|
||||
// //查询订单信息
|
||||
// orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
// orderInfo, err := orderModel.FindOne(l.ctx, userinfo.UserId, req.ID)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the order is not exists")
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatus(basic.CodeServiceErr, "failed to get order info")
|
||||
// }
|
||||
|
||||
// 判断订单状态
|
||||
var notCancelStatusMap = make(map[int64]struct{}, 3)
|
||||
notCancelStatusMap[int64(constants.STATUS_NEW_NOT_PAY)] = struct{}{}
|
||||
notCancelStatusMap[int64(constants.STATUS_NEW_PART_PAY)] = struct{}{}
|
||||
notCancelStatusMap[int64(constants.STATUS_NEW_PAY_COMPLETED)] = struct{}{}
|
||||
_, ok := notCancelStatusMap[int64(*orderInfo.Status)]
|
||||
if !ok {
|
||||
return resp.SetStatusWithMessage(basic.CodeOrderNotCancelledErr, "the order status not cancle")
|
||||
}
|
||||
// // 判断订单状态
|
||||
// var notCancelStatusMap = make(map[int64]struct{}, 3)
|
||||
// notCancelStatusMap[int64(constants.STATUS_NEW_NOT_PAY)] = struct{}{}
|
||||
// notCancelStatusMap[int64(constants.STATUS_NEW_PART_PAY)] = struct{}{}
|
||||
// notCancelStatusMap[int64(constants.STATUS_NEW_PAY_COMPLETED)] = struct{}{}
|
||||
// _, ok := notCancelStatusMap[int64(*orderInfo.Status)]
|
||||
// if !ok {
|
||||
// return resp.SetStatusWithMessage(basic.CodeOrderNotCancelledErr, "the order status not cancle")
|
||||
// }
|
||||
|
||||
var cancelTime int64 = time.Now().UTC().Unix() - (*orderInfo.Ctime + int64(constants.CANCLE_ORDER_EXPIRE))
|
||||
// 第一次支付成功后48小时后不能进行取消操作
|
||||
if *orderInfo.IsPayCompleted == 1 && cancelTime > 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeOrderNotCancelledErr, "The current order cannot be cancelled")
|
||||
}
|
||||
// var cancelTime int64 = time.Now().UTC().Unix() - (*orderInfo.Ctime + int64(constants.CANCLE_ORDER_EXPIRE))
|
||||
// // 第一次支付成功后48小时后不能进行取消操作
|
||||
// if *orderInfo.IsPayCompleted == 1 && cancelTime > 0 {
|
||||
// return resp.SetStatusWithMessage(basic.CodeOrderNotCancelledErr, "The current order cannot be cancelled")
|
||||
// }
|
||||
|
||||
// 修改订单--取消状态和取消原因
|
||||
*orderInfo.Status = int64(constants.STATUS_NEW_CANCEL)
|
||||
*orderInfo.IsCancel = 1
|
||||
orderInfo.RefundReasonId = &req.RefundReasonId
|
||||
orderInfo.RefundReason = &req.RefundReason
|
||||
// // 修改订单--取消状态和取消原因
|
||||
// *orderInfo.Status = int64(constants.STATUS_NEW_CANCEL)
|
||||
// *orderInfo.IsCancel = 1
|
||||
// orderInfo.RefundReasonId = &req.RefundReasonId
|
||||
// orderInfo.RefundReason = &req.RefundReason
|
||||
|
||||
var nowTime = time.Now().UTC().Unix()
|
||||
var payList []handlers.PayInfo
|
||||
// 事务处理
|
||||
ctx := l.ctx
|
||||
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||
// 修改订单信息
|
||||
orderModelTS := gmodel.NewFsOrderModel(tx)
|
||||
err = orderModelTS.RBUpdate(ctx, orderInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 新增退款记录
|
||||
var isRefund int64 = 0
|
||||
refundReasonModelTS := gmodel.NewFsRefundReasonModel(tx)
|
||||
refundReasonModelTS.RBCreateOrUpdate(ctx, &gmodel.FsRefundReason{
|
||||
IsRefund: &isRefund,
|
||||
RefundReasonId: &req.RefundReasonId,
|
||||
RefundReason: &req.RefundReason,
|
||||
OrderId: &orderInfo.Id,
|
||||
CreatedAt: &nowTime,
|
||||
})
|
||||
// 退款申请
|
||||
// 退款申请--查询支付信息
|
||||
fsPayModelTS := gmodel.NewFsPayModel(tx)
|
||||
rbFsPay := fsPayModelTS.RowSelectBuilder(nil).Where("order_number = ?", orderInfo.Sn).Where("pay_status =?", constants.PAYSTATUS_SUCCESS).Where("is_refund =?", 0)
|
||||
payInfoList, err := fsPayModelTS.FindAll(ctx, rbFsPay, nil, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, payInfo := range payInfoList {
|
||||
var key string
|
||||
if *payInfo.PaymentMethod == int64(constants.PAYMETHOD_STRIPE) {
|
||||
key = l.svcCtx.Config.PayConfig.Stripe.Key
|
||||
}
|
||||
payList = append(payList, handlers.PayInfo{
|
||||
TradeNo: *payInfo.TradeNo,
|
||||
PaymentMethod: *payInfo.PaymentMethod,
|
||||
Key: key,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
// 退款申请--调取第三方接口发起退款
|
||||
handlers.PayRefundHandler(&handlers.PayRefundHandlerReq{
|
||||
PayInfoList: payList,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeOrderCancelledNotOk, "the order cancle failed")
|
||||
}
|
||||
// var nowTime = time.Now().UTC().Unix()
|
||||
// var payList []handlers.PayInfo
|
||||
// // 事务处理
|
||||
// ctx := l.ctx
|
||||
// err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||
// // 修改订单信息
|
||||
// orderModelTS := gmodel.NewFsOrderModel(tx)
|
||||
// err = orderModelTS.RBUpdate(ctx, orderInfo)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // 新增退款记录
|
||||
// var isRefund int64 = 0
|
||||
// refundReasonModelTS := gmodel.NewFsRefundReasonModel(tx)
|
||||
// refundReasonModelTS.RBCreateOrUpdate(ctx, &gmodel.FsRefundReason{
|
||||
// IsRefund: &isRefund,
|
||||
// RefundReasonId: &req.RefundReasonId,
|
||||
// RefundReason: &req.RefundReason,
|
||||
// OrderId: &orderInfo.Id,
|
||||
// CreatedAt: &nowTime,
|
||||
// })
|
||||
// // 退款申请
|
||||
// // 退款申请--查询支付信息
|
||||
// fsPayModelTS := gmodel.NewFsPayModel(tx)
|
||||
// rbFsPay := fsPayModelTS.RowSelectBuilder(nil).Where("order_number = ?", orderInfo.Sn).Where("pay_status =?", constants.PAYSTATUS_SUCCESS).Where("is_refund =?", 0)
|
||||
// payInfoList, err := fsPayModelTS.FindAll(ctx, rbFsPay, nil, "")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// for _, payInfo := range payInfoList {
|
||||
// var key string
|
||||
// if *payInfo.PaymentMethod == int64(constants.PAYMETHOD_STRIPE) {
|
||||
// key = l.svcCtx.Config.PayConfig.Stripe.Key
|
||||
// }
|
||||
// payList = append(payList, handlers.PayInfo{
|
||||
// TradeNo: *payInfo.TradeNo,
|
||||
// PaymentMethod: *payInfo.PaymentMethod,
|
||||
// Key: key,
|
||||
// })
|
||||
// }
|
||||
// return nil
|
||||
// })
|
||||
// // 退款申请--调取第三方接口发起退款
|
||||
// handlers.PayRefundHandler(&handlers.PayRefundHandlerReq{
|
||||
// PayInfoList: payList,
|
||||
// })
|
||||
// if err != nil {
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatusWithMessage(basic.CodeOrderCancelledNotOk, "the order cancle failed")
|
||||
// }
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
@@ -13,7 +10,6 @@ import (
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserOrderDeleteLogic struct {
|
||||
@@ -43,36 +39,36 @@ func (l *UserOrderDeleteLogic) UserOrderDelete(req *types.UserOrderDeleteReq, us
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if userinfo == nil || userinfo.UserId == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
}
|
||||
// if userinfo == nil || userinfo.UserId == 0 {
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
// }
|
||||
|
||||
orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
orderInfo, err := orderModel.FindOne(l.ctx, userinfo.UserId, req.ID)
|
||||
// orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
// orderInfo, err := orderModel.FindOne(l.ctx, userinfo.UserId, req.ID)
|
||||
|
||||
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 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")
|
||||
// }
|
||||
|
||||
updateStatusMap := make(map[constants.Order]struct{}, 4)
|
||||
updateStatusMap[constants.STATUS_NEW_COMPLETED] = struct{}{}
|
||||
updateStatusMap[constants.STATUS_NEW_CANCEL] = struct{}{}
|
||||
updateStatusMap[constants.STATUS_NEW_REFUNDED] = struct{}{}
|
||||
updateStatusMap[constants.STATUS_NEW_CLOSE] = struct{}{}
|
||||
if _, ok := updateStatusMap[constants.Order(*orderInfo.Status)]; !ok {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
}
|
||||
*orderInfo.Status = int64(constants.STATUS_NEW_DELETE)
|
||||
*orderInfo.IsDeleted = 1
|
||||
err = orderModel.Update(l.ctx, orderInfo)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "fail to delete")
|
||||
}
|
||||
// updateStatusMap := make(map[constants.Order]struct{}, 4)
|
||||
// updateStatusMap[constants.STATUS_NEW_COMPLETED] = struct{}{}
|
||||
// updateStatusMap[constants.STATUS_NEW_CANCEL] = struct{}{}
|
||||
// updateStatusMap[constants.STATUS_NEW_REFUNDED] = struct{}{}
|
||||
// updateStatusMap[constants.STATUS_NEW_CLOSE] = struct{}{}
|
||||
// if _, ok := updateStatusMap[constants.Order(*orderInfo.Status)]; !ok {
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
// }
|
||||
// *orderInfo.Status = int64(constants.STATUS_NEW_DELETE)
|
||||
// *orderInfo.IsDeleted = 1
|
||||
// err = orderModel.Update(l.ctx, orderInfo)
|
||||
// if err != nil {
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "fail to delete")
|
||||
// }
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/configs"
|
||||
"fusenapi/utils/image"
|
||||
"strings"
|
||||
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/order"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -22,7 +10,6 @@ import (
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type UserOrderListLogic struct {
|
||||
@@ -43,263 +30,264 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
size := req.Size
|
||||
// size := req.Size
|
||||
|
||||
if size > 0 {
|
||||
size = int64(image.GetCurrentSize(uint32(size)))
|
||||
}
|
||||
// if size > 0 {
|
||||
// size = int64(image.GetCurrentSize(uint32(size)))
|
||||
// }
|
||||
|
||||
orderDetailModel := gmodel.NewFsOrderDetailModel(l.svcCtx.MysqlConn)
|
||||
orderDetailTemplateModel := gmodel.NewFsOrderDetailTemplateModel(l.svcCtx.MysqlConn)
|
||||
fsProductDesignModel := gmodel.NewFsProductDesignModel(l.svcCtx.MysqlConn)
|
||||
orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
rowBuilder := orderModel.RowSelectBuilder(nil)
|
||||
if userinfo == nil || userinfo.UserId == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
}
|
||||
// orderDetailModel := gmodel.NewFsOrderDetailModel(l.svcCtx.MysqlConn)
|
||||
// orderDetailTemplateModel := gmodel.NewFsOrderDetailTemplateModel(l.svcCtx.MysqlConn)
|
||||
// fsProductDesignModel := gmodel.NewFsProductDesignModel(l.svcCtx.MysqlConn)
|
||||
// orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
// rowBuilder := orderModel.RowSelectBuilder(nil)
|
||||
// if userinfo == nil || userinfo.UserId == 0 {
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
// }
|
||||
|
||||
// 查询条件
|
||||
var page = req.Page
|
||||
var pageSize = req.PageSize
|
||||
var listRes []*gmodel.FsOrderRel
|
||||
rowBuilder = rowBuilder.Where("user_id =?", userinfo.UserId).Where("status <> ?", constants.STATUS_NEW_NOT_PAY).Where("status <>?", constants.STATUS_NEW_DELETE)
|
||||
// // 查询条件
|
||||
// var page = req.Page
|
||||
// var pageSize = req.PageSize
|
||||
// var listRes []*gmodel.FsOrderRel
|
||||
// rowBuilder = rowBuilder.Where("user_id =?", userinfo.UserId).Where("status <> ?", constants.STATUS_NEW_NOT_PAY).Where("status <>?", constants.STATUS_NEW_DELETE)
|
||||
|
||||
// 根据时间来查询不同范围的订单
|
||||
switch req.Time {
|
||||
case 1:
|
||||
rowBuilder = rowBuilder.Where("ctime >?", time.Now().UTC().AddDate(0, -1, 0).Unix())
|
||||
case 2:
|
||||
rowBuilder = rowBuilder.Where("ctime >?", time.Now().UTC().AddDate(0, -3, 0).Unix())
|
||||
case 3:
|
||||
rowBuilder = rowBuilder.Where("ctime >?", time.Now().UTC().AddDate(0, -6, 0).Unix())
|
||||
case 4:
|
||||
rowBuilder = rowBuilder.Where("ctime >?", time.Now().UTC().AddDate(-1, 0, 0).Unix())
|
||||
default:
|
||||
}
|
||||
// // 根据时间来查询不同范围的订单
|
||||
// switch req.Time {
|
||||
// case 1:
|
||||
// rowBuilder = rowBuilder.Where("ctime >?", time.Now().UTC().AddDate(0, -1, 0).Unix())
|
||||
// case 2:
|
||||
// rowBuilder = rowBuilder.Where("ctime >?", time.Now().UTC().AddDate(0, -3, 0).Unix())
|
||||
// case 3:
|
||||
// rowBuilder = rowBuilder.Where("ctime >?", time.Now().UTC().AddDate(0, -6, 0).Unix())
|
||||
// case 4:
|
||||
// rowBuilder = rowBuilder.Where("ctime >?", time.Now().UTC().AddDate(-1, 0, 0).Unix())
|
||||
// default:
|
||||
// }
|
||||
|
||||
//按照订单状态查询不同的订单
|
||||
if req.Status != -1 {
|
||||
switch req.Status {
|
||||
case 1:
|
||||
rowBuilder = rowBuilder.Where("status in ?", [3]constants.Order{constants.STATUS_NEW_PART_PAY, constants.STATUS_NEW_PAY_COMPLETED, constants.STATUS_NEW_SURE})
|
||||
case 2:
|
||||
rowBuilder = rowBuilder.Where("status in ?", [2]constants.Order{constants.STATUS_NEW_PRODUTING, constants.STATUS_NEW_PRODUT_COMPLETED})
|
||||
case 3:
|
||||
rowBuilder = rowBuilder.Where("status in ?", [2]constants.Order{constants.STATUS_NEW_DELIVER, constants.STATUS_NEW_UPS})
|
||||
case 4:
|
||||
rowBuilder = rowBuilder.Where("status =?", constants.STATUS_NEW_ARRIVAL)
|
||||
case 5:
|
||||
rowBuilder = rowBuilder.Where("status =?", constants.STATUS_NEW_COMPLETED).Where("delivery_method =?", constants.DELIVERY_METHOD_ADDRESS)
|
||||
case 7:
|
||||
rowBuilder = rowBuilder.Where("status in ?", [3]constants.Order{constants.STATUS_NEW_CANCEL, constants.STATUS_NEW_REFUNDED, constants.STATUS_NEW_REFUNDING})
|
||||
case 8:
|
||||
rowBuilder = rowBuilder.Where("status =?", constants.STATUS_NEW_COMPLETED).Where("delivery_method =?", constants.DELIVERY_METHOD_CLOUD)
|
||||
}
|
||||
}
|
||||
// //按照订单状态查询不同的订单
|
||||
// if req.Status != -1 {
|
||||
// switch req.Status {
|
||||
// case 1:
|
||||
// rowBuilder = rowBuilder.Where("status in ?", [3]constants.Order{constants.STATUS_NEW_PART_PAY, constants.STATUS_NEW_PAY_COMPLETED, constants.STATUS_NEW_SURE})
|
||||
// case 2:
|
||||
// rowBuilder = rowBuilder.Where("status in ?", [2]constants.Order{constants.STATUS_NEW_PRODUTING, constants.STATUS_NEW_PRODUT_COMPLETED})
|
||||
// case 3:
|
||||
// rowBuilder = rowBuilder.Where("status in ?", [2]constants.Order{constants.STATUS_NEW_DELIVER, constants.STATUS_NEW_UPS})
|
||||
// case 4:
|
||||
// rowBuilder = rowBuilder.Where("status =?", constants.STATUS_NEW_ARRIVAL)
|
||||
// case 5:
|
||||
// rowBuilder = rowBuilder.Where("status =?", constants.STATUS_NEW_COMPLETED).Where("delivery_method =?", constants.DELIVERY_METHOD_ADDRESS)
|
||||
// case 7:
|
||||
// rowBuilder = rowBuilder.Where("status in ?", [3]constants.Order{constants.STATUS_NEW_CANCEL, constants.STATUS_NEW_REFUNDED, constants.STATUS_NEW_REFUNDING})
|
||||
// case 8:
|
||||
// rowBuilder = rowBuilder.Where("status =?", constants.STATUS_NEW_COMPLETED).Where("delivery_method =?", constants.DELIVERY_METHOD_CLOUD)
|
||||
// }
|
||||
// }
|
||||
|
||||
// 查询总数
|
||||
total, err := orderModel.FindCount(l.ctx, rowBuilder, nil)
|
||||
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")
|
||||
}
|
||||
// // 查询总数
|
||||
// total, err := orderModel.FindCount(l.ctx, rowBuilder, nil)
|
||||
// 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 total > 0 {
|
||||
rowBuilder = rowBuilder.Preload("FsOrderAffiliateInfo").Preload("FsOrderDetails", func(dbPreload *gorm.DB) *gorm.DB {
|
||||
return dbPreload.Table(orderDetailModel.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()).Preload("OptionData").Preload("TemplateData")
|
||||
}).Preload("FsProductSizeInfo")
|
||||
}).Preload("FsProductInfo")
|
||||
})
|
||||
listRes, err = orderModel.FindPageListByPage(l.ctx, rowBuilder, &page, &pageSize, nil, "")
|
||||
}
|
||||
// // 查询数据
|
||||
// if total > 0 {
|
||||
// rowBuilder = rowBuilder.Preload("FsOrderAffiliateInfo").Preload("FsOrderDetails", func(dbPreload *gorm.DB) *gorm.DB {
|
||||
// return dbPreload.Table(orderDetailModel.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()).Preload("OptionData").Preload("TemplateData")
|
||||
// }).Preload("FsProductSizeInfo")
|
||||
// }).Preload("FsProductInfo")
|
||||
// })
|
||||
// listRes, err = orderModel.FindPageListByPage(l.ctx, rowBuilder, &page, &pageSize, nil, "")
|
||||
// }
|
||||
|
||||
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")
|
||||
}
|
||||
listResLen := len(listRes)
|
||||
// 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")
|
||||
// }
|
||||
// listResLen := len(listRes)
|
||||
|
||||
var respList []types.Items
|
||||
if listResLen > 0 {
|
||||
// 获取订单时间配置
|
||||
orderTimeConfig, err := configs.GetOrderTimeConfig(l.ctx, l.svcCtx.MysqlConn)
|
||||
if err != nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get config time info")
|
||||
}
|
||||
// var respList []types.Items
|
||||
// if listResLen > 0 {
|
||||
// // 获取订单时间配置
|
||||
// orderTimeConfig, err := configs.GetOrderTimeConfig(l.ctx, l.svcCtx.MysqlConn)
|
||||
// if err != nil {
|
||||
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get config time info")
|
||||
// }
|
||||
|
||||
// 数据处理
|
||||
for _, item := range listRes {
|
||||
var pbData types.Items
|
||||
pbData.ID = item.Id
|
||||
pbData.Sn = *item.Sn
|
||||
pbData.UserID = *item.UserId
|
||||
pbData.TotalAmount = *item.TotalAmount
|
||||
pbData.Ctime = format.TimeIntToFormat(*item.Ctime)
|
||||
pbData.Status = *item.Status
|
||||
pbData.DeliveryMethod = *item.DeliveryMethod
|
||||
pbData.TsTime = format.TimeToFormat(*item.TsTime)
|
||||
pbData.IsPayCompleted = *item.IsPayCompleted
|
||||
pbData.DeliverSn = *item.DeliverSn
|
||||
// // 数据处理
|
||||
// for _, item := range listRes {
|
||||
// var pbData types.Items
|
||||
// pbData.ID = item.Id
|
||||
// pbData.Sn = *item.Sn
|
||||
// pbData.UserID = *item.UserId
|
||||
// pbData.TotalAmount = *item.TotalAmount
|
||||
// pbData.Ctime = format.TimeIntToFormat(*item.Ctime)
|
||||
// pbData.Status = *item.Status
|
||||
// pbData.DeliveryMethod = *item.DeliveryMethod
|
||||
// pbData.TsTime = format.TimeToFormat(*item.TsTime)
|
||||
// pbData.IsPayCompleted = *item.IsPayCompleted
|
||||
// pbData.DeliverSn = *item.DeliverSn
|
||||
|
||||
var pcsBox int64
|
||||
var pcs int64
|
||||
var productList []types.Product
|
||||
// var pcsBox int64
|
||||
// var pcs int64
|
||||
// var productList []types.Product
|
||||
|
||||
var surplusAt int64
|
||||
// var surplusAt int64
|
||||
|
||||
//如果是部分支付状态,那么取消订单倒计时2天
|
||||
if *item.Status == int64(constants.STATUS_NEW_PART_PAY) {
|
||||
surplusAt = (*item.Ctime + int64(constants.CANCLE_ORDER_EXPIRE)) - time.Now().UTC().Unix()
|
||||
if surplusAt < 0 {
|
||||
surplusAt = 0
|
||||
}
|
||||
}
|
||||
// //如果是部分支付状态,那么取消订单倒计时2天
|
||||
// if *item.Status == int64(constants.STATUS_NEW_PART_PAY) {
|
||||
// surplusAt = (*item.Ctime + int64(constants.CANCLE_ORDER_EXPIRE)) - time.Now().UTC().Unix()
|
||||
// if surplusAt < 0 {
|
||||
// surplusAt = 0
|
||||
// }
|
||||
// }
|
||||
|
||||
fsOrderAffiliateInfo := item.FsOrderAffiliateInfo
|
||||
// fsOrderAffiliateInfo := item.FsOrderAffiliateInfo
|
||||
|
||||
var sureTime int64
|
||||
var productTime int64
|
||||
var ProductEndtime int64
|
||||
var deliverTime int64
|
||||
var upsDeliverTime int64
|
||||
var upsTime int64
|
||||
var arrivalTime int64
|
||||
var recevieTime int64
|
||||
if fsOrderAffiliateInfo.Id > 0 {
|
||||
sureTime = *fsOrderAffiliateInfo.SureTime
|
||||
productTime = *fsOrderAffiliateInfo.ProductTime
|
||||
ProductEndtime = *fsOrderAffiliateInfo.ProductEndtime
|
||||
deliverTime = *fsOrderAffiliateInfo.DeliverTime
|
||||
upsDeliverTime = *fsOrderAffiliateInfo.UpsDeliverTime
|
||||
upsTime = *fsOrderAffiliateInfo.UpsTime
|
||||
arrivalTime = *fsOrderAffiliateInfo.ArrivalTime
|
||||
recevieTime = *fsOrderAffiliateInfo.RecevieTime
|
||||
}
|
||||
// var sureTime int64
|
||||
// var productTime int64
|
||||
// var ProductEndtime int64
|
||||
// var deliverTime int64
|
||||
// var upsDeliverTime int64
|
||||
// var upsTime int64
|
||||
// var arrivalTime int64
|
||||
// var recevieTime int64
|
||||
// if fsOrderAffiliateInfo.Id > 0 {
|
||||
// sureTime = *fsOrderAffiliateInfo.SureTime
|
||||
// productTime = *fsOrderAffiliateInfo.ProductTime
|
||||
// ProductEndtime = *fsOrderAffiliateInfo.ProductEndtime
|
||||
// deliverTime = *fsOrderAffiliateInfo.DeliverTime
|
||||
// upsDeliverTime = *fsOrderAffiliateInfo.UpsDeliverTime
|
||||
// upsTime = *fsOrderAffiliateInfo.UpsTime
|
||||
// arrivalTime = *fsOrderAffiliateInfo.ArrivalTime
|
||||
// recevieTime = *fsOrderAffiliateInfo.RecevieTime
|
||||
// }
|
||||
|
||||
var getOrderStatusAndLogisticsReq = order.GetOrderStatusAndLogisticsReq{
|
||||
OrderStatus: constants.Order(*item.Status),
|
||||
DeliveryMethod: constants.DeliveryMethod(*item.DeliveryMethod),
|
||||
IsPayCompleted: *item.IsAllProductCompleted,
|
||||
OrderCtime: *item.Ctime,
|
||||
// var getOrderStatusAndLogisticsReq = order.GetOrderStatusAndLogisticsReq{
|
||||
// OrderStatus: constants.Order(*item.Status),
|
||||
// DeliveryMethod: constants.DeliveryMethod(*item.DeliveryMethod),
|
||||
// IsPayCompleted: *item.IsAllProductCompleted,
|
||||
// OrderCtime: *item.Ctime,
|
||||
|
||||
SureTime: sureTime,
|
||||
ProductTime: productTime,
|
||||
ProductEndtime: ProductEndtime,
|
||||
DeliverTime: deliverTime,
|
||||
UpsDeliverTime: upsDeliverTime,
|
||||
UpsTime: upsTime,
|
||||
ArrivalTime: arrivalTime,
|
||||
RecevieTime: recevieTime,
|
||||
// SureTime: sureTime,
|
||||
// ProductTime: productTime,
|
||||
// ProductEndtime: ProductEndtime,
|
||||
// DeliverTime: deliverTime,
|
||||
// UpsDeliverTime: upsDeliverTime,
|
||||
// UpsTime: upsTime,
|
||||
// ArrivalTime: arrivalTime,
|
||||
// RecevieTime: recevieTime,
|
||||
|
||||
WebSetTimeInfo: orderTimeConfig,
|
||||
}
|
||||
// WebSetTimeInfo: orderTimeConfig,
|
||||
// }
|
||||
|
||||
statusAndLogisticsRes := order.GetOrderStatusAndLogistics(getOrderStatusAndLogisticsReq)
|
||||
// statusAndLogisticsRes := order.GetOrderStatusAndLogistics(getOrderStatusAndLogisticsReq)
|
||||
|
||||
// 流程控制
|
||||
var statusTime []types.StatusTime
|
||||
for _, itemTimes := range statusAndLogisticsRes.Times {
|
||||
statusTime = append(statusTime, types.StatusTime{
|
||||
Key: itemTimes.Key,
|
||||
Time: itemTimes.Time,
|
||||
})
|
||||
}
|
||||
pbData.StatusTimes = statusTime
|
||||
pbData.LogisticsStatus = int64(statusAndLogisticsRes.LogisticsStatus)
|
||||
pbData.Status = int64(statusAndLogisticsRes.OrderStatus)
|
||||
// // 流程控制
|
||||
// var statusTime []types.StatusTime
|
||||
// for _, itemTimes := range statusAndLogisticsRes.Times {
|
||||
// statusTime = append(statusTime, types.StatusTime{
|
||||
// Key: itemTimes.Key,
|
||||
// Time: itemTimes.Time,
|
||||
// })
|
||||
// }
|
||||
// pbData.StatusTimes = statusTime
|
||||
// pbData.LogisticsStatus = int64(statusAndLogisticsRes.LogisticsStatus)
|
||||
// pbData.Status = int64(statusAndLogisticsRes.OrderStatus)
|
||||
|
||||
var isStopMax int64
|
||||
if len(item.FsOrderDetails) > 0 {
|
||||
for _, fsOrderDetailItem := range item.FsOrderDetails {
|
||||
// var isStopMax int64
|
||||
// if len(item.FsOrderDetails) > 0 {
|
||||
// for _, fsOrderDetailItem := range item.FsOrderDetails {
|
||||
|
||||
fsOrderDetailBuyNum := *fsOrderDetailItem.FsOrderDetail.BuyNum
|
||||
fsOrderDetailEachBoxNum := *fsOrderDetailItem.FsOrderDetailTemplateInfo.EachBoxNum
|
||||
pcs = pcs + fsOrderDetailBuyNum
|
||||
pcsBoxNum := fsOrderDetailBuyNum / fsOrderDetailEachBoxNum
|
||||
var csBoxNumF int64
|
||||
if (fsOrderDetailBuyNum % fsOrderDetailEachBoxNum) > 0 {
|
||||
csBoxNumF = 1
|
||||
}
|
||||
pcsBox = pcsBox + pcsBoxNum + csBoxNumF
|
||||
// fsOrderDetailBuyNum := *fsOrderDetailItem.FsOrderDetail.BuyNum
|
||||
// fsOrderDetailEachBoxNum := *fsOrderDetailItem.FsOrderDetailTemplateInfo.EachBoxNum
|
||||
// pcs = pcs + fsOrderDetailBuyNum
|
||||
// pcsBoxNum := fsOrderDetailBuyNum / fsOrderDetailEachBoxNum
|
||||
// var csBoxNumF int64
|
||||
// if (fsOrderDetailBuyNum % fsOrderDetailEachBoxNum) > 0 {
|
||||
// csBoxNumF = 1
|
||||
// }
|
||||
// pcsBox = pcsBox + pcsBoxNum + csBoxNumF
|
||||
|
||||
productCover := *fsOrderDetailItem.Cover
|
||||
// 尺寸
|
||||
if size >= 200 {
|
||||
coverArr := strings.Split(*fsOrderDetailItem.Cover, ".")
|
||||
if len(coverArr) < 2 {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "cover split slice item count is less than 2")
|
||||
}
|
||||
productCover = fmt.Sprintf("%s_%d.%s", coverArr[0], req.Size, coverArr[1])
|
||||
}
|
||||
// productCover := *fsOrderDetailItem.Cover
|
||||
// // 尺寸
|
||||
// if size >= 200 {
|
||||
// coverArr := strings.Split(*fsOrderDetailItem.Cover, ".")
|
||||
// if len(coverArr) < 2 {
|
||||
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "cover split slice item count is less than 2")
|
||||
// }
|
||||
// productCover = fmt.Sprintf("%s_%d.%s", coverArr[0], req.Size, coverArr[1])
|
||||
// }
|
||||
|
||||
// 判断stop
|
||||
var isStop int64
|
||||
if fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductDesignInfo.OptionData.Id != 0 {
|
||||
// 尺寸或者模板下架
|
||||
if fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductDesignInfo.Id != 0 {
|
||||
isStop = 1
|
||||
} else {
|
||||
isStop = 3
|
||||
}
|
||||
} else {
|
||||
if fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductDesignInfo.Id != 0 {
|
||||
isStop = 1
|
||||
}
|
||||
}
|
||||
// // 判断stop
|
||||
// var isStop int64
|
||||
// if fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductDesignInfo.OptionData.Id != 0 {
|
||||
// // 尺寸或者模板下架
|
||||
// if fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductDesignInfo.Id != 0 {
|
||||
// isStop = 1
|
||||
// } else {
|
||||
// isStop = 3
|
||||
// }
|
||||
// } else {
|
||||
// if fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductDesignInfo.Id != 0 {
|
||||
// isStop = 1
|
||||
// }
|
||||
// }
|
||||
|
||||
// 判断产品是否下架
|
||||
if *fsOrderDetailItem.FsProductInfo.IsShelf == 0 || *fsOrderDetailItem.FsProductInfo.IsDel == 1 {
|
||||
isStop = 2
|
||||
}
|
||||
if isStop > isStopMax {
|
||||
isStopMax = isStop
|
||||
}
|
||||
// // 判断产品是否下架
|
||||
// if *fsOrderDetailItem.FsProductInfo.IsShelf == 0 || *fsOrderDetailItem.FsProductInfo.IsDel == 1 {
|
||||
// isStop = 2
|
||||
// }
|
||||
// if isStop > isStopMax {
|
||||
// isStopMax = isStop
|
||||
// }
|
||||
|
||||
productList = append(productList, types.Product{
|
||||
Cover: productCover,
|
||||
Fitting: *fsOrderDetailItem.OptionalTitle,
|
||||
OptionPrice: *fsOrderDetailItem.OptionPrice,
|
||||
OrderDetailTemplateId: *fsOrderDetailItem.OrderDetailTemplateId,
|
||||
OrderId: *fsOrderDetailItem.OrderId,
|
||||
Pcs: fsOrderDetailBuyNum,
|
||||
PcsBox: pcsBox,
|
||||
Price: *fsOrderDetailItem.FsOrderDetail.Amount,
|
||||
ProductId: *fsOrderDetailItem.OptionPrice,
|
||||
Title: *fsOrderDetailItem.FsProductInfo.Title,
|
||||
Size: *fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductSizeInfo.Capacity,
|
||||
IsStop: isStop,
|
||||
})
|
||||
}
|
||||
pbData.ProductList = productList
|
||||
}
|
||||
// productList = append(productList, types.Product{
|
||||
// Cover: productCover,
|
||||
// Fitting: *fsOrderDetailItem.OptionalTitle,
|
||||
// OptionPrice: *fsOrderDetailItem.OptionPrice,
|
||||
// OrderDetailTemplateId: *fsOrderDetailItem.OrderDetailTemplateId,
|
||||
// OrderId: *fsOrderDetailItem.OrderId,
|
||||
// Pcs: fsOrderDetailBuyNum,
|
||||
// PcsBox: pcsBox,
|
||||
// Price: *fsOrderDetailItem.FsOrderDetail.Amount,
|
||||
// ProductId: *fsOrderDetailItem.OptionPrice,
|
||||
// Title: *fsOrderDetailItem.FsProductInfo.Title,
|
||||
// Size: *fsOrderDetailItem.FsOrderDetailTemplateInfo.FsProductSizeInfo.Capacity,
|
||||
// IsStop: isStop,
|
||||
// })
|
||||
// }
|
||||
// pbData.ProductList = productList
|
||||
// }
|
||||
|
||||
pbData.IsStop = isStopMax
|
||||
pbData.PcsBox = pcsBox
|
||||
pbData.Pcs = pcs
|
||||
pbData.SurplusAt = surplusAt
|
||||
pbData.Deposit = *item.TotalAmount / 2
|
||||
pbData.Remaining = pbData.Deposit
|
||||
respList = append(respList, pbData)
|
||||
}
|
||||
// pbData.IsStop = isStopMax
|
||||
// pbData.PcsBox = pcsBox
|
||||
// pbData.Pcs = pcs
|
||||
// pbData.SurplusAt = surplusAt
|
||||
// pbData.Deposit = *item.TotalAmount / 2
|
||||
// pbData.Remaining = pbData.Deposit
|
||||
// respList = append(respList, pbData)
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.UserOrderListRsp{
|
||||
Items: respList,
|
||||
Meta: types.Meta{
|
||||
TotalCount: total,
|
||||
PageCount: int64(math.Ceil(float64(total) / float64(pageSize))),
|
||||
CurrentPage: int(page),
|
||||
PerPage: int(pageSize),
|
||||
},
|
||||
})
|
||||
// return resp.SetStatusWithMessage(basic.CodeOK, "success", types.UserOrderListRsp{
|
||||
// Items: respList,
|
||||
// Meta: types.Meta{
|
||||
// TotalCount: total,
|
||||
// PageCount: int64(math.Ceil(float64(total) / float64(pageSize))),
|
||||
// CurrentPage: int(page),
|
||||
// PerPage: int(pageSize),
|
||||
// },
|
||||
// })
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/pay"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -15,7 +10,6 @@ import (
|
||||
"fusenapi/server/pay/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type OrderPaymentIntentLogic struct {
|
||||
@@ -45,143 +39,143 @@ func (l *OrderPaymentIntentLogic) OrderPaymentIntent(req *types.OrderPaymentInte
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if userinfo == nil || userinfo.UserId == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
}
|
||||
// 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)
|
||||
// // 查询订单数据
|
||||
// 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 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")
|
||||
}
|
||||
// // 校验订单状态
|
||||
// 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)
|
||||
// // 校验地址信息
|
||||
// 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 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")
|
||||
}
|
||||
// // 校验订单支付信息
|
||||
// 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
|
||||
}
|
||||
// // 判断订单状态以及该支付金额
|
||||
// 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: "支付描述",
|
||||
}
|
||||
// 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
|
||||
}
|
||||
// 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
|
||||
}
|
||||
// // 支付预付--生成
|
||||
// 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
|
||||
}
|
||||
// // 订单信息--修改
|
||||
// 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
|
||||
// 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
|
||||
}
|
||||
// _, err = newFsPayModel.RBCreateOrUpdate(ctx, fspay)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
resData.RedirectUrl = prepaymentRes.URL
|
||||
resData.ClientSecret = prepaymentRes.ClientSecret
|
||||
// resData.RedirectUrl = prepaymentRes.URL
|
||||
// resData.ClientSecret = prepaymentRes.ClientSecret
|
||||
|
||||
return nil
|
||||
})
|
||||
// return nil
|
||||
// })
|
||||
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to make payment")
|
||||
}
|
||||
// if err != nil {
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to make payment")
|
||||
// }
|
||||
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", resData)
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -15,9 +11,7 @@ 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/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type StripeWebhookLogic struct {
|
||||
@@ -48,97 +42,97 @@ 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 {
|
||||
// logx.Error(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)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "Webhook signature verification failed")
|
||||
}
|
||||
// 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().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)
|
||||
// // 新增支付回调事件日志
|
||||
// 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")
|
||||
// }
|
||||
// // 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)
|
||||
if err != nil {
|
||||
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)
|
||||
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")
|
||||
}
|
||||
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:%+v,desc:%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:%+v,desc:%s", err, "pay notify handle charge.refunded")
|
||||
return resp.SetStatusWithMessage(basic.CodeAesCbcDecryptionErr, "pay notify handle charge.refunded")
|
||||
}
|
||||
// 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)
|
||||
// if err != nil {
|
||||
// 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)
|
||||
// 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")
|
||||
// }
|
||||
// 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:%+v,desc:%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:%+v,desc:%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)
|
||||
}
|
||||
@@ -151,62 +145,62 @@ func (l *StripeWebhookLogic) HandlePayEventCreate(fsPayEvent *gmodel.FsPayEvent)
|
||||
|
||||
// 退款成功
|
||||
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 {
|
||||
// 查询支付记录
|
||||
payModelT := gmodel.NewFsPayModel(connGorm)
|
||||
payModelTRSB := payModelT.BuilderTrans(nil)
|
||||
payModelTRSB1 := payModelTRSB.Where("trade_no = ?", chargeRefunded.PaymentIntent.ID).Where("pay_status = ?", constants.PAYSTATUS_SUCCESS).Where("is_refund = ?", 0)
|
||||
payInfo, err := payModelT.FindOneByQuery(ctx, payModelTRSB1, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 更新支付记录
|
||||
*payInfo.IsRefund = 1
|
||||
_, err = payModelT.RBCreateOrUpdate(ctx, payInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 获取是否还有未退款的数据
|
||||
payModelTRSB2 := payModelTRSB.Where("order_number = ?", payInfo.OrderNumber).Where("pay_status = ?", constants.PAYSTATUS_SUCCESS).Where("is_refund = ?", 0)
|
||||
count, err := payModelT.FindCount(l.ctx, payModelTRSB2, nil)
|
||||
if count == 0 {
|
||||
// 退款完成更新订单状态
|
||||
orderModelT := gmodel.NewFsOrderModel(connGorm)
|
||||
orderModelTRSB := orderModelT.BuilderTrans(nil).Where("sn =?", payInfo.OrderNumber)
|
||||
orderInfoRel, err := orderModelT.FindOneByQuery(ctx, orderModelTRSB, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var isRefunded int64 = 1
|
||||
var isRefunding int64 = 1
|
||||
var orderStatus int64 = int64(constants.STATUS_NEW_REFUNDED)
|
||||
var orderInfo = &gmodel.FsOrder{}
|
||||
orderInfo.Id = orderInfoRel.Id
|
||||
orderInfo.IsRefunded = &isRefunded
|
||||
orderInfo.IsRefunding = &isRefunding
|
||||
orderInfo.Status = &orderStatus
|
||||
orderModelT.Update(ctx, orderInfo)
|
||||
// // 退款成功
|
||||
// if chargeRefunded.Status == "succeeded" {
|
||||
// ctx := l.ctx
|
||||
// err = l.svcCtx.MysqlConn.Transaction(func(connGorm *gorm.DB) error {
|
||||
// // 查询支付记录
|
||||
// payModelT := gmodel.NewFsPayModel(connGorm)
|
||||
// payModelTRSB := payModelT.BuilderTrans(nil)
|
||||
// payModelTRSB1 := payModelTRSB.Where("trade_no = ?", chargeRefunded.PaymentIntent.ID).Where("pay_status = ?", constants.PAYSTATUS_SUCCESS).Where("is_refund = ?", 0)
|
||||
// payInfo, err := payModelT.FindOneByQuery(ctx, payModelTRSB1, nil)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // 更新支付记录
|
||||
// *payInfo.IsRefund = 1
|
||||
// _, err = payModelT.RBCreateOrUpdate(ctx, payInfo)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // 获取是否还有未退款的数据
|
||||
// payModelTRSB2 := payModelTRSB.Where("order_number = ?", payInfo.OrderNumber).Where("pay_status = ?", constants.PAYSTATUS_SUCCESS).Where("is_refund = ?", 0)
|
||||
// count, err := payModelT.FindCount(l.ctx, payModelTRSB2, nil)
|
||||
// if count == 0 {
|
||||
// // 退款完成更新订单状态
|
||||
// orderModelT := gmodel.NewFsOrderModel(connGorm)
|
||||
// orderModelTRSB := orderModelT.BuilderTrans(nil).Where("sn =?", payInfo.OrderNumber)
|
||||
// orderInfoRel, err := orderModelT.FindOneByQuery(ctx, orderModelTRSB, nil)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// var isRefunded int64 = 1
|
||||
// var isRefunding int64 = 1
|
||||
// var orderStatus int64 = int64(constants.STATUS_NEW_REFUNDED)
|
||||
// var orderInfo = &gmodel.FsOrder{}
|
||||
// orderInfo.Id = orderInfoRel.Id
|
||||
// orderInfo.IsRefunded = &isRefunded
|
||||
// orderInfo.IsRefunding = &isRefunding
|
||||
// orderInfo.Status = &orderStatus
|
||||
// orderModelT.Update(ctx, orderInfo)
|
||||
|
||||
// 记录退款原因
|
||||
refundReasonModelT := gmodel.NewFsRefundReasonModel(connGorm)
|
||||
refundReasonModelTRSB := refundReasonModelT.BuilderTrans(nil)
|
||||
refundReasonModelTRSB1 := refundReasonModelTRSB.Where("order_id =?", orderInfoRel.Id)
|
||||
refundReasonInfo, err := refundReasonModelT.FindOneByQuery(ctx, refundReasonModelTRSB1, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*refundReasonInfo.IsRefund = 1
|
||||
_, err = refundReasonModelT.RBCreateOrUpdate(ctx, refundReasonInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
})
|
||||
}
|
||||
// // 记录退款原因
|
||||
// refundReasonModelT := gmodel.NewFsRefundReasonModel(connGorm)
|
||||
// refundReasonModelTRSB := refundReasonModelT.BuilderTrans(nil)
|
||||
// refundReasonModelTRSB1 := refundReasonModelTRSB.Where("order_id =?", orderInfoRel.Id)
|
||||
// refundReasonInfo, err := refundReasonModelT.FindOneByQuery(ctx, refundReasonModelTRSB1, nil)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// *refundReasonInfo.IsRefund = 1
|
||||
// _, err = refundReasonModelT.RBCreateOrUpdate(ctx, refundReasonInfo)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// })
|
||||
// }
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -234,160 +228,160 @@ func (l *StripeWebhookLogic) HandleChargeRefunded(chargeRefunded *stripe.Charge)
|
||||
|
||||
// 付款成功
|
||||
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")
|
||||
// }
|
||||
|
||||
// 查询支付记录
|
||||
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
|
||||
}
|
||||
// // 查询支付记录
|
||||
// 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)
|
||||
// //订单信息
|
||||
// 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
|
||||
}
|
||||
// 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 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()
|
||||
// var nowTime int64 = time.Now().UTC().Unix()
|
||||
|
||||
// 支付成功
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
// // 支付成功
|
||||
// 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
|
||||
}
|
||||
// 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
|
||||
}
|
||||
// // 更新设计数据
|
||||
// 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
|
||||
// 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
|
||||
}
|
||||
}
|
||||
// // 删除购物车
|
||||
// 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
|
||||
}
|
||||
// // 支付记录是尾款
|
||||
// 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
|
||||
}
|
||||
// // 更新订单信息
|
||||
// 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);
|
||||
// //千人千面的处理
|
||||
// // $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
|
||||
|
||||
@@ -2,11 +2,10 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
@@ -47,64 +46,64 @@ func (l *GetLastProductDesignLogic) GetLastProductDesign(req *types.Request, use
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success:IsOpenRender switch is closed")
|
||||
}
|
||||
//查询用户最近下单成功的数据
|
||||
orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, user.Id, int64(constants.STATUS_NEW_NOT_PAY))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "none of order is found")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusAddMessage(basic.CodeDbSqlErr, "failed to get your last order")
|
||||
}
|
||||
// orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, user.Id, int64(constants.STATUS_NEW_NOT_PAY))
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "none of order is found")
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatusAddMessage(basic.CodeDbSqlErr, "failed to get your last order")
|
||||
// }
|
||||
//获取该订单相关设计信息
|
||||
orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order detail is not found")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusAddMessage(basic.CodeDbSqlErr, "failed to get order detail")
|
||||
}
|
||||
//获取设计模板详情,便于获得design_id
|
||||
orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order detail template is not found")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get order detail template")
|
||||
}
|
||||
// orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order detail is not found")
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatusAddMessage(basic.CodeDbSqlErr, "failed to get order detail")
|
||||
// }
|
||||
// //获取设计模板详情,便于获得design_id
|
||||
// orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order detail template is not found")
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get order detail template")
|
||||
// }
|
||||
//最后一次设计不存在,则不返回该设计相关数据
|
||||
if *orderDetailTemplate.DesignId <= 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success:last design id is not set")
|
||||
}
|
||||
// if *orderDetailTemplate.DesignId <= 0 {
|
||||
// return resp.SetStatusWithMessage(basic.CodeOK, "success:last design id is not set")
|
||||
// }
|
||||
//获取设计数据
|
||||
productDesign, err := l.svcCtx.AllModels.FsProductDesign.FindOne(l.ctx, *orderDetailTemplate.DesignId, user.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product design is not found")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product design")
|
||||
}
|
||||
var info interface{}
|
||||
if productDesign.Info != nil && *productDesign.Info != "" {
|
||||
if err := json.Unmarshal([]byte(*productDesign.Info), &info); err != nil {
|
||||
logx.Error(err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
var logoColor interface{}
|
||||
if productDesign.LogoColor != nil && *productDesign.LogoColor != "" {
|
||||
if err := json.Unmarshal([]byte(*productDesign.LogoColor), &logoColor); err != nil {
|
||||
logx.Error(err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
// productDesign, err := l.svcCtx.AllModels.FsProductDesign.FindOne(l.ctx, *orderDetailTemplate.DesignId, user.Id)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product design is not found")
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product design")
|
||||
// }
|
||||
// var info interface{}
|
||||
// if productDesign.Info != nil && *productDesign.Info != "" {
|
||||
// if err := json.Unmarshal([]byte(*productDesign.Info), &info); err != nil {
|
||||
// logx.Error(err)
|
||||
// return nil
|
||||
// }
|
||||
// }
|
||||
// var logoColor interface{}
|
||||
// if productDesign.LogoColor != nil && *productDesign.LogoColor != "" {
|
||||
// if err := json.Unmarshal([]byte(*productDesign.LogoColor), &logoColor); err != nil {
|
||||
// logx.Error(err)
|
||||
// return nil
|
||||
// }
|
||||
// }
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetLastProductDesignRsp{
|
||||
Id: productDesign.Id,
|
||||
OptionalId: *productDesign.OptionalId,
|
||||
SizeId: *productDesign.SizeId,
|
||||
LogoColor: logoColor,
|
||||
Info: info,
|
||||
Id: 1,
|
||||
OptionalId: 1,
|
||||
SizeId: 1,
|
||||
LogoColor: 1,
|
||||
Info: nil,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/step_price"
|
||||
"gorm.io/gorm"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
|
||||
@@ -14,10 +14,11 @@ import (
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/image"
|
||||
"fusenapi/utils/step_price"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
|
||||
@@ -460,66 +461,66 @@ func (l *GetProductInfoLogic) getRenderDesign(clientNo string) interface{} {
|
||||
// 获取用户最新设计
|
||||
func (l *GetProductInfoLogic) getLastDesign(userInfo gmodel.FsUser) interface{} {
|
||||
//查询用户最近下单成功的数据
|
||||
orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, userInfo.Id, int64(constants.STATUS_NEW_NOT_PAY))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil
|
||||
}
|
||||
logx.Error(err)
|
||||
return nil
|
||||
}
|
||||
// orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, userInfo.Id, int64(constants.STATUS_NEW_NOT_PAY))
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return nil
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return nil
|
||||
// }
|
||||
//获取该订单相关设计信息
|
||||
orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil
|
||||
}
|
||||
logx.Error(err)
|
||||
return nil
|
||||
}
|
||||
//获取设计模板详情,便于获得design_id
|
||||
orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil
|
||||
}
|
||||
logx.Error(err)
|
||||
return nil
|
||||
}
|
||||
// orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return nil
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return nil
|
||||
// }
|
||||
// //获取设计模板详情,便于获得design_id
|
||||
// orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return nil
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return nil
|
||||
// }
|
||||
//若没打开了个性化渲染按钮或者最后一次设计不存在,则不返回该设计相关数据
|
||||
if *userInfo.IsOpenRender != 1 || *orderDetailTemplate.DesignId <= 0 {
|
||||
return nil
|
||||
}
|
||||
//获取设计数据
|
||||
productDesign, err := l.svcCtx.AllModels.FsProductDesign.FindOne(l.ctx, *orderDetailTemplate.DesignId, userInfo.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil
|
||||
}
|
||||
logx.Error(err)
|
||||
return nil
|
||||
}
|
||||
var info interface{}
|
||||
if productDesign.Info != nil && *productDesign.Info != "" {
|
||||
if err := json.Unmarshal([]byte(*productDesign.Info), &info); err != nil {
|
||||
logx.Error(err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
var logoColor interface{}
|
||||
if productDesign.LogoColor != nil && *productDesign.LogoColor != "" {
|
||||
if err := json.Unmarshal([]byte(*productDesign.LogoColor), &logoColor); err != nil {
|
||||
logx.Error(err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
// if *userInfo.IsOpenRender != 1 || *orderDetailTemplate.DesignId <= 0 {
|
||||
// return nil
|
||||
// }
|
||||
// //获取设计数据
|
||||
// productDesign, err := l.svcCtx.AllModels.FsProductDesign.FindOne(l.ctx, *orderDetailTemplate.DesignId, userInfo.Id)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return nil
|
||||
// }
|
||||
// logx.Error(err)
|
||||
// return nil
|
||||
// }
|
||||
// var info interface{}
|
||||
// if productDesign.Info != nil && *productDesign.Info != "" {
|
||||
// if err := json.Unmarshal([]byte(*productDesign.Info), &info); err != nil {
|
||||
// logx.Error(err)
|
||||
// return nil
|
||||
// }
|
||||
// }
|
||||
// var logoColor interface{}
|
||||
// if productDesign.LogoColor != nil && *productDesign.LogoColor != "" {
|
||||
// if err := json.Unmarshal([]byte(*productDesign.LogoColor), &logoColor); err != nil {
|
||||
// logx.Error(err)
|
||||
// return nil
|
||||
// }
|
||||
// }
|
||||
return map[string]interface{}{
|
||||
"id": productDesign.Id,
|
||||
"info": info,
|
||||
"logo_color": logoColor,
|
||||
"material_id": *productDesign.MaterialId,
|
||||
"optional_id": *productDesign.OptionalId,
|
||||
"size_id": *productDesign.SizeId,
|
||||
"id": 1,
|
||||
"info": 1,
|
||||
"logo_color": 1,
|
||||
"material_id": 1,
|
||||
"optional_id": 1,
|
||||
"size_id": 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/color_list"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
@@ -126,28 +126,28 @@ func (l *GetRenderSettingByPidLogic) checkRenderDesign(clientNo string) (bool, e
|
||||
// 查询是否存在最新设计
|
||||
func (l *GetRenderSettingByPidLogic) checkLastDesignExists(userId int64) (bool, error) {
|
||||
//查询用户最近下单成功的数据
|
||||
orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, userId, int64(constants.STATUS_NEW_NOT_PAY))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
// orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, userId, int64(constants.STATUS_NEW_NOT_PAY))
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return false, nil
|
||||
// }
|
||||
// return false, err
|
||||
// }
|
||||
//获取该订单相关设计信息
|
||||
orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
//获取设计模板详情,便于获得design_id
|
||||
orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return *orderDetailTemplate.DesignId > 0, nil
|
||||
// orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return false, nil
|
||||
// }
|
||||
// return false, err
|
||||
// }
|
||||
// //获取设计模板详情,便于获得design_id
|
||||
// orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
// return false, nil
|
||||
// }
|
||||
// return false, err
|
||||
// }
|
||||
return false, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user