59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
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"
|
|
)
|
|
|
|
// Campaign ...
|
|
type Campaign struct{}
|
|
|
|
// GetCampaign ...
|
|
func GetCampaign() Campaign {
|
|
return Campaign{}
|
|
}
|
|
|
|
// GetCampaignTransaction ...
|
|
func (c Campaign) GetCampaignTransaction(p model.GetCampaignTransactionsRequest) (*model.ResponseCampaignTransactionAll, error) {
|
|
msg, err := natsio.GetServer().Request(subject.Campaign.GetListCampaignTransactionAdminInfoByIDs, toBytes(p))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var r struct {
|
|
Data *model.ResponseCampaignTransactionAll `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
|
|
}
|
|
|
|
// GetCampaignSellerStatistic ....
|
|
func (c Campaign) GetCampaignSellerStatistic(req model.GetCampaignSellerStatisticBySellerIDs) (*model.ResponseCampaignSellerStatisticList, error) {
|
|
msg, err := natsio.GetServer().Request(subject.Campaign.GetCampaignSellerStatisticBySellerIDs, toBytes(req))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var r struct {
|
|
Data *model.ResponseCampaignSellerStatisticList `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
|
|
}
|