mergeDev/campaign #73

Closed
Ghost wants to merge 208 commits from mergeDev/campaign into develop
16 changed files with 344 additions and 82 deletions
Showing only changes of commit e26762916c - Show all commits

View File

@ -98,3 +98,24 @@ func (o Order) ORNotUpdateStatus(p model.OrderORsNotUpdateStatus) error {
}
return nil
}
// GetSupplierOrders ...
func (o Order) GetSupplierOrders(p model.OrderSupplierQuery) (*model.SupplierOrderList, error) {
msg, err := natsio.GetServer().Request(subject.Order.GetSupplierOrders, toBytes(p))
if err != nil {
return nil, err
}
var (
r struct {
Data model.SupplierOrderList `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
}

58
client/supplier_role.go Normal file
View File

@ -0,0 +1,58 @@
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"
)
// SupplierRole ...
type SupplierRole struct{}
// GetSupplierRole ...
func GetSupplierRole() SupplierRole {
return SupplierRole{}
}
func (s SupplierRole) CreateRole(p model.CreateRoleRequest) (*model.CreateRoleResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateRoleResponse `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 SupplierRole) UpdateRole(p model.UpdateRoleRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierRole.Update, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}

View File

@ -16,15 +16,15 @@ func GetSupplierUser() SupplierUser {
return SupplierUser{}
}
func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateSupplierOwnerUserRequest) (*model.CreateSupplierUserOwnerResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierOwnerUser, toBytes(p))
func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateOwnerRequest) (*model.CreateOwnerResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateSupplierUserOwnerResponse `json:"data"`
Error string `json:"error"`
Data *model.CreateOwnerResponse `json:"data"`
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
@ -37,8 +37,8 @@ func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateSupplierOwnerUserRe
return r.Data, nil
}
func (s SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateSupplierOwnerUserRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateSupplierOwnerUser, toBytes(p))
func (s SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateOwnerRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateOwner, toBytes(p))
if err != nil {
return err
}
@ -57,15 +57,15 @@ func (s SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateSupplierOwnerUserRe
return nil
}
func (s SupplierUser) CreateSupplierStaffUsers(p model.CreateSupplierStaffUserRequest) (*model.CreateSupplierUserStaffResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierStaffUser, toBytes(p))
func (s SupplierUser) CreateSupplierStaffUsers(p model.CreateStaffRequest) (*model.CreateStaffResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateStaff, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateSupplierUserStaffResponse `json:"data"`
Error string `json:"error"`
Data *model.CreateStaffResponse `json:"data"`
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
@ -78,8 +78,8 @@ func (s SupplierUser) CreateSupplierStaffUsers(p model.CreateSupplierStaffUserRe
return r.Data, nil
}
func (s SupplierUser) UpdateSupplierStaffUsers(p model.CreateSupplierStaffUserRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateSupplierStaffUser, toBytes(p))
func (s SupplierUser) UpdateSupplierStaffUsers(p model.UpdateStaffRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p))
if err != nil {
return err
}
@ -97,3 +97,44 @@ func (s SupplierUser) UpdateSupplierStaffUsers(p model.CreateSupplierStaffUserRe
return nil
}
func (s SupplierUser) UpdateStatus(p model.UpdateStatusRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
func (s SupplierUser) ResetPassword(p model.ResetPasswordRequest) (*model.ResetPasswordResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.ResetPassword, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResetPasswordResponse `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
}

View File

@ -3,6 +3,7 @@ package client
import (
"encoding/json"
"errors"
"fmt"
"git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model"
@ -163,3 +164,21 @@ func (w Warehouse) GetWarehouses(p model.GetWarehousesRequest) (*model.GetWareho
}
return r.Data, nil
}
// UpdateORDeliveryStatus ...
func (w Warehouse) UpdateORDeliveryStatus(p model.WarehouseORUpdateDeliveryStatus) error {
msg, err := natsio.GetServer().Request(subject.Warehouse.GetWarehouses, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return fmt.Errorf("nats: update_or_delivery_status %v", err)
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}

View File

@ -2,6 +2,7 @@ package model
// OrderUpdateORStatus ...
type OrderUpdateORStatus struct {
ID string `json:"id"`
OrderCode string `json:"orderCode"`
ORCode string `json:"orCode"`
Status string `json:"status"`
@ -38,3 +39,13 @@ type OrderUpdateLogisticInfoFailed struct {
type OrderORsNotUpdateStatus struct {
ORCodes []string `json:"orCodes"`
}
// OrderSupplierQuery ...
type OrderSupplierQuery struct {
Limit int64 `json:"limit"`
Page int64 `json:"page"`
FromDate string `json:"fromDate"`
ToDate string `json:"toDate"`
SupplierID string `json:"supplierId"`
WarehouseIDs []string `json:"warehouseIDs"`
}

35
model/order_response.go Normal file
View File

@ -0,0 +1,35 @@
package model
import "time"
// SupplierOrderList ...
type SupplierOrderList struct {
List []SupplierOrder `json:"list"`
Total int64 `json:"total" example:"100"`
Limit int64 `json:"limit" example:"20"`
}
// SupplierOrder ...
type SupplierOrder struct {
ID string `json:"_id"`
Code string `json:"code"`
CreatedAt time.Time `json:"createdAt"`
Status string `json:"status"`
WarehouseStatus string `json:"warehouseStatus"`
Items []SupplierOrderItem `json:"items"`
Delivery SupplierOrderDelivery `json:"delivery"`
}
// SupplierOrderItem ...
type SupplierOrderItem struct {
ID string `json:"_id" example:"1231"`
SupplierSKU string `json:"supplierSku" example:"SUPPLIER_SKU"`
Quantity int64 `json:"quantity" example:"2"`
}
// SupplierOrderDelivery ...
type SupplierOrderDelivery struct {
Code string `json:"code" example:"123187287"`
Status string `json:"status" enums:"waiting_to_confirm,waiting_to_pick,picking,picked,delay_pickup,pickup_failed,delivering,delay_delivery,delivered,cancelled,delivery_failed,waiting_to_return,returning,delay_return,compensation,returned"`
TPLCode string `json:"tplCode" enums:"SLY,GHTK,GHN,SSC,SPY,VTP,SE,NTL,BEST"`
}

View File

@ -0,0 +1,14 @@
package model
type CreateRoleRequest struct {
Name string `json:"name"`
Code string `json:"code"`
Type string `json:"type"`
}
type UpdateRoleRequest struct {
ID string `json:"_id"`
Name string `json:"name"`
Code string `json:"code"`
Type string `json:"type"`
}

View File

@ -0,0 +1,5 @@
package model
type CreateRoleResponse struct {
ID string `json:"_id"`
}

View File

@ -1,6 +1,6 @@
package model
type CreateSupplierOwnerUserRequest struct {
type CreateOwnerRequest struct {
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
@ -9,7 +9,7 @@ type CreateSupplierOwnerUserRequest struct {
Password string `json:"password"`
}
type UpdateSupplierOwnerUserRequest struct {
type UpdateOwnerRequest struct {
ID string `json:"_id"`
SupplierID string `json:"supplierId"`
Name string `json:"name"`
@ -18,7 +18,7 @@ type UpdateSupplierOwnerUserRequest struct {
RoleID string `json:"roleId"`
}
type CreateSupplierStaffUserRequest struct {
type CreateStaffRequest struct {
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
@ -28,14 +28,24 @@ type CreateSupplierStaffUserRequest struct {
Warehouses []string `json:"warehouses"`
}
type UpdateSupplierStaffUserRequest struct {
ID string `json:"_id"`
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
SupplierID string `json:"supplierId"`
Role string `json:"role"`
Password string `json:"password"`
Warehouses []string `json:"warehouses"`
RoleId string `json:"roleId"`
type UpdateStaffRequest struct {
ID string `json:"_id"`
Name string `json:"name"`
Phone string `json:"phone"`
Email string `json:"email"`
SupplierID string `json:"supplierId"`
RoleID string `json:"roleId"`
Password string `json:"password"`
SupplierUserWarehouseID string `json:"supplierUserWarehouseId"`
Warehouses []string `json:"warehouses"`
}
type UpdateStatusRequest struct {
ID string `json:"_id"`
Status string `json:"status"`
}
type ResetPasswordRequest struct {
ID string `json:"_id"`
Password string `json:"password"`
}

View File

@ -1,9 +1,13 @@
package model
type CreateSupplierUserOwnerResponse struct {
type CreateOwnerResponse struct {
ID string `json:"_id"`
}
type CreateSupplierUserStaffResponse struct {
type CreateStaffResponse struct {
ID string `json:"_id"`
}
type ResetPasswordResponse struct {
Password string `json:"password"`
}

View File

@ -2,17 +2,18 @@ package model
// OutboundRequestPayload ...
type OutboundRequestPayload struct {
OrderID string `json:"orderId"`
OrderCode string `json:"orderCode"`
TrackingCode string `json:"trackingCode"`
WarehouseID string `json:"warehouseId"`
SupplierID string `json:"supplierId"`
Note string `json:"note"`
CODAmount float64 `json:"codAmount"`
TPLCode string `json:"tplCode"`
Customer CustomerInfo `json:"customer"`
Items []OutboundRequestItem `json:"items"`
Insurance *InsuranceOpts `json:"insurance"`
OrderID string `json:"orderId"`
OrderCode string `json:"orderCode"`
TrackingCode string `json:"trackingCode"`
WarehouseID string `json:"warehouseId"`
SupplierID string `json:"supplierId"`
Note string `json:"note"`
CODAmount float64 `json:"codAmount"`
TPLCode string `json:"tplCode"`
Customer CustomerInfo `json:"customer"`
Items []OutboundRequestItem `json:"items"`
Insurance *InsuranceOpts `json:"insurance"`
PaymentMethod string `json:"paymentMethod"`
}
// InsuranceOpts ...
@ -36,9 +37,11 @@ type InsuranceOpts struct {
// OutboundRequestItem ...
type OutboundRequestItem struct {
SupplierSKU string `json:"supplierSKU"`
Quantity int64 `json:"quantity"`
UnitCode string `json:"unitCode"`
SupplierSKU string `json:"supplierSKU"`
Quantity int64 `json:"quantity"`
UnitCode string `json:"unitCode"`
Price float64 `json:"price"`
Name string `json:"name"`
}
// CustomerInfo ...
@ -63,18 +66,22 @@ type UpdateOutboundRequestLogisticInfoPayload struct {
ShippingLabel string `json:"shippingLabel"`
TrackingCode string `json:"trackingCode"`
ORCode string `json:"orCode"`
TPLCode string `json:"tplCode"`
OrderID string `json:"orderId"`
}
// CancelOutboundRequest ...
type CancelOutboundRequest struct {
ORCode string `json:"orCode"`
Note string `json:"note"`
ORCode string `json:"orCode"`
OrderID string `json:"orderId"`
Note string `json:"note"`
}
// SyncORStatusRequest ...
type SyncORStatusRequest struct {
ORCode string `json:"orCode"`
OrderCode string `json:"orderCode"`
OrderID string `json:"orderId"`
}
// UpdateSupplierIsClosedRequest ...
@ -98,3 +105,11 @@ type GetWarehousesRequest struct {
Page int64 `json:"page"`
Limit int64 `json:"limit"`
}
// WarehouseORUpdateDeliveryStatus ...
type WarehouseORUpdateDeliveryStatus struct {
ORCode string `json:"orCode"`
OrderCode string `json:"orderCode"`
OrderID string `json:"orderId"`
DeliveryStatus string `json:"deliveryStatus"`
}

View File

@ -10,6 +10,7 @@ var prefixes = struct {
Supplier string
Seller string
SupplierUser string
SupplierRole string
}{
Communication: "communication",
Order: "order",
@ -20,4 +21,5 @@ var prefixes = struct {
Bank: "bank",
Seller: "seller",
SupplierUser: "supplier_user",
SupplierRole: "supplier_role",
}

View File

@ -12,10 +12,12 @@ var Order = struct {
ChangeDeliveryStatus string
UpdateLogisticInfoFailed string
ORNotUpdateStatus string
GetSupplierOrders string
}{
UpdateORStatus: getOrderValue("update_outbound_request_status"),
CancelDelivery: getOrderValue("cancel_delivery"),
ChangeDeliveryStatus: getOrderValue("change_delivery_status"),
UpdateLogisticInfoFailed: getOrderValue("update_logistic_info_failed"),
ORNotUpdateStatus: getOrderValue("outbound_request_not_update_status"),
GetSupplierOrders: getOrderValue("get_supplier_orders"),
}

15
subject/supplier_role.go Normal file
View File

@ -0,0 +1,15 @@
package subject
import "fmt"
func getRoleValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.SupplierRole, val)
}
var SupplierRole = struct {
Create string
Update string
}{
Create: getRoleValue("create"),
Update: getRoleValue("update"),
}

View File

@ -2,18 +2,24 @@ package subject
import "fmt"
func getAuthSMSValue(val string) string {
func getSupplierUserValue(val string) string {
return fmt.Sprintf("%s.%s", prefixes.SupplierUser, val)
}
var SupplierUser = struct {
CreateSupplierOwnerUser string
UpdateSupplierOwnerUser string
CreateSupplierStaffUser string
UpdateSupplierStaffUser string
// Users
CreateOwner string
UpdateOwner string
CreateStaff string
UpdateStaff string
UpdateStatus string
ResetPassword string
}{
CreateSupplierOwnerUser: getAuthSMSValue("create_supplier_owner_user"),
UpdateSupplierOwnerUser: getAuthSMSValue("update_supplier_owner_user"),
CreateSupplierStaffUser: getAuthSMSValue("create_supplier_staff_user"),
UpdateSupplierStaffUser: getAuthSMSValue("update_supplier_staff_user"),
// Users
CreateOwner: getSupplierUserValue("create_owner"),
UpdateOwner: getSupplierUserValue("update_owner"),
CreateStaff: getSupplierUserValue("create_staff"),
UpdateStaff: getSupplierUserValue("update_staff"),
UpdateStatus: getSupplierUserValue("update_status"),
ResetPassword: getSupplierUserValue("reset_password"),
}

View File

@ -9,37 +9,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
FindOne string
FindByCondition string
Distinct string
Count string
AfterUpdateWarehouse string
AfterCreateWarehouse string
UpdateIsClosedSupplier string
GetWarehouses 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"),
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"),
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"),
}