gplint
This commit is contained in:
parent
07e5ce0eca
commit
73f91be649
|
@ -1,6 +1,6 @@
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
package tweeting;
|
package order;
|
||||||
option go_package = "./tweeting";
|
option go_package = "./order";
|
||||||
|
|
||||||
// ========== 基本回應 ===========
|
// ========== 基本回應 ===========
|
||||||
message OKResp {}
|
message OKResp {}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package orderservicelogic
|
package orderservicelogic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
"app-cloudep-order-server/internal/domain"
|
"app-cloudep-order-server/internal/domain"
|
||||||
model "app-cloudep-order-server/internal/model/mongo"
|
model "app-cloudep-order-server/internal/model/mongo"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
ers "code.30cm.net/digimon/library-go/errs"
|
ers "code.30cm.net/digimon/library-go/errs"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -34,7 +34,7 @@ type CancelOrderQuery struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CancelOrder 取消訂單
|
// CancelOrder 取消訂單
|
||||||
func (l *CancelOrderLogic) CancelOrder(in *tweeting.CancelOrderReq) (*tweeting.OKResp, error) {
|
func (l *CancelOrderLogic) CancelOrder(in *order.CancelOrderReq) (*order.OKResp, error) {
|
||||||
// 驗證資料
|
// 驗證資料
|
||||||
if err := l.svcCtx.Validate.ValidateAll(&CancelOrderQuery{
|
if err := l.svcCtx.Validate.ValidateAll(&CancelOrderQuery{
|
||||||
BusinessID: in.GetBusinessId(),
|
BusinessID: in.GetBusinessId(),
|
||||||
|
@ -64,5 +64,5 @@ func (l *CancelOrderLogic) CancelOrder(in *tweeting.CancelOrderReq) (*tweeting.O
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tweeting.OKResp{}, nil
|
return &order.OKResp{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package orderservicelogic
|
package orderservicelogic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
"app-cloudep-order-server/internal/domain"
|
"app-cloudep-order-server/internal/domain"
|
||||||
model "app-cloudep-order-server/internal/model/mongo"
|
model "app-cloudep-order-server/internal/model/mongo"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ers "code.30cm.net/digimon/library-go/errs"
|
ers "code.30cm.net/digimon/library-go/errs"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -30,55 +31,59 @@ func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Creat
|
||||||
}
|
}
|
||||||
|
|
||||||
type createOrderReq struct { // 訂單ID
|
type createOrderReq struct { // 訂單ID
|
||||||
BusinessID string `json:"business_id" validate:"required"` // 訂單業務流水號
|
BusinessID string `json:"business_id" validate:"required"` // 訂單業務流水號
|
||||||
OrderType int8 `json:"order_type" validate:"required"` // 訂單類型
|
OrderType int8 `json:"order_type" validate:"required"` // 訂單類型
|
||||||
OrderStatus int8 `json:"order_status" validate:"required,oneof=0 1 2 3 4 5 6 7 8 9 10 11"` // 訂單狀態
|
OrderStatus int8 `json:"order_status" validate:"oneof=0 1 2 3 4 5 6 7 8 9 10 11"` // 訂單狀態
|
||||||
Brand string `json:"brand" validate:"required"` // 下單平台
|
Brand string `json:"brand" validate:"required"` // 下單平台
|
||||||
OrderUID string `json:"order_uid" validate:"required"` // 下單用戶 UID
|
OrderUID string `json:"order_uid" validate:"required"` // 下單用戶 UID
|
||||||
ReferenceID string `json:"reference_id" validate:"required"` // 訂單來源
|
ReferenceID string `json:"reference_id" validate:"required"` // 訂單來源
|
||||||
Count decimal.Decimal `json:"count" validate:"required,gt=0"` // 訂單數量
|
Count decimal.Decimal `json:"count" validate:"required,decimalGt=0"` // 訂單數量
|
||||||
OrderFee decimal.Decimal `json:"order_fee" validate:"required,gte=0"` // 訂單手續費
|
OrderFee decimal.Decimal `json:"order_fee" validate:"required,decimalGte=0"` // 訂單手續費
|
||||||
Amount decimal.Decimal `json:"amount" validate:"required,gte=0"` // 單價
|
Amount decimal.Decimal `json:"amount" validate:"required,decimalGte=0"` // 單價
|
||||||
ReferenceBrand *string `json:"reference_brand,omitempty" validate:"omitempty"` // 訂單來源平台
|
ReferenceBrand *string `json:"reference_brand,omitempty" validate:"omitempty"` // 訂單來源平台
|
||||||
ReferenceUID *string `json:"reference_uid,omitempty" validate:"omitempty"` // 訂單來源用戶 UID
|
ReferenceUID *string `json:"reference_uid,omitempty" validate:"omitempty"` // 訂單來源用戶 UID
|
||||||
WalletStatus *int64 `json:"wallet_status,omitempty" validate:"omitempty,oneof=1 2 3 4 5 6 7"` // 交易金額狀態
|
WalletStatus *int64 `json:"wallet_status,omitempty" validate:"omitempty,oneof=1 2 3 4 5 6 7"` // 交易金額狀態
|
||||||
ThreePartyStatus *int64 `json:"three_party_status,omitempty" validate:"omitempty,oneof=1 2 3"` // 三方請求狀態
|
ThreePartyStatus *int64 `json:"three_party_status,omitempty" validate:"omitempty,oneof=1 2 3"` // 三方請求狀態
|
||||||
DirectionType *int64 `json:"direction_type,omitempty" validate:"omitempty,oneof=1 2"` // 交易方向
|
DirectionType *int64 `json:"direction_type,omitempty" validate:"omitempty,oneof=1 2"` // 交易方向
|
||||||
CryptoType *string `json:"crypto_type,omitempty" validate:"omitempty"` // 交易幣種
|
CryptoType *string `json:"crypto_type,omitempty" validate:"omitempty"` // 交易幣種
|
||||||
ThirdPartyFee *decimal.Decimal `json:"third_party_fee,omitempty" validate:"omitempty,gte=0"` // 第三方手續費
|
ThirdPartyFee *decimal.Decimal `json:"third_party_fee,omitempty" validate:"omitempty,decimalGte=0"` // 第三方手續費
|
||||||
CryptoToUSDTRate *decimal.Decimal `json:"crypto_to_usdt_rate,omitempty" validate:"omitempty,gte=0"` // 交易幣種對 USDT 匯率
|
CryptoToUSDTRate *decimal.Decimal `json:"crypto_to_usdt_rate,omitempty" validate:"omitempty,decimalGte=0"` // 交易幣種對 USDT 匯率
|
||||||
FiatToUSDRate *decimal.Decimal `json:"fiat_to_usd_rate,omitempty" validate:"omitempty,gte=0"` // 法幣對 USD 匯率
|
FiatToUSDRate *decimal.Decimal `json:"fiat_to_usd_rate,omitempty" validate:"omitempty,decimalGte=0"` // 法幣對 USD 匯率
|
||||||
FeeCryptoToUSDTRate *decimal.Decimal `json:"fee_crypto_to_usdt_rate,omitempty" validate:"omitempty,gte=0"` // 手續費幣種對 USDT 匯率
|
FeeCryptoToUSDTRate *decimal.Decimal `json:"fee_crypto_to_usdt_rate,omitempty" validate:"omitempty,decimalGte=0"` // 手續費幣種對 USDT 匯率
|
||||||
USDTToCryptoTypeRate *decimal.Decimal `json:"usdt_to_crypto_type_rate,omitempty" validate:"omitempty,gte=0"` // USDT 對交易幣種匯率
|
USDTToCryptoTypeRate *decimal.Decimal `json:"usdt_to_crypto_type_rate,omitempty" validate:"omitempty,decimalGte=0"` // USDT 對交易幣種匯率
|
||||||
PaymentFiat *string `json:"payment_fiat,omitempty" validate:"omitempty"` // 支付法幣
|
PaymentFiat *string `json:"payment_fiat,omitempty" validate:"omitempty"` // 支付法幣
|
||||||
PaymentUnitPrice *decimal.Decimal `json:"payment_unit_price,omitempty" validate:"omitempty,gte=0"` // crypto 單價
|
PaymentUnitPrice *decimal.Decimal `json:"payment_unit_price,omitempty" validate:"omitempty,decimalGte=0"` // crypto 單價
|
||||||
PaymentTemplateID *string `json:"payment_template_id,omitempty" validate:"omitempty"` // 支付方式配置 ID
|
PaymentTemplateID *string `json:"payment_template_id,omitempty" validate:"omitempty"` // 支付方式配置 ID
|
||||||
OrderArrivalTime *int64 `json:"order_arrival_time,omitempty" validate:"omitempty"` // 訂單到帳時間
|
OrderArrivalTime *int64 `json:"order_arrival_time,omitempty" validate:"omitempty"` // 訂單到帳時間
|
||||||
OrderPaymentTime *int64 `json:"order_payment_time,omitempty" validate:"omitempty"` // 訂單付款時間
|
OrderPaymentTime *int64 `json:"order_payment_time,omitempty" validate:"omitempty"` // 訂單付款時間
|
||||||
UnpaidTimeoutSecond *int64 `json:"unpaid_timeout_second,omitempty" validate:"omitempty,gte=0"` // 支付期限秒數
|
UnpaidTimeoutSecond *int64 `json:"unpaid_timeout_second,omitempty" validate:"omitempty,decimalGte=0"` // 支付期限秒數
|
||||||
ChainType *string `json:"chain_type,omitempty" validate:"omitempty"` // 主網類型
|
ChainType *string `json:"chain_type,omitempty" validate:"omitempty"` // 主網類型
|
||||||
TxHash *string `json:"tx_hash,omitempty" validate:"omitempty"` // 交易哈希
|
TxHash *string `json:"tx_hash,omitempty" validate:"omitempty"` // 交易哈希
|
||||||
FromAddress *string `json:"from_address,omitempty" validate:"omitempty"` // 來源地址
|
FromAddress *string `json:"from_address,omitempty" validate:"omitempty"` // 來源地址
|
||||||
ToAddress *string `json:"to_address,omitempty" validate:"omitempty"` // 目標地址
|
ToAddress *string `json:"to_address,omitempty" validate:"omitempty"` // 目標地址
|
||||||
ChainFee *decimal.Decimal `json:"chain_fee,omitempty" validate:"omitempty,gte=0"` // 鏈上交易手續費
|
ChainFee *decimal.Decimal `json:"chain_fee,omitempty" validate:"omitempty,decimalGte=0"` // 鏈上交易手續費
|
||||||
ChainFeeCrypto *string `json:"chain_fee_crypto,omitempty" validate:"omitempty"` // 鏈上手續費使用幣別
|
ChainFeeCrypto *string `json:"chain_fee_crypto,omitempty" validate:"omitempty"` // 鏈上手續費使用幣別
|
||||||
Memo *string `json:"memo,omitempty" validate:"omitempty"` // 鏈上備註
|
Memo *string `json:"memo,omitempty" validate:"omitempty"` // 鏈上備註
|
||||||
OrderNote *string `json:"order_note,omitempty" validate:"omitempty"`
|
OrderNote *string `json:"order_note,omitempty" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrder 建立訂單
|
// CreateOrder 建立訂單
|
||||||
func (l *CreateOrderLogic) CreateOrder(in *tweeting.CreateOrderReq) (*tweeting.OKResp, error) {
|
func (l *CreateOrderLogic) CreateOrder(in *order.CreateOrderReq) (*order.OKResp, error) {
|
||||||
req, err := buildCreateOrderReq(in)
|
req, err := buildCreateOrderReq(in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 錯誤代碼 06-011-00
|
// 錯誤代碼 06-011-00
|
||||||
return nil, ers.InvalidFormat(err.Error())
|
fmt.Println("1", err)
|
||||||
}
|
|
||||||
// 驗證資料
|
|
||||||
if err := l.svcCtx.Validate.ValidateAll(&req); err != nil {
|
|
||||||
// 錯誤代碼 06-011-00
|
|
||||||
return nil, ers.InvalidFormat(err.Error())
|
return nil, ers.InvalidFormat(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(req)
|
||||||
|
// 驗證資料
|
||||||
|
if err := l.svcCtx.Validate.ValidateAll(req); err != nil {
|
||||||
|
// 錯誤代碼 06-011-00
|
||||||
|
fmt.Println("2", err)
|
||||||
|
return nil, ers.InvalidFormat(err.Error())
|
||||||
|
}
|
||||||
|
fmt.Println(req)
|
||||||
now := time.Now().UTC().UnixNano()
|
now := time.Now().UTC().UnixNano()
|
||||||
// 插入資料庫
|
// 插入資料庫
|
||||||
o := &model.Order{
|
o := &model.Order{
|
||||||
|
@ -137,11 +142,11 @@ func (l *CreateOrderLogic) CreateOrder(in *tweeting.CreateOrderReq) (*tweeting.O
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tweeting.OKResp{}, nil
|
return &order.OKResp{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocyclo,gocognit
|
//nolint:gocyclo,gocognit
|
||||||
func buildCreateOrderReq(in *tweeting.CreateOrderReq) (*createOrderReq, error) {
|
func buildCreateOrderReq(in *order.CreateOrderReq) (*createOrderReq, error) {
|
||||||
createOrderReq := &createOrderReq{
|
createOrderReq := &createOrderReq{
|
||||||
BusinessID: in.BusinessId,
|
BusinessID: in.BusinessId,
|
||||||
OrderType: int8(in.OrderType),
|
OrderType: int8(in.OrderType),
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package orderservicelogic
|
package orderservicelogic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
ers "code.30cm.net/digimon/library-go/errs"
|
ers "code.30cm.net/digimon/library-go/errs"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -31,7 +31,7 @@ type DeleteOrderQuery struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteOrder 刪除訂單(軟刪除)
|
// DeleteOrder 刪除訂單(軟刪除)
|
||||||
func (l *DeleteOrderLogic) DeleteOrder(in *tweeting.DeleteOrderReq) (*tweeting.OKResp, error) {
|
func (l *DeleteOrderLogic) DeleteOrder(in *order.DeleteOrderReq) (*order.OKResp, error) {
|
||||||
// 驗證資料
|
// 驗證資料
|
||||||
if err := l.svcCtx.Validate.ValidateAll(&DeleteOrderQuery{
|
if err := l.svcCtx.Validate.ValidateAll(&DeleteOrderQuery{
|
||||||
BusinessID: in.GetBusinessId(),
|
BusinessID: in.GetBusinessId(),
|
||||||
|
@ -45,5 +45,5 @@ func (l *DeleteOrderLogic) DeleteOrder(in *tweeting.DeleteOrderReq) (*tweeting.O
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tweeting.OKResp{}, nil
|
return &order.OKResp{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package orderservicelogic
|
package orderservicelogic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
ers "code.30cm.net/digimon/library-go/errs"
|
ers "code.30cm.net/digimon/library-go/errs"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -32,7 +32,7 @@ type GetOrderQuery struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOrder 取得訂單詳情
|
// GetOrder 取得訂單詳情
|
||||||
func (l *GetOrderLogic) GetOrder(in *tweeting.GetOrderReq) (*tweeting.GetOrderResp, error) {
|
func (l *GetOrderLogic) GetOrder(in *order.GetOrderReq) (*order.GetOrderResp, error) {
|
||||||
// 驗證資料
|
// 驗證資料
|
||||||
if err := l.svcCtx.Validate.ValidateAll(&GetOrderQuery{
|
if err := l.svcCtx.Validate.ValidateAll(&GetOrderQuery{
|
||||||
BusinessID: in.GetBusinessId(),
|
BusinessID: in.GetBusinessId(),
|
||||||
|
@ -41,49 +41,49 @@ func (l *GetOrderLogic) GetOrder(in *tweeting.GetOrderReq) (*tweeting.GetOrderRe
|
||||||
return nil, ers.InvalidFormat(err.Error())
|
return nil, ers.InvalidFormat(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
order, err := l.svcCtx.OrderModel.FindOneBusinessID(l.ctx, in.GetBusinessId())
|
o, err := l.svcCtx.OrderModel.FindOneBusinessID(l.ctx, in.GetBusinessId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tweeting.GetOrderResp{
|
return &order.GetOrderResp{
|
||||||
UpdateTime: order.UpdateTime,
|
UpdateTime: o.UpdateTime,
|
||||||
CreateTime: order.CreateTime,
|
CreateTime: o.CreateTime,
|
||||||
BusinessId: order.BusinessID,
|
BusinessId: o.BusinessID,
|
||||||
OrderType: int32(order.OrderType),
|
OrderType: int32(o.OrderType),
|
||||||
OrderStatus: int32(order.OrderStatus),
|
OrderStatus: int32(o.OrderStatus),
|
||||||
Brand: order.Brand,
|
Brand: o.Brand,
|
||||||
OrderUid: order.OrderUID,
|
OrderUid: o.OrderUID,
|
||||||
ReferenceId: order.ReferenceID,
|
ReferenceId: o.ReferenceID,
|
||||||
Count: order.Count.String(),
|
Count: o.Count.String(),
|
||||||
OrderFee: order.OrderFee.String(),
|
OrderFee: o.OrderFee.String(),
|
||||||
Amount: order.Amount.String(),
|
Amount: o.Amount.String(),
|
||||||
// 下面的是未來擴充用,加密貨幣用,或者幣別轉換用,普通訂單用不到
|
// 下面的是未來擴充用,加密貨幣用,或者幣別轉換用,普通訂單用不到
|
||||||
ReferenceBrand: order.ReferenceBrand,
|
ReferenceBrand: o.ReferenceBrand,
|
||||||
ReferenceUid: order.ReferenceUID,
|
ReferenceUid: o.ReferenceUID,
|
||||||
WalletStatus: order.WalletStatus,
|
WalletStatus: o.WalletStatus,
|
||||||
ThreePartyStatus: order.ThreePartyStatus,
|
ThreePartyStatus: o.ThreePartyStatus,
|
||||||
DirectionType: order.DirectionType,
|
DirectionType: o.DirectionType,
|
||||||
CryptoType: order.CryptoType,
|
CryptoType: o.CryptoType,
|
||||||
ThirdPartyFee: decimalToString(*order.ThirdPartyFee),
|
ThirdPartyFee: decimalToString(*o.ThirdPartyFee),
|
||||||
CryptoToUsdtRate: decimalToString(*order.CryptoToUSDTRate),
|
CryptoToUsdtRate: decimalToString(*o.CryptoToUSDTRate),
|
||||||
FiatToUsdRate: decimalToString(*order.FiatToUSDRate),
|
FiatToUsdRate: decimalToString(*o.FiatToUSDRate),
|
||||||
FeeCryptoToUsdtRate: decimalToString(*order.FeeCryptoToUSDTRate),
|
FeeCryptoToUsdtRate: decimalToString(*o.FeeCryptoToUSDTRate),
|
||||||
UsdtToCryptoTypeRate: decimalToString(*order.USDTToCryptoTypeRate),
|
UsdtToCryptoTypeRate: decimalToString(*o.USDTToCryptoTypeRate),
|
||||||
PaymentFiat: order.PaymentFiat,
|
PaymentFiat: o.PaymentFiat,
|
||||||
PaymentUnitPrice: decimalToString(*order.PaymentUnitPrice),
|
PaymentUnitPrice: decimalToString(*o.PaymentUnitPrice),
|
||||||
PaymentTemplateId: order.PaymentTemplateID,
|
PaymentTemplateId: o.PaymentTemplateID,
|
||||||
OrderArrivalTime: order.OrderArrivalTime,
|
OrderArrivalTime: o.OrderArrivalTime,
|
||||||
OrderPaymentTime: order.OrderPaymentTime,
|
OrderPaymentTime: o.OrderPaymentTime,
|
||||||
UnpaidTimeoutSecond: order.UnpaidTimeoutSecond,
|
UnpaidTimeoutSecond: o.UnpaidTimeoutSecond,
|
||||||
ChainType: order.ChainType,
|
ChainType: o.ChainType,
|
||||||
TxHash: order.TxHash,
|
TxHash: o.TxHash,
|
||||||
FromAddress: order.FromAddress,
|
FromAddress: o.FromAddress,
|
||||||
ToAddress: order.ToAddress,
|
ToAddress: o.ToAddress,
|
||||||
ChainFee: decimalToString(*order.ChainFee),
|
ChainFee: decimalToString(*o.ChainFee),
|
||||||
ChainFeeCrypto: order.ChainFeeCrypto,
|
ChainFeeCrypto: o.ChainFeeCrypto,
|
||||||
Memo: order.Memo,
|
Memo: o.Memo,
|
||||||
OrderNote: order.OrderNote,
|
OrderNote: o.OrderNote,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package orderservicelogic
|
package orderservicelogic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
model "app-cloudep-order-server/internal/model/mongo"
|
model "app-cloudep-order-server/internal/model/mongo"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
ers "code.30cm.net/digimon/library-go/errs"
|
ers "code.30cm.net/digimon/library-go/errs"
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -53,7 +53,7 @@ type GetOrderListReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListOrder 取得訂單列表
|
// ListOrder 取得訂單列表
|
||||||
func (l *ListOrderLogic) ListOrder(in *tweeting.ListOrderReq) (*tweeting.ListOrderResp, error) {
|
func (l *ListOrderLogic) ListOrder(in *order.ListOrderReq) (*order.ListOrderResp, error) {
|
||||||
// 驗證資料,目前只有 Page 必帶,其他要驗證在驗證
|
// 驗證資料,目前只有 Page 必帶,其他要驗證在驗證
|
||||||
if err := l.svcCtx.Validate.ValidateAll(&GetOrderListReq{
|
if err := l.svcCtx.Validate.ValidateAll(&GetOrderListReq{
|
||||||
PageIndex: in.GetPageIndex(),
|
PageIndex: in.GetPageIndex(),
|
||||||
|
@ -68,14 +68,14 @@ func (l *ListOrderLogic) ListOrder(in *tweeting.ListOrderReq) (*tweeting.ListOrd
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res := make([]*tweeting.GetOrderResp, 0, len(orders))
|
res := make([]*order.GetOrderResp, 0, len(orders))
|
||||||
for _, item := range orders {
|
for _, item := range orders {
|
||||||
res = append(res, ConvertOrderToGetOrderResp(item))
|
res = append(res, ConvertOrderToGetOrderResp(item))
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tweeting.ListOrderResp{
|
return &order.ListOrderResp{
|
||||||
Data: res,
|
Data: res,
|
||||||
Page: &tweeting.Pager{
|
Page: &order.Pager{
|
||||||
Total: total,
|
Total: total,
|
||||||
Index: in.GetPageIndex(),
|
Index: in.GetPageIndex(),
|
||||||
Size: in.GetPageSize(),
|
Size: in.GetPageSize(),
|
||||||
|
@ -84,44 +84,44 @@ func (l *ListOrderLogic) ListOrder(in *tweeting.ListOrderReq) (*tweeting.ListOrd
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvertOrderToGetOrderResp 將 Order 結構轉換為 GetOrderResp
|
// ConvertOrderToGetOrderResp 將 Order 結構轉換為 GetOrderResp
|
||||||
func ConvertOrderToGetOrderResp(order model.Order) *tweeting.GetOrderResp {
|
func ConvertOrderToGetOrderResp(o model.Order) *order.GetOrderResp {
|
||||||
return &tweeting.GetOrderResp{
|
return &order.GetOrderResp{
|
||||||
BusinessId: order.BusinessID,
|
BusinessId: o.BusinessID,
|
||||||
OrderType: int32(order.OrderType),
|
OrderType: int32(o.OrderType),
|
||||||
OrderStatus: int32(order.OrderStatus),
|
OrderStatus: int32(o.OrderStatus),
|
||||||
Brand: order.Brand,
|
Brand: o.Brand,
|
||||||
OrderUid: order.OrderUID,
|
OrderUid: o.OrderUID,
|
||||||
ReferenceId: order.ReferenceID,
|
ReferenceId: o.ReferenceID,
|
||||||
Count: order.Count.String(),
|
Count: o.Count.String(),
|
||||||
OrderFee: order.OrderFee.String(),
|
OrderFee: o.OrderFee.String(),
|
||||||
Amount: order.Amount.String(),
|
Amount: o.Amount.String(),
|
||||||
ReferenceBrand: optionalString(order.ReferenceBrand),
|
ReferenceBrand: optionalString(o.ReferenceBrand),
|
||||||
ReferenceUid: optionalString(order.ReferenceUID),
|
ReferenceUid: optionalString(o.ReferenceUID),
|
||||||
WalletStatus: optionalInt64(order.WalletStatus),
|
WalletStatus: optionalInt64(o.WalletStatus),
|
||||||
ThreePartyStatus: optionalInt64(order.ThreePartyStatus),
|
ThreePartyStatus: optionalInt64(o.ThreePartyStatus),
|
||||||
DirectionType: optionalInt64(order.DirectionType),
|
DirectionType: optionalInt64(o.DirectionType),
|
||||||
CryptoType: optionalString(order.CryptoType),
|
CryptoType: optionalString(o.CryptoType),
|
||||||
ThirdPartyFee: optionalDecimalToString(order.ThirdPartyFee),
|
ThirdPartyFee: optionalDecimalToString(o.ThirdPartyFee),
|
||||||
CryptoToUsdtRate: optionalDecimalToString(order.CryptoToUSDTRate),
|
CryptoToUsdtRate: optionalDecimalToString(o.CryptoToUSDTRate),
|
||||||
FiatToUsdRate: optionalDecimalToString(order.FiatToUSDRate),
|
FiatToUsdRate: optionalDecimalToString(o.FiatToUSDRate),
|
||||||
FeeCryptoToUsdtRate: optionalDecimalToString(order.FeeCryptoToUSDTRate),
|
FeeCryptoToUsdtRate: optionalDecimalToString(o.FeeCryptoToUSDTRate),
|
||||||
UsdtToCryptoTypeRate: optionalDecimalToString(order.USDTToCryptoTypeRate),
|
UsdtToCryptoTypeRate: optionalDecimalToString(o.USDTToCryptoTypeRate),
|
||||||
PaymentFiat: optionalString(order.PaymentFiat),
|
PaymentFiat: optionalString(o.PaymentFiat),
|
||||||
PaymentUnitPrice: optionalDecimalToString(order.PaymentUnitPrice),
|
PaymentUnitPrice: optionalDecimalToString(o.PaymentUnitPrice),
|
||||||
PaymentTemplateId: optionalString(order.PaymentTemplateID),
|
PaymentTemplateId: optionalString(o.PaymentTemplateID),
|
||||||
OrderArrivalTime: optionalInt64(order.OrderArrivalTime),
|
OrderArrivalTime: optionalInt64(o.OrderArrivalTime),
|
||||||
OrderPaymentTime: optionalInt64(order.OrderPaymentTime),
|
OrderPaymentTime: optionalInt64(o.OrderPaymentTime),
|
||||||
UnpaidTimeoutSecond: optionalInt64(order.UnpaidTimeoutSecond),
|
UnpaidTimeoutSecond: optionalInt64(o.UnpaidTimeoutSecond),
|
||||||
ChainType: optionalString(order.ChainType),
|
ChainType: optionalString(o.ChainType),
|
||||||
TxHash: optionalString(order.TxHash),
|
TxHash: optionalString(o.TxHash),
|
||||||
FromAddress: optionalString(order.FromAddress),
|
FromAddress: optionalString(o.FromAddress),
|
||||||
ToAddress: optionalString(order.ToAddress),
|
ToAddress: optionalString(o.ToAddress),
|
||||||
ChainFee: optionalDecimalToString(order.ChainFee),
|
ChainFee: optionalDecimalToString(o.ChainFee),
|
||||||
ChainFeeCrypto: optionalString(order.ChainFeeCrypto),
|
ChainFeeCrypto: optionalString(o.ChainFeeCrypto),
|
||||||
Memo: optionalString(order.Memo),
|
Memo: optionalString(o.Memo),
|
||||||
OrderNote: optionalString(order.OrderNote),
|
OrderNote: optionalString(o.OrderNote),
|
||||||
CreateTime: order.CreateTime,
|
CreateTime: o.CreateTime,
|
||||||
UpdateTime: order.UpdateTime,
|
UpdateTime: o.UpdateTime,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,10 +152,10 @@ func optionalDecimalToString(d *decimal.Decimal) *string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertOrdersToGetOrderResp(orders []model.Order) []*tweeting.GetOrderResp {
|
func ConvertOrdersToGetOrderResp(orders []model.Order) []*order.GetOrderResp {
|
||||||
res := make([]*tweeting.GetOrderResp, 0, len(orders))
|
res := make([]*order.GetOrderResp, 0, len(orders))
|
||||||
for _, order := range orders {
|
for _, o := range orders {
|
||||||
res = append(res, ConvertOrderToGetOrderResp(order))
|
res = append(res, ConvertOrderToGetOrderResp(o))
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package orderservicelogic
|
package orderservicelogic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -24,8 +24,8 @@ func NewModifyOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Modif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModifyOrder 修改訂單
|
// ModifyOrder 修改訂單
|
||||||
func (l *ModifyOrderLogic) ModifyOrder(in *tweeting.ModifyOrderReq) (*tweeting.OKResp, error) {
|
func (l *ModifyOrderLogic) ModifyOrder(in *order.ModifyOrderReq) (*order.OKResp, error) {
|
||||||
// todo: add your logic here and delete this line
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
return &tweeting.OKResp{}, nil
|
return &order.OKResp{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package orderservicelogic
|
package orderservicelogic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
"app-cloudep-order-server/internal/domain"
|
"app-cloudep-order-server/internal/domain"
|
||||||
model "app-cloudep-order-server/internal/model/mongo"
|
model "app-cloudep-order-server/internal/model/mongo"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
ers "code.30cm.net/digimon/library-go/errs"
|
ers "code.30cm.net/digimon/library-go/errs"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -38,7 +38,7 @@ type ModifyOrderQuery struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModifyOrderStatus 修改訂單狀態
|
// ModifyOrderStatus 修改訂單狀態
|
||||||
func (l *ModifyOrderStatusLogic) ModifyOrderStatus(in *tweeting.ModifyOrderStatusReq) (*tweeting.OKResp, error) {
|
func (l *ModifyOrderStatusLogic) ModifyOrderStatus(in *order.ModifyOrderStatusReq) (*order.OKResp, error) {
|
||||||
// 驗證資料
|
// 驗證資料
|
||||||
if err := l.svcCtx.Validate.ValidateAll(&ModifyOrderQuery{
|
if err := l.svcCtx.Validate.ValidateAll(&ModifyOrderQuery{
|
||||||
BusinessID: in.GetBusinessId(),
|
BusinessID: in.GetBusinessId(),
|
||||||
|
@ -68,5 +68,5 @@ func (l *ModifyOrderStatusLogic) ModifyOrderStatus(in *tweeting.ModifyOrderStatu
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tweeting.OKResp{}, nil
|
return &order.OKResp{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package orderservicelogic
|
package orderservicelogic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
"app-cloudep-order-server/internal/domain"
|
"app-cloudep-order-server/internal/domain"
|
||||||
model "app-cloudep-order-server/internal/model/mongo"
|
model "app-cloudep-order-server/internal/model/mongo"
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -27,7 +27,7 @@ func NewOrderStatusTimeoutLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderStatusTimeout 訂單超時任務/cron/order-status/timeout
|
// OrderStatusTimeout 訂單超時任務/cron/order-status/timeout
|
||||||
func (l *OrderStatusTimeoutLogic) OrderStatusTimeout(_ *tweeting.OrderStatusTimeoutReq) (*tweeting.OKResp, error) {
|
func (l *OrderStatusTimeoutLogic) OrderStatusTimeout(_ *order.OrderStatusTimeoutReq) (*order.OKResp, error) {
|
||||||
now := time.Now().UTC().UnixNano()
|
now := time.Now().UTC().UnixNano()
|
||||||
_, err := l.svcCtx.OrderModel.UpdateTimeoutOrder(l.ctx, model.UpdateTimeoutReq{
|
_, err := l.svcCtx.OrderModel.UpdateTimeoutOrder(l.ctx, model.UpdateTimeoutReq{
|
||||||
CreateTimeBefore: now,
|
CreateTimeBefore: now,
|
||||||
|
@ -47,5 +47,5 @@ func (l *OrderStatusTimeoutLogic) OrderStatusTimeout(_ *tweeting.OrderStatusTime
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tweeting.OKResp{}, nil
|
return &order.OKResp{}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
package mock
|
package mock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
mongo "app-cloudep-order-server/internal/model/mongo"
|
model "app-cloudep-order-server/internal/model/mongo"
|
||||||
context "context"
|
context "context"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
|
|
||||||
mongo0 "go.mongodb.org/mongo-driver/mongo"
|
mongo "go.mongodb.org/mongo-driver/mongo"
|
||||||
gomock "go.uber.org/mock/gomock"
|
gomock "go.uber.org/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,11 +56,26 @@ func (mr *MockOrderModelMockRecorder) Delete(ctx, id any) *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockOrderModel)(nil).Delete), ctx, id)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockOrderModel)(nil).Delete), ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteByBusinessID mocks base method.
|
||||||
|
func (m *MockOrderModel) DeleteByBusinessID(ctx context.Context, id string) (*mongo.UpdateResult, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "DeleteByBusinessID", ctx, id)
|
||||||
|
ret0, _ := ret[0].(*mongo.UpdateResult)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteByBusinessID indicates an expected call of DeleteByBusinessID.
|
||||||
|
func (mr *MockOrderModelMockRecorder) DeleteByBusinessID(ctx, id any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteByBusinessID", reflect.TypeOf((*MockOrderModel)(nil).DeleteByBusinessID), ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
// FindOne mocks base method.
|
// FindOne mocks base method.
|
||||||
func (m *MockOrderModel) FindOne(ctx context.Context, id string) (*mongo.Order, error) {
|
func (m *MockOrderModel) FindOne(ctx context.Context, id string) (*model.Order, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "FindOne", ctx, id)
|
ret := m.ctrl.Call(m, "FindOne", ctx, id)
|
||||||
ret0, _ := ret[0].(*mongo.Order)
|
ret0, _ := ret[0].(*model.Order)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
@ -71,8 +86,23 @@ func (mr *MockOrderModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockOrderModel)(nil).FindOne), ctx, id)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOne", reflect.TypeOf((*MockOrderModel)(nil).FindOne), ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindOneBusinessID mocks base method.
|
||||||
|
func (m *MockOrderModel) FindOneBusinessID(ctx context.Context, id string) (*model.Order, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "FindOneBusinessID", ctx, id)
|
||||||
|
ret0, _ := ret[0].(*model.Order)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindOneBusinessID indicates an expected call of FindOneBusinessID.
|
||||||
|
func (mr *MockOrderModelMockRecorder) FindOneBusinessID(ctx, id any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindOneBusinessID", reflect.TypeOf((*MockOrderModel)(nil).FindOneBusinessID), ctx, id)
|
||||||
|
}
|
||||||
|
|
||||||
// Insert mocks base method.
|
// Insert mocks base method.
|
||||||
func (m *MockOrderModel) Insert(ctx context.Context, data *mongo.Order) error {
|
func (m *MockOrderModel) Insert(ctx context.Context, data *model.Order) error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Insert", ctx, data)
|
ret := m.ctrl.Call(m, "Insert", ctx, data)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
|
@ -85,11 +115,27 @@ func (mr *MockOrderModelMockRecorder) Insert(ctx, data any) *gomock.Call {
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockOrderModel)(nil).Insert), ctx, data)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockOrderModel)(nil).Insert), ctx, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListOrder mocks base method.
|
||||||
|
func (m *MockOrderModel) ListOrder(ctx context.Context, req model.GetOrderListReq) ([]model.Order, int64, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "ListOrder", ctx, req)
|
||||||
|
ret0, _ := ret[0].([]model.Order)
|
||||||
|
ret1, _ := ret[1].(int64)
|
||||||
|
ret2, _ := ret[2].(error)
|
||||||
|
return ret0, ret1, ret2
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListOrder indicates an expected call of ListOrder.
|
||||||
|
func (mr *MockOrderModelMockRecorder) ListOrder(ctx, req any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListOrder", reflect.TypeOf((*MockOrderModel)(nil).ListOrder), ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
// Update mocks base method.
|
// Update mocks base method.
|
||||||
func (m *MockOrderModel) Update(ctx context.Context, data *mongo.Order) (*mongo0.UpdateResult, error) {
|
func (m *MockOrderModel) Update(ctx context.Context, data *model.Order) (*mongo.UpdateResult, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Update", ctx, data)
|
ret := m.ctrl.Call(m, "Update", ctx, data)
|
||||||
ret0, _ := ret[0].(*mongo0.UpdateResult)
|
ret0, _ := ret[0].(*mongo.UpdateResult)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
@ -99,3 +145,33 @@ func (mr *MockOrderModelMockRecorder) Update(ctx, data any) *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockOrderModel)(nil).Update), ctx, data)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockOrderModel)(nil).Update), ctx, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateStatus mocks base method.
|
||||||
|
func (m *MockOrderModel) UpdateStatus(ctx context.Context, data model.UpdateStatusReq) (*mongo.UpdateResult, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "UpdateStatus", ctx, data)
|
||||||
|
ret0, _ := ret[0].(*mongo.UpdateResult)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateStatus indicates an expected call of UpdateStatus.
|
||||||
|
func (mr *MockOrderModelMockRecorder) UpdateStatus(ctx, data any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateStatus", reflect.TypeOf((*MockOrderModel)(nil).UpdateStatus), ctx, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeoutOrder mocks base method.
|
||||||
|
func (m *MockOrderModel) UpdateTimeoutOrder(ctx context.Context, req model.UpdateTimeoutReq) (*mongo.UpdateResult, error) {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "UpdateTimeoutOrder", ctx, req)
|
||||||
|
ret0, _ := ret[0].(*mongo.UpdateResult)
|
||||||
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTimeoutOrder indicates an expected call of UpdateTimeoutOrder.
|
||||||
|
func (mr *MockOrderModelMockRecorder) UpdateTimeoutOrder(ctx, req any) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateTimeoutOrder", reflect.TypeOf((*MockOrderModel)(nil).UpdateTimeoutOrder), ctx, req)
|
||||||
|
}
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
package mock
|
package mock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
mongo "app-cloudep-order-server/internal/model/mongo"
|
model "app-cloudep-order-server/internal/model/mongo"
|
||||||
context "context"
|
context "context"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
|
|
||||||
mongo0 "go.mongodb.org/mongo-driver/mongo"
|
mongo "go.mongodb.org/mongo-driver/mongo"
|
||||||
gomock "go.uber.org/mock/gomock"
|
gomock "go.uber.org/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,10 +57,10 @@ func (mr *MockorderModelMockRecorder) Delete(ctx, id any) *gomock.Call {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindOne mocks base method.
|
// FindOne mocks base method.
|
||||||
func (m *MockorderModel) FindOne(ctx context.Context, id string) (*mongo.Order, error) {
|
func (m *MockorderModel) FindOne(ctx context.Context, id string) (*model.Order, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "FindOne", ctx, id)
|
ret := m.ctrl.Call(m, "FindOne", ctx, id)
|
||||||
ret0, _ := ret[0].(*mongo.Order)
|
ret0, _ := ret[0].(*model.Order)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func (mr *MockorderModelMockRecorder) FindOne(ctx, id any) *gomock.Call {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert mocks base method.
|
// Insert mocks base method.
|
||||||
func (m *MockorderModel) Insert(ctx context.Context, data *mongo.Order) error {
|
func (m *MockorderModel) Insert(ctx context.Context, data *model.Order) error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Insert", ctx, data)
|
ret := m.ctrl.Call(m, "Insert", ctx, data)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
|
@ -86,10 +86,10 @@ func (mr *MockorderModelMockRecorder) Insert(ctx, data any) *gomock.Call {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update mocks base method.
|
// Update mocks base method.
|
||||||
func (m *MockorderModel) Update(ctx context.Context, data *mongo.Order) (*mongo0.UpdateResult, error) {
|
func (m *MockorderModel) Update(ctx context.Context, data *model.Order) (*mongo.UpdateResult, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Update", ctx, data)
|
ret := m.ctrl.Call(m, "Update", ctx, data)
|
||||||
ret0, _ := ret[0].(*mongo0.UpdateResult)
|
ret0, _ := ret[0].(*mongo.UpdateResult)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,14 @@ package server
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
orderservicelogic "app-cloudep-order-server/internal/logic/orderservice"
|
orderservicelogic "app-cloudep-order-server/internal/logic/orderservice"
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OrderServiceServer struct {
|
type OrderServiceServer struct {
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
tweeting.UnimplementedOrderServiceServer
|
order.UnimplementedOrderServiceServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOrderServiceServer(svcCtx *svc.ServiceContext) *OrderServiceServer {
|
func NewOrderServiceServer(svcCtx *svc.ServiceContext) *OrderServiceServer {
|
||||||
|
@ -23,49 +23,49 @@ func NewOrderServiceServer(svcCtx *svc.ServiceContext) *OrderServiceServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrder 建立訂單
|
// CreateOrder 建立訂單
|
||||||
func (s *OrderServiceServer) CreateOrder(ctx context.Context, in *tweeting.CreateOrderReq) (*tweeting.OKResp, error) {
|
func (s *OrderServiceServer) CreateOrder(ctx context.Context, in *order.CreateOrderReq) (*order.OKResp, error) {
|
||||||
l := orderservicelogic.NewCreateOrderLogic(ctx, s.svcCtx)
|
l := orderservicelogic.NewCreateOrderLogic(ctx, s.svcCtx)
|
||||||
return l.CreateOrder(in)
|
return l.CreateOrder(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CancelOrder 取消訂單
|
// CancelOrder 取消訂單
|
||||||
func (s *OrderServiceServer) CancelOrder(ctx context.Context, in *tweeting.CancelOrderReq) (*tweeting.OKResp, error) {
|
func (s *OrderServiceServer) CancelOrder(ctx context.Context, in *order.CancelOrderReq) (*order.OKResp, error) {
|
||||||
l := orderservicelogic.NewCancelOrderLogic(ctx, s.svcCtx)
|
l := orderservicelogic.NewCancelOrderLogic(ctx, s.svcCtx)
|
||||||
return l.CancelOrder(in)
|
return l.CancelOrder(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModifyOrder 修改訂單
|
// ModifyOrder 修改訂單
|
||||||
func (s *OrderServiceServer) ModifyOrder(ctx context.Context, in *tweeting.ModifyOrderReq) (*tweeting.OKResp, error) {
|
func (s *OrderServiceServer) ModifyOrder(ctx context.Context, in *order.ModifyOrderReq) (*order.OKResp, error) {
|
||||||
l := orderservicelogic.NewModifyOrderLogic(ctx, s.svcCtx)
|
l := orderservicelogic.NewModifyOrderLogic(ctx, s.svcCtx)
|
||||||
return l.ModifyOrder(in)
|
return l.ModifyOrder(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModifyOrderStatus 修改訂單狀態
|
// ModifyOrderStatus 修改訂單狀態
|
||||||
func (s *OrderServiceServer) ModifyOrderStatus(ctx context.Context, in *tweeting.ModifyOrderStatusReq) (*tweeting.OKResp, error) {
|
func (s *OrderServiceServer) ModifyOrderStatus(ctx context.Context, in *order.ModifyOrderStatusReq) (*order.OKResp, error) {
|
||||||
l := orderservicelogic.NewModifyOrderStatusLogic(ctx, s.svcCtx)
|
l := orderservicelogic.NewModifyOrderStatusLogic(ctx, s.svcCtx)
|
||||||
return l.ModifyOrderStatus(in)
|
return l.ModifyOrderStatus(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteOrder 刪除訂單(軟刪除)
|
// DeleteOrder 刪除訂單(軟刪除)
|
||||||
func (s *OrderServiceServer) DeleteOrder(ctx context.Context, in *tweeting.DeleteOrderReq) (*tweeting.OKResp, error) {
|
func (s *OrderServiceServer) DeleteOrder(ctx context.Context, in *order.DeleteOrderReq) (*order.OKResp, error) {
|
||||||
l := orderservicelogic.NewDeleteOrderLogic(ctx, s.svcCtx)
|
l := orderservicelogic.NewDeleteOrderLogic(ctx, s.svcCtx)
|
||||||
return l.DeleteOrder(in)
|
return l.DeleteOrder(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOrder 取得訂單詳情
|
// GetOrder 取得訂單詳情
|
||||||
func (s *OrderServiceServer) GetOrder(ctx context.Context, in *tweeting.GetOrderReq) (*tweeting.GetOrderResp, error) {
|
func (s *OrderServiceServer) GetOrder(ctx context.Context, in *order.GetOrderReq) (*order.GetOrderResp, error) {
|
||||||
l := orderservicelogic.NewGetOrderLogic(ctx, s.svcCtx)
|
l := orderservicelogic.NewGetOrderLogic(ctx, s.svcCtx)
|
||||||
return l.GetOrder(in)
|
return l.GetOrder(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListOrder 取得訂單列表
|
// ListOrder 取得訂單列表
|
||||||
func (s *OrderServiceServer) ListOrder(ctx context.Context, in *tweeting.ListOrderReq) (*tweeting.ListOrderResp, error) {
|
func (s *OrderServiceServer) ListOrder(ctx context.Context, in *order.ListOrderReq) (*order.ListOrderResp, error) {
|
||||||
l := orderservicelogic.NewListOrderLogic(ctx, s.svcCtx)
|
l := orderservicelogic.NewListOrderLogic(ctx, s.svcCtx)
|
||||||
return l.ListOrder(in)
|
return l.ListOrder(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderStatusTimeout 訂單超時任務/cron/order-status/timeout
|
// OrderStatusTimeout 訂單超時任務/cron/order-status/timeout
|
||||||
func (s *OrderServiceServer) OrderStatusTimeout(ctx context.Context, in *tweeting.OrderStatusTimeoutReq) (*tweeting.OKResp, error) {
|
func (s *OrderServiceServer) OrderStatusTimeout(ctx context.Context, in *order.OrderStatusTimeoutReq) (*order.OKResp, error) {
|
||||||
l := orderservicelogic.NewOrderStatusTimeoutLogic(ctx, s.svcCtx)
|
l := orderservicelogic.NewOrderStatusTimeoutLogic(ctx, s.svcCtx)
|
||||||
return l.OrderStatusTimeout(in)
|
return l.OrderStatusTimeout(in)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package svc
|
||||||
|
|
||||||
|
import (
|
||||||
|
vi "code.30cm.net/digimon/library-go/validator"
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithDecimalGt 是否大於等於
|
||||||
|
func WithDecimalGt() vi.Option {
|
||||||
|
return vi.Option{
|
||||||
|
ValidatorName: "decimalGt",
|
||||||
|
ValidatorFunc: func(fl validator.FieldLevel) bool {
|
||||||
|
if val, ok := fl.Field().Interface().(string); ok {
|
||||||
|
value, err := decimal.NewFromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
conditionValue, err := decimal.NewFromString(fl.Param())
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.GreaterThan(conditionValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithDecimalGte 是否大於等於
|
||||||
|
func WithDecimalGte() vi.Option {
|
||||||
|
return vi.Option{
|
||||||
|
ValidatorName: "decimalGte",
|
||||||
|
ValidatorFunc: func(fl validator.FieldLevel) bool {
|
||||||
|
if val, ok := fl.Field().Interface().(string); ok {
|
||||||
|
value, err := decimal.NewFromString(val)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
conditionValue, err := decimal.NewFromString(fl.Param())
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.GreaterThanOrEqual(conditionValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
Validate: vi.MustValidator(),
|
Validate: vi.MustValidator(WithDecimalGt(), WithDecimalGte()),
|
||||||
OrderModel: MustOrderModel(c),
|
OrderModel: MustOrderModel(c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
order.go
4
order.go
|
@ -1,10 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"app-cloudep-order-server/gen_result/pb/order"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"app-cloudep-order-server/gen_result/pb/tweeting"
|
|
||||||
"app-cloudep-order-server/internal/config"
|
"app-cloudep-order-server/internal/config"
|
||||||
orderserviceServer "app-cloudep-order-server/internal/server/orderservice"
|
orderserviceServer "app-cloudep-order-server/internal/server/orderservice"
|
||||||
"app-cloudep-order-server/internal/svc"
|
"app-cloudep-order-server/internal/svc"
|
||||||
|
@ -26,7 +26,7 @@ func main() {
|
||||||
ctx := svc.NewServiceContext(c)
|
ctx := svc.NewServiceContext(c)
|
||||||
|
|
||||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||||
tweeting.RegisterOrderServiceServer(grpcServer, orderserviceServer.NewOrderServiceServer(ctx))
|
order.RegisterOrderServiceServer(grpcServer, orderserviceServer.NewOrderServiceServer(ctx))
|
||||||
|
|
||||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||||
reflection.Register(grpcServer)
|
reflection.Register(grpcServer)
|
||||||
|
|
Loading…
Reference in New Issue