纯文件级移动,无行为变更: - 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。
97 lines
2.7 KiB
Go
97 lines
2.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"affiliate_dash/internal/middleware"
|
|
"affiliate_dash/internal/pkg/response"
|
|
"affiliate_dash/internal/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
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)
|
|
referenceNo := c.Query("reference_no")
|
|
entryType := c.Query("type")
|
|
list, total, err := h.fulfillmentSvc.ListWalletLedger(middleware.GetMerchantID(c), page, size, referenceNo, entryType)
|
|
if err != nil {
|
|
response.ServerError(c, err.Error())
|
|
return
|
|
}
|
|
response.Page(c, list, total, page, size)
|
|
}
|
|
|
|
// AdminGetWallet 供平台管理员查看指定商户的钱包。
|
|
func (h *MerchantHandler) AdminGetWallet(c *gin.Context) {
|
|
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if id == 0 {
|
|
response.BadRequest(c, "商户 ID 无效")
|
|
return
|
|
}
|
|
wallet, err := h.fulfillmentSvc.GetWallet(uint(id))
|
|
if err != nil {
|
|
response.ServerError(c, err.Error())
|
|
return
|
|
}
|
|
response.OK(c, wallet)
|
|
}
|
|
|
|
// AdminListWalletLedger 供平台管理员查看指定商户的积分流水。
|
|
func (h *MerchantHandler) AdminListWalletLedger(c *gin.Context) {
|
|
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if id == 0 {
|
|
response.BadRequest(c, "商户 ID 无效")
|
|
return
|
|
}
|
|
page, size := pageParams(c)
|
|
list, total, err := h.fulfillmentSvc.ListWalletLedger(uint(id), page, size, c.Query("reference_no"), c.Query("type"))
|
|
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"`
|
|
}
|
|
|
|
// AdminAdjustWallet 供平台管理员手动调整指定商户的积分,商户侧无任何调账入口。
|
|
func (h *MerchantHandler) AdminAdjustWallet(c *gin.Context) {
|
|
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if id == 0 {
|
|
response.BadRequest(c, "商户 ID 无效")
|
|
return
|
|
}
|
|
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: uint(id),
|
|
ActorUserID: middleware.GetUserID(c),
|
|
Amount: req.Amount,
|
|
IdempotencyKey: req.IdempotencyKey,
|
|
Note: req.Note,
|
|
})
|
|
if err != nil {
|
|
response.BadRequest(c, err.Error())
|
|
return
|
|
}
|
|
h.rechargeSvc.CheckLowBalanceAndNotify(uint(id))
|
|
response.OK(c, wallet)
|
|
}
|