refactor: 统一状态名称映射为公共函数,清理废弃换卡/商户类型常量和模型
This commit is contained in:
@@ -469,23 +469,6 @@ func (s *Service) generateRechargeNo() string {
|
||||
return fmt.Sprintf("%s%s%06d", constants.AgentRechargeOrderPrefix, timestamp, randomNum)
|
||||
}
|
||||
|
||||
func agentRechargeStatusName(status int) string {
|
||||
switch status {
|
||||
case constants.RechargeStatusPending:
|
||||
return "待支付"
|
||||
case constants.RechargeStatusPaid:
|
||||
return "已支付"
|
||||
case constants.RechargeStatusCompleted:
|
||||
return "已完成"
|
||||
case constants.RechargeStatusClosed:
|
||||
return "已关闭"
|
||||
case constants.RechargeStatusRefunded:
|
||||
return "已退款"
|
||||
default:
|
||||
return "未知"
|
||||
}
|
||||
}
|
||||
|
||||
// toResponse 将模型转换为响应 DTO
|
||||
func toResponse(record *model.AgentRechargeRecord, shopName string) *dto.AgentRechargeResponse {
|
||||
resp := &dto.AgentRechargeResponse{
|
||||
@@ -497,7 +480,7 @@ func toResponse(record *model.AgentRechargeRecord, shopName string) *dto.AgentRe
|
||||
Amount: record.Amount,
|
||||
PaymentMethod: record.PaymentMethod,
|
||||
Status: record.Status,
|
||||
StatusName: agentRechargeStatusName(record.Status),
|
||||
StatusName: constants.GetRechargeStatusName(record.Status),
|
||||
CreatedAt: record.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: record.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ func (s *Service) buildWithdrawalRequestItem(r *model.CommissionWithdrawalReques
|
||||
Fee: r.Fee,
|
||||
ActualAmount: r.ActualAmount,
|
||||
Status: r.Status,
|
||||
StatusName: getWithdrawalStatusName(r.Status),
|
||||
StatusName: constants.GetWithdrawalStatusName(r.Status),
|
||||
ShopID: r.ShopID,
|
||||
ShopName: shopName,
|
||||
ShopHierarchy: shopHierarchy,
|
||||
@@ -402,21 +402,6 @@ func (s *Service) buildWithdrawalRequestItem(r *model.CommissionWithdrawalReques
|
||||
}
|
||||
}
|
||||
|
||||
func getWithdrawalStatusName(status int) string {
|
||||
switch status {
|
||||
case constants.WithdrawalStatusPending:
|
||||
return "待审核"
|
||||
case constants.WithdrawalStatusApproved:
|
||||
return "已通过"
|
||||
case constants.WithdrawalStatusRejected:
|
||||
return "已拒绝"
|
||||
case constants.WithdrawalStatusPaid:
|
||||
return "已到账"
|
||||
default:
|
||||
return "未知"
|
||||
}
|
||||
}
|
||||
|
||||
func containsSubstring(s, substr string) bool {
|
||||
for i := 0; i <= len(s)-len(substr); i++ {
|
||||
if s[i:i+len(substr)] == substr {
|
||||
|
||||
@@ -131,7 +131,7 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateEnterpriseReq) (*dt
|
||||
District: enterprise.District,
|
||||
Address: enterprise.Address,
|
||||
Status: enterprise.Status,
|
||||
StatusName: getStatusName(enterprise.Status),
|
||||
StatusName: constants.GetStatusName(enterprise.Status),
|
||||
CreatedAt: enterprise.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
},
|
||||
AccountID: account.ID,
|
||||
@@ -345,7 +345,7 @@ func (s *Service) List(ctx context.Context, req *dto.EnterpriseListReq) (*dto.En
|
||||
District: e.District,
|
||||
Address: e.Address,
|
||||
Status: e.Status,
|
||||
StatusName: getStatusName(e.Status),
|
||||
StatusName: constants.GetStatusName(e.Status),
|
||||
CreatedAt: e.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
@@ -357,10 +357,3 @@ func (s *Service) List(ctx context.Context, req *dto.EnterpriseListReq) (*dto.En
|
||||
Size: opts.PageSize,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getStatusName(status int) string {
|
||||
if status == constants.StatusEnabled {
|
||||
return "启用"
|
||||
}
|
||||
return "禁用"
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func (s *Service) AllocateCardsPreview(ctx context.Context, enterpriseID uint, r
|
||||
IotCardID: card.ID,
|
||||
MSISDN: card.MSISDN,
|
||||
CarrierID: card.CarrierID,
|
||||
StatusName: getCardStatusName(card.Status),
|
||||
StatusName: constants.GetIotCardStatusName(card.Status),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -305,9 +305,9 @@ func (s *Service) ListCards(ctx context.Context, enterpriseID uint, req *dto.Ent
|
||||
CarrierName: card.CarrierName,
|
||||
PackageName: packageNameMap[card.ID],
|
||||
Status: card.Status,
|
||||
StatusName: getCardStatusName(card.Status),
|
||||
StatusName: constants.GetIotCardStatusName(card.Status),
|
||||
NetworkStatus: card.NetworkStatus,
|
||||
NetworkStatusName: getNetworkStatusName(card.NetworkStatus),
|
||||
NetworkStatusName: constants.GetNetworkStatusName(card.NetworkStatus),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -377,25 +377,3 @@ func (s *Service) updateCardNetworkStatus(ctx context.Context, enterpriseID, car
|
||||
Where("id = ?", cardID).
|
||||
Update("network_status", networkStatus).Error
|
||||
}
|
||||
|
||||
func getCardStatusName(status int) string {
|
||||
switch status {
|
||||
case 1:
|
||||
return "在库"
|
||||
case 2:
|
||||
return "已分销"
|
||||
case 3:
|
||||
return "已激活"
|
||||
case 4:
|
||||
return "已停用"
|
||||
default:
|
||||
return "未知"
|
||||
}
|
||||
}
|
||||
|
||||
func getNetworkStatusName(status int) string {
|
||||
if status == 1 {
|
||||
return "开机"
|
||||
}
|
||||
return "停机"
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ func (s *Service) GetDeviceDetail(ctx context.Context, deviceID uint) (*dto.Ente
|
||||
MSISDN: card.MSISDN,
|
||||
CarrierName: carrierMap[card.CarrierID],
|
||||
NetworkStatus: card.NetworkStatus,
|
||||
NetworkStatusName: getNetworkStatusName(card.NetworkStatus),
|
||||
NetworkStatusName: constants.GetNetworkStatusName(card.NetworkStatus),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -602,10 +602,3 @@ func (s *Service) validateCardOperation(ctx context.Context, deviceID, cardID ui
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getNetworkStatusName(status int) string {
|
||||
if status == 1 {
|
||||
return "开机"
|
||||
}
|
||||
return "停机"
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ func (s *Service) buildWithdrawalRequestItem(r *model.CommissionWithdrawalReques
|
||||
Fee: r.Fee,
|
||||
ActualAmount: r.ActualAmount,
|
||||
Status: r.Status,
|
||||
StatusName: getWithdrawalStatusName(r.Status),
|
||||
StatusName: constants.GetWithdrawalStatusName(r.Status),
|
||||
ShopID: r.ShopID,
|
||||
ShopName: shopName,
|
||||
ShopHierarchy: shopHierarchy,
|
||||
@@ -443,7 +443,7 @@ func (s *Service) ListShopCommissionRecords(ctx context.Context, shopID uint, re
|
||||
BalanceAfter: r.BalanceAfter,
|
||||
CommissionSource: r.CommissionSource,
|
||||
Status: r.Status,
|
||||
StatusName: getCommissionStatusName(r.Status),
|
||||
StatusName: constants.GetCommissionRecordStatusName(r.Status),
|
||||
OrderID: r.OrderID,
|
||||
OrderNo: r.OrderNo,
|
||||
VirtualNo: r.VirtualNo,
|
||||
@@ -672,7 +672,7 @@ func (s *Service) CreateWithdrawalRequest(ctx context.Context, shopID uint, req
|
||||
Fee: withdrawalRequest.Fee,
|
||||
ActualAmount: withdrawalRequest.ActualAmount,
|
||||
Status: withdrawalRequest.Status,
|
||||
StatusName: getWithdrawalStatusName(withdrawalRequest.Status),
|
||||
StatusName: constants.GetWithdrawalStatusName(withdrawalRequest.Status),
|
||||
CreatedAt: withdrawalRequest.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
}, nil
|
||||
}
|
||||
@@ -823,38 +823,6 @@ func (s *Service) ResolveCommissionRecord(ctx context.Context, recordID uint, re
|
||||
})
|
||||
}
|
||||
|
||||
// getWithdrawalStatusName 获取提现状态名称
|
||||
func getWithdrawalStatusName(status int) string {
|
||||
switch status {
|
||||
case constants.WithdrawalStatusPending:
|
||||
return "待审核"
|
||||
case constants.WithdrawalStatusApproved:
|
||||
return "已通过"
|
||||
case constants.WithdrawalStatusRejected:
|
||||
return "已拒绝"
|
||||
case constants.WithdrawalStatusPaid:
|
||||
return "已到账"
|
||||
default:
|
||||
return "未知"
|
||||
}
|
||||
}
|
||||
|
||||
// getCommissionStatusName 获取佣金状态名称
|
||||
func getCommissionStatusName(status int) string {
|
||||
switch status {
|
||||
case constants.CommissionStatusFrozen:
|
||||
return "已冻结"
|
||||
case constants.CommissionStatusUnfreezing:
|
||||
return "解冻中"
|
||||
case constants.CommissionStatusReleased:
|
||||
return "已发放"
|
||||
case constants.CommissionStatusInvalid:
|
||||
return "已失效"
|
||||
default:
|
||||
return "未知"
|
||||
}
|
||||
}
|
||||
|
||||
// generateWithdrawalNo 生成提现单号
|
||||
func generateWithdrawalNo() string {
|
||||
now := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user