From d45da3e74c6d7d02ed728c8d630c47462af6efcc Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 18 Nov 2022 10:13:41 +0700 Subject: [PATCH 1/5] nats - get supplier from old server --- client/supplier.go | 21 +++++++++++++++++++++ model/supplier_request.go | 7 +++++++ subject/supplier.go | 2 ++ 3 files changed, 30 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index 1ed20d0..e278f46 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -80,6 +80,27 @@ func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.Suppl return r.Data, nil } +func (s Supplier) FindAllOld(req model.SupplierFindAllReq) (*model.SupplierAll, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.FindAllOld, toBytes(req)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.SupplierAll `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 Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) { msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID)) if err != nil { diff --git a/model/supplier_request.go b/model/supplier_request.go index 5a19924..118737d 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -38,3 +38,10 @@ type UpdateSupplierWarehousePayload struct { DistrictCode int `json:"districtCode"` WardCode int `json:"wardCode"` } + +type SupplierFindAllReq struct { + Page int64 `json:"page"` + Limit int64 `json:"limit"` + Segment string `json:"segment"` + IDs []string `json:"ids"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 17ca8d0..92af7b3 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -10,8 +10,10 @@ var Supplier = struct { GetListSupplierInfo string GetSupplierContractBySupplierID string FindAll string + FindAllOld string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), + FindAllOld: getSupplierValue("find_all_old"), } -- 2.34.1 From 8248069bb86310fb30d839ff03d50553ea508530 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 23 Nov 2022 10:08:52 +0700 Subject: [PATCH 2/5] count supplier --- client/supplier.go | 21 +++++++++++++++++++++ model/supplier_request.go | 5 +++++ model/supplier_response.go | 4 ++++ subject/supplier.go | 2 ++ 4 files changed, 32 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index e278f46..9b53826 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -122,6 +122,27 @@ func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*mod return r.Data, nil } +func (s Supplier) Count(req model.SupplierCountReq) (*model.SupplierCountRes, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.Count, toBytes(req)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.SupplierCountRes `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 +} + // CreateWarehouseIntoServiceSupplier ... func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehousePayload) error { msg, err := natsio.GetServer().Request(subject.Warehouse.CreateWarehouseIntoServiceSupplier, toBytes(p)) diff --git a/model/supplier_request.go b/model/supplier_request.go index 118737d..bbba857 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -45,3 +45,8 @@ type SupplierFindAllReq struct { Segment string `json:"segment"` IDs []string `json:"ids"` } + +type SupplierCountReq struct { + Segment string `json:"segment"` + IDs []string `json:"ids"` +} diff --git a/model/supplier_response.go b/model/supplier_response.go index 975a8de..2b9dd10 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -29,3 +29,7 @@ type SupplierAll struct { Suppliers []SupplierBrief `json:"suppliers"` Total int64 `json:"total"` } + +type SupplierCountRes struct { + Total int64 `json:"total"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 92af7b3..edc797f 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -11,9 +11,11 @@ var Supplier = struct { GetSupplierContractBySupplierID string FindAll string FindAllOld string + Count string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), FindAllOld: getSupplierValue("find_all_old"), + Count: getSupplierValue("count"), } -- 2.34.1 From c47768308c66c19d120519ba5e1feaef6ff811b4 Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Wed, 23 Nov 2022 10:29:50 +0700 Subject: [PATCH 3/5] add nats --- client/segmnet.go | 41 +++++++++++++++++++++++++++++++++++++++ client/staff.go | 41 +++++++++++++++++++++++++++++++++++++++ model/segment_request.go | 6 ++++++ model/segment_response.go | 12 ++++++++++++ model/staff_request.go | 6 ++++++ model/staff_response.go | 12 ++++++++++++ subject/config.go | 4 ++++ subject/segment.go | 15 ++++++++++++++ subject/staff.go | 14 +++++++++++++ 9 files changed, 151 insertions(+) create mode 100644 client/segmnet.go create mode 100644 client/staff.go create mode 100644 model/segment_request.go create mode 100644 model/segment_response.go create mode 100644 model/staff_request.go create mode 100644 model/staff_response.go create mode 100644 subject/segment.go create mode 100644 subject/staff.go diff --git a/client/segmnet.go b/client/segmnet.go new file mode 100644 index 0000000..bcc7bab --- /dev/null +++ b/client/segmnet.go @@ -0,0 +1,41 @@ +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" +) + +// Segment ... +type Segment struct{} + +// GetSegment ... +func GetSegment() Segment { + return Segment{} +} + +// GetListSegmentInfoByIds ... +func (s Segment) GetListSegmentInfoByIds(p model.GetListSegmentRequest) (*model.ResponseListSegmentInfo, error) { + msg, err := natsio.GetServer().Request(subject.Segment.GetListSegmentInfo, toBytes(p)) + + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseListSegmentInfo `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/client/staff.go b/client/staff.go new file mode 100644 index 0000000..b175f53 --- /dev/null +++ b/client/staff.go @@ -0,0 +1,41 @@ +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" +) + +// Staff ... +type Staff struct{} + +func GetStaff() Staff { + return Staff{} +} + +// GetListStaffInfoByIds ... +func (s Staff) GetListStaffInfoByIds(p model.GetListStaffRequest) (*model.ResponseListStaffInfo, error) { + msg, err := natsio.GetServer().Request(subject.Staff.GetListStaffInfo, toBytes(p)) + + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseListStaffInfo `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/segment_request.go b/model/segment_request.go new file mode 100644 index 0000000..138f347 --- /dev/null +++ b/model/segment_request.go @@ -0,0 +1,6 @@ +package model + +// GetListSegmentRequest ... +type GetListSegmentRequest struct { + SegmentIds []string `json:"segmentIds"` +} diff --git a/model/segment_response.go b/model/segment_response.go new file mode 100644 index 0000000..84a1571 --- /dev/null +++ b/model/segment_response.go @@ -0,0 +1,12 @@ +package model + +// ResponseSegmentInfo ... +type ResponseSegmentInfo struct { + ID string `json:"_id"` + Name string `json:"name"` +} + +// ResponseListSegmentInfo ... +type ResponseListSegmentInfo struct { + Segments []ResponseSegmentInfo `json:"segments"` +} diff --git a/model/staff_request.go b/model/staff_request.go new file mode 100644 index 0000000..176b34e --- /dev/null +++ b/model/staff_request.go @@ -0,0 +1,6 @@ +package model + +// GetListStaffRequest ... +type GetListStaffRequest struct { + StaffIds []string `json:"staffIds"` +} diff --git a/model/staff_response.go b/model/staff_response.go new file mode 100644 index 0000000..5076d0c --- /dev/null +++ b/model/staff_response.go @@ -0,0 +1,12 @@ +package model + +// ResponseListStaffInfo ... +type ResponseListStaffInfo struct { + Staffs []ResponseStaffInfo `json:"staffs"` +} + +// ResponseStaffInfo ... +type ResponseStaffInfo struct { + ID string `json:"_id"` + Name string `json:"name"` +} diff --git a/subject/config.go b/subject/config.go index 90a014f..b3117b3 100644 --- a/subject/config.go +++ b/subject/config.go @@ -11,6 +11,8 @@ var prefixes = struct { Seller string SupplierUser string SupplierRole string + Staff string + Segment string }{ Communication: "communication", Order: "order", @@ -22,4 +24,6 @@ var prefixes = struct { Seller: "seller", SupplierUser: "supplier_user", SupplierRole: "supplier_role", + Staff: "staff", + Segment: "segment", } diff --git a/subject/segment.go b/subject/segment.go new file mode 100644 index 0000000..f6021ca --- /dev/null +++ b/subject/segment.go @@ -0,0 +1,15 @@ +package subject + +import "fmt" + +// getSegmentValue ... +func getSegmentValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Segment, val) +} + +// Segment ... +var Segment = struct { + GetListSegmentInfo string +}{ + GetListSegmentInfo: getSegmentValue("get_list_segment_info"), +} diff --git a/subject/staff.go b/subject/staff.go new file mode 100644 index 0000000..4777f06 --- /dev/null +++ b/subject/staff.go @@ -0,0 +1,14 @@ +package subject + +import "fmt" + +func getStaffValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Staff, val) +} + +// Staff ... +var Staff = struct { + GetListStaffInfo string +}{ + GetListStaffInfo: getStaffValue("get_list_staff_info"), +} -- 2.34.1 From fb87ac7911f53a6fafed85702b42439b25cd2b14 Mon Sep 17 00:00:00 2001 From: Sinh Date: Thu, 24 Nov 2022 09:38:10 +0700 Subject: [PATCH 4/5] update nats --- model/supplier_request.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/model/supplier_request.go b/model/supplier_request.go index bbba857..18034af 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -44,9 +44,11 @@ type SupplierFindAllReq struct { Limit int64 `json:"limit"` Segment string `json:"segment"` IDs []string `json:"ids"` + Status string `json:"status"` // active,inactive } type SupplierCountReq struct { Segment string `json:"segment"` IDs []string `json:"ids"` + Status string `json:"status"` // active,inactive } -- 2.34.1 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 5/5] 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