define nats func - get supplier order cash and supplier withdraw cash

This commit is contained in:
Sinh 2022-11-02 17:27:10 +07:00
parent 816316b558
commit ac1ec030db
2 changed files with 60 additions and 0 deletions

View File

@ -119,3 +119,24 @@ func (o Order) GetSupplierOrders(p model.OrderSupplierQuery) (*model.SupplierOrd
} }
return &r.Data, nil return &r.Data, nil
} }
// GetSupplierCash ...
func (o Order) GetSupplierCash(p model.OrderSupplierCashReq) (*model.OrderSupplierCashRes, error) {
msg, err := natsio.GetServer().Request(subject.Order.GetSupplierCash, toBytes(p))
if err != nil {
return nil, err
}
var (
r struct {
Data model.OrderSupplierCashRes `json:"data"`
Error string `json:"error"`
}
)
if err = json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
if r.Error != "" {
return nil, errors.New(r.Error)
}
return &r.Data, nil
}

39
client/withdraw.go Normal file
View File

@ -0,0 +1,39 @@
package client
import (
"encoding/json"
"errors"
"git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model"
"git.selly.red/Selly-Modules/natsio/subject"
)
// Withdraw ...
type Withdraw struct{}
// GetWithdraw ...
func GetWithdraw() Withdraw {
return Withdraw{}
}
// GetSupplierCash ...
func (o Withdraw) GetSupplierCash(p model.WithdrawSupplierCashReq) (*model.WithdrawSupplierCashRes, error) {
msg, err := natsio.GetServer().Request(subject.Withdraw.GetSupplierCash, toBytes(p))
if err != nil {
return nil, err
}
var (
r struct {
Data model.WithdrawSupplierCashRes `json:"data"`
Error string `json:"error"`
}
)
if err = json.Unmarshal(msg.Data, &r); err != nil {
return nil, err
}
if r.Error != "" {
return nil, errors.New(r.Error)
}
return &r.Data, nil
}