From 23be0a7d3edd0a41ef6fd2a9258334adead766fa Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 21 Jan 2026 18:42:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20OpenAPI=20=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=8F=82=E6=95=B0=20path=20=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E5=AF=BC=E8=87=B4=E5=90=AF=E5=8A=A8=20panic?= =?UTF-8?q?=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为 enterprise_card_authorization_dto.go 中的 DTO 添加 path 标签 - 为 customer_account_dto.go 中的 DTO 添加 path 标签并重构结构 - 为 enterprise_dto.go 中的 DTO 添加 path 标签并重构结构 - 更新 handler 和 service 层使用正确的请求体类型 --- internal/handler/admin/customer_account.go | 6 ++--- internal/handler/admin/enterprise.go | 6 ++--- internal/model/commission_withdrawal_dto.go | 2 ++ internal/model/customer_account_dto.go | 24 ++++++++++++++++--- .../enterprise_card_authorization_dto.go | 16 +++++++++++++ internal/model/enterprise_dto.go | 23 ++++++++++++++---- internal/model/shop_commission_dto.go | 2 ++ internal/routes/enterprise_card.go | 4 ++-- internal/service/customer_account/service.go | 2 +- 9 files changed, 69 insertions(+), 16 deletions(-) diff --git a/internal/handler/admin/customer_account.go b/internal/handler/admin/customer_account.go index 98f9a6e..5c9ea81 100644 --- a/internal/handler/admin/customer_account.go +++ b/internal/handler/admin/customer_account.go @@ -54,7 +54,7 @@ func (h *CustomerAccountHandler) Update(c *fiber.Ctx) error { return errors.New(errors.CodeInvalidParam, "无效的账号ID") } - var req model.UpdateCustomerAccountReq + var req model.UpdateCustomerAccountRequest if err := c.BodyParser(&req); err != nil { return errors.New(errors.CodeInvalidParam, "请求参数解析失败") } @@ -74,7 +74,7 @@ func (h *CustomerAccountHandler) UpdatePassword(c *fiber.Ctx) error { return errors.New(errors.CodeInvalidParam, "无效的账号ID") } - var req model.UpdateCustomerAccountPasswordReq + var req model.UpdateCustomerAccountPasswordRequest if err := c.BodyParser(&req); err != nil { return errors.New(errors.CodeInvalidParam, "请求参数解析失败") } @@ -93,7 +93,7 @@ func (h *CustomerAccountHandler) UpdateStatus(c *fiber.Ctx) error { return errors.New(errors.CodeInvalidParam, "无效的账号ID") } - var req model.UpdateCustomerAccountStatusReq + var req model.UpdateCustomerAccountStatusRequest if err := c.BodyParser(&req); err != nil { return errors.New(errors.CodeInvalidParam, "请求参数解析失败") } diff --git a/internal/handler/admin/enterprise.go b/internal/handler/admin/enterprise.go index 016189f..f1650e9 100644 --- a/internal/handler/admin/enterprise.go +++ b/internal/handler/admin/enterprise.go @@ -54,7 +54,7 @@ func (h *EnterpriseHandler) Update(c *fiber.Ctx) error { return errors.New(errors.CodeInvalidParam, "无效的企业ID") } - var req model.UpdateEnterpriseReq + var req model.UpdateEnterpriseBody if err := c.BodyParser(&req); err != nil { return errors.New(errors.CodeInvalidParam, "请求参数解析失败") } @@ -74,7 +74,7 @@ func (h *EnterpriseHandler) UpdateStatus(c *fiber.Ctx) error { return errors.New(errors.CodeInvalidParam, "无效的企业ID") } - var req model.UpdateEnterpriseStatusReq + var req model.UpdateEnterpriseStatusBody if err := c.BodyParser(&req); err != nil { return errors.New(errors.CodeInvalidParam, "请求参数解析失败") } @@ -93,7 +93,7 @@ func (h *EnterpriseHandler) UpdatePassword(c *fiber.Ctx) error { return errors.New(errors.CodeInvalidParam, "无效的企业ID") } - var req model.UpdateEnterprisePasswordReq + var req model.UpdateEnterprisePasswordBody if err := c.BodyParser(&req); err != nil { return errors.New(errors.CodeInvalidParam, "请求参数解析失败") } diff --git a/internal/model/commission_withdrawal_dto.go b/internal/model/commission_withdrawal_dto.go index baa9c53..d9bf906 100644 --- a/internal/model/commission_withdrawal_dto.go +++ b/internal/model/commission_withdrawal_dto.go @@ -49,6 +49,7 @@ type WithdrawalRequestPageResult struct { // ApproveWithdrawalReq 审批通过提现申请请求 type ApproveWithdrawalReq struct { + ID uint `json:"-" params:"id" path:"id" validate:"required" description:"提现申请ID"` PaymentType string `json:"payment_type" validate:"required,oneof=manual" required:"true" description:"放款类型(目前只支持manual人工打款)"` Amount *int64 `json:"amount" validate:"omitempty,min=1" minimum:"1" description:"修正后的提现金额(分),不填则使用原金额"` WithdrawalMethod *string `json:"withdrawal_method" validate:"omitempty,oneof=alipay wechat bank" description:"修正后的收款类型 (alipay:支付宝, wechat:微信, bank:银行卡)"` @@ -59,6 +60,7 @@ type ApproveWithdrawalReq struct { // RejectWithdrawalReq 拒绝提现申请请求 type RejectWithdrawalReq struct { + ID uint `json:"-" params:"id" path:"id" validate:"required" description:"提现申请ID"` Remark string `json:"remark" validate:"required,max=500" required:"true" maxLength:"500" description:"拒绝原因(必填)"` } diff --git a/internal/model/customer_account_dto.go b/internal/model/customer_account_dto.go index 199d0f6..4f51b71 100644 --- a/internal/model/customer_account_dto.go +++ b/internal/model/customer_account_dto.go @@ -40,15 +40,33 @@ type CreateCustomerAccountReq struct { ShopID uint `json:"shop_id" validate:"required" required:"true" description:"店铺ID"` } -type UpdateCustomerAccountReq struct { +type UpdateCustomerAccountRequest struct { Username *string `json:"username" validate:"omitempty,min=2,max=50" minimum:"2" maximum:"50" description:"用户名"` Phone *string `json:"phone" validate:"omitempty,len=11" description:"手机号"` } -type UpdateCustomerAccountPasswordReq struct { +// UpdateCustomerAccountReq 更新客户账号请求(用于文档生成,包含路径参数) +type UpdateCustomerAccountReq struct { + IDReq + UpdateCustomerAccountRequest +} + +type UpdateCustomerAccountPasswordRequest struct { Password string `json:"password" validate:"required,min=6,max=20" required:"true" minimum:"6" maximum:"20" description:"新密码"` } -type UpdateCustomerAccountStatusReq struct { +// UpdateCustomerAccountPasswordReq 修改客户账号密码请求(用于文档生成,包含路径参数) +type UpdateCustomerAccountPasswordReq struct { + IDReq + UpdateCustomerAccountPasswordRequest +} + +type UpdateCustomerAccountStatusRequest struct { Status int `json:"status" validate:"required,oneof=0 1" required:"true" enum:"0,1" description:"状态(0=禁用, 1=启用)"` } + +// UpdateCustomerAccountStatusReq 修改客户账号状态请求(用于文档生成,包含路径参数) +type UpdateCustomerAccountStatusReq struct { + IDReq + UpdateCustomerAccountStatusRequest +} diff --git a/internal/model/enterprise_card_authorization_dto.go b/internal/model/enterprise_card_authorization_dto.go index 3fedaf9..bdecbb3 100644 --- a/internal/model/enterprise_card_authorization_dto.go +++ b/internal/model/enterprise_card_authorization_dto.go @@ -1,6 +1,7 @@ package model type AllocateCardsPreviewReq struct { + ID uint `json:"-" params:"id" path:"id" validate:"required" required:"true" description:"企业ID"` ICCIDs []string `json:"iccids" validate:"required,min=1,max=1000,dive,required" required:"true" description:"需要授权的 ICCID 列表(最多1000个)"` } @@ -46,6 +47,7 @@ type AllocateCardsPreviewResp struct { } type AllocateCardsReq struct { + ID uint `json:"-" params:"id" path:"id" validate:"required" required:"true" description:"企业ID"` ICCIDs []string `json:"iccids" validate:"required,min=1,max=1000,dive,required" required:"true" description:"需要授权的 ICCID 列表"` ConfirmDeviceBundles bool `json:"confirm_device_bundles" description:"确认整体授权设备下所有卡"` } @@ -65,6 +67,7 @@ type AllocateCardsResp struct { } type RecallCardsReq struct { + ID uint `json:"-" params:"id" path:"id" validate:"required" required:"true" description:"企业ID"` ICCIDs []string `json:"iccids" validate:"required,min=1,max=1000,dive,required" required:"true" description:"需要回收授权的 ICCID 列表"` } @@ -83,6 +86,7 @@ type RecallCardsResp struct { } type EnterpriseCardListReq struct { + ID uint `json:"-" params:"id" path:"id" validate:"required" required:"true" description:"企业ID"` Page int `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码"` PageSize int `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量"` Status *int `json:"status" query:"status" description:"卡状态"` @@ -113,3 +117,15 @@ type EnterpriseCardPageResult struct { Page int `json:"page" description:"当前页码"` Size int `json:"size" description:"每页数量"` } + +// SuspendCardReq 停机卡请求 +type SuspendCardReq struct { + ID uint `json:"-" params:"id" path:"id" validate:"required" required:"true" description:"企业ID"` + CardID uint `json:"-" params:"card_id" path:"card_id" validate:"required" required:"true" description:"卡ID"` +} + +// ResumeCardReq 复机卡请求 +type ResumeCardReq struct { + ID uint `json:"-" params:"id" path:"id" validate:"required" required:"true" description:"企业ID"` + CardID uint `json:"-" params:"card_id" path:"card_id" validate:"required" required:"true" description:"卡ID"` +} diff --git a/internal/model/enterprise_dto.go b/internal/model/enterprise_dto.go index 21d571a..b7a7b7b 100644 --- a/internal/model/enterprise_dto.go +++ b/internal/model/enterprise_dto.go @@ -16,7 +16,7 @@ type CreateEnterpriseReq struct { Address string `json:"address" validate:"max=255" maximum:"255" description:"详细地址"` } -type UpdateEnterpriseReq struct { +type UpdateEnterpriseBody struct { OwnerShopID *uint `json:"owner_shop_id" description:"归属店铺ID"` EnterpriseName *string `json:"enterprise_name" validate:"omitempty,max=100" maximum:"100" description:"企业名称"` EnterpriseCode *string `json:"enterprise_code" validate:"omitempty,max=50" maximum:"50" description:"企业编号"` @@ -30,6 +30,11 @@ type UpdateEnterpriseReq struct { Address *string `json:"address" validate:"omitempty,max=255" maximum:"255" description:"详细地址"` } +type UpdateEnterpriseReq struct { + IDReq + UpdateEnterpriseBody +} + type EnterpriseListReq struct { Page int `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码(默认1)"` PageSize int `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量(默认20,最大100)"` @@ -67,14 +72,24 @@ type EnterprisePageResult struct { Size int `json:"size" description:"每页数量"` } -type UpdateEnterpriseStatusReq struct { +type UpdateEnterpriseStatusBody struct { Status int `json:"status" validate:"required,oneof=0 1" required:"true" enum:"0,1" description:"状态(0=禁用, 1=启用)"` } -type UpdateEnterprisePasswordReq struct { +type UpdateEnterpriseStatusReq struct { + IDReq + UpdateEnterpriseStatusBody +} + +type UpdateEnterprisePasswordBody struct { Password string `json:"password" validate:"required,min=6,max=20" required:"true" minimum:"6" maximum:"20" description:"新密码"` } +type UpdateEnterprisePasswordReq struct { + IDReq + UpdateEnterprisePasswordBody +} + type CreateEnterpriseResp struct { Enterprise EnterpriseItem `json:"enterprise" description:"企业信息"` AccountID uint `json:"account_id" description:"账号ID"` @@ -84,7 +99,7 @@ type CreateEnterpriseResp struct { type CreateEnterpriseRequest = CreateEnterpriseReq // UpdateEnterpriseRequest 更新企业请求(兼容旧接口) -type UpdateEnterpriseRequest = UpdateEnterpriseReq +type UpdateEnterpriseRequest = UpdateEnterpriseBody // EnterpriseResponse 企业响应(兼容旧接口) type EnterpriseResponse = EnterpriseItem diff --git a/internal/model/shop_commission_dto.go b/internal/model/shop_commission_dto.go index 0a1be69..08acfd0 100644 --- a/internal/model/shop_commission_dto.go +++ b/internal/model/shop_commission_dto.go @@ -42,6 +42,7 @@ type ShopCommissionSummaryPageResult struct { // ShopWithdrawalRequestListReq 代理商提现记录查询请求 type ShopWithdrawalRequestListReq struct { + ShopID uint `json:"-" params:"shop_id" path:"shop_id" validate:"required" description:"店铺ID"` Page int `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码(默认1)"` PageSize int `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量(默认20,最大100)"` WithdrawalNo string `json:"withdrawal_no" query:"withdrawal_no" validate:"omitempty,max=50" maxLength:"50" description:"提现单号(精确查询)"` @@ -92,6 +93,7 @@ type ShopWithdrawalRequestPageResult struct { // ShopCommissionRecordListReq 代理商佣金明细查询请求 type ShopCommissionRecordListReq struct { + ShopID uint `json:"-" params:"shop_id" path:"shop_id" validate:"required" description:"店铺ID"` Page int `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码(默认1)"` PageSize int `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量(默认20,最大100)"` CommissionType string `json:"commission_type" query:"commission_type" validate:"omitempty,oneof=one_time long_term" description:"佣金类型 (one_time:一次性, long_term:长期)"` diff --git a/internal/routes/enterprise_card.go b/internal/routes/enterprise_card.go index 6cff0c8..2c8206c 100644 --- a/internal/routes/enterprise_card.go +++ b/internal/routes/enterprise_card.go @@ -47,7 +47,7 @@ func registerEnterpriseCardRoutes(router fiber.Router, handler *admin.Enterprise Register(enterprises, doc, groupPath, "POST", "/:id/cards/:card_id/suspend", handler.SuspendCard, RouteSpec{ Summary: "停机卡", Tags: []string{"企业卡授权"}, - Input: nil, + Input: new(model.SuspendCardReq), Output: nil, Auth: true, }) @@ -55,7 +55,7 @@ func registerEnterpriseCardRoutes(router fiber.Router, handler *admin.Enterprise Register(enterprises, doc, groupPath, "POST", "/:id/cards/:card_id/resume", handler.ResumeCard, RouteSpec{ Summary: "复机卡", Tags: []string{"企业卡授权"}, - Input: nil, + Input: new(model.ResumeCardReq), Output: nil, Auth: true, }) diff --git a/internal/service/customer_account/service.go b/internal/service/customer_account/service.go index a6b85b1..f3efc51 100644 --- a/internal/service/customer_account/service.go +++ b/internal/service/customer_account/service.go @@ -196,7 +196,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateCustomerAccountRe }, nil } -func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateCustomerAccountReq) (*model.CustomerAccountItem, error) { +func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateCustomerAccountRequest) (*model.CustomerAccountItem, error) { currentUserID := middleware.GetUserIDFromContext(ctx) if currentUserID == 0 { return nil, errors.New(errors.CodeUnauthorized, "未授权访问")