重构: 手续费改为百分比/固定二选一,清理旧 Skin/Order/ShipLog 演示链路
手续费: - 新增 fee_type 字段(rate/fixed),百分比与固定金额二选一,不再叠加 - calculateServiceFee 按 fee_type 分支计算 - 商户创建/更新校验 fee_type,订单落库快照 fee_type - 前端表单改为下拉选择手续费类型,动态显示对应输入框 - 测试拆为 TestFeeRate + TestFeeFixed 清理旧链路: - 删除旧 Skin/Order/ShipLog 模型及 OrderService/SkinService - Dashboard 迁移到 FulfillmentService - 上游 /api/open/v1 改为基于 FulfillmentOrder 实现,接口契约不变 - 推送留痕改用 AuditLog,不再建 ShipLog 表 - 删除前端 Skins/Orders/ShipLogs/Distributors 页面及路由、菜单、API、类型 - 新增迁移 003: 添加 fee_type 列并 DROP 旧表
This commit is contained in:
@@ -330,25 +330,39 @@ func (h *MerchantHandler) ListPlatformMerchants(c *gin.Context) {
|
||||
}
|
||||
|
||||
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"`
|
||||
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、owner_user_id 必填")
|
||||
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,
|
||||
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())
|
||||
@@ -357,6 +371,40 @@ func (h *MerchantHandler) CreateMerchant(c *gin.Context) {
|
||||
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 {
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// OpenHandler 皮肤源头开放接口
|
||||
// OpenHandler 皮肤源头开放接口(上游 SourceOpen),基于 FulfillmentOrder 履约模型。
|
||||
type OpenHandler struct {
|
||||
orderSvc *service.OrderService
|
||||
fulfillmentSvc *service.FulfillmentService
|
||||
}
|
||||
|
||||
func NewOpenHandler(orderSvc *service.OrderService) *OpenHandler {
|
||||
return &OpenHandler{orderSvc: orderSvc}
|
||||
func NewOpenHandler(fulfillmentSvc *service.FulfillmentService) *OpenHandler {
|
||||
return &OpenHandler{fulfillmentSvc: fulfillmentSvc}
|
||||
}
|
||||
|
||||
// QueryOrder GET /api/open/v1/orders/:order_no
|
||||
@@ -29,7 +29,7 @@ func (h *OpenHandler) QueryOrder(c *gin.Context) {
|
||||
}
|
||||
openlog.Info(c, "query_order start order_no=%s", orderNo)
|
||||
|
||||
data, err := h.orderSvc.QueryOpenOrder(orderNo)
|
||||
data, err := h.fulfillmentSvc.QueryOpenOrder(orderNo)
|
||||
if err != nil {
|
||||
openlog.Warn(c, "query_order fail order_no=%s err=%s", orderNo, err.Error())
|
||||
if err.Error() == "订单不存在" {
|
||||
@@ -90,7 +90,7 @@ func (h *OpenHandler) ShipNotify(c *gin.Context) {
|
||||
shippedAt = &t
|
||||
}
|
||||
|
||||
result, err := h.orderSvc.HandleShipNotify(service.ShipNotifyInput{
|
||||
result, err := h.fulfillmentSvc.HandleShipNotify(service.ShipNotifyInput{
|
||||
OrderNo: req.OrderNo,
|
||||
ShipStatus: req.ShipStatus,
|
||||
ProviderOrderNo: req.ProviderOrderNo,
|
||||
|
||||
@@ -202,6 +202,9 @@ func buildOpenOrderResponse(order *model.FulfillmentOrder) gin.H {
|
||||
"name": order.ProductName,
|
||||
},
|
||||
"quantity": order.Quantity,
|
||||
"base_amount": order.BaseAmount,
|
||||
"fee_type": order.FeeType,
|
||||
"service_fee_amount": order.ServiceFeeAmount,
|
||||
"amount": order.Amount,
|
||||
"currency": order.Currency,
|
||||
"buyer_reference": order.BuyerReference,
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"affiliate_dash/internal/middleware"
|
||||
"affiliate_dash/internal/model"
|
||||
"affiliate_dash/internal/pkg/response"
|
||||
@@ -11,126 +9,20 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type OrderHandler struct {
|
||||
svc *service.OrderService
|
||||
// DashboardHandler 仪表盘统计接口。
|
||||
type DashboardHandler struct {
|
||||
svc *service.FulfillmentService
|
||||
}
|
||||
|
||||
func NewOrderHandler(svc *service.OrderService) *OrderHandler {
|
||||
return &OrderHandler{svc: svc}
|
||||
func NewDashboardHandler(svc *service.FulfillmentService) *DashboardHandler {
|
||||
return &DashboardHandler{svc: svc}
|
||||
}
|
||||
|
||||
func (h *OrderHandler) List(c *gin.Context) {
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
|
||||
q := service.OrderListQuery{
|
||||
MerchantID: middleware.GetMerchantID(c),
|
||||
Page: page,
|
||||
Size: size,
|
||||
Status: c.Query("status"),
|
||||
}
|
||||
// 分销商只能看自己的订单
|
||||
if middleware.GetRole(c) == model.RoleDistributor {
|
||||
id := middleware.GetUserID(c)
|
||||
q.DistributorID = &id
|
||||
} else if d := c.Query("distributor_id"); d != "" {
|
||||
id, _ := strconv.ParseUint(d, 10, 64)
|
||||
uid := uint(id)
|
||||
q.DistributorID = &uid
|
||||
}
|
||||
list, total, err := h.svc.List(q)
|
||||
if err != nil {
|
||||
response.ServerError(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.Page(c, list, total, page, size)
|
||||
}
|
||||
|
||||
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"` // 管理员可指定分销商
|
||||
}
|
||||
|
||||
func (h *OrderHandler) Create(c *gin.Context) {
|
||||
var req createOrderReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.BadRequest(c, "参数错误:请选择商品")
|
||||
return
|
||||
}
|
||||
distributorID := middleware.GetUserID(c)
|
||||
status := ""
|
||||
// 管理员可指定分销商、任意初始状态(方便联调)
|
||||
if middleware.GetRole(c) == model.RoleAdmin {
|
||||
if req.DistributorID != nil && *req.DistributorID > 0 {
|
||||
distributorID = *req.DistributorID
|
||||
}
|
||||
if d := c.Query("distributor_id"); d != "" {
|
||||
id, _ := strconv.ParseUint(d, 10, 64)
|
||||
distributorID = uint(id)
|
||||
}
|
||||
status = req.Status
|
||||
}
|
||||
if req.BuyerName == "" {
|
||||
req.BuyerName = "测试买家"
|
||||
}
|
||||
order, err := h.svc.Create(service.CreateOrderInput{
|
||||
MerchantID: middleware.GetMerchantID(c),
|
||||
SkinID: req.SkinID,
|
||||
DistributorID: distributorID,
|
||||
BuyerName: req.BuyerName,
|
||||
Remark: req.Remark,
|
||||
Status: status,
|
||||
})
|
||||
if err != nil {
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, order)
|
||||
}
|
||||
|
||||
type orderStatusReq struct {
|
||||
Status string `json:"status" binding:"required"`
|
||||
}
|
||||
|
||||
func (h *OrderHandler) UpdateStatus(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
var req orderStatusReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.BadRequest(c, "参数错误")
|
||||
return
|
||||
}
|
||||
if err := h.svc.UpdateStatus(middleware.GetMerchantID(c), uint(id), req.Status); err != nil {
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, nil)
|
||||
}
|
||||
|
||||
func (h *OrderHandler) Dashboard(c *gin.Context) {
|
||||
stats, err := h.svc.Dashboard(middleware.GetMerchantID(c))
|
||||
func (h *DashboardHandler) Dashboard(c *gin.Context) {
|
||||
stats, err := h.svc.Dashboard(middleware.GetMerchantID(c), middleware.GetRole(c) == model.RoleAdmin)
|
||||
if err != nil {
|
||||
response.ServerError(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, stats)
|
||||
}
|
||||
|
||||
// ListShipLogs 发货推送记录(管理端)
|
||||
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"),
|
||||
ShipStatus: c.Query("ship_status"),
|
||||
})
|
||||
if err != nil {
|
||||
response.ServerError(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.Page(c, list, total, page, size)
|
||||
}
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"affiliate_dash/internal/middleware"
|
||||
"affiliate_dash/internal/model"
|
||||
"affiliate_dash/internal/pkg/response"
|
||||
"affiliate_dash/internal/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type SkinHandler struct {
|
||||
svc *service.SkinService
|
||||
}
|
||||
|
||||
func NewSkinHandler(svc *service.SkinService) *SkinHandler {
|
||||
return &SkinHandler{svc: svc}
|
||||
}
|
||||
|
||||
func (h *SkinHandler) List(c *gin.Context) {
|
||||
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
size, _ := strconv.Atoi(c.DefaultQuery("size", "20"))
|
||||
q := service.SkinListQuery{
|
||||
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)
|
||||
q.Status = &v
|
||||
}
|
||||
list, total, err := h.svc.List(q)
|
||||
if err != nil {
|
||||
response.ServerError(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.Page(c, list, total, page, size)
|
||||
}
|
||||
|
||||
func (h *SkinHandler) Get(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
skin, err := h.svc.Get(middleware.GetMerchantID(c), uint(id))
|
||||
if err != nil {
|
||||
response.NotFound(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, skin)
|
||||
}
|
||||
|
||||
type skinCreateReq struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
SKU string `json:"sku" binding:"required"`
|
||||
Game string `json:"game"`
|
||||
Category string `json:"category"`
|
||||
CoverURL string `json:"cover_url"`
|
||||
Price float64 `json:"price"`
|
||||
CostPrice float64 `json:"cost_price"`
|
||||
Commission float64 `json:"commission"`
|
||||
Stock int `json:"stock"`
|
||||
Status int `json:"status"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func (h *SkinHandler) Create(c *gin.Context) {
|
||||
var req skinCreateReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.BadRequest(c, "参数错误:名称与 sku 必填")
|
||||
return
|
||||
}
|
||||
status := req.Status
|
||||
if status != 1 {
|
||||
// 未传或非 1 时:创建默认上架;若传 0 仍默认上架(下架请创建后更新)
|
||||
status = 1
|
||||
}
|
||||
if req.Game == "" {
|
||||
req.Game = "和平精英"
|
||||
}
|
||||
skin := &model.Skin{
|
||||
MerchantID: middleware.GetMerchantID(c),
|
||||
Name: req.Name,
|
||||
SKU: req.SKU,
|
||||
Game: req.Game,
|
||||
Category: req.Category,
|
||||
CoverURL: req.CoverURL,
|
||||
Price: req.Price,
|
||||
CostPrice: req.CostPrice,
|
||||
Commission: req.Commission,
|
||||
Stock: req.Stock,
|
||||
Status: status,
|
||||
Description: req.Description,
|
||||
}
|
||||
if err := h.svc.Create(skin); err != nil {
|
||||
response.ServerError(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, skin)
|
||||
}
|
||||
|
||||
func (h *SkinHandler) Update(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
var updates map[string]interface{}
|
||||
if err := c.ShouldBindJSON(&updates); err != nil {
|
||||
response.BadRequest(c, "参数错误")
|
||||
return
|
||||
}
|
||||
delete(updates, "id")
|
||||
delete(updates, "created_at")
|
||||
delete(updates, "updated_at")
|
||||
if err := h.svc.Update(middleware.GetMerchantID(c), uint(id), updates); err != nil {
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, nil)
|
||||
}
|
||||
|
||||
func (h *SkinHandler) Delete(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err := h.svc.Delete(middleware.GetMerchantID(c), uint(id)); err != nil {
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, nil)
|
||||
}
|
||||
@@ -45,7 +45,6 @@ type createUserReq struct {
|
||||
Password string `json:"password" binding:"required,min=6"`
|
||||
Nickname string `json:"nickname"`
|
||||
Role string `json:"role"`
|
||||
ParentID *uint `json:"parent_id"`
|
||||
}
|
||||
|
||||
func (h *UserHandler) Create(c *gin.Context) {
|
||||
@@ -54,7 +53,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, middleware.GetMerchantID(c))
|
||||
user, err := h.svc.Create(req.Username, req.Password, req.Nickname, req.Role, middleware.GetMerchantID(c))
|
||||
if err != nil {
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user