- 数据库升级:新增 pickup_shop_mappings 映射别名表,并在 admin_pickups 增加 raw_shop_name 永久保留原始店铺录入值 - 后端映射能力:提供历史店铺聚合统计、单条/批量映射至目标标准店铺、映射规则撤销与提号单还原接口;新建提号时若录入已映射别名自动归一化 - 前端管理升级:PickupShopDialog 升级为双 Tab 结构,Tab 2「历史店铺映射与清洗」支持总览统计卡片、状态筛选、单条/批量映射清洗、一键设为标准店铺及撤销还原 - 验证方式:执行并通过全套代码门禁(scripts/check.sh:SQL约束、go vet/build/test、MySQL测试库覆盖率、vue大小、eslint、prettier、vue-tsc及vite构建)
201 lines
6.2 KiB
Go
201 lines
6.2 KiB
Go
package pickup
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"hfb_sys/backend/internal/auditlog"
|
|
)
|
|
|
|
type Service struct {
|
|
repo *Repository
|
|
}
|
|
|
|
func NewService(repo *Repository) *Service {
|
|
return &Service{repo: repo}
|
|
}
|
|
|
|
func (s *Service) Create(ctx context.Context, req CreateRequest, adminID uint64, meta auditlog.Meta) (*PickupDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if req.ListingID == 0 {
|
|
return nil, ErrListingUnavailable
|
|
}
|
|
if req.ProfitAmountCent < 0 {
|
|
return nil, ErrInvalidProfit
|
|
}
|
|
return s.repo.Create(ctx, req, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) Complete(ctx context.Context, pickupID uint64, req CompleteRequest, adminID uint64, meta auditlog.Meta) (*PickupDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if pickupID == 0 || req.SettleAmountCent <= 0 {
|
|
return nil, ErrInvalidAmount
|
|
}
|
|
if req.ProfitAmountCent != nil && *req.ProfitAmountCent < 0 {
|
|
return nil, ErrInvalidProfit
|
|
}
|
|
return s.repo.Complete(ctx, pickupID, req, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) MarkOfflineSettlement(ctx context.Context, pickupID uint64, req OfflineSettlementRequest, adminID uint64, meta auditlog.Meta) (*PickupDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if pickupID == 0 {
|
|
return nil, ErrPickupNotFound
|
|
}
|
|
return s.repo.MarkOfflineSettlement(ctx, pickupID, req, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) UpdateProfit(ctx context.Context, pickupID uint64, req UpdateProfitRequest, adminID uint64, meta auditlog.Meta) (*PickupDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if pickupID == 0 {
|
|
return nil, ErrPickupNotFound
|
|
}
|
|
if req.ProfitAmountCent < 0 {
|
|
return nil, ErrInvalidProfit
|
|
}
|
|
return s.repo.UpdateProfit(ctx, pickupID, req, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) CreateFinancialAdjustment(ctx context.Context, pickupID uint64, req FinancialAdjustmentRequest, adminID uint64, meta auditlog.Meta) (*PickupDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if pickupID == 0 || (req.ProfitAmountCent == nil && req.SettleAmountCent == nil) || strings.TrimSpace(req.Reason) == "" {
|
|
return nil, ErrFinancialAdjustmentInvalid
|
|
}
|
|
if (req.ProfitAmountCent != nil && *req.ProfitAmountCent < 0) || (req.SettleAmountCent != nil && *req.SettleAmountCent < 0) {
|
|
return nil, ErrFinancialAdjustmentInvalid
|
|
}
|
|
return s.repo.CreateFinancialAdjustment(ctx, pickupID, req, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) ListFinancialAdjustments(ctx context.Context, pickupID uint64) ([]FinancialAdjustmentDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if pickupID == 0 {
|
|
return nil, ErrPickupNotFound
|
|
}
|
|
return s.repo.ListFinancialAdjustments(ctx, pickupID)
|
|
}
|
|
|
|
func (s *Service) ProcessEvents(ctx context.Context, pickupID uint64) ([]ProcessEventDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ProcessEvents(ctx, pickupID)
|
|
}
|
|
|
|
func (s *Service) SettleFinancialAdjustment(ctx context.Context, adjustmentID uint64, req FinancialAdjustmentSettlementRequest, adminID uint64, meta auditlog.Meta) error {
|
|
if s.repo == nil {
|
|
return ErrDependencyUnavailable
|
|
}
|
|
if adjustmentID == 0 {
|
|
return ErrFinancialAdjustmentNotFound
|
|
}
|
|
return s.repo.SettleFinancialAdjustment(ctx, adjustmentID, req, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) Cancel(ctx context.Context, pickupID uint64, reason string, adminID uint64, meta auditlog.Meta) error {
|
|
if s.repo == nil {
|
|
return ErrDependencyUnavailable
|
|
}
|
|
if pickupID == 0 || reason == "" {
|
|
return ErrPickupNotPickingUp
|
|
}
|
|
return s.repo.Cancel(ctx, pickupID, reason, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) FindByID(ctx context.Context, id uint64) (*PickupDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.FindByID(ctx, id)
|
|
}
|
|
|
|
func (s *Service) ListAdmin(ctx context.Context, query AdminPickupQuery) (*PaginatedResult, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ListAdmin(ctx, query)
|
|
}
|
|
|
|
func (s *Service) ListShopNames(ctx context.Context, platform string) ([]string, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ListShopNames(ctx, platform)
|
|
}
|
|
|
|
func (s *Service) ListForSeller(ctx context.Context, ownerID uint64, query SellerPickupQuery) (*PaginatedResult, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ListForSeller(ctx, ownerID, query)
|
|
}
|
|
|
|
func (s *Service) ListAvailableListings(ctx context.Context, query AvailableListingQuery) (*AvailableListingsResult, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ListAvailableListings(ctx, query)
|
|
}
|
|
|
|
func (s *Service) ListShops(ctx context.Context, query PickupShopQuery) ([]PickupShopDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.ListShops(ctx, query)
|
|
}
|
|
|
|
func (s *Service) CreateShop(ctx context.Context, req CreatePickupShopRequest, adminID uint64, meta auditlog.Meta) (*PickupShopDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.CreateShop(ctx, req, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) UpdateShop(ctx context.Context, id uint64, req UpdatePickupShopRequest, adminID uint64, meta auditlog.Meta) (*PickupShopDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.UpdateShop(ctx, id, req, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) DeleteShop(ctx context.Context, id uint64, adminID uint64, meta auditlog.Meta) error {
|
|
if s.repo == nil {
|
|
return ErrDependencyUnavailable
|
|
}
|
|
return s.repo.DeleteShop(ctx, id, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) GetHistoricalShopStats(ctx context.Context) (*PickupShopHistoricalStatsDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.GetHistoricalShopStats(ctx)
|
|
}
|
|
|
|
func (s *Service) MapHistoricalShops(ctx context.Context, req MapHistoricalShopsRequest, adminID uint64, meta auditlog.Meta) (*MapHistoricalShopsResultDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
return s.repo.MapHistoricalShops(ctx, req, adminID, meta)
|
|
}
|
|
|
|
func (s *Service) DeleteShopMapping(ctx context.Context, sourceName string, adminID uint64, meta auditlog.Meta) error {
|
|
if s.repo == nil {
|
|
return ErrDependencyUnavailable
|
|
}
|
|
return s.repo.DeleteShopMapping(ctx, sourceName, adminID, meta)
|
|
}
|
|
|