From 7c05aa7011d716be204344841bd2f993f2630576 Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Sun, 4 Dec 2022 20:43:54 +0700 Subject: [PATCH 1/6] get list affiliate-transaction --- client/affiliate.go | 36 ++++++++++++++++++++++++ model/affiliate_request.go | 12 ++++++++ model/affiliate_response.go | 56 +++++++++++++++++++++++++++++++++++++ subject/affiliate.go | 13 +++++++++ subject/config.go | 2 ++ 5 files changed, 119 insertions(+) create mode 100644 client/affiliate.go create mode 100644 model/affiliate_request.go create mode 100644 model/affiliate_response.go create mode 100644 subject/affiliate.go diff --git a/client/affiliate.go b/client/affiliate.go new file mode 100644 index 0000000..58e8bd0 --- /dev/null +++ b/client/affiliate.go @@ -0,0 +1,36 @@ +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" +) + +// Affiliate ... +type Affiliate struct{} + +// GetAffiliate ... +func GetAffiliate() Affiliate { + return Affiliate{} +} + +// GetTransactions ... +func (w Affiliate) GetTransactions(p model.GetTransactionsRequest) (*model.GetTransactionsResponse, error) { + msg, err := natsio.GetServer().Request(subject.Affiliate.GetTransactions, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data *model.GetTransactionsResponse `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/affiliate_request.go b/model/affiliate_request.go new file mode 100644 index 0000000..a4aa104 --- /dev/null +++ b/model/affiliate_request.go @@ -0,0 +1,12 @@ +package model + +// GetTransactionsRequest ... +type GetTransactionsRequest struct { + Page int64 `json:"page"` + Limit int64 `json:"limit"` + Keyword string `json:"keyword"` + Statuses string `json:"statuses"` + Source string `json:"source"` + Campaign string `json:"campaign"` + Seller string `json:"seller"` +} diff --git a/model/affiliate_response.go b/model/affiliate_response.go new file mode 100644 index 0000000..5ab3245 --- /dev/null +++ b/model/affiliate_response.go @@ -0,0 +1,56 @@ +package model + +import "time" + +// GetTransactionsResponse ... +type GetTransactionsResponse struct { + Total int64 `json:"total"` + Limit int64 `json:"limit"` + List []TransactionInfo `json:"list"` +} + +// TransactionInfo ... +type TransactionInfo struct { + ID string `json:"_id"` + Code string `json:"code"` + Campaign ResponseCampaignShort `json:"campaign"` + Seller ResponseSellerInfo `json:"seller"` + Source string `json:"source"` + Commission ResponseCampaignCommission `json:"commission"` + EstimateSellerCommission float64 `json:"estimateSellerCommission"` + TransactionTime time.Time `json:"transactionTime"` + Status string `json:"status"` + RejectedReason string `json:"rejectedReason"` + EstimateCashbackAt time.Time `json:"estimateCashbackAt"` +} + +// ResponseCampaignCommission ... +type ResponseCampaignCommission struct { + Real float64 `json:"real"` + SellerPercent float64 `json:"sellerPercent"` + Selly float64 `json:"selly"` + Seller float64 `json:"seller"` +} + +// ResponseCampaignShort ... +type ResponseCampaignShort struct { + ID string `json:"_id"` + Name string `json:"name"` + Logo *FilePhoto `json:"logo"` +} + +var ( + transcationInfoTitle = []string{ + "ID lượt thưởng", + "Tên sản phẩm", + "ID Seller", + "Tên Seller", + "Thời gian phát sinh", + "Thời gian đối soát dự kiến", + "Trạng thái", + "Hoa hồng nhận từ đối tác", + "Phần trăm hóa hồng cho Seller", + "Hoa hồng cho Seller", + "Hoa hồng cho Selly", + } +) diff --git a/subject/affiliate.go b/subject/affiliate.go new file mode 100644 index 0000000..cd59597 --- /dev/null +++ b/subject/affiliate.go @@ -0,0 +1,13 @@ +package subject + +import "fmt" + +func getAffiliateValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Affiliate, val) +} + +var Affiliate = struct { + GetTransactions string +}{ + GetTransactions: getAffiliateValue("get_transactions"), +} diff --git a/subject/config.go b/subject/config.go index bb4e723..1954121 100644 --- a/subject/config.go +++ b/subject/config.go @@ -15,6 +15,7 @@ var prefixes = struct { Staff string Segment string Campaign string + Affiliate string }{ Communication: "communication", Order: "order", @@ -30,4 +31,5 @@ var prefixes = struct { Staff: "staff", Segment: "segment", Campaign: "campaign", + Affiliate: "affiliate", } -- 2.34.1 From 599d36120e37549b914c088f164c70f7552c39c7 Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Sun, 4 Dec 2022 20:57:25 +0700 Subject: [PATCH 2/6] edit getTransactionRequest --- model/affiliate_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/affiliate_request.go b/model/affiliate_request.go index a4aa104..7e04190 100644 --- a/model/affiliate_request.go +++ b/model/affiliate_request.go @@ -5,7 +5,7 @@ type GetTransactionsRequest struct { Page int64 `json:"page"` Limit int64 `json:"limit"` Keyword string `json:"keyword"` - Statuses string `json:"statuses"` + status string `json:"status"` Source string `json:"source"` Campaign string `json:"campaign"` Seller string `json:"seller"` -- 2.34.1 From d7c2660ae29b67e8028a0bb920d3513cebf5b2b2 Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:01:43 +0700 Subject: [PATCH 3/6] edit getTransactionRequest --- model/affiliate_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/affiliate_request.go b/model/affiliate_request.go index 7e04190..1e6a369 100644 --- a/model/affiliate_request.go +++ b/model/affiliate_request.go @@ -5,7 +5,7 @@ type GetTransactionsRequest struct { Page int64 `json:"page"` Limit int64 `json:"limit"` Keyword string `json:"keyword"` - status string `json:"status"` + Status string `json:"status"` Source string `json:"source"` Campaign string `json:"campaign"` Seller string `json:"seller"` -- 2.34.1 From 5b7d8329aef2d5c623060db3292e55b11f16e22b Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:05:25 +0700 Subject: [PATCH 4/6] update model gettransaction --- model/affiliate_request.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/model/affiliate_request.go b/model/affiliate_request.go index 1e6a369..359391b 100644 --- a/model/affiliate_request.go +++ b/model/affiliate_request.go @@ -1,12 +1,16 @@ package model +import "time" + // GetTransactionsRequest ... type GetTransactionsRequest struct { - Page int64 `json:"page"` - Limit int64 `json:"limit"` - Keyword string `json:"keyword"` - Status string `json:"status"` - Source string `json:"source"` - Campaign string `json:"campaign"` - Seller string `json:"seller"` + Page int64 `json:"page"` + Limit int64 `json:"limit"` + Keyword string `json:"keyword"` + Status string `json:"status"` + Source string `json:"source"` + Campaign string `json:"campaign"` + Seller string `json:"seller"` + FromAt time.Time `json:"fromAt"` + ToAt time.Time `json:"toAt"` } -- 2.34.1 From 0d69cc3357375c90c46e54211fd20a0f83b4dc48 Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:25:42 +0700 Subject: [PATCH 5/6] change model get transaction --- model/affiliate_response.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/model/affiliate_response.go b/model/affiliate_response.go index 5ab3245..80a4707 100644 --- a/model/affiliate_response.go +++ b/model/affiliate_response.go @@ -1,7 +1,5 @@ package model -import "time" - // GetTransactionsResponse ... type GetTransactionsResponse struct { Total int64 `json:"total"` @@ -18,10 +16,10 @@ type TransactionInfo struct { Source string `json:"source"` Commission ResponseCampaignCommission `json:"commission"` EstimateSellerCommission float64 `json:"estimateSellerCommission"` - TransactionTime time.Time `json:"transactionTime"` + TransactionTime string `json:"transactionTime"` Status string `json:"status"` RejectedReason string `json:"rejectedReason"` - EstimateCashbackAt time.Time `json:"estimateCashbackAt"` + EstimateCashbackAt string `json:"estimateCashbackAt"` } // ResponseCampaignCommission ... -- 2.34.1 From 23eebdce8adc9f9b0adc14c8a33b41b0257434c2 Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Wed, 7 Dec 2022 13:48:43 +0700 Subject: [PATCH 6/6] change code --- model/affiliate_response.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/model/affiliate_response.go b/model/affiliate_response.go index 80a4707..bb8f804 100644 --- a/model/affiliate_response.go +++ b/model/affiliate_response.go @@ -36,19 +36,3 @@ type ResponseCampaignShort struct { Name string `json:"name"` Logo *FilePhoto `json:"logo"` } - -var ( - transcationInfoTitle = []string{ - "ID lượt thưởng", - "Tên sản phẩm", - "ID Seller", - "Tên Seller", - "Thời gian phát sinh", - "Thời gian đối soát dự kiến", - "Trạng thái", - "Hoa hồng nhận từ đối tác", - "Phần trăm hóa hồng cho Seller", - "Hoa hồng cho Seller", - "Hoa hồng cho Selly", - } -) -- 2.34.1