重构: 手续费改为百分比/固定二选一,清理旧 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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user