feat: 代理商资金可见性重构(agent-fund-visibility)
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m10s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m10s
- 将 GET /shops/commission-summary 重命名为 GET /shops/fund-summary, 响应新增 main_balance、main_frozen_balance 两个预充值钱包字段 - 新增 GET /shops/:id/main-wallet/transactions 预充值钱包流水接口 - 将佣金统计、每日统计、发起提现从 /my/ 路径迁移至 /shops/:id/ 路径: GET /shops/:id/commission-stats GET /shops/:id/commission-daily-stats POST /shops/:id/withdrawal-requests - 删除 MyCommissionService、MyCommissionHandler 及全部 /my/ 路由 - 补齐 ListShopWithdrawalRequests、ListShopCommissionRecords 的 CanManageShop 越权校验(安全修复) - 提现接口增加严格权限:仅代理账号本人可为自己店铺发起提现 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
myCommissionService "github.com/break/junhong_cmp_fiber/internal/service/my_commission"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type MyCommissionHandler struct {
|
||||
service *myCommissionService.Service
|
||||
}
|
||||
|
||||
func NewMyCommissionHandler(service *myCommissionService.Service) *MyCommissionHandler {
|
||||
return &MyCommissionHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *MyCommissionHandler) GetSummary(c *fiber.Ctx) error {
|
||||
result, err := h.service.GetCommissionSummary(c.UserContext())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
func (h *MyCommissionHandler) CreateWithdrawal(c *fiber.Ctx) error {
|
||||
var req dto.CreateMyWithdrawalReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.CreateWithdrawalRequest(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
func (h *MyCommissionHandler) ListWithdrawals(c *fiber.Ctx) error {
|
||||
var req dto.MyWithdrawalListReq
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.ListMyWithdrawalRequests(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, result.Items, result.Total, result.Page, result.Size)
|
||||
}
|
||||
|
||||
func (h *MyCommissionHandler) ListRecords(c *fiber.Ctx) error {
|
||||
var req dto.MyCommissionRecordListReq
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.ListMyCommissionRecords(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, result.Items, result.Total, result.Page, result.Size)
|
||||
}
|
||||
|
||||
func (h *MyCommissionHandler) GetStats(c *fiber.Ctx) error {
|
||||
var req dto.CommissionStatsRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.GetStats(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
func (h *MyCommissionHandler) GetDailyStats(c *fiber.Ctx) error {
|
||||
var req dto.DailyCommissionStatsRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.GetDailyStats(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
@@ -11,21 +11,25 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
// ShopCommissionHandler 代理商资金管理 Handler
|
||||
type ShopCommissionHandler struct {
|
||||
service *shopCommissionService.Service
|
||||
}
|
||||
|
||||
// NewShopCommissionHandler 创建代理商资金管理 Handler
|
||||
func NewShopCommissionHandler(service *shopCommissionService.Service) *ShopCommissionHandler {
|
||||
return &ShopCommissionHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *ShopCommissionHandler) ListCommissionSummary(c *fiber.Ctx) error {
|
||||
var req dto.ShopCommissionSummaryListReq
|
||||
// ListFundSummary 代理商资金概况列表
|
||||
// GET /api/admin/shops/fund-summary
|
||||
func (h *ShopCommissionHandler) ListFundSummary(c *fiber.Ctx) error {
|
||||
var req dto.ShopFundSummaryListReq
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
return errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
|
||||
result, err := h.service.ListShopCommissionSummary(c.UserContext(), &req)
|
||||
result, err := h.service.ListShopFundSummary(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -33,6 +37,8 @@ func (h *ShopCommissionHandler) ListCommissionSummary(c *fiber.Ctx) error {
|
||||
return response.SuccessWithPagination(c, result.Items, result.Total, result.Page, result.Size)
|
||||
}
|
||||
|
||||
// ListWithdrawalRequests 代理商提现记录列表
|
||||
// GET /api/admin/shops/:shop_id/withdrawal-requests
|
||||
func (h *ShopCommissionHandler) ListWithdrawalRequests(c *fiber.Ctx) error {
|
||||
shopID, err := strconv.ParseUint(c.Params("shop_id"), 10, 64)
|
||||
if err != nil {
|
||||
@@ -41,7 +47,7 @@ func (h *ShopCommissionHandler) ListWithdrawalRequests(c *fiber.Ctx) error {
|
||||
|
||||
var req dto.ShopWithdrawalRequestListReq
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
return errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
|
||||
result, err := h.service.ListShopWithdrawalRequests(c.UserContext(), uint(shopID), &req)
|
||||
@@ -52,6 +58,8 @@ func (h *ShopCommissionHandler) ListWithdrawalRequests(c *fiber.Ctx) error {
|
||||
return response.SuccessWithPagination(c, result.Items, result.Total, result.Page, result.Size)
|
||||
}
|
||||
|
||||
// ListCommissionRecords 代理商佣金明细列表
|
||||
// GET /api/admin/shops/:shop_id/commission-records
|
||||
func (h *ShopCommissionHandler) ListCommissionRecords(c *fiber.Ctx) error {
|
||||
shopID, err := strconv.ParseUint(c.Params("shop_id"), 10, 64)
|
||||
if err != nil {
|
||||
@@ -60,7 +68,7 @@ func (h *ShopCommissionHandler) ListCommissionRecords(c *fiber.Ctx) error {
|
||||
|
||||
var req dto.ShopCommissionRecordListReq
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
return errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
|
||||
result, err := h.service.ListShopCommissionRecords(c.UserContext(), uint(shopID), &req)
|
||||
@@ -90,3 +98,87 @@ func (h *ShopCommissionHandler) ResolveCommissionRecord(c *fiber.Ctx) error {
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
|
||||
// GetCommissionStats 代理商佣金统计
|
||||
// GET /api/admin/shops/:shop_id/commission-stats
|
||||
func (h *ShopCommissionHandler) GetCommissionStats(c *fiber.Ctx) error {
|
||||
shopID, err := strconv.ParseUint(c.Params("shop_id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺 ID")
|
||||
}
|
||||
|
||||
var req dto.CommissionStatsRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
|
||||
result, err := h.service.GetStats(c.UserContext(), uint(shopID), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// GetCommissionDailyStats 代理商每日佣金统计
|
||||
// GET /api/admin/shops/:shop_id/commission-daily-stats
|
||||
func (h *ShopCommissionHandler) GetCommissionDailyStats(c *fiber.Ctx) error {
|
||||
shopID, err := strconv.ParseUint(c.Params("shop_id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺 ID")
|
||||
}
|
||||
|
||||
var req dto.DailyCommissionStatsRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
|
||||
result, err := h.service.GetDailyStats(c.UserContext(), uint(shopID), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// CreateWithdrawal 发起提现申请
|
||||
// POST /api/admin/shops/:shop_id/withdrawal-requests
|
||||
func (h *ShopCommissionHandler) CreateWithdrawal(c *fiber.Ctx) error {
|
||||
shopID, err := strconv.ParseUint(c.Params("shop_id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺 ID")
|
||||
}
|
||||
|
||||
var req dto.CreateMyWithdrawalReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
|
||||
result, err := h.service.CreateWithdrawalRequest(c.UserContext(), uint(shopID), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
// ListMainWalletTransactions 预充值钱包流水列表
|
||||
// GET /api/admin/shops/:shop_id/main-wallet/transactions
|
||||
func (h *ShopCommissionHandler) ListMainWalletTransactions(c *fiber.Ctx) error {
|
||||
shopID, err := strconv.ParseUint(c.Params("shop_id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺 ID")
|
||||
}
|
||||
|
||||
var req dto.MainWalletTransactionListRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
|
||||
result, err := h.service.ListMainWalletTransactions(c.UserContext(), uint(shopID), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, result.Items, result.Total, result.Page, result.Size)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user