手续费: - 新增 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 旧表
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package middleware
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"affiliate_dash/internal/model"
|
|
"affiliate_dash/internal/pkg/response"
|
|
"affiliate_dash/internal/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// RequireMerchantFeature 校验当前商户是否开通指定功能。
|
|
func RequireMerchantFeature(db *gorm.DB, features ...string) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
merchantID := GetMerchantID(c)
|
|
if merchantID == 0 {
|
|
response.Forbidden(c, "当前请求未绑定商户")
|
|
c.Abort()
|
|
return
|
|
}
|
|
var merchant model.Merchant
|
|
if err := db.Select("id", "status", "features").First(&merchant, merchantID).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
response.Forbidden(c, "商户不存在")
|
|
} else {
|
|
response.ServerError(c, err.Error())
|
|
}
|
|
c.Abort()
|
|
return
|
|
}
|
|
if merchant.Status != model.MerchantStatusActive {
|
|
response.Forbidden(c, "商户已禁用")
|
|
c.Abort()
|
|
return
|
|
}
|
|
if !service.MerchantHasFeature(merchant.Features, features...) {
|
|
response.Forbidden(c, "商户功能未开通")
|
|
c.Abort()
|
|
return
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|