feat: 订单创建时快照买家手机号/昵称和套餐类型
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
新增字段: - tb_order: buyer_phone, buyer_nickname(个人客户下单时快照) - tb_order_item: package_type(套餐类型快照) 后台订单列表支持按 buyer_phone 精确过滤查询。 OpenSpec: order-buyer-snapshot
This commit is contained in:
@@ -48,22 +48,24 @@ type ForceRechargeRequirement struct {
|
||||
|
||||
// Service 客户端订单服务。
|
||||
type Service struct {
|
||||
assetService *asset.Service
|
||||
purchaseValidationService *purchase_validation.Service
|
||||
orderStore *postgres.OrderStore
|
||||
rechargeRecordStore *postgres.AssetRechargeStore
|
||||
walletStore *postgres.AssetWalletStore
|
||||
personalDeviceStore *postgres.PersonalCustomerDeviceStore
|
||||
openIDStore *postgres.PersonalCustomerOpenIDStore
|
||||
wechatConfigService WechatConfigServiceInterface
|
||||
orderPaymentService OrderWalletPayServiceInterface
|
||||
packageSeriesStore *postgres.PackageSeriesStore
|
||||
shopSeriesAllocationStore *postgres.ShopSeriesAllocationStore
|
||||
iotCardStore *postgres.IotCardStore
|
||||
deviceStore *postgres.DeviceStore
|
||||
db *gorm.DB
|
||||
redis *redis.Client
|
||||
logger *zap.Logger
|
||||
assetService *asset.Service
|
||||
purchaseValidationService *purchase_validation.Service
|
||||
orderStore *postgres.OrderStore
|
||||
rechargeRecordStore *postgres.AssetRechargeStore
|
||||
walletStore *postgres.AssetWalletStore
|
||||
personalDeviceStore *postgres.PersonalCustomerDeviceStore
|
||||
openIDStore *postgres.PersonalCustomerOpenIDStore
|
||||
personalCustomerStore *postgres.PersonalCustomerStore
|
||||
personalCustomerPhoneStore *postgres.PersonalCustomerPhoneStore
|
||||
wechatConfigService WechatConfigServiceInterface
|
||||
orderPaymentService OrderWalletPayServiceInterface
|
||||
packageSeriesStore *postgres.PackageSeriesStore
|
||||
shopSeriesAllocationStore *postgres.ShopSeriesAllocationStore
|
||||
iotCardStore *postgres.IotCardStore
|
||||
deviceStore *postgres.DeviceStore
|
||||
db *gorm.DB
|
||||
redis *redis.Client
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// New 创建客户端订单服务。
|
||||
@@ -75,6 +77,8 @@ func New(
|
||||
walletStore *postgres.AssetWalletStore,
|
||||
personalDeviceStore *postgres.PersonalCustomerDeviceStore,
|
||||
openIDStore *postgres.PersonalCustomerOpenIDStore,
|
||||
personalCustomerStore *postgres.PersonalCustomerStore,
|
||||
personalCustomerPhoneStore *postgres.PersonalCustomerPhoneStore,
|
||||
wechatConfigService WechatConfigServiceInterface,
|
||||
orderPaymentService OrderWalletPayServiceInterface,
|
||||
packageSeriesStore *postgres.PackageSeriesStore,
|
||||
@@ -86,22 +90,24 @@ func New(
|
||||
logger *zap.Logger,
|
||||
) *Service {
|
||||
return &Service{
|
||||
assetService: assetService,
|
||||
purchaseValidationService: purchaseValidationService,
|
||||
orderStore: orderStore,
|
||||
rechargeRecordStore: rechargeRecordStore,
|
||||
walletStore: walletStore,
|
||||
personalDeviceStore: personalDeviceStore,
|
||||
openIDStore: openIDStore,
|
||||
wechatConfigService: wechatConfigService,
|
||||
orderPaymentService: orderPaymentService,
|
||||
packageSeriesStore: packageSeriesStore,
|
||||
shopSeriesAllocationStore: shopSeriesAllocationStore,
|
||||
iotCardStore: iotCardStore,
|
||||
deviceStore: deviceStore,
|
||||
db: db,
|
||||
redis: redisClient,
|
||||
logger: logger,
|
||||
assetService: assetService,
|
||||
purchaseValidationService: purchaseValidationService,
|
||||
orderStore: orderStore,
|
||||
rechargeRecordStore: rechargeRecordStore,
|
||||
walletStore: walletStore,
|
||||
personalDeviceStore: personalDeviceStore,
|
||||
openIDStore: openIDStore,
|
||||
personalCustomerStore: personalCustomerStore,
|
||||
personalCustomerPhoneStore: personalCustomerPhoneStore,
|
||||
wechatConfigService: wechatConfigService,
|
||||
orderPaymentService: orderPaymentService,
|
||||
packageSeriesStore: packageSeriesStore,
|
||||
shopSeriesAllocationStore: shopSeriesAllocationStore,
|
||||
iotCardStore: iotCardStore,
|
||||
deviceStore: deviceStore,
|
||||
db: db,
|
||||
redis: redisClient,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +302,7 @@ func (s *Service) createPackageOrder(
|
||||
sellerCostPrice = costPrice
|
||||
}
|
||||
|
||||
order, err := s.buildPendingOrder(customerID, validationResult, sellerCostPrice)
|
||||
order, err := s.buildPendingOrder(ctx, customerID, validationResult, sellerCostPrice)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -401,7 +407,27 @@ func (s *Service) createForceRechargeOrder(
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) buildPendingOrder(customerID uint, result *purchase_validation.PurchaseValidationResult, sellerCostPrice int64) (*model.Order, error) {
|
||||
func (s *Service) fetchBuyerSnapshot(ctx context.Context, customerID uint) (phone, nickname *string) {
|
||||
if customerID == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
customer, err := s.personalCustomerStore.GetByID(ctx, customerID)
|
||||
if err != nil {
|
||||
s.logger.Warn("fetchBuyerSnapshot: 查询个人客户失败", zap.Uint("customer_id", customerID), zap.Error(err))
|
||||
} else if customer != nil && customer.Nickname != "" {
|
||||
nickname = &customer.Nickname
|
||||
}
|
||||
|
||||
phoneRecord, err := s.personalCustomerPhoneStore.GetPrimaryPhone(ctx, customerID)
|
||||
if err != nil {
|
||||
s.logger.Warn("fetchBuyerSnapshot: 查询买家手机号失败", zap.Uint("customer_id", customerID), zap.Error(err))
|
||||
} else if phoneRecord != nil && phoneRecord.Phone != "" {
|
||||
phone = &phoneRecord.Phone
|
||||
}
|
||||
return phone, nickname
|
||||
}
|
||||
|
||||
func (s *Service) buildPendingOrder(ctx context.Context, customerID uint, result *purchase_validation.PurchaseValidationResult, sellerCostPrice int64) (*model.Order, error) {
|
||||
orderType := resolveOrderType(result)
|
||||
if orderType == "" {
|
||||
return nil, errors.New(errors.CodeInvalidParam)
|
||||
@@ -438,6 +464,8 @@ func (s *Service) buildPendingOrder(customerID uint, result *purchase_validation
|
||||
order.SellerShopID = result.Device.ShopID
|
||||
}
|
||||
|
||||
order.BuyerPhone, order.BuyerNickname = s.fetchBuyerSnapshot(ctx, customerID)
|
||||
|
||||
return order, nil
|
||||
}
|
||||
|
||||
@@ -462,6 +490,7 @@ func (s *Service) buildOrderItems(ctx context.Context, customerID uint, result *
|
||||
},
|
||||
PackageID: pkg.ID,
|
||||
PackageName: pkg.PackageName,
|
||||
PackageType: &pkg.PackageType,
|
||||
Quantity: 1,
|
||||
UnitPrice: unitPrice,
|
||||
Amount: unitPrice,
|
||||
|
||||
Reference in New Issue
Block a user