纯文件级移动,无行为变更: - merchant.go 结构体、构造函数与跨域共用辅助(mapKeys/pageParams) - merchant_product.go 商品目录与分配 - merchant_order.go 订单、人工/测试下单与发货链接 - merchant_wallet.go 钱包、积分流水与管理员调账 - merchant_api_client.go API 客户端与回调订阅 - merchant_member.go 成员与角色 - merchant_platform.go 平台侧租户管理 校验:与 HEAD 的声明行 diff 为空,MerchantHandler 方法数 41 → 41。
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package handler
|
|
|
|
import (
|
|
"sort"
|
|
"strconv"
|
|
|
|
"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
|
|
deliverySvc *service.DeliveryService
|
|
rechargeSvc *service.RechargeService
|
|
}
|
|
|
|
func NewMerchantHandler(merchantSvc *service.MerchantService, fulfillmentSvc *service.FulfillmentService, callbackSvc *service.CallbackService, deliverySvc *service.DeliveryService, rechargeSvc *service.RechargeService) *MerchantHandler {
|
|
return &MerchantHandler{
|
|
merchantSvc: merchantSvc,
|
|
fulfillmentSvc: fulfillmentSvc,
|
|
callbackSvc: callbackSvc,
|
|
deliverySvc: deliverySvc,
|
|
rechargeSvc: rechargeSvc,
|
|
}
|
|
}
|
|
|
|
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),
|
|
"permissions": mapKeys(middleware.GetMerchantPermissions(c)),
|
|
})
|
|
}
|
|
|
|
func mapKeys(values map[string]struct{}) []string {
|
|
keys := make([]string, 0, len(values))
|
|
for key := range values {
|
|
keys = append(keys, key)
|
|
}
|
|
sort.Strings(keys)
|
|
return keys
|
|
}
|
|
|
|
func pageParams(c *gin.Context) (int, int) {
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
|
|
return page, size
|
|
}
|