纯文件级移动,无行为变更: - 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。
170 lines
5.2 KiB
Go
170 lines
5.2 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) 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"`
|
|
OwnerUsername string `json:"owner_username"`
|
|
OwnerPassword string `json:"owner_password"`
|
|
OwnerNickname string `json:"owner_nickname"`
|
|
Features string `json:"features"`
|
|
FeeType string `json:"fee_type"`
|
|
FeeRateBP int64 `json:"fee_rate_bp"`
|
|
FeeFixedAmount int64 `json:"fee_fixed_amount"`
|
|
}
|
|
|
|
func (h *MerchantHandler) CreateMerchant(c *gin.Context) {
|
|
var req createMerchantReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.BadRequest(c, "参数错误:code、name 必填")
|
|
return
|
|
}
|
|
merchant, err := h.merchantSvc.CreateMerchant(service.CreateMerchantInput{
|
|
Code: req.Code,
|
|
Name: req.Name,
|
|
ContactName: req.ContactName,
|
|
ContactInfo: req.ContactInfo,
|
|
OwnerUserID: req.OwnerUserID,
|
|
OwnerUsername: req.OwnerUsername,
|
|
OwnerPassword: req.OwnerPassword,
|
|
OwnerNickname: req.OwnerNickname,
|
|
Features: req.Features,
|
|
FeeType: req.FeeType,
|
|
FeeRateBP: req.FeeRateBP,
|
|
FeeFixedAmount: req.FeeFixedAmount,
|
|
}, middleware.GetUserID(c))
|
|
if err != nil {
|
|
response.BadRequest(c, err.Error())
|
|
return
|
|
}
|
|
response.OK(c, merchant)
|
|
}
|
|
|
|
type updateMerchantSettingsReq struct {
|
|
Name *string `json:"name"`
|
|
Status *string `json:"status"`
|
|
ContactName *string `json:"contact_name"`
|
|
ContactInfo *string `json:"contact_info"`
|
|
Features *string `json:"features"`
|
|
FeeType *string `json:"fee_type"`
|
|
FeeRateBP *int64 `json:"fee_rate_bp"`
|
|
FeeFixedAmount *int64 `json:"fee_fixed_amount"`
|
|
}
|
|
|
|
func (h *MerchantHandler) UpdateMerchantSettings(c *gin.Context) {
|
|
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
var req updateMerchantSettingsReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.BadRequest(c, "参数错误")
|
|
return
|
|
}
|
|
if err := h.merchantSvc.UpdateMerchantSettings(uint(id), service.UpdateMerchantSettingsInput{
|
|
Name: req.Name,
|
|
Status: req.Status,
|
|
ContactName: req.ContactName,
|
|
ContactInfo: req.ContactInfo,
|
|
Features: req.Features,
|
|
FeeType: req.FeeType,
|
|
FeeRateBP: req.FeeRateBP,
|
|
FeeFixedAmount: req.FeeFixedAmount,
|
|
}, middleware.GetUserID(c)); err != nil {
|
|
response.BadRequest(c, err.Error())
|
|
return
|
|
}
|
|
response.OK(c, nil)
|
|
}
|
|
|
|
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,
|
|
Username: req.Username,
|
|
Password: req.Password,
|
|
Nickname: req.Nickname,
|
|
Role: req.Role,
|
|
IsDefault: req.IsDefault,
|
|
}, middleware.GetUserID(c))
|
|
if err != nil {
|
|
response.BadRequest(c, err.Error())
|
|
return
|
|
}
|
|
response.OK(c, member)
|
|
}
|
|
|
|
// AdminGetMerchantAccount 平台管理员查看指定商户的负责人登录账号。
|
|
func (h *MerchantHandler) AdminGetMerchantAccount(c *gin.Context) {
|
|
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if id == 0 {
|
|
response.BadRequest(c, "商户 ID 无效")
|
|
return
|
|
}
|
|
accounts, err := h.merchantSvc.ListOwnerAccounts(uint(id))
|
|
if err != nil {
|
|
response.ServerError(c, err.Error())
|
|
return
|
|
}
|
|
response.OK(c, accounts)
|
|
}
|
|
|
|
type adminUpdateMerchantAccountReq struct {
|
|
UserID uint `json:"user_id" binding:"required"`
|
|
Username string `json:"username" binding:"required,min=3,max=64"`
|
|
Nickname string `json:"nickname" binding:"max=64"`
|
|
Password string `json:"password" binding:"omitempty,min=6,max=128"`
|
|
Status *int `json:"status"`
|
|
}
|
|
|
|
// AdminUpdateMerchantAccount 平台管理员维护指定商户的负责人登录账号:
|
|
// 修改用户名/昵称、重置密码、启用停用;密码留空表示不重置。
|
|
func (h *MerchantHandler) AdminUpdateMerchantAccount(c *gin.Context) {
|
|
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
var req adminUpdateMerchantAccountReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.BadRequest(c, "参数错误:用户名必填(3-64 位),密码至少 6 位")
|
|
return
|
|
}
|
|
if id == 0 {
|
|
response.BadRequest(c, "商户 ID 无效")
|
|
return
|
|
}
|
|
account, err := h.merchantSvc.UpdateMerchantOwnerAccount(uint(id), service.UpdateMerchantOwnerAccountInput{
|
|
UserID: req.UserID,
|
|
Username: req.Username,
|
|
Nickname: req.Nickname,
|
|
Password: req.Password,
|
|
Status: req.Status,
|
|
}, middleware.GetUserID(c))
|
|
if err != nil {
|
|
response.BadRequest(c, err.Error())
|
|
return
|
|
}
|
|
response.OK(c, account)
|
|
}
|