diff --git a/.gitignore b/.gitignore index bbfd2cb..1eb601b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ # Dependency directories (remove the comment below to include it) # vendor/ -.idea \ No newline at end of file +.idea +*.DS_Store diff --git a/client/seller.go b/client/seller.go index da0fc23..8bebaef 100644 --- a/client/seller.go +++ b/client/seller.go @@ -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 +} diff --git a/model/seller_request.go b/model/seller_request.go index a54996c..a223c3d 100644 --- a/model/seller_request.go +++ b/model/seller_request.go @@ -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"` +} diff --git a/model/seller_response.go b/model/seller_response.go index e380435..900341c 100644 --- a/model/seller_response.go +++ b/model/seller_response.go @@ -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"` +} diff --git a/subject/config.go b/subject/config.go index d319a6f..db6189e 100644 --- a/subject/config.go +++ b/subject/config.go @@ -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", } diff --git a/subject/promotion.go b/subject/promotion.go new file mode 100644 index 0000000..34ab439 --- /dev/null +++ b/subject/promotion.go @@ -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"), +} diff --git a/subject/seller.go b/subject/seller.go index eba9131..a69bf32 100644 --- a/subject/seller.go +++ b/subject/seller.go @@ -8,11 +8,17 @@ func getSellerValue(val string) string { // Seller ... var Seller = struct { - GetSellerInfoByID string - GetListSellerInfoByIDs string + 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"), + 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 ...