实现多商户履约平台基础

This commit is contained in:
yml2213
2026-07-30 12:02:32 +08:00
parent dde6f2c269
commit 83429456a6
41 changed files with 5487 additions and 504 deletions
+383
View File
@@ -0,0 +1,383 @@
package handler
import (
"strconv"
"time"
"affiliate_dash/internal/middleware"
"affiliate_dash/internal/pkg/response"
"affiliate_dash/internal/service"
"github.com/gin-gonic/gin"
)
// MerchantHandler 提供商户后台与平台管理员的多租户管理能力。
type MerchantHandler struct {
merchantSvc *service.MerchantService
fulfillmentSvc *service.FulfillmentService
callbackSvc *service.CallbackService
}
func NewMerchantHandler(merchantSvc *service.MerchantService, fulfillmentSvc *service.FulfillmentService, callbackSvc *service.CallbackService) *MerchantHandler {
return &MerchantHandler{
merchantSvc: merchantSvc,
fulfillmentSvc: fulfillmentSvc,
callbackSvc: callbackSvc,
}
}
func (h *MerchantHandler) Current(c *gin.Context) {
merchant, err := h.merchantSvc.GetMerchant(middleware.GetMerchantID(c))
if err != nil {
response.NotFound(c, err.Error())
return
}
response.OK(c, gin.H{
"merchant": merchant,
"role": middleware.GetMerchantRole(c),
})
}
func (h *MerchantHandler) ListProducts(c *gin.Context) {
page, size := pageParams(c)
list, total, err := h.merchantSvc.ListMerchantProducts(middleware.GetMerchantID(c), page, size, false)
if err != nil {
response.ServerError(c, err.Error())
return
}
response.Page(c, list, total, page, size)
}
type merchantProductReq struct {
ProductCode string `json:"product_code"`
ProductName string `json:"product_name"`
Category string `json:"category"`
Description string `json:"description"`
Attributes string `json:"attributes"`
SKU string `json:"sku" binding:"required"`
DisplayName string `json:"display_name"`
PriceAmount int64 `json:"price_amount"`
CostAmount int64 `json:"cost_amount"`
Currency string `json:"currency"`
Stock int64 `json:"stock"`
Status string `json:"status"`
FulfillmentConfig string `json:"fulfillment_config"`
}
func (h *MerchantHandler) CreateProduct(c *gin.Context) {
var req merchantProductReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误:sku 必填")
return
}
product, err := h.merchantSvc.CreateMerchantProduct(middleware.GetMerchantID(c), service.CreateMerchantProductInput{
ProductCode: req.ProductCode,
ProductName: req.ProductName,
Category: req.Category,
Description: req.Description,
Attributes: req.Attributes,
SKU: req.SKU,
DisplayName: req.DisplayName,
PriceAmount: req.PriceAmount,
CostAmount: req.CostAmount,
Currency: req.Currency,
Stock: req.Stock,
Status: req.Status,
FulfillmentConfig: req.FulfillmentConfig,
}, middleware.GetUserID(c))
if err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, product)
}
type merchantProductUpdateReq struct {
DisplayName *string `json:"display_name"`
PriceAmount *int64 `json:"price_amount"`
CostAmount *int64 `json:"cost_amount"`
Stock *int64 `json:"stock"`
Status *string `json:"status"`
FulfillmentConfig *string `json:"fulfillment_config"`
}
func (h *MerchantHandler) UpdateProduct(c *gin.Context) {
var req merchantProductUpdateReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误")
return
}
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
if err := h.merchantSvc.UpdateMerchantProduct(middleware.GetMerchantID(c), uint(id), service.UpdateMerchantProductInput{
DisplayName: req.DisplayName,
PriceAmount: req.PriceAmount,
CostAmount: req.CostAmount,
Stock: req.Stock,
Status: req.Status,
FulfillmentConfig: req.FulfillmentConfig,
}, middleware.GetUserID(c)); err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, nil)
}
func (h *MerchantHandler) ListOrders(c *gin.Context) {
page, size := pageParams(c)
list, total, err := h.fulfillmentSvc.ListOrders(middleware.GetMerchantID(c), page, size, c.Query("fulfillment_status"))
if err != nil {
response.ServerError(c, err.Error())
return
}
response.Page(c, list, total, page, size)
}
func (h *MerchantHandler) GetWallet(c *gin.Context) {
wallet, err := h.fulfillmentSvc.GetWallet(middleware.GetMerchantID(c))
if err != nil {
response.ServerError(c, err.Error())
return
}
response.OK(c, wallet)
}
func (h *MerchantHandler) ListWalletLedger(c *gin.Context) {
page, size := pageParams(c)
list, total, err := h.fulfillmentSvc.ListWalletLedger(middleware.GetMerchantID(c), page, size)
if err != nil {
response.ServerError(c, err.Error())
return
}
response.Page(c, list, total, page, size)
}
type walletAdjustReq struct {
Amount int64 `json:"amount" binding:"required"`
IdempotencyKey string `json:"idempotency_key" binding:"required"`
Note string `json:"note"`
}
func (h *MerchantHandler) AdjustWallet(c *gin.Context) {
var req walletAdjustReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误:amount 与 idempotency_key 必填")
return
}
wallet, err := h.fulfillmentSvc.AdjustWallet(service.WalletAdjustInput{
MerchantID: middleware.GetMerchantID(c),
ActorUserID: middleware.GetUserID(c),
Amount: req.Amount,
IdempotencyKey: req.IdempotencyKey,
Note: req.Note,
})
if err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, wallet)
}
func (h *MerchantHandler) ListAPIClients(c *gin.Context) {
clients, err := h.merchantSvc.ListAPIClients(middleware.GetMerchantID(c))
if err != nil {
response.ServerError(c, err.Error())
return
}
response.OK(c, clients)
}
type apiClientReq struct {
Name string `json:"name" binding:"required"`
Scopes string `json:"scopes" binding:"required"`
SignatureVersion string `json:"signature_version"`
ExpiresAt string `json:"expires_at"`
}
func (h *MerchantHandler) CreateAPIClient(c *gin.Context) {
var req apiClientReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误:name 与 scopes 必填")
return
}
var expiresAt *time.Time
if req.ExpiresAt != "" {
value, err := time.Parse(time.RFC3339, req.ExpiresAt)
if err != nil {
response.BadRequest(c, "expires_at 必须是 RFC3339 时间")
return
}
expiresAt = &value
}
credential, err := h.merchantSvc.CreateAPIClient(middleware.GetMerchantID(c), service.CreateAPIClientInput{
Name: req.Name,
Scopes: req.Scopes,
SignatureVersion: req.SignatureVersion,
ExpiresAt: expiresAt,
}, middleware.GetUserID(c))
if err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, credential)
}
type statusReq struct {
Status string `json:"status" binding:"required"`
}
func (h *MerchantHandler) UpdateAPIClientStatus(c *gin.Context) {
var req statusReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误")
return
}
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
if err := h.merchantSvc.UpdateAPIClientStatus(middleware.GetMerchantID(c), uint(id), req.Status, middleware.GetUserID(c)); err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, nil)
}
func (h *MerchantHandler) ListCallbacks(c *gin.Context) {
list, err := h.callbackSvc.ListSubscriptions(middleware.GetMerchantID(c))
if err != nil {
response.ServerError(c, err.Error())
return
}
response.OK(c, list)
}
type callbackReq struct {
Name string `json:"name" binding:"required"`
URL string `json:"url" binding:"required"`
Events string `json:"events" binding:"required"`
}
func (h *MerchantHandler) CreateCallback(c *gin.Context) {
var req callbackReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误:name、url、events 必填")
return
}
credential, err := h.callbackSvc.CreateSubscription(middleware.GetMerchantID(c), service.CreateCallbackInput{
Name: req.Name,
URL: req.URL,
Events: req.Events,
}, middleware.GetUserID(c))
if err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, credential)
}
func (h *MerchantHandler) UpdateCallbackStatus(c *gin.Context) {
var req statusReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误")
return
}
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
if err := h.callbackSvc.UpdateSubscriptionStatus(middleware.GetMerchantID(c), uint(id), req.Status, middleware.GetUserID(c)); err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, nil)
}
func (h *MerchantHandler) ListMembers(c *gin.Context) {
members, err := h.merchantSvc.ListMembers(middleware.GetMerchantID(c))
if err != nil {
response.ServerError(c, err.Error())
return
}
response.OK(c, members)
}
type addMemberReq struct {
UserID uint `json:"user_id" binding:"required"`
Role string `json:"role" binding:"required"`
IsDefault bool `json:"is_default"`
}
func (h *MerchantHandler) AddCurrentMerchantMember(c *gin.Context) {
var req addMemberReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误:user_id 与 role 必填")
return
}
member, err := h.merchantSvc.AddMember(middleware.GetMerchantID(c), service.AddMemberInput{
UserID: req.UserID,
Role: req.Role,
IsDefault: req.IsDefault,
}, middleware.GetUserID(c))
if err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, member)
}
func (h *MerchantHandler) ListPlatformMerchants(c *gin.Context) {
page, size := pageParams(c)
list, total, err := h.merchantSvc.ListMerchants(page, size)
if err != nil {
response.ServerError(c, err.Error())
return
}
response.Page(c, list, total, page, size)
}
type createMerchantReq struct {
Code string `json:"code" binding:"required"`
Name string `json:"name" binding:"required"`
ContactName string `json:"contact_name"`
ContactInfo string `json:"contact_info"`
OwnerUserID uint `json:"owner_user_id" binding:"required"`
}
func (h *MerchantHandler) CreateMerchant(c *gin.Context) {
var req createMerchantReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误:code、name、owner_user_id 必填")
return
}
merchant, err := h.merchantSvc.CreateMerchant(service.CreateMerchantInput{
Code: req.Code,
Name: req.Name,
ContactName: req.ContactName,
ContactInfo: req.ContactInfo,
OwnerUserID: req.OwnerUserID,
}, middleware.GetUserID(c))
if err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, merchant)
}
func (h *MerchantHandler) AddPlatformMerchantMember(c *gin.Context) {
var req addMemberReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误:user_id 与 role 必填")
return
}
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
member, err := h.merchantSvc.AddMember(uint(id), service.AddMemberInput{
UserID: req.UserID,
Role: req.Role,
IsDefault: req.IsDefault,
}, middleware.GetUserID(c))
if err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, member)
}
func pageParams(c *gin.Context) (int, int) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
return page, size
}
+221
View File
@@ -0,0 +1,221 @@
package handler
import (
"encoding/json"
"net/http"
"strconv"
"affiliate_dash/internal/middleware"
"affiliate_dash/internal/model"
"affiliate_dash/internal/pkg/response"
"affiliate_dash/internal/service"
"github.com/gin-gonic/gin"
)
// OpenV1Handler 提供面向商户系统和履约器的通用开放接口。
type OpenV1Handler struct {
merchantSvc *service.MerchantService
fulfillmentSvc *service.FulfillmentService
}
func NewOpenV1Handler(merchantSvc *service.MerchantService, fulfillmentSvc *service.FulfillmentService) *OpenV1Handler {
return &OpenV1Handler{merchantSvc: merchantSvc, fulfillmentSvc: fulfillmentSvc}
}
func (h *OpenV1Handler) ListProducts(c *gin.Context) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
list, total, err := h.merchantSvc.ListMerchantProducts(middleware.GetMerchantID(c), page, size, true)
if err != nil {
response.ServerError(c, err.Error())
return
}
response.Page(c, list, total, page, size)
}
type openCreateOrderReq struct {
ClientOrderNo string `json:"client_order_no" binding:"required"`
SKU string `json:"sku" binding:"required"`
Quantity int64 `json:"quantity"`
BuyerReference string `json:"buyer_reference"`
Data json.RawMessage `json:"data"`
}
func (h *OpenV1Handler) CreateOrder(c *gin.Context) {
var req openCreateOrderReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误:client_order_no 与 sku 必填")
return
}
if key := c.GetHeader("Idempotency-Key"); key != "" && key != req.ClientOrderNo {
response.BadRequest(c, "Idempotency-Key 必须与 client_order_no 一致")
return
}
var data interface{}
if len(req.Data) > 0 {
var decoded interface{}
if err := json.Unmarshal(req.Data, &decoded); err != nil {
response.BadRequest(c, "data 必须是有效 JSON")
return
}
data = decoded
}
client := middleware.GetAPIClient(c)
result, err := h.fulfillmentSvc.CreateOrder(service.CreateFulfillmentOrderInput{
MerchantID: middleware.GetMerchantID(c),
APIClientID: client.ID,
ClientOrderNo: req.ClientOrderNo,
SKU: req.SKU,
Quantity: req.Quantity,
BuyerReference: req.BuyerReference,
RequestData: data,
})
if err != nil {
response.BadRequest(c, err.Error())
return
}
status := http.StatusOK
if !result.Idempotent {
status = http.StatusCreated
}
c.JSON(status, response.Body{
Code: 0,
Message: "ok",
Data: gin.H{
"order": buildOpenOrderResponse(result.Order),
"idempotent": result.Idempotent,
},
})
}
func (h *OpenV1Handler) QueryOrder(c *gin.Context) {
order, err := h.fulfillmentSvc.GetOrder(middleware.GetMerchantID(c), c.Param("order_no"))
if err != nil {
if err.Error() == "订单不存在" {
response.NotFound(c, err.Error())
return
}
response.ServerError(c, err.Error())
return
}
response.OK(c, buildOpenOrderResponse(order))
}
type openCancelOrderReq struct {
Reason string `json:"reason"`
}
func (h *OpenV1Handler) CancelOrder(c *gin.Context) {
var req openCancelOrderReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误")
return
}
client := middleware.GetAPIClient(c)
order, err := h.fulfillmentSvc.CancelOrder(middleware.GetMerchantID(c), client.ID, c.Param("order_no"), req.Reason)
if err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, buildOpenOrderResponse(order))
}
type openShipNotifyReq struct {
OrderNo string `json:"order_no"`
ShipStatus string `json:"ship_status" binding:"required"`
ProviderOrderNo string `json:"provider_order_no"`
FailReason string `json:"fail_reason"`
Result json.RawMessage `json:"result"`
}
func (h *OpenV1Handler) ShipNotify(c *gin.Context) {
var req openShipNotifyReq
if err := c.ShouldBindJSON(&req); err != nil {
response.BadRequest(c, "参数错误:ship_status 必填")
return
}
status := ""
switch req.ShipStatus {
case "processing":
status = model.FulfillmentStatusProcessing
case "success":
status = model.FulfillmentStatusSucceeded
case "failed":
status = model.FulfillmentStatusFailed
default:
response.BadRequest(c, "ship_status 仅支持 processing、success、failed")
return
}
var result interface{}
if len(req.Result) > 0 {
if err := json.Unmarshal(req.Result, &result); err != nil {
response.BadRequest(c, "result 必须是有效 JSON")
return
}
}
client := middleware.GetAPIClient(c)
orderNo := c.Param("order_no")
if orderNo == "" {
orderNo = req.OrderNo
}
if orderNo == "" {
response.BadRequest(c, "order_no 必填")
return
}
order, err := h.fulfillmentSvc.UpdateFulfillment(service.FulfillmentUpdateInput{
MerchantID: middleware.GetMerchantID(c),
APIClientID: client.ID,
OrderNo: orderNo,
Status: status,
ProviderOrderNo: req.ProviderOrderNo,
FailureReason: req.FailReason,
ResultData: result,
})
if err != nil {
response.BadRequest(c, err.Error())
return
}
response.OK(c, buildOpenOrderResponse(order))
}
func (h *OpenV1Handler) GetWallet(c *gin.Context) {
wallet, err := h.fulfillmentSvc.GetWallet(middleware.GetMerchantID(c))
if err != nil {
response.ServerError(c, err.Error())
return
}
response.OK(c, wallet)
}
func buildOpenOrderResponse(order *model.FulfillmentOrder) gin.H {
canFulfill, reason := service.CanFulfill(order)
data := gin.H{
"order_no": order.OrderNo,
"client_order_no": order.ClientOrderNo,
"payment_status": order.PaymentStatus,
"fulfillment_status": order.FulfillmentStatus,
"can_fulfill": canFulfill,
"cannot_fulfill_reason": reason,
"product": gin.H{
"sku": order.ProductSKU,
"name": order.ProductName,
},
"quantity": order.Quantity,
"amount": order.Amount,
"currency": order.Currency,
"buyer_reference": order.BuyerReference,
"provider_order_no": order.ProviderOrderNo,
"failure_reason": order.FailureReason,
"created_at": order.CreatedAt,
"delivered_at": order.DeliveredAt,
"cancelled_at": order.CancelledAt,
}
if json.Valid([]byte(order.RequestData)) {
data["data"] = json.RawMessage(order.RequestData)
}
if json.Valid([]byte(order.ResultData)) {
data["result"] = json.RawMessage(order.ResultData)
}
return data
}
+13 -10
View File
@@ -23,9 +23,10 @@ func (h *OrderHandler) List(c *gin.Context) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
q := service.OrderListQuery{
Page: page,
Size: size,
Status: c.Query("status"),
MerchantID: middleware.GetMerchantID(c),
Page: page,
Size: size,
Status: c.Query("status"),
}
// 分销商只能看自己的订单
if middleware.GetRole(c) == model.RoleDistributor {
@@ -45,11 +46,11 @@ func (h *OrderHandler) List(c *gin.Context) {
}
type createOrderReq struct {
SkinID uint `json:"skin_id" binding:"required"`
BuyerName string `json:"buyer_name"`
Remark string `json:"remark"`
Status string `json:"status"` // 管理员可指定初始状态(联调造异常单)
DistributorID *uint `json:"distributor_id"` // 管理员可指定分销商
SkinID uint `json:"skin_id" binding:"required"`
BuyerName string `json:"buyer_name"`
Remark string `json:"remark"`
Status string `json:"status"` // 管理员可指定初始状态(联调造异常单)
DistributorID *uint `json:"distributor_id"` // 管理员可指定分销商
}
func (h *OrderHandler) Create(c *gin.Context) {
@@ -75,6 +76,7 @@ func (h *OrderHandler) Create(c *gin.Context) {
req.BuyerName = "测试买家"
}
order, err := h.svc.Create(service.CreateOrderInput{
MerchantID: middleware.GetMerchantID(c),
SkinID: req.SkinID,
DistributorID: distributorID,
BuyerName: req.BuyerName,
@@ -99,7 +101,7 @@ func (h *OrderHandler) UpdateStatus(c *gin.Context) {
response.BadRequest(c, "参数错误")
return
}
if err := h.svc.UpdateStatus(uint(id), req.Status); err != nil {
if err := h.svc.UpdateStatus(middleware.GetMerchantID(c), uint(id), req.Status); err != nil {
response.BadRequest(c, err.Error())
return
}
@@ -107,7 +109,7 @@ func (h *OrderHandler) UpdateStatus(c *gin.Context) {
}
func (h *OrderHandler) Dashboard(c *gin.Context) {
stats, err := h.svc.Dashboard()
stats, err := h.svc.Dashboard(middleware.GetMerchantID(c))
if err != nil {
response.ServerError(c, err.Error())
return
@@ -120,6 +122,7 @@ func (h *OrderHandler) ListShipLogs(c *gin.Context) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
list, total, err := h.svc.ListShipLogs(service.ShipLogListQuery{
MerchantID: middleware.GetMerchantID(c),
Page: page,
Size: size,
OrderNo: c.Query("order_no"),
+11 -8
View File
@@ -3,6 +3,7 @@ package handler
import (
"strconv"
"affiliate_dash/internal/middleware"
"affiliate_dash/internal/model"
"affiliate_dash/internal/pkg/response"
"affiliate_dash/internal/service"
@@ -22,11 +23,12 @@ func (h *SkinHandler) List(c *gin.Context) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
q := service.SkinListQuery{
Page: page,
Size: size,
Keyword: c.Query("keyword"),
Game: c.Query("game"),
Category: c.Query("category"),
MerchantID: middleware.GetMerchantID(c),
Page: page,
Size: size,
Keyword: c.Query("keyword"),
Game: c.Query("game"),
Category: c.Query("category"),
}
if s := c.Query("status"); s != "" {
v, _ := strconv.Atoi(s)
@@ -42,7 +44,7 @@ func (h *SkinHandler) List(c *gin.Context) {
func (h *SkinHandler) Get(c *gin.Context) {
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
skin, err := h.svc.Get(uint(id))
skin, err := h.svc.Get(middleware.GetMerchantID(c), uint(id))
if err != nil {
response.NotFound(c, err.Error())
return
@@ -79,6 +81,7 @@ func (h *SkinHandler) Create(c *gin.Context) {
req.Game = "和平精英"
}
skin := &model.Skin{
MerchantID: middleware.GetMerchantID(c),
Name: req.Name,
SKU: req.SKU,
Game: req.Game,
@@ -108,7 +111,7 @@ func (h *SkinHandler) Update(c *gin.Context) {
delete(updates, "id")
delete(updates, "created_at")
delete(updates, "updated_at")
if err := h.svc.Update(uint(id), updates); err != nil {
if err := h.svc.Update(middleware.GetMerchantID(c), uint(id), updates); err != nil {
response.BadRequest(c, err.Error())
return
}
@@ -117,7 +120,7 @@ func (h *SkinHandler) Update(c *gin.Context) {
func (h *SkinHandler) Delete(c *gin.Context) {
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
if err := h.svc.Delete(uint(id)); err != nil {
if err := h.svc.Delete(middleware.GetMerchantID(c), uint(id)); err != nil {
response.BadRequest(c, err.Error())
return
}
+7 -5
View File
@@ -3,6 +3,7 @@ package handler
import (
"strconv"
"affiliate_dash/internal/middleware"
"affiliate_dash/internal/pkg/response"
"affiliate_dash/internal/service"
@@ -21,10 +22,11 @@ func (h *UserHandler) List(c *gin.Context) {
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
q := service.UserListQuery{
Page: page,
Size: size,
Keyword: c.Query("keyword"),
Role: c.Query("role"),
MerchantID: middleware.GetMerchantID(c),
Page: page,
Size: size,
Keyword: c.Query("keyword"),
Role: c.Query("role"),
}
if s := c.Query("status"); s != "" {
v, _ := strconv.Atoi(s)
@@ -52,7 +54,7 @@ func (h *UserHandler) Create(c *gin.Context) {
response.BadRequest(c, "参数错误")
return
}
user, err := h.svc.Create(req.Username, req.Password, req.Nickname, req.Role, req.ParentID)
user, err := h.svc.Create(req.Username, req.Password, req.Nickname, req.Role, req.ParentID, middleware.GetMerchantID(c))
if err != nil {
response.BadRequest(c, err.Error())
return