refactor: 将 DTO 文件从 internal/model 移动到 internal/model/dto 目录
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m22s

- 移动 17 个 DTO 文件到 internal/model/dto/ 目录
- 更新所有 DTO 文件的 package 声明从 model 改为 dto
- 更新所有引用文件的 import 和类型引用
  - Handler 层:admin 和 h5 所有处理器
  - Service 层:所有业务服务
  - Routes 层:所有路由定义
  - Tests 层:单元测试和集成测试
- 清理未使用的 import 语句
- 验证:项目构建成功,测试编译通过,LSP 无错误
This commit is contained in:
2026-01-22 10:15:04 +08:00
parent 23be0a7d3e
commit 46e4e5f4f1
73 changed files with 531 additions and 501 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -33,7 +34,7 @@ func New(accountStore *postgres.AccountStore, roleStore *postgres.RoleStore, acc
}
// Create 创建账号
func (s *Service) Create(ctx context.Context, req *model.CreateAccountRequest) (*model.Account, error) {
func (s *Service) Create(ctx context.Context, req *dto.CreateAccountRequest) (*model.Account, error) {
// 获取当前用户 ID
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
@@ -102,7 +103,7 @@ func (s *Service) Get(ctx context.Context, id uint) (*model.Account, error) {
}
// Update 更新账号
func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateAccountRequest) (*model.Account, error) {
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateAccountRequest) (*model.Account, error) {
// 获取当前用户 ID
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
@@ -180,7 +181,7 @@ func (s *Service) Delete(ctx context.Context, id uint) error {
}
// List 查询账号列表
func (s *Service) List(ctx context.Context, req *model.AccountListRequest) ([]*model.Account, int64, error) {
func (s *Service) List(ctx context.Context, req *dto.AccountListRequest) ([]*model.Account, int64, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,
@@ -397,7 +398,7 @@ func (s *Service) UpdateStatus(ctx context.Context, accountID uint, status int)
}
// ListPlatformAccounts 查询平台账号列表(自动筛选 user_type IN (1, 2)
func (s *Service) ListPlatformAccounts(ctx context.Context, req *model.PlatformAccountListRequest) ([]*model.Account, int64, error) {
func (s *Service) ListPlatformAccounts(ctx context.Context, req *dto.PlatformAccountListRequest) ([]*model.Account, int64, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/auth"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -42,7 +43,7 @@ func New(
}
}
func (s *Service) Login(ctx context.Context, req *model.LoginRequest, clientIP string) (*model.LoginResponse, error) {
func (s *Service) Login(ctx context.Context, req *dto.LoginRequest, clientIP string) (*dto.LoginResponse, error) {
ctx = pkgGorm.SkipDataPermission(ctx)
account, err := s.accountStore.GetByUsernameOrPhone(ctx, req.Username)
@@ -107,7 +108,7 @@ func (s *Service) Login(ctx context.Context, req *model.LoginRequest, clientIP s
zap.String("ip", clientIP),
)
return &model.LoginResponse{
return &dto.LoginResponse{
AccessToken: accessToken,
RefreshToken: refreshToken,
ExpiresIn: int64(constants.DefaultAccessTokenTTL.Seconds()),
@@ -134,7 +135,7 @@ func (s *Service) RefreshToken(ctx context.Context, refreshToken string) (string
return s.tokenManager.RefreshAccessToken(ctx, refreshToken)
}
func (s *Service) GetCurrentUser(ctx context.Context, userID uint) (*model.UserInfo, []string, error) {
func (s *Service) GetCurrentUser(ctx context.Context, userID uint) (*dto.UserInfo, []string, error) {
account, err := s.accountStore.GetByID(ctx, userID)
if err != nil {
if err == gorm.ErrRecordNotFound {
@@ -222,7 +223,7 @@ func (s *Service) getUserPermissions(ctx context.Context, userID uint) ([]string
return permCodes, nil
}
func (s *Service) buildUserInfo(account *model.Account) model.UserInfo {
func (s *Service) buildUserInfo(account *model.Account) dto.UserInfo {
userTypeName := s.getUserTypeName(account.UserType)
var shopID, enterpriseID uint
@@ -233,7 +234,7 @@ func (s *Service) buildUserInfo(account *model.Account) model.UserInfo {
enterpriseID = *account.EnterpriseID
}
return model.UserInfo{
return dto.UserInfo{
ID: account.ID,
Username: account.Username,
Phone: account.Phone,

View File

@@ -7,6 +7,7 @@ import (
"time"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -42,7 +43,7 @@ func New(
}
}
func (s *Service) ListWithdrawalRequests(ctx context.Context, req *model.WithdrawalRequestListReq) (*model.WithdrawalRequestPageResult, error) {
func (s *Service) ListWithdrawalRequests(ctx context.Context, req *dto.WithdrawalRequestListReq) (*dto.WithdrawalRequestPageResult, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,
@@ -116,7 +117,7 @@ func (s *Service) ListWithdrawalRequests(ctx context.Context, req *model.Withdra
}
}
items := make([]model.WithdrawalRequestItem, 0, len(requests))
items := make([]dto.WithdrawalRequestItem, 0, len(requests))
for _, r := range requests {
shop := shopMap[r.ShopID]
shopName := ""
@@ -134,7 +135,7 @@ func (s *Service) ListWithdrawalRequests(ctx context.Context, req *model.Withdra
items = append(items, item)
}
return &model.WithdrawalRequestPageResult{
return &dto.WithdrawalRequestPageResult{
Items: items,
Total: total,
Page: opts.Page,
@@ -142,7 +143,7 @@ func (s *Service) ListWithdrawalRequests(ctx context.Context, req *model.Withdra
}, nil
}
func (s *Service) Approve(ctx context.Context, id uint, req *model.ApproveWithdrawalReq) (*model.WithdrawalApprovalResp, error) {
func (s *Service) Approve(ctx context.Context, id uint, req *dto.ApproveWithdrawalReq) (*dto.WithdrawalApprovalResp, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -241,7 +242,7 @@ func (s *Service) Approve(ctx context.Context, id uint, req *model.ApproveWithdr
return nil, err
}
return &model.WithdrawalApprovalResp{
return &dto.WithdrawalApprovalResp{
ID: withdrawal.ID,
WithdrawalNo: withdrawal.WithdrawalNo,
Status: constants.WithdrawalStatusApproved,
@@ -250,7 +251,7 @@ func (s *Service) Approve(ctx context.Context, id uint, req *model.ApproveWithdr
}, nil
}
func (s *Service) Reject(ctx context.Context, id uint, req *model.RejectWithdrawalReq) (*model.WithdrawalApprovalResp, error) {
func (s *Service) Reject(ctx context.Context, id uint, req *dto.RejectWithdrawalReq) (*dto.WithdrawalApprovalResp, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -312,7 +313,7 @@ func (s *Service) Reject(ctx context.Context, id uint, req *model.RejectWithdraw
return nil, err
}
return &model.WithdrawalApprovalResp{
return &dto.WithdrawalApprovalResp{
ID: withdrawal.ID,
WithdrawalNo: withdrawal.WithdrawalNo,
Status: constants.WithdrawalStatusRejected,
@@ -340,7 +341,7 @@ func (s *Service) buildShopHierarchyPath(ctx context.Context, shop *model.Shop)
return path
}
func (s *Service) buildWithdrawalRequestItem(r *model.CommissionWithdrawalRequest, shopName, shopHierarchy string, applicantMap, processorMap map[uint]string) model.WithdrawalRequestItem {
func (s *Service) buildWithdrawalRequestItem(r *model.CommissionWithdrawalRequest, shopName, shopHierarchy string, applicantMap, processorMap map[uint]string) dto.WithdrawalRequestItem {
var processorID *uint
if r.ProcessorID > 0 {
processorID = &r.ProcessorID
@@ -367,7 +368,7 @@ func (s *Service) buildWithdrawalRequestItem(r *model.CommissionWithdrawalReques
processedAt = r.ProcessedAt.Format("2006-01-02 15:04:05")
}
return model.WithdrawalRequestItem{
return dto.WithdrawalRequestItem{
ID: r.ID,
WithdrawalNo: r.WithdrawalNo,
Amount: r.Amount,

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -31,7 +32,7 @@ func New(
}
}
func (s *Service) Create(ctx context.Context, req *model.CreateWithdrawalSettingReq) (*model.WithdrawalSettingItem, error) {
func (s *Service) Create(ctx context.Context, req *dto.CreateWithdrawalSettingReq) (*dto.WithdrawalSettingItem, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -65,7 +66,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateWithdrawalSetting
creatorName = creator.Username
}
return &model.WithdrawalSettingItem{
return &dto.WithdrawalSettingItem{
ID: setting.ID,
DailyWithdrawalLimit: setting.DailyWithdrawalLimit,
MinWithdrawalAmount: setting.MinWithdrawalAmount,
@@ -78,7 +79,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateWithdrawalSetting
}, nil
}
func (s *Service) List(ctx context.Context, req *model.WithdrawalSettingListReq) (*model.WithdrawalSettingPageResult, error) {
func (s *Service) List(ctx context.Context, req *dto.WithdrawalSettingListReq) (*dto.WithdrawalSettingPageResult, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,
@@ -110,9 +111,9 @@ func (s *Service) List(ctx context.Context, req *model.WithdrawalSettingListReq)
}
}
items := make([]model.WithdrawalSettingItem, 0, len(settings))
items := make([]dto.WithdrawalSettingItem, 0, len(settings))
for _, setting := range settings {
items = append(items, model.WithdrawalSettingItem{
items = append(items, dto.WithdrawalSettingItem{
ID: setting.ID,
DailyWithdrawalLimit: setting.DailyWithdrawalLimit,
MinWithdrawalAmount: setting.MinWithdrawalAmount,
@@ -125,7 +126,7 @@ func (s *Service) List(ctx context.Context, req *model.WithdrawalSettingListReq)
})
}
return &model.WithdrawalSettingPageResult{
return &dto.WithdrawalSettingPageResult{
Items: items,
Total: total,
Page: opts.Page,
@@ -133,7 +134,7 @@ func (s *Service) List(ctx context.Context, req *model.WithdrawalSettingListReq)
}, nil
}
func (s *Service) GetCurrent(ctx context.Context) (*model.WithdrawalSettingItem, error) {
func (s *Service) GetCurrent(ctx context.Context) (*dto.WithdrawalSettingItem, error) {
setting, err := s.commissionWithdrawalSettingStore.GetCurrent(ctx)
if err != nil {
if err == gorm.ErrRecordNotFound {
@@ -147,7 +148,7 @@ func (s *Service) GetCurrent(ctx context.Context) (*model.WithdrawalSettingItem,
creatorName = creator.Username
}
return &model.WithdrawalSettingItem{
return &dto.WithdrawalSettingItem{
ID: setting.ID,
DailyWithdrawalLimit: setting.DailyWithdrawalLimit,
MinWithdrawalAmount: setting.MinWithdrawalAmount,

View File

@@ -6,6 +6,7 @@ import (
"context"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -25,7 +26,7 @@ func New(customerStore *postgres.PersonalCustomerStore) *Service {
}
// Create 创建个人客户
func (s *Service) Create(ctx context.Context, req *model.CreatePersonalCustomerRequest) (*model.PersonalCustomer, error) {
func (s *Service) Create(ctx context.Context, req *dto.CreatePersonalCustomerRequest) (*model.PersonalCustomer, error) {
// 检查手机号唯一性
if req.Phone != "" {
existing, err := s.customerStore.GetByPhone(ctx, req.Phone)
@@ -55,7 +56,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreatePersonalCustomerR
}
// Update 更新个人客户信息
func (s *Service) Update(ctx context.Context, id uint, req *model.UpdatePersonalCustomerRequest) (*model.PersonalCustomer, error) {
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdatePersonalCustomerRequest) (*model.PersonalCustomer, error) {
// 查询客户
customer, err := s.customerStore.GetByID(ctx, id)
if err != nil {

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
"github.com/break/junhong_cmp_fiber/pkg/errors"
@@ -34,7 +35,7 @@ func New(
}
}
func (s *Service) List(ctx context.Context, req *model.CustomerAccountListReq) (*model.CustomerAccountPageResult, error) {
func (s *Service) List(ctx context.Context, req *dto.CustomerAccountListReq) (*dto.CustomerAccountPageResult, error) {
page := req.Page
pageSize := req.PageSize
if page == 0 {
@@ -106,7 +107,7 @@ func (s *Service) List(ctx context.Context, req *model.CustomerAccountListReq) (
}
}
items := make([]model.CustomerAccountItem, 0, len(accounts))
items := make([]dto.CustomerAccountItem, 0, len(accounts))
for _, acc := range accounts {
shopName := ""
if acc.ShopID != nil {
@@ -116,7 +117,7 @@ func (s *Service) List(ctx context.Context, req *model.CustomerAccountListReq) (
if acc.EnterpriseID != nil {
enterpriseName = enterpriseMap[*acc.EnterpriseID]
}
items = append(items, model.CustomerAccountItem{
items = append(items, dto.CustomerAccountItem{
ID: acc.ID,
Username: acc.Username,
Phone: acc.Phone,
@@ -132,7 +133,7 @@ func (s *Service) List(ctx context.Context, req *model.CustomerAccountListReq) (
})
}
return &model.CustomerAccountPageResult{
return &dto.CustomerAccountPageResult{
Items: items,
Total: total,
Page: page,
@@ -140,7 +141,7 @@ func (s *Service) List(ctx context.Context, req *model.CustomerAccountListReq) (
}, nil
}
func (s *Service) Create(ctx context.Context, req *model.CreateCustomerAccountReq) (*model.CustomerAccountItem, error) {
func (s *Service) Create(ctx context.Context, req *dto.CreateCustomerAccountReq) (*dto.CustomerAccountItem, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -182,7 +183,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateCustomerAccountRe
shopName = shop.ShopName
}
return &model.CustomerAccountItem{
return &dto.CustomerAccountItem{
ID: account.ID,
Username: account.Username,
Phone: account.Phone,
@@ -196,7 +197,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateCustomerAccountRe
}, nil
}
func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateCustomerAccountRequest) (*model.CustomerAccountItem, error) {
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateCustomerAccountRequest) (*dto.CustomerAccountItem, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -242,7 +243,7 @@ func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateCustomer
}
}
return &model.CustomerAccountItem{
return &dto.CustomerAccountItem{
ID: account.ID,
Username: account.Username,
Phone: account.Phone,

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -30,7 +31,7 @@ func New(db *gorm.DB, enterpriseStore *postgres.EnterpriseStore, shopStore *post
}
}
func (s *Service) Create(ctx context.Context, req *model.CreateEnterpriseReq) (*model.CreateEnterpriseResp, error) {
func (s *Service) Create(ctx context.Context, req *dto.CreateEnterpriseReq) (*dto.CreateEnterpriseResp, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -114,8 +115,8 @@ func (s *Service) Create(ctx context.Context, req *model.CreateEnterpriseReq) (*
}
}
return &model.CreateEnterpriseResp{
Enterprise: model.EnterpriseItem{
return &dto.CreateEnterpriseResp{
Enterprise: dto.EnterpriseItem{
ID: enterprise.ID,
EnterpriseName: enterprise.EnterpriseName,
EnterpriseCode: enterprise.EnterpriseCode,
@@ -139,7 +140,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateEnterpriseReq) (*
}
// Update 更新企业信息
func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateEnterpriseRequest) (*model.Enterprise, error) {
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateEnterpriseRequest) (*model.Enterprise, error) {
// 获取当前用户 ID
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
@@ -262,7 +263,7 @@ func (s *Service) GetByID(ctx context.Context, id uint) (*model.Enterprise, erro
return enterprise, nil
}
func (s *Service) List(ctx context.Context, req *model.EnterpriseListReq) (*model.EnterprisePageResult, error) {
func (s *Service) List(ctx context.Context, req *dto.EnterpriseListReq) (*dto.EnterprisePageResult, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,
@@ -322,13 +323,13 @@ func (s *Service) List(ctx context.Context, req *model.EnterpriseListReq) (*mode
}
}
items := make([]model.EnterpriseItem, 0, len(enterprises))
items := make([]dto.EnterpriseItem, 0, len(enterprises))
for _, e := range enterprises {
ownerShopName := ""
if e.OwnerShopID != nil {
ownerShopName = shopMap[*e.OwnerShopID]
}
items = append(items, model.EnterpriseItem{
items = append(items, dto.EnterpriseItem{
ID: e.ID,
EnterpriseName: e.EnterpriseName,
EnterpriseCode: e.EnterpriseCode,
@@ -349,7 +350,7 @@ func (s *Service) List(ctx context.Context, req *model.EnterpriseListReq) (*mode
})
}
return &model.EnterprisePageResult{
return &dto.EnterprisePageResult{
Items: items,
Total: total,
Page: opts.Page,

View File

@@ -6,6 +6,7 @@ import (
"time"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
"github.com/break/junhong_cmp_fiber/pkg/errors"
@@ -31,7 +32,7 @@ func New(
}
}
func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, req *model.AllocateCardsPreviewReq) (*model.AllocateCardsPreviewResp, error) {
func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, req *dto.AllocateCardsPreviewReq) (*dto.AllocateCardsPreviewResp, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -84,10 +85,10 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
}
}
resp := &model.AllocateCardsPreviewResp{
StandaloneCards: make([]model.StandaloneCard, 0),
DeviceBundles: make([]model.DeviceBundle, 0),
FailedItems: make([]model.FailedItem, 0),
resp := &dto.AllocateCardsPreviewResp{
StandaloneCards: make([]dto.StandaloneCard, 0),
DeviceBundles: make([]dto.DeviceBundle, 0),
FailedItems: make([]dto.FailedItem, 0),
}
processedDevices := make(map[uint]bool)
@@ -95,7 +96,7 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
for _, iccid := range req.ICCIDs {
card, exists := cardMap[iccid]
if !exists {
resp.FailedItems = append(resp.FailedItems, model.FailedItem{
resp.FailedItems = append(resp.FailedItems, dto.FailedItem{
ICCID: iccid,
Reason: "卡不存在",
})
@@ -104,7 +105,7 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
deviceID, hasDevice := cardToDevice[card.ID]
if !hasDevice {
resp.StandaloneCards = append(resp.StandaloneCards, model.StandaloneCard{
resp.StandaloneCards = append(resp.StandaloneCards, dto.StandaloneCard{
ICCID: card.ICCID,
IotCardID: card.ID,
MSISDN: card.MSISDN,
@@ -123,10 +124,10 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
}
bundleCardIDs := deviceCards[deviceID]
bundle := model.DeviceBundle{
bundle := dto.DeviceBundle{
DeviceID: deviceID,
DeviceNo: device.DeviceNo,
BundleCards: make([]model.DeviceBundleCard, 0),
BundleCards: make([]dto.DeviceBundleCard, 0),
}
for _, bundleCardID := range bundleCardIDs {
@@ -135,13 +136,13 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
continue
}
if bundleCard.ID == card.ID {
bundle.TriggerCard = model.DeviceBundleCard{
bundle.TriggerCard = dto.DeviceBundleCard{
ICCID: bundleCard.ICCID,
IotCardID: bundleCard.ID,
MSISDN: bundleCard.MSISDN,
}
} else {
bundle.BundleCards = append(bundle.BundleCards, model.DeviceBundleCard{
bundle.BundleCards = append(bundle.BundleCards, dto.DeviceBundleCard{
ICCID: bundleCard.ICCID,
IotCardID: bundleCard.ID,
MSISDN: bundleCard.MSISDN,
@@ -158,7 +159,7 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
deviceCardCount += 1 + len(bundle.BundleCards)
}
resp.Summary = model.AllocatePreviewSummary{
resp.Summary = dto.AllocatePreviewSummary{
StandaloneCardCount: len(resp.StandaloneCards),
DeviceCount: len(resp.DeviceBundles),
DeviceCardCount: deviceCardCount,
@@ -169,7 +170,7 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
return resp, nil
}
func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *model.AllocateCardsReq) (*model.AllocateCardsResp, error) {
func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *dto.AllocateCardsReq) (*dto.AllocateCardsResp, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
currentShopID := middleware.GetShopIDFromContext(ctx)
if currentUserID == 0 {
@@ -181,7 +182,7 @@ func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *mod
return nil, errors.New(errors.CodeEnterpriseNotFound, "企业不存在")
}
preview, err := s.AllocateCardsPreview(ctx, enterpriseID, &model.AllocateCardsPreviewReq{ICCIDs: req.ICCIDs})
preview, err := s.AllocateCardsPreview(ctx, enterpriseID, &dto.AllocateCardsPreviewReq{ICCIDs: req.ICCIDs})
if err != nil {
return nil, err
}
@@ -190,10 +191,10 @@ func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *mod
return nil, errors.New(errors.CodeInvalidParam, "存在设备包,请确认整体授权设备下所有卡")
}
resp := &model.AllocateCardsResp{
resp := &dto.AllocateCardsResp{
FailedItems: preview.FailedItems,
FailCount: len(preview.FailedItems),
AllocatedDevices: make([]model.AllocatedDevice, 0),
AllocatedDevices: make([]dto.AllocatedDevice, 0),
}
cardIDsToAllocate := make([]uint, 0)
@@ -209,7 +210,7 @@ func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *mod
for _, card := range bundle.BundleCards {
iccids = append(iccids, card.ICCID)
}
resp.AllocatedDevices = append(resp.AllocatedDevices, model.AllocatedDevice{
resp.AllocatedDevices = append(resp.AllocatedDevices, dto.AllocatedDevice{
DeviceID: bundle.DeviceID,
DeviceNo: bundle.DeviceNo,
CardCount: 1 + len(bundle.BundleCards),
@@ -248,7 +249,7 @@ func (s *Service) AllocateCards(ctx context.Context, enterpriseID uint, req *mod
return resp, nil
}
func (s *Service) RecallCards(ctx context.Context, enterpriseID uint, req *model.RecallCardsReq) (*model.RecallCardsResp, error) {
func (s *Service) RecallCards(ctx context.Context, enterpriseID uint, req *dto.RecallCardsReq) (*dto.RecallCardsResp, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -278,23 +279,23 @@ func (s *Service) RecallCards(ctx context.Context, enterpriseID uint, req *model
return nil, fmt.Errorf("查询已有授权失败: %w", err)
}
resp := &model.RecallCardsResp{
FailedItems: make([]model.FailedItem, 0),
RecalledDevices: make([]model.RecalledDevice, 0),
resp := &dto.RecallCardsResp{
FailedItems: make([]dto.FailedItem, 0),
RecalledDevices: make([]dto.RecalledDevice, 0),
}
cardIDsToRecall := make([]uint, 0)
for _, iccid := range req.ICCIDs {
card, exists := cardMap[iccid]
if !exists {
resp.FailedItems = append(resp.FailedItems, model.FailedItem{
resp.FailedItems = append(resp.FailedItems, dto.FailedItem{
ICCID: iccid,
Reason: "卡不存在",
})
continue
}
if !existingAuths[card.ID] {
resp.FailedItems = append(resp.FailedItems, model.FailedItem{
resp.FailedItems = append(resp.FailedItems, dto.FailedItem{
ICCID: iccid,
Reason: "该卡未授权给此企业",
})
@@ -314,7 +315,7 @@ func (s *Service) RecallCards(ctx context.Context, enterpriseID uint, req *model
return resp, nil
}
func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *model.EnterpriseCardListReq) (*model.EnterpriseCardPageResult, error) {
func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *dto.EnterpriseCardListReq) (*dto.EnterpriseCardPageResult, error) {
_, err := s.enterpriseStore.GetByID(ctx, enterpriseID)
if err != nil {
return nil, errors.New(errors.CodeEnterpriseNotFound, "企业不存在")
@@ -326,8 +327,8 @@ func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *model.E
}
if len(cardIDs) == 0 {
return &model.EnterpriseCardPageResult{
Items: make([]model.EnterpriseCardItem, 0),
return &dto.EnterpriseCardPageResult{
Items: make([]dto.EnterpriseCardItem, 0),
Total: 0,
Page: req.Page,
Size: req.PageSize,
@@ -366,9 +367,9 @@ func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *model.E
return nil, fmt.Errorf("查询卡列表失败: %w", err)
}
items := make([]model.EnterpriseCardItem, 0, len(cards))
items := make([]dto.EnterpriseCardItem, 0, len(cards))
for _, card := range cards {
items = append(items, model.EnterpriseCardItem{
items = append(items, dto.EnterpriseCardItem{
ID: card.ID,
ICCID: card.ICCID,
MSISDN: card.MSISDN,
@@ -380,7 +381,7 @@ func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *model.E
})
}
return &model.EnterpriseCardPageResult{
return &dto.EnterpriseCardPageResult{
Items: items,
Total: total,
Page: page,

View File

@@ -8,6 +8,7 @@ import (
"time"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
"github.com/break/junhong_cmp_fiber/pkg/errors"
@@ -46,7 +47,7 @@ func New(
}
// GetCommissionSummary 获取我的佣金概览
func (s *Service) GetCommissionSummary(ctx context.Context) (*model.MyCommissionSummaryResp, error) {
func (s *Service) GetCommissionSummary(ctx context.Context) (*dto.MyCommissionSummaryResp, error) {
userType := middleware.GetUserTypeFromContext(ctx)
if userType != constants.UserTypeAgent {
return nil, errors.New(errors.CodeForbidden, "仅代理商用户可访问")
@@ -66,7 +67,7 @@ func (s *Service) GetCommissionSummary(ctx context.Context) (*model.MyCommission
wallet, err := s.walletStore.GetShopCommissionWallet(ctx, shopID)
if err != nil {
// 钱包不存在时返回空数据
return &model.MyCommissionSummaryResp{
return &dto.MyCommissionSummaryResp{
ShopID: shopID,
ShopName: shop.ShopName,
}, nil
@@ -82,7 +83,7 @@ func (s *Service) GetCommissionSummary(ctx context.Context) (*model.MyCommission
totalCommission := wallet.Balance + wallet.FrozenBalance + totalWithdrawn
return &model.MyCommissionSummaryResp{
return &dto.MyCommissionSummaryResp{
ShopID: shopID,
ShopName: shop.ShopName,
TotalCommission: totalCommission,
@@ -95,7 +96,7 @@ func (s *Service) GetCommissionSummary(ctx context.Context) (*model.MyCommission
}
// CreateWithdrawalRequest 发起提现申请
func (s *Service) CreateWithdrawalRequest(ctx context.Context, req *model.CreateMyWithdrawalReq) (*model.CreateMyWithdrawalResp, error) {
func (s *Service) CreateWithdrawalRequest(ctx context.Context, req *dto.CreateMyWithdrawalReq) (*dto.CreateMyWithdrawalResp, error) {
userType := middleware.GetUserTypeFromContext(ctx)
if userType != constants.UserTypeAgent {
return nil, errors.New(errors.CodeForbidden, "仅代理商用户可访问")
@@ -216,7 +217,7 @@ func (s *Service) CreateWithdrawalRequest(ctx context.Context, req *model.Create
return nil, err
}
return &model.CreateMyWithdrawalResp{
return &dto.CreateMyWithdrawalResp{
ID: withdrawalRequest.ID,
WithdrawalNo: withdrawalRequest.WithdrawalNo,
Amount: withdrawalRequest.Amount,
@@ -230,7 +231,7 @@ func (s *Service) CreateWithdrawalRequest(ctx context.Context, req *model.Create
}
// ListMyWithdrawalRequests 查询我的提现记录
func (s *Service) ListMyWithdrawalRequests(ctx context.Context, req *model.MyWithdrawalListReq) (*model.WithdrawalRequestPageResult, error) {
func (s *Service) ListMyWithdrawalRequests(ctx context.Context, req *dto.MyWithdrawalListReq) (*dto.WithdrawalRequestPageResult, error) {
userType := middleware.GetUserTypeFromContext(ctx)
if userType != constants.UserTypeAgent {
return nil, errors.New(errors.CodeForbidden, "仅代理商用户可访问")
@@ -274,12 +275,12 @@ func (s *Service) ListMyWithdrawalRequests(ctx context.Context, req *model.MyWit
return nil, fmt.Errorf("查询提现记录失败: %w", err)
}
items := make([]model.WithdrawalRequestItem, 0, len(requests))
items := make([]dto.WithdrawalRequestItem, 0, len(requests))
for _, r := range requests {
// 解析账户信息
accountName, accountNumber := parseAccountInfo(r.AccountInfo)
items = append(items, model.WithdrawalRequestItem{
items = append(items, dto.WithdrawalRequestItem{
ID: r.ID,
WithdrawalNo: r.WithdrawalNo,
ShopID: r.ShopID,
@@ -296,7 +297,7 @@ func (s *Service) ListMyWithdrawalRequests(ctx context.Context, req *model.MyWit
})
}
return &model.WithdrawalRequestPageResult{
return &dto.WithdrawalRequestPageResult{
Items: items,
Total: total,
Page: page,
@@ -305,7 +306,7 @@ func (s *Service) ListMyWithdrawalRequests(ctx context.Context, req *model.MyWit
}
// ListMyCommissionRecords 查询我的佣金明细
func (s *Service) ListMyCommissionRecords(ctx context.Context, req *model.MyCommissionRecordListReq) (*model.MyCommissionRecordPageResult, error) {
func (s *Service) ListMyCommissionRecords(ctx context.Context, req *dto.MyCommissionRecordListReq) (*dto.MyCommissionRecordPageResult, error) {
userType := middleware.GetUserTypeFromContext(ctx)
if userType != constants.UserTypeAgent {
return nil, errors.New(errors.CodeForbidden, "仅代理商用户可访问")
@@ -343,9 +344,9 @@ func (s *Service) ListMyCommissionRecords(ctx context.Context, req *model.MyComm
return nil, fmt.Errorf("查询佣金记录失败: %w", err)
}
items := make([]model.MyCommissionRecordItem, 0, len(records))
items := make([]dto.MyCommissionRecordItem, 0, len(records))
for _, r := range records {
items = append(items, model.MyCommissionRecordItem{
items = append(items, dto.MyCommissionRecordItem{
ID: r.ID,
ShopID: r.ShopID,
OrderID: r.OrderID,
@@ -357,7 +358,7 @@ func (s *Service) ListMyCommissionRecords(ctx context.Context, req *model.MyComm
})
}
return &model.MyCommissionRecordPageResult{
return &dto.MyCommissionRecordPageResult{
Items: items,
Total: total,
Page: page,

View File

@@ -10,6 +10,7 @@ import (
"time"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -46,7 +47,7 @@ func New(
}
// Create 创建权限
func (s *Service) Create(ctx context.Context, req *model.CreatePermissionRequest) (*model.Permission, error) {
func (s *Service) Create(ctx context.Context, req *dto.CreatePermissionRequest) (*model.Permission, error) {
// 获取当前用户 ID
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
@@ -109,7 +110,7 @@ func (s *Service) Get(ctx context.Context, id uint) (*model.Permission, error) {
}
// Update 更新权限
func (s *Service) Update(ctx context.Context, id uint, req *model.UpdatePermissionRequest) (*model.Permission, error) {
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdatePermissionRequest) (*model.Permission, error) {
// 获取当前用户 ID
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
@@ -190,7 +191,7 @@ func (s *Service) Delete(ctx context.Context, id uint) error {
}
// List 查询权限列表
func (s *Service) List(ctx context.Context, req *model.PermissionListRequest) ([]*model.Permission, int64, error) {
func (s *Service) List(ctx context.Context, req *dto.PermissionListRequest) ([]*model.Permission, int64, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,
@@ -230,7 +231,7 @@ func (s *Service) List(ctx context.Context, req *model.PermissionListRequest) ([
}
// GetTree 获取权限树
func (s *Service) GetTree(ctx context.Context, availableForRoleType *int) ([]*model.PermissionTreeNode, error) {
func (s *Service) GetTree(ctx context.Context, availableForRoleType *int) ([]*dto.PermissionTreeNode, error) {
permissions, err := s.permissionStore.GetAll(ctx, availableForRoleType)
if err != nil {
return nil, fmt.Errorf("获取权限列表失败: %w", err)
@@ -240,10 +241,10 @@ func (s *Service) GetTree(ctx context.Context, availableForRoleType *int) ([]*mo
}
// buildPermissionTree 构建权限树
func buildPermissionTree(permissions []*model.Permission) []*model.PermissionTreeNode {
nodeMap := make(map[uint]*model.PermissionTreeNode)
func buildPermissionTree(permissions []*model.Permission) []*dto.PermissionTreeNode {
nodeMap := make(map[uint]*dto.PermissionTreeNode)
for _, p := range permissions {
nodeMap[p.ID] = &model.PermissionTreeNode{
nodeMap[p.ID] = &dto.PermissionTreeNode{
ID: p.ID,
PermName: p.PermName,
PermCode: p.PermCode,
@@ -252,11 +253,11 @@ func buildPermissionTree(permissions []*model.Permission) []*model.PermissionTre
AvailableForRoleTypes: p.AvailableForRoleTypes,
URL: p.URL,
Sort: p.Sort,
Children: make([]*model.PermissionTreeNode, 0),
Children: make([]*dto.PermissionTreeNode, 0),
}
}
var roots []*model.PermissionTreeNode
var roots []*dto.PermissionTreeNode
for _, p := range permissions {
node := nodeMap[p.ID]
if p.ParentID == nil || *p.ParentID == 0 {

View File

@@ -8,6 +8,7 @@ import (
"strings"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -33,7 +34,7 @@ func New(roleStore *postgres.RoleStore, permissionStore *postgres.PermissionStor
}
// Create 创建角色
func (s *Service) Create(ctx context.Context, req *model.CreateRoleRequest) (*model.Role, error) {
func (s *Service) Create(ctx context.Context, req *dto.CreateRoleRequest) (*model.Role, error) {
// 获取当前用户 ID
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
@@ -68,7 +69,7 @@ func (s *Service) Get(ctx context.Context, id uint) (*model.Role, error) {
}
// Update 更新角色
func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateRoleRequest) (*model.Role, error) {
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateRoleRequest) (*model.Role, error) {
// 获取当前用户 ID
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
@@ -123,7 +124,7 @@ func (s *Service) Delete(ctx context.Context, id uint) error {
}
// List 查询角色列表
func (s *Service) List(ctx context.Context, req *model.RoleListRequest) ([]*model.Role, int64, error) {
func (s *Service) List(ctx context.Context, req *dto.RoleListRequest) ([]*model.Role, int64, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -26,7 +27,7 @@ func New(shopStore *postgres.ShopStore, accountStore *postgres.AccountStore) *Se
}
}
func (s *Service) Create(ctx context.Context, req *model.CreateShopRequest) (*model.ShopResponse, error) {
func (s *Service) Create(ctx context.Context, req *dto.CreateShopRequest) (*dto.ShopResponse, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -99,7 +100,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateShopRequest) (*mo
return nil, fmt.Errorf("创建初始账号失败: %w", err)
}
return &model.ShopResponse{
return &dto.ShopResponse{
ID: shop.ID,
ShopName: shop.ShopName,
ShopCode: shop.ShopCode,
@@ -117,7 +118,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateShopRequest) (*mo
}, nil
}
func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateShopRequest) (*model.ShopResponse, error) {
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateShopRequest) (*dto.ShopResponse, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -142,7 +143,7 @@ func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateShopRequ
return nil, err
}
return &model.ShopResponse{
return &dto.ShopResponse{
ID: shop.ID,
ShopName: shop.ShopName,
ShopCode: shop.ShopCode,
@@ -211,7 +212,7 @@ func (s *Service) GetByID(ctx context.Context, id uint) (*model.Shop, error) {
return shop, nil
}
func (s *Service) ListShopResponses(ctx context.Context, req *model.ShopListRequest) ([]*model.ShopResponse, int64, error) {
func (s *Service) ListShopResponses(ctx context.Context, req *dto.ShopListRequest) ([]*dto.ShopResponse, int64, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,
@@ -246,9 +247,9 @@ func (s *Service) ListShopResponses(ctx context.Context, req *model.ShopListRequ
return nil, 0, fmt.Errorf("查询店铺列表失败: %w", err)
}
responses := make([]*model.ShopResponse, 0, len(shops))
responses := make([]*dto.ShopResponse, 0, len(shops))
for _, shop := range shops {
responses = append(responses, &model.ShopResponse{
responses = append(responses, &dto.ShopResponse{
ID: shop.ID,
ShopName: shop.ShopName,
ShopCode: shop.ShopCode,

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -26,7 +27,7 @@ func New(accountStore *postgres.AccountStore, shopStore *postgres.ShopStore) *Se
}
}
func (s *Service) List(ctx context.Context, req *model.ShopAccountListRequest) ([]*model.ShopAccountResponse, int64, error) {
func (s *Service) List(ctx context.Context, req *dto.ShopAccountListRequest) ([]*dto.ShopAccountResponse, int64, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,
@@ -78,9 +79,9 @@ func (s *Service) List(ctx context.Context, req *model.ShopAccountListRequest) (
}
}
responses := make([]*model.ShopAccountResponse, 0, len(accounts))
responses := make([]*dto.ShopAccountResponse, 0, len(accounts))
for _, account := range accounts {
resp := &model.ShopAccountResponse{
resp := &dto.ShopAccountResponse{
ID: account.ID,
Username: account.Username,
Phone: account.Phone,
@@ -101,7 +102,7 @@ func (s *Service) List(ctx context.Context, req *model.ShopAccountListRequest) (
return responses, total, nil
}
func (s *Service) Create(ctx context.Context, req *model.CreateShopAccountRequest) (*model.ShopAccountResponse, error) {
func (s *Service) Create(ctx context.Context, req *dto.CreateShopAccountRequest) (*dto.ShopAccountResponse, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -145,7 +146,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateShopAccountReques
return nil, fmt.Errorf("创建代理商账号失败: %w", err)
}
return &model.ShopAccountResponse{
return &dto.ShopAccountResponse{
ID: account.ID,
ShopID: *account.ShopID,
ShopName: shop.ShopName,
@@ -158,7 +159,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreateShopAccountReques
}, nil
}
func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateShopAccountRequest) (*model.ShopAccountResponse, error) {
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateShopAccountRequest) (*dto.ShopAccountResponse, error) {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return nil, errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -196,7 +197,7 @@ func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateShopAcco
}
}
return &model.ShopAccountResponse{
return &dto.ShopAccountResponse{
ID: account.ID,
ShopID: *account.ShopID,
ShopName: shopName,
@@ -209,7 +210,7 @@ func (s *Service) Update(ctx context.Context, id uint, req *model.UpdateShopAcco
}, nil
}
func (s *Service) UpdatePassword(ctx context.Context, id uint, req *model.UpdateShopAccountPasswordRequest) error {
func (s *Service) UpdatePassword(ctx context.Context, id uint, req *dto.UpdateShopAccountPasswordRequest) error {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return errors.New(errors.CodeUnauthorized, "未授权访问")
@@ -239,7 +240,7 @@ func (s *Service) UpdatePassword(ctx context.Context, id uint, req *model.Update
return nil
}
func (s *Service) UpdateStatus(ctx context.Context, id uint, req *model.UpdateShopAccountStatusRequest) error {
func (s *Service) UpdateStatus(ctx context.Context, id uint, req *dto.UpdateShopAccountStatusRequest) error {
currentUserID := middleware.GetUserIDFromContext(ctx)
if currentUserID == 0 {
return errors.New(errors.CodeUnauthorized, "未授权访问")

View File

@@ -7,6 +7,7 @@ import (
"time"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/internal/store"
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
@@ -37,7 +38,7 @@ func New(
}
}
func (s *Service) ListShopCommissionSummary(ctx context.Context, req *model.ShopCommissionSummaryListReq) (*model.ShopCommissionSummaryPageResult, error) {
func (s *Service) ListShopCommissionSummary(ctx context.Context, req *dto.ShopCommissionSummaryListReq) (*dto.ShopCommissionSummaryPageResult, error) {
opts := &store.QueryOptions{
Page: req.Page,
PageSize: req.PageSize,
@@ -61,8 +62,8 @@ func (s *Service) ListShopCommissionSummary(ctx context.Context, req *model.Shop
}
if len(shops) == 0 {
return &model.ShopCommissionSummaryPageResult{
Items: []model.ShopCommissionSummaryItem{},
return &dto.ShopCommissionSummaryPageResult{
Items: []dto.ShopCommissionSummaryItem{},
Total: 0,
Page: opts.Page,
Size: opts.PageSize,
@@ -101,7 +102,7 @@ func (s *Service) ListShopCommissionSummary(ctx context.Context, req *model.Shop
}
}
items := make([]model.ShopCommissionSummaryItem, 0, len(shops))
items := make([]dto.ShopCommissionSummaryItem, 0, len(shops))
for _, shop := range shops {
if req.Username != "" {
acc := accountMap[shop.ID]
@@ -115,7 +116,7 @@ func (s *Service) ListShopCommissionSummary(ctx context.Context, req *model.Shop
items = append(items, item)
}
return &model.ShopCommissionSummaryPageResult{
return &dto.ShopCommissionSummaryPageResult{
Items: items,
Total: total,
Page: opts.Page,
@@ -123,7 +124,7 @@ func (s *Service) ListShopCommissionSummary(ctx context.Context, req *model.Shop
}, nil
}
func (s *Service) buildCommissionSummaryItem(shop *model.Shop, walletSummary *postgres.ShopCommissionSummary, withdrawnAmount, withdrawingAmount int64, account *model.Account) model.ShopCommissionSummaryItem {
func (s *Service) buildCommissionSummaryItem(shop *model.Shop, walletSummary *postgres.ShopCommissionSummary, withdrawnAmount, withdrawingAmount int64, account *model.Account) dto.ShopCommissionSummaryItem {
var balance, frozenBalance int64
if walletSummary != nil {
balance = walletSummary.Balance
@@ -143,7 +144,7 @@ func (s *Service) buildCommissionSummaryItem(shop *model.Shop, walletSummary *po
phone = account.Phone
}
return model.ShopCommissionSummaryItem{
return dto.ShopCommissionSummaryItem{
ShopID: shop.ID,
ShopName: shop.ShopName,
ShopCode: shop.ShopCode,
@@ -159,7 +160,7 @@ func (s *Service) buildCommissionSummaryItem(shop *model.Shop, walletSummary *po
}
}
func (s *Service) ListShopWithdrawalRequests(ctx context.Context, shopID uint, req *model.ShopWithdrawalRequestListReq) (*model.ShopWithdrawalRequestPageResult, error) {
func (s *Service) ListShopWithdrawalRequests(ctx context.Context, shopID uint, req *dto.ShopWithdrawalRequestListReq) (*dto.ShopWithdrawalRequestPageResult, error) {
_, err := s.shopStore.GetByID(ctx, shopID)
if err != nil {
return nil, errors.New(errors.CodeShopNotFound, "店铺不存在")
@@ -230,13 +231,13 @@ func (s *Service) ListShopWithdrawalRequests(ctx context.Context, shopID uint, r
}
}
items := make([]model.ShopWithdrawalRequestItem, 0, len(requests))
items := make([]dto.ShopWithdrawalRequestItem, 0, len(requests))
for _, r := range requests {
item := s.buildWithdrawalRequestItem(r, shop.ShopName, shopHierarchy, applicantMap, processorMap)
items = append(items, item)
}
return &model.ShopWithdrawalRequestPageResult{
return &dto.ShopWithdrawalRequestPageResult{
Items: items,
Total: total,
Page: opts.Page,
@@ -244,7 +245,7 @@ func (s *Service) ListShopWithdrawalRequests(ctx context.Context, shopID uint, r
}, nil
}
func (s *Service) buildWithdrawalRequestItem(r *model.CommissionWithdrawalRequest, shopName, shopHierarchy string, applicantMap, processorMap map[uint]string) model.ShopWithdrawalRequestItem {
func (s *Service) buildWithdrawalRequestItem(r *model.CommissionWithdrawalRequest, shopName, shopHierarchy string, applicantMap, processorMap map[uint]string) dto.ShopWithdrawalRequestItem {
var processorID *uint
if r.ProcessorID > 0 {
processorID = &r.ProcessorID
@@ -274,7 +275,7 @@ func (s *Service) buildWithdrawalRequestItem(r *model.CommissionWithdrawalReques
paidAt = r.PaidAt.Format("2006-01-02 15:04:05")
}
return model.ShopWithdrawalRequestItem{
return dto.ShopWithdrawalRequestItem{
ID: r.ID,
WithdrawalNo: r.WithdrawalNo,
Amount: r.Amount,
@@ -325,7 +326,7 @@ func (s *Service) buildShopHierarchyPath(ctx context.Context, shop *model.Shop)
return path
}
func (s *Service) ListShopCommissionRecords(ctx context.Context, shopID uint, req *model.ShopCommissionRecordListReq) (*model.ShopCommissionRecordPageResult, error) {
func (s *Service) ListShopCommissionRecords(ctx context.Context, shopID uint, req *dto.ShopCommissionRecordListReq) (*dto.ShopCommissionRecordPageResult, error) {
_, err := s.shopStore.GetByID(ctx, shopID)
if err != nil {
return nil, errors.New(errors.CodeShopNotFound, "店铺不存在")
@@ -356,9 +357,9 @@ func (s *Service) ListShopCommissionRecords(ctx context.Context, shopID uint, re
return nil, fmt.Errorf("查询佣金明细失败: %w", err)
}
items := make([]model.ShopCommissionRecordItem, 0, len(records))
items := make([]dto.ShopCommissionRecordItem, 0, len(records))
for _, r := range records {
item := model.ShopCommissionRecordItem{
item := dto.ShopCommissionRecordItem{
ID: r.ID,
Amount: r.Amount,
BalanceAfter: r.BalanceAfter,
@@ -375,7 +376,7 @@ func (s *Service) ListShopCommissionRecords(ctx context.Context, shopID uint, re
items = append(items, item)
}
return &model.ShopCommissionRecordPageResult{
return &dto.ShopCommissionRecordPageResult{
Items: items,
Total: total,
Page: opts.Page,