diff --git a/client/socket.go b/client/socket.go new file mode 100644 index 0000000..6c0a125 --- /dev/null +++ b/client/socket.go @@ -0,0 +1,21 @@ +package client + +import ( + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// Socket ... +type Socket struct{} + +// GetSocket ... +func GetSocket() Socket { + return Socket{} +} + +// EmitSocketEventDataReward ... +func (s Socket) EmitSocketEventDataReward(p model.PayloadEmitSocketEvent) error { + _, err := natsio.GetServer().Request(subject.Socket.EmitEventReward, toBytes(p)) + return err +} diff --git a/js/consumer/selly.go b/js/consumer/selly.go index 103d030..1402a4b 100644 --- a/js/consumer/selly.go +++ b/js/consumer/selly.go @@ -2,13 +2,17 @@ package jsconsumer // Selly ... var Selly = struct { - PushNotification string - UpdateSellerAffiliateStatistic string - CheckAnDInsertCashflowBySeller string - SubscriberTopic string + PushNotification string + UpdateSellerAffiliateStatistic string + CheckAnDInsertCashflowBySeller string + SubscriberTopic string + UpdateSellerSavingCampaignStatistic string + GenerateVoucherPromotion string }{ - PushNotification: "PULL_PUSH_NOTIFICATION", - UpdateSellerAffiliateStatistic: "PULL_UPDATE_SELLER_AFFILIATE_STATISTIC", - CheckAnDInsertCashflowBySeller: "PULL_CHECK_AND_INSERT_CASHFLOW_BY_SELLER", - SubscriberTopic: "PULL_SUBSCRIBER_TOPIC", + PushNotification: "PULL_PUSH_NOTIFICATION", + UpdateSellerAffiliateStatistic: "PULL_UPDATE_SELLER_AFFILIATE_STATISTIC", + CheckAnDInsertCashflowBySeller: "PULL_CHECK_AND_INSERT_CASHFLOW_BY_SELLER", + SubscriberTopic: "PULL_SUBSCRIBER_TOPIC", + UpdateSellerSavingCampaignStatistic: "PULL_UPDATE_SELLER_SAVING_CAMPAIGN_STATISTIC", + GenerateVoucherPromotion: "PULL_GENERATE_VOUCHER_PROMOTION", } diff --git a/js/model/selly.go b/js/model/selly.go index 8f5e19c..f7ef3e4 100644 --- a/js/model/selly.go +++ b/js/model/selly.go @@ -1,5 +1,7 @@ package jsmodel +import "go.mongodb.org/mongo-driver/bson/primitive" + // PushNotification ... type PushNotification struct { User string `json:"user"` @@ -12,9 +14,11 @@ type PushNotification struct { // NotificationOptions ... type NotificationOptions struct { - Title string `json:"title"` - Content string `json:"content"` - CampaignID string `json:"campaignId,omitempty"` + Title string `json:"title"` + Content string `json:"content"` + CampaignID string `json:"campaignId,omitempty"` + SellerSavingCampaignID string `json:"sellerSavingCampaignId,omitempty"` + SellerSavingCampaignStatus string `json:"sellerSavingCampaignStatus,omitempty"` } // PayloadUpdateSellerAffiliateStatistic ... @@ -62,6 +66,39 @@ type CashFlowOptions struct { // 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"` +} + +// PayloadUpdateSellerSavingCampaignStatistic ... +type PayloadUpdateSellerSavingCampaignStatistic struct { + SellerID string `json:"sellerId"` + Statistic SellerSavingCampaignStatistic `json:"statistic"` +} + +// SellerSavingCampaignStatistic ... +type SellerSavingCampaignStatistic struct { + SavingCampaignCashPending float64 `json:"savingCampaignCashPending"` + SavingCampaignCashCompleted float64 `json:"savingCampaignCashCompleted"` +} + +// GenerateVoucherPromotion ... +type GenerateVoucherPromotion struct { + Cash float64 `json:"cash"` + TargetID primitive.ObjectID `json:"targetId"` + TargetType string `json:"targetType"` + Options GenerateVoucherPromotionOptions `json:"options"` + Seller primitive.ObjectID `json:"seller"` +} + +// GenerateVoucherPromotionOptions ... +type GenerateVoucherPromotionOptions struct { + Title string `json:"title"` } // SubscriberNotificationTopic ... diff --git a/js/subject/selly.go b/js/subject/selly.go index 668f249..fbb6eed 100644 --- a/js/subject/selly.go +++ b/js/subject/selly.go @@ -11,13 +11,17 @@ func getSellyValue(val string) string { // Selly ... var Selly = struct { - PushNotification string - UpdateSellerAffiliateStatistic string - CheckAnDInsertCashflowBySeller string - SubscriberTopic string + PushNotification string + UpdateSellerAffiliateStatistic string + CheckAnDInsertCashflowBySeller string + SubscriberTopic string + UpdateSellerSavingCampaignStatistic string + GenerateVoucherPromotion string }{ - PushNotification: getSellyValue("push_notifications"), - UpdateSellerAffiliateStatistic: getSellyValue("update_seller_affiliate_statistic"), - CheckAnDInsertCashflowBySeller: getSellyValue("check_and_insert_cashflow_statistic"), - SubscriberTopic: getSellyValue("subscriber_topic"), + PushNotification: getSellyValue("push_notifications"), + UpdateSellerAffiliateStatistic: getSellyValue("update_seller_affiliate_statistic"), + CheckAnDInsertCashflowBySeller: getSellyValue("check_and_insert_cashflow_statistic"), + SubscriberTopic: getSellyValue("subscriber_topic"), + UpdateSellerSavingCampaignStatistic: getSellyValue("update_seller_saving_campaign_statistic"), + GenerateVoucherPromotion: getSellyValue("generate_voucher_promotion"), } diff --git a/model/seller_response.go b/model/seller_response.go index 01c80e5..e380435 100644 --- a/model/seller_response.go +++ b/model/seller_response.go @@ -4,9 +4,11 @@ import "time" // ResponseSellerInfo ... type ResponseSellerInfo struct { - ID string `json:"_id"` - Name string `json:"name"` - Code string `json:"code"` + ID string `json:"_id"` + Name string `json:"name"` + Code string `json:"code"` + IsAccountPro bool `json:"isAccountPro"` + CashRemaining float64 `json:"cashRemaining"` } // ResponseListSellerInfo ... diff --git a/model/socket.go b/model/socket.go new file mode 100644 index 0000000..f9f6de8 --- /dev/null +++ b/model/socket.go @@ -0,0 +1,19 @@ +package model + +// PayloadEmitSocketEvent ... +type PayloadEmitSocketEvent struct { + User string `json:"user"` + Message string `json:"message"` + Data string `json:"data"` + IsNotRemove bool `json:"isNotRemove"` +} + +// PayloadEventSocketReward ... +type PayloadEventSocketReward struct { + Type string `json:"type"` + Title string `json:"title"` + Cash float64 `json:"cash"` + Message string `json:"message"` + Photo interface{} `json:"photo"` + Action *ActionType `json:"action"` +} diff --git a/subject/config.go b/subject/config.go index 0ba5952..d319a6f 100644 --- a/subject/config.go +++ b/subject/config.go @@ -18,6 +18,7 @@ var prefixes = struct { Queue string Campaign string Affiliate string + Socket string }{ Communication: "communication", Order: "order", @@ -36,4 +37,5 @@ var prefixes = struct { Queue: "queue", Campaign: "campaign", Affiliate: "affiliate", + Socket: "socket", } diff --git a/subject/socket.go b/subject/socket.go new file mode 100644 index 0000000..dae77c1 --- /dev/null +++ b/subject/socket.go @@ -0,0 +1,14 @@ +package subject + +import "fmt" + +func getSocketValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Socket, val) +} + +// Socket ... +var Socket = struct { + EmitEventReward string +}{ + EmitEventReward: getSocketValue("emit_event_reward"), +}