From ffff325e788abd46c2f98e5c259d1805fc336c18 Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 8 Nov 2022 13:53:52 +0700 Subject: [PATCH 1/3] build authsms --- client/bank.go | 11 ++-- client/bank_branch.go | 39 ------------- client/supplier.go | 108 +++++++++++++++++++++++++++++++++-- model/bank_branch_reponse.go | 11 ---- model/bank_branch_request.go | 6 -- model/bank_response.go | 39 +++++++++---- model/supplier_request.go | 32 ++++++++--- model/supplier_response.go | 39 ++++++++++++- subject/bank.go | 8 +-- subject/config.go | 44 +++++++------- subject/supplier.go | 12 ++++ subject/warehouse.go | 74 ++++++++++++------------ 12 files changed, 275 insertions(+), 148 deletions(-) delete mode 100644 client/bank_branch.go delete mode 100644 model/bank_branch_reponse.go delete mode 100644 model/bank_branch_request.go diff --git a/client/bank.go b/client/bank.go index 3391911..27eac4e 100644 --- a/client/bank.go +++ b/client/bank.go @@ -17,15 +17,16 @@ func GetBank() Bank { return Bank{} } -func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) { - msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID)) +// GetBankInfo ... +func (s Bank) GetBankInfo(p []model.GetBankInfoRequest) ([]*model.ResponseBankInfo, error) { + msg, err := natsio.GetServer().Request(subject.Bank.GetBankInfo, toBytes(p)) if err != nil { return nil, err } var r struct { - Data *model.BankBrief `json:"data"` - Error string `json:"error"` + Data []*model.ResponseBankInfo `json:"data"` + Error string `json:"error"` } if err = json.Unmarshal(msg.Data, &r); err != nil { @@ -38,7 +39,7 @@ func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) { return r.Data, nil } -func (s Bank) CheckBankAndBranchByID(p model.BankBranchRequest) bool { +func (s Bank) CheckBankAndBranchByID(p model.CheckBankAndBranchByIDRequest) bool { msg, err := natsio.GetServer().Request(subject.Bank.CheckBankAndBranchByID, toBytes(p)) if err != nil { return false diff --git a/client/bank_branch.go b/client/bank_branch.go deleted file mode 100644 index 5890e75..0000000 --- a/client/bank_branch.go +++ /dev/null @@ -1,39 +0,0 @@ -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" -) - -// BankBranch ... -type BankBranch struct{} - -// GetBankBranch ... -func GetBankBranch() BankBranch { - return BankBranch{} -} - -func (s BankBranch) GetBankBranchById(bankBranchID string) (*model.BankBranchBrief, error) { - msg, err := natsio.GetServer().Request(subject.Bank.GetBankBranchById, toBytes(bankBranchID)) - if err != nil { - return nil, err - } - - var r struct { - Data *model.BankBranchBrief `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/supplier.go b/client/supplier.go index 1ed20d0..fa96d66 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -3,6 +3,7 @@ package client import ( "encoding/json" "errors" + "go.mongodb.org/mongo-driver/bson" "git.selly.red/Selly-Modules/natsio" "git.selly.red/Selly-Modules/natsio/model" @@ -101,9 +102,9 @@ func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*mod return r.Data, nil } -// CreateWarehouseIntoServiceSupplier ... -func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehousePayload) error { - msg, err := natsio.GetServer().Request(subject.Warehouse.CreateWarehouseIntoServiceSupplier, toBytes(p)) +// SyncWarehouseIntoServiceSupplier ... +func (s Supplier) SyncWarehouseIntoServiceSupplier(p model.SyncSupplierWarehousePayload) error { + msg, err := natsio.GetServer().Request(subject.Warehouse.SyncWarehouseIntoServiceSupplier, toBytes(p)) if err != nil { return err } @@ -119,9 +120,104 @@ func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWareh return nil } -// UpdateWarehouseIntoServiceSupplier ... -func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWarehousePayload) error { - msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateWarehouseIntoServiceSupplier, toBytes(p)) +// GetListWarehouseFreeShip ... +func (s Supplier) GetListWarehouseFreeShip() (*model.SupplierListWarehouseFreeShipResponse, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetListWarehouseFreeShip, toBytes(bson.M{})) + if err != nil { + return nil, err + } + + var r struct { + Data *model.SupplierListWarehouseFreeShipResponse `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 +} + +// GetFreeShipInfo ... +func (s Supplier) GetFreeShipInfo(p model.SupplierFreeShipInfoRequestPayload) ([]*model.SupplierFreeShipInfoResponse, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetFreeShipInfo, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data []*model.SupplierFreeShipInfoResponse `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 +} + +// CreateCashflow ... +func (s Supplier) CreateCashflow(p model.SupplierCashflowCreatePayload) (*model.SupplierCashflowCreateResponse, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.CreateCashflow, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Error string `json:"error"` + Data *model.SupplierCashflowCreateResponse `json:"data"` + } + 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) UpdateBalance(p model.SupplierUpdateBalanceReq) (*model.SupplierUpdateBalanceRes, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.UpdateBalance, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Error string `json:"error"` + Data *model.SupplierUpdateBalanceRes `json:"data"` + } + 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) GetCurrentBalance(p model.SupplierGetCurrentBalanceReq) (*model.SupplierGetCurrentBalanceRes, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetCurrentBalance, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Error string `json:"error"` + Data *model.SupplierGetCurrentBalanceRes `json:"data"` + } + 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) DeleteCashflow(p model.SupplierDeleteCashflowReq) error { + msg, err := natsio.GetServer().Request(subject.Supplier.DeleteCashflow, toBytes(p)) if err != nil { return err } diff --git a/model/bank_branch_reponse.go b/model/bank_branch_reponse.go deleted file mode 100644 index 1fa1432..0000000 --- a/model/bank_branch_reponse.go +++ /dev/null @@ -1,11 +0,0 @@ -package model - -// BankBranchBrief ... -type BankBranchBrief struct { - ID string `json:"_id"` - City string `json:"city"` - BankCode string `json:"bankCode"` - Bank string `json:"bank"` - Active bool `json:"active"` - Name string `json:"name"` -} diff --git a/model/bank_branch_request.go b/model/bank_branch_request.go deleted file mode 100644 index 6de1216..0000000 --- a/model/bank_branch_request.go +++ /dev/null @@ -1,6 +0,0 @@ -package model - -type BankBranchRequest struct { - BankID string `json:"bankId"` - BranchID string `json:"branchId"` -} diff --git a/model/bank_response.go b/model/bank_response.go index 74fc10e..4880d03 100644 --- a/model/bank_response.go +++ b/model/bank_response.go @@ -1,21 +1,40 @@ package model +import "time" + // MultiLang ... type MultiLang struct { En string `json:"en"` Vi string `json:"vi"` } +// BankBranchBrief ... +type BranchBrief struct { + ID string `json:"_id"` + City string `json:"city"` + BankCode string `json:"bankCode"` + BankID string `json:"bankId"` + Active bool `json:"active"` + Name string `json:"name"` +} + // BankBrief ... type BankBrief struct { - ID string `json:"_id"` - Name MultiLang `json:"name"` - ShortName string `json:"shortName"` - Active bool `json:"active"` - BenBankName string `json:"benBankName"` - BankCode int `json:"bankCode"` - IsBranchRequired bool `json:"isBranchRequired"` - SearchString string `json:"searchString"` - BeneficiaryForVietinbank string `json:"beneficiaryForVietinbank"` - CreatedBy string `json:"createdBy,omitempty"` + ID string `json:"_id"` + Name MultiLang `json:"name"` + ShortName string `json:"shortName"` + Active bool `json:"active"` + BenBankName string `json:"benBankName"` + BankCode int `json:"bankCode"` + IsBranchRequired bool `json:"isBranchRequired"` + BeneficiaryForVietinbank string `json:"beneficiaryForVietinbank"` + CreatedBy string `json:"createdBy,omitempty"` + CreatedAt time.Time `json:"createdAt"` + BranchTotal int64 `json:"branchTotal"` + Logo interface{} `json:"logo"` +} + +type ResponseBankInfo struct { + Bank BankBrief `json:"bank"` + Branch BranchBrief `json:"branch"` } diff --git a/model/supplier_request.go b/model/supplier_request.go index 5a19924..2f20416 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -23,7 +23,7 @@ type SupplierRequestPayload struct { ContractStatus string } -type CreateSupplierWarehousePayload struct { +type SyncSupplierWarehousePayload struct { Supplier string `json:"supplier"` Warehouse string `json:"warehouse"` ProvinceCode int `json:"provinceCode"` @@ -31,10 +31,28 @@ type CreateSupplierWarehousePayload struct { WardCode int `json:"wardCode"` } -type UpdateSupplierWarehousePayload struct { - Supplier string `json:"supplier"` - Warehouse string `json:"warehouse"` - ProvinceCode int `json:"provinceCode"` - DistrictCode int `json:"districtCode"` - WardCode int `json:"wardCode"` +// SupplierCashflowCreatePayload ... +type SupplierCashflowCreatePayload struct { + Supplier string `json:"supplier"` + Action string `json:"action"` + Name string `json:"name"` + TargetID string `json:"targetId"` + Value float64 `json:"value"` + ClickAction *ClickAction `json:"clickAction"` +} + +type SupplierFreeShipInfoRequestPayload struct { + SupplierIDs []string `json:"supplierIds"` +} + +type SupplierUpdateBalanceReq struct { + SupplierID string `json:"supplierId"` +} + +type SupplierGetCurrentBalanceReq struct { + SupplierID string `json:"supplierId"` +} + +type SupplierDeleteCashflowReq struct { + CashflowID string `json:"cashflowId"` } diff --git a/model/supplier_response.go b/model/supplier_response.go index 4df67b7..655e85b 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -30,8 +30,45 @@ type SupplierAll struct { Total int64 `json:"total"` } +type SupplierListWarehouseFreeShipResponse struct { + Warehouses []string `json:"warehouses"` +} + +type SupplierCashflowCreateResponse struct { + ID string `json:"id"` +} + +type FreeShip struct { + ID string `json:"_id"` + ShortName string `json:"shortName"` + ListMilestoneText []string `json:"milestoneText"` + Order int `json:"-"` +} + +type SupplierFreeShipInfoResponse struct { + SupplierID string `json:"supplierId"` + FreeShips []FreeShip `json:"freeShips"` +} + type SupplierShort struct { ID string `json:"_id"` Name string `json:"name"` Logo interface{} `json:"logo"` -} \ No newline at end of file +} + +type SupplierUpdateBalanceRes struct { + CurrentCash float64 `json:"currentCash"` + TotalPendingCash float64 `json:"totalPendingCash"` + OrderPendingCash float64 `json:"orderPendingCash"` + OrderWaitingForReconcileCash float64 `json:"orderWaitingForReconcileCash"` + OrderReconciledCash float64 `json:"orderReconciledCash"` + WithdrawPendingCash float64 `json:"withdrawPendingCash"` + WithdrawSuccessCash float64 `json:"withdrawSuccessCash"` + WithdrawRejectCash float64 `json:"withdrawRejectCash"` + ChangeBalanceRequestApproved float64 `json:"changeBalanceRequestApproved"` + UpdatedAt string `json:"updatedAt"` +} + +type SupplierGetCurrentBalanceRes struct { + CurrentCash float64 `json:"currentCash"` +} diff --git a/subject/bank.go b/subject/bank.go index 9f7f8bb..601ecb4 100644 --- a/subject/bank.go +++ b/subject/bank.go @@ -7,11 +7,9 @@ func getBankValue(val string) string { } var Bank = struct { - GetBankById string - GetBankBranchById string + GetBankInfo string CheckBankAndBranchByID string }{ - GetBankById: getBankValue("get_bank_by_id"), - GetBankBranchById: getBankValue("get_bank_branch_by_id"), - CheckBankAndBranchByID: getBankValue("check_bank_and_brach_by_id"), + GetBankInfo: getBankValue("get_bank_info"), + CheckBankAndBranchByID: getBankValue("check_bank_and_branch_by_id"), } diff --git a/subject/config.go b/subject/config.go index 37e3055..c838f87 100644 --- a/subject/config.go +++ b/subject/config.go @@ -1,27 +1,31 @@ package subject var prefixes = struct { - Communication string - Order string - News string - Warehouse string - Location string - Bank string - Supplier string - Seller string - SupplierUser string - SupplierRole string + Communication string + Order string + News string + Warehouse string + Location string + Bank string + Supplier string + Seller string + AuthSMS string + Selly string + SupplierUser string + SupplierRole string SupplierPermission string }{ - Communication: "communication", - Order: "order", - News: "news", - Warehouse: "warehouse", - Location: "location", - Supplier: "supplier", - Bank: "bank", - Seller: "seller", - SupplierUser: "supplier_user", - SupplierRole: "supplier_role", + Communication: "communication", + Order: "order", + News: "news", + Warehouse: "warehouse", + Location: "location", + Supplier: "supplier", + Bank: "bank", + Seller: "seller", + AuthSMS: "auth_sms", + Selly: "selly", + SupplierUser: "supplier_user", + SupplierRole: "supplier_role", SupplierPermission: "supplier_permission", } diff --git a/subject/supplier.go b/subject/supplier.go index 17ca8d0..441118f 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -10,8 +10,20 @@ var Supplier = struct { GetListSupplierInfo string GetSupplierContractBySupplierID string FindAll string + GetListWarehouseFreeShip string + CreateCashflow string + DeleteCashflow string + UpdateBalance string + GetCurrentBalance string + GetFreeShipInfo string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), + GetListWarehouseFreeShip: getSupplierValue("get_list_warehouse_free_ship"), + CreateCashflow: getSupplierValue("create_cashflow"), + DeleteCashflow: getSupplierValue("delete_cashflow"), + UpdateBalance: getSupplierValue("update_balance"), + GetCurrentBalance: getSupplierValue("get_current_balance"), + GetFreeShipInfo: getSupplierValue("get_free_ship_info"), } diff --git a/subject/warehouse.go b/subject/warehouse.go index bb184b5..6bb0d6e 100644 --- a/subject/warehouse.go +++ b/subject/warehouse.go @@ -7,43 +7,41 @@ func getWarehouseValue(val string) string { } var Warehouse = struct { - CreateWarehouseIntoServiceSupplier string - UpdateWarehouseIntoServiceSupplier string - CreateOutboundRequest string - UpdateOutboundRequestLogistic string - CancelOutboundRequest string - GetConfiguration string - SyncORStatus string - WebhookTNC string - WebhookGlobalCare string - WebhookOnPoint string - FindOne string - FindByCondition string - Distinct string - Count string - AfterUpdateWarehouse string - AfterCreateWarehouse string - UpdateIsClosedSupplier string - GetWarehouses string - UpdateORDeliveryStatus string + SyncWarehouseIntoServiceSupplier string + CreateOutboundRequest string + UpdateOutboundRequestLogistic string + CancelOutboundRequest string + GetConfiguration string + SyncORStatus string + WebhookTNC string + WebhookGlobalCare string + WebhookOnPoint string + FindOne string + FindByCondition string + Distinct string + Count string + AfterUpdateWarehouse string + AfterCreateWarehouse string + UpdateIsClosedSupplier string + GetWarehouses string + UpdateORDeliveryStatus string }{ - CreateWarehouseIntoServiceSupplier: getWarehouseValue("create_warehouse_into_service_supplier"), - UpdateWarehouseIntoServiceSupplier: getWarehouseValue("update_warehouse_into_service_supplier"), - AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), - AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), - CreateOutboundRequest: getWarehouseValue("create_outbound_request"), - UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"), - CancelOutboundRequest: getWarehouseValue("cancel_outbound_request"), - GetConfiguration: getWarehouseValue("get_configuration"), - SyncORStatus: getWarehouseValue("sync_or_status"), - WebhookTNC: getWarehouseValue("webhook_tnc"), - WebhookGlobalCare: getWarehouseValue("webhook_global_care"), - WebhookOnPoint: getWarehouseValue("webhook_on_point"), - FindOne: getWarehouseValue("find_one"), - FindByCondition: getWarehouseValue("find_all_by_condition"), - Distinct: getWarehouseValue("distinct"), - Count: getWarehouseValue("count"), - UpdateIsClosedSupplier: getWarehouseValue("update_is_closed_supplier"), - GetWarehouses: getWarehouseValue("get_warehouses"), - UpdateORDeliveryStatus: getWarehouseValue("update_or_delivery_status"), + SyncWarehouseIntoServiceSupplier: getWarehouseValue("sync_warehouse_into_service_supplier"), + AfterCreateWarehouse: getWarehouseValue("after_create_warehouse"), + AfterUpdateWarehouse: getWarehouseValue("after_update_warehouse"), + CreateOutboundRequest: getWarehouseValue("create_outbound_request"), + UpdateOutboundRequestLogistic: getWarehouseValue("update_outbound_request_logistic_info"), + CancelOutboundRequest: getWarehouseValue("cancel_outbound_request"), + GetConfiguration: getWarehouseValue("get_configuration"), + SyncORStatus: getWarehouseValue("sync_or_status"), + WebhookTNC: getWarehouseValue("webhook_tnc"), + WebhookGlobalCare: getWarehouseValue("webhook_global_care"), + WebhookOnPoint: getWarehouseValue("webhook_on_point"), + FindOne: getWarehouseValue("find_one"), + FindByCondition: getWarehouseValue("find_all_by_condition"), + Distinct: getWarehouseValue("distinct"), + Count: getWarehouseValue("count"), + UpdateIsClosedSupplier: getWarehouseValue("update_is_closed_supplier"), + GetWarehouses: getWarehouseValue("get_warehouses"), + UpdateORDeliveryStatus: getWarehouseValue("update_or_delivery_status"), } From 4d501a437c7d4b65d8f766cb38c28821364f6371 Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 8 Nov 2022 13:57:22 +0700 Subject: [PATCH 2/3] build authsms --- client/withdraw.go | 39 +++++++++++++++++++++++++++++++++++++++ model/bank_request.go | 11 +++++++++++ 2 files changed, 50 insertions(+) create mode 100644 client/withdraw.go create mode 100644 model/bank_request.go diff --git a/client/withdraw.go b/client/withdraw.go new file mode 100644 index 0000000..006d7a7 --- /dev/null +++ b/client/withdraw.go @@ -0,0 +1,39 @@ +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" +) + +// Withdraw ... +type Withdraw struct{} + +// GetWithdraw ... +func GetWithdraw() Withdraw { + return Withdraw{} +} + +// GetSupplierCash ... +func (o Withdraw) GetSupplierCash(p model.WithdrawSupplierCashReq) (*model.WithdrawSupplierCashRes, error) { + msg, err := natsio.GetServer().Request(subject.Withdraw.GetSupplierCash, toBytes(p)) + if err != nil { + return nil, err + } + var ( + r struct { + Data model.WithdrawSupplierCashRes `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/bank_request.go b/model/bank_request.go new file mode 100644 index 0000000..3b76615 --- /dev/null +++ b/model/bank_request.go @@ -0,0 +1,11 @@ +package model + +type CheckBankAndBranchByIDRequest struct { + BankID string `json:"bankId"` + BranchID string `json:"branchId"` +} + +type GetBankInfoRequest struct { + BankID string `json:"bankId"` + BranchID string `json:"branchId"` +} From 1cacdae5475dd8ed418981e6a6e26b23a2229d9c Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 8 Nov 2022 13:58:30 +0700 Subject: [PATCH 3/3] build authsms --- model/common_request.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/model/common_request.go b/model/common_request.go index 0ce5163..e83fa2c 100644 --- a/model/common_request.go +++ b/model/common_request.go @@ -20,3 +20,25 @@ type ActionBy struct { ID string `json:"id"` Name string `json:"name"` } + +// ClickAction ... +type ClickAction struct { + Type string `json:"type"` + Value string `json:"value"` +} + +// RequestCondition ... +type RequestCondition struct { + Code int `json:"code"` + Codes []int `json:"codes"` + DistrictCode int `json:"districtCode"` + ProvinceCode int `json:"provinceCode"` + + Slug string `json:"slug"` + Slugs []string `json:"slugs"` + DistrictSlug string `json:"districtSlug"` + ProvinceSlug string `json:"provinceSlug"` + + Keyword string `json:"keyword"` + Region string `json:"region"` +}