natsio/client/order.go

143 lines
3.2 KiB
Go
Raw Normal View History

2022-08-20 14:21:51 +00:00
package client
import (
"encoding/json"
"errors"
2022-10-10 04:11:39 +00:00
"git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model"
"git.selly.red/Selly-Modules/natsio/subject"
2022-08-20 14:21:51 +00:00
)
// Order ...
type Order struct{}
// GetOrder ...
func GetOrder() Order {
return Order{}
}
// UpdateORStatus ...
2022-08-23 07:26:49 +00:00
func (o Order) UpdateORStatus(p model.OrderUpdateORStatus) error {
2022-08-26 08:56:36 +00:00
msg, err := natsio.GetServer().Request(subject.Order.UpdateORStatus, toBytes(p))
2022-08-20 14:21:51 +00:00
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
2022-08-23 07:26:49 +00:00
// CancelDelivery ...
func (o Order) CancelDelivery(p model.OrderCancelDelivery) error {
2022-08-29 08:57:18 +00:00
msg, err := natsio.GetServer().Request(subject.Order.CancelDelivery, toBytes(p))
2022-08-23 07:26:49 +00:00
if err != nil {
return err
}
var r model.CommonResponseData
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
2022-08-31 03:53:51 +00:00
// ChangeDeliveryStatus ...
func (o Order) ChangeDeliveryStatus(p model.OrderChangeDeliveryStatus) error {
msg, err := natsio.GetServer().Request(subject.Order.ChangeDeliveryStatus, toBytes(p))
if err != nil {
return err
}
var r model.CommonResponseData
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
2022-09-07 05:00:40 +00:00
// UpdateLogisticInfoFailed ...
func (o Order) UpdateLogisticInfoFailed(p model.OrderUpdateLogisticInfoFailed) error {
msg, err := natsio.GetServer().Request(subject.Order.UpdateLogisticInfoFailed, toBytes(p))
if err != nil {
return err
}
var r model.CommonResponseData
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
2022-09-08 07:47:52 +00:00
// ORNotUpdateStatus ...
func (o Order) ORNotUpdateStatus(p model.OrderORsNotUpdateStatus) error {
msg, err := natsio.GetServer().Request(subject.Order.ORNotUpdateStatus, toBytes(p))
if err != nil {
return err
}
var r model.CommonResponseData
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
2022-09-21 10:40:49 +00:00
// GetSupplierOrders ...
func (o Order) GetSupplierOrders(p model.OrderSupplierQuery) (*model.SupplierOrderList, error) {
msg, err := natsio.GetServer().Request(subject.Order.GetSupplierOrders, toBytes(p))
if err != nil {
return nil, err
}
var (
r struct {
Data model.SupplierOrderList `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
}
2022-11-08 07:15:47 +00:00
// 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
}