feat(server): define subject reqres user #179

Merged
minhnguyen merged 1 commits from feature/nats-subject-user-cashflow into master 2025-01-21 03:42:23 +00:00
7 changed files with 167 additions and 13 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@
# vendor/
.idea
*.DS_Store

View File

@ -9,15 +9,12 @@ import (
"git.selly.red/Selly-Modules/natsio/subject"
)
// Seller ...
type Seller struct{}
// GetSeller ...
func GetSeller() Seller {
return Seller{}
}
// GetSellerInfoByID ...
func (s Seller) GetSellerInfoByID(p model.GetSellerByIDRequest) (*model.ResponseSellerInfo, error) {
msg, err := natsio.GetServer().Request(subject.Seller.GetSellerInfoByID, toBytes(p))
if err != nil {
@ -40,7 +37,6 @@ func (s Seller) GetSellerInfoByID(p model.GetSellerByIDRequest) (*model.Response
return r.Data, nil
}
// GetListSellerInfoByIDs ...
func (s Seller) GetListSellerInfoByIDs(p model.GetListSellerByIDsRequest) (*model.ResponseListSellerInfo, error) {
msg, err := natsio.GetServer().Request(subject.Seller.GetListSellerInfoByIDs, toBytes(p))
@ -64,7 +60,6 @@ func (s Seller) GetListSellerInfoByIDs(p model.GetListSellerByIDsRequest) (*mode
return r.Data, nil
}
// GetListSellerInfoSupportChatByIDs ...
func (s Seller) GetListSellerInfoSupportChatByIDs(p model.GetListSellerSupportChatByIDsRequest) (*model.ResponseListSellerInfoSupportChat, error) {
msg, err := natsio.GetServer().Request(subject.SupportChat.GetListSellerInfoSupportChatByIDs, toBytes(p))
if err != nil {
@ -85,3 +80,69 @@ func (s Seller) GetListSellerInfoSupportChatByIDs(p model.GetListSellerSupportCh
}
return r.Data, nil
}
func (s Seller) CheckAndInsertCashflows(p model.CheckAndInsertCashflowsRequest) (*model.ResponseCheckAndInsertCashflows, error) {
msg, err := natsio.GetServer().Request(subject.Seller.CheckAndInsertCashflows, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseCheckAndInsertCashflows `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
}
func (s Seller) UpdateSellerAffiliateStatistic(p model.UpdateSellerAffiliateStatisticRequest) (*model.ResponseUpdateSellerAffiliateStatistic, error) {
msg, err := natsio.GetServer().Request(subject.Seller.UpdateSellerAffiliateStatistic, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseUpdateSellerAffiliateStatistic `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
}
func (s Seller) UpdateSellerSavingCampaignStatistic(p model.UpdateSellerSavingCampaignStatisticRequest) (*model.ResponseUpdateSellerSavingCampaignStatistic, error) {
msg, err := natsio.GetServer().Request(subject.Seller.UpdateSellerSavingCampaignStatistic, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseUpdateSellerSavingCampaignStatistic `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
}

View File

@ -2,17 +2,73 @@ package model
import "go.mongodb.org/mongo-driver/bson/primitive"
// GetSellerByIDRequest ...
type GetSellerByIDRequest struct {
SellerID primitive.ObjectID `json:"sellerId"`
}
// GetListSellerByIDsRequest ...
type GetListSellerByIDsRequest struct {
SellerIDs []primitive.ObjectID `json:"sellerIds"`
}
// GetListSellerSupportChatByIDsRequest ...
type GetListSellerSupportChatByIDsRequest struct {
SellerIDs []primitive.ObjectID `json:"sellerIds"`
}
type CheckAndInsertCashflowsRequest struct {
SellerID string `json:"sellerId"`
List []CashflowSeller `json:"list"`
}
type CashflowSeller struct {
Value float64 `json:"value"`
Action string `json:"action"`
Category string `json:"category"`
TargetID string `json:"targetId"`
TargetType string `json:"targetType"`
Options *CashFlowOptions `json:"options"`
}
type CashFlowOptions struct {
AffiliateTransactionCode string `json:"affiliateTransactionCode,omitempty"`
AffiliateCampaignID string `json:"affiliateCampaignId,omitempty"`
AffiliateCampaignName string `json:"affiliateCampaignName,omitempty"`
// Campaign
CampaignID string `json:"campaignId,omitempty"`
CampaignName string `json:"campaignName,omitempty"`
// SavingCampaign
SavingCampaignID string `json:"savingCampaignId,omitempty"`
SavingCampaignName string `json:"savingCampaignName,omitempty"`
SavingCampaignItemID string `json:"savingCampaignItemId,omitempty"`
SavingCampaignItemName string `json:"savingCampaignItemName,omitempty"`
}
type UpdateSellerAffiliateStatisticRequest struct {
SellerID string `json:"sellerId"`
Statistic SellerAffiliateStatistic `json:"statistic"`
}
type SellerAffiliateStatistic struct {
TransactionTotal int `json:"transactionTotal"`
TransactionCashback int `json:"transactionCashback"`
TransactionPending int `json:"transactionPending"`
TransactionApproved int `json:"transactionApproved"`
TransactionRejected int `json:"transactionRejected"`
CommissionTransactionTotal float64 `json:"commissionTransactionTotal"`
CommissionTransactionCashback float64 `json:"commissionTransactionCashback"`
CommissionTransactionApproved float64 `json:"commissionTransactionApproved"`
CommissionTransactionPending float64 `json:"commissionTransactionPending"`
CommissionTransactionRejected float64 `json:"commissionTransactionRejected"`
}
type UpdateSellerSavingCampaignStatisticRequest struct {
SellerID string `json:"sellerId"`
Statistic SellerSavingCampaignStatistic `json:"statistic"`
}
type SellerSavingCampaignStatistic struct {
SavingCampaignCashPending float64 `json:"savingCampaignCashPending"`
SavingCampaignCashCompleted float64 `json:"savingCampaignCashCompleted"`
}

View File

@ -90,3 +90,18 @@ type SellerMembershipInfo struct {
Level int `json:"level"`
Name string `json:"name"`
}
type ResponseCheckAndInsertCashflows struct {
Success bool `json:"success"`
Error string `json:"error"`
}
type ResponseUpdateSellerAffiliateStatistic struct {
Success bool `json:"success"`
Error string `json:"error"`
}
type ResponseUpdateSellerSavingCampaignStatistic struct {
Success bool `json:"success"`
Error string `json:"error"`
}

View File

@ -19,6 +19,7 @@ var prefixes = struct {
Campaign string
Affiliate string
Socket string
Promotion string
}{
Communication: "communication",
Order: "order",
@ -38,4 +39,5 @@ var prefixes = struct {
Campaign: "campaign",
Affiliate: "affiliate",
Socket: "socket",
Promotion: "promotion",
}

13
subject/promotion.go Normal file
View File

@ -0,0 +1,13 @@
package subject
import "fmt"
func getPromotionValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.Promotion, val)
}
var Promotion = struct {
GenerateVoucherPromotion string
}{
GenerateVoucherPromotion: getPromotionValue("generate_voucher_promotion"),
}

View File

@ -10,9 +10,15 @@ func getSellerValue(val string) string {
var Seller = struct {
GetSellerInfoByID string
GetListSellerInfoByIDs string
CheckAndInsertCashflows string
UpdateSellerAffiliateStatistic string
UpdateSellerSavingCampaignStatistic string
}{
GetSellerInfoByID: getSellerValue("get_seller_info_by_id"),
GetListSellerInfoByIDs: getSellerValue("get_list_seller_info_by_ids"),
CheckAndInsertCashflows: getSellerValue("check_and_insert_cashflows"),
UpdateSellerAffiliateStatistic: getSellerValue("update_seller_affiliate_statistic"),
UpdateSellerSavingCampaignStatistic: getSellerValue("update_seller_saving_campaign_statistic"),
}
// SupportChat ...