订单相关以及佣金相关修复
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m57s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m57s
This commit is contained in:
@@ -45,8 +45,7 @@ func (s *OrderStore) Create(ctx context.Context, order *model.Order, items []*mo
|
||||
func (s *OrderStore) GetByID(ctx context.Context, id uint) (*model.Order, error) {
|
||||
var order model.Order
|
||||
query := s.db.WithContext(ctx).Where("id = ?", id)
|
||||
// 应用数据权限过滤(使用 seller_shop_id 字段)
|
||||
query = middleware.ApplySellerShopFilter(ctx, query)
|
||||
query = s.applyOrderScope(ctx, query)
|
||||
if err := query.First(&order).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -56,8 +55,7 @@ func (s *OrderStore) GetByID(ctx context.Context, id uint) (*model.Order, error)
|
||||
func (s *OrderStore) GetByIDWithItems(ctx context.Context, id uint) (*model.Order, []*model.OrderItem, error) {
|
||||
var order model.Order
|
||||
query := s.db.WithContext(ctx).Where("id = ?", id)
|
||||
// 应用数据权限过滤(使用 seller_shop_id 字段)
|
||||
query = middleware.ApplySellerShopFilter(ctx, query)
|
||||
query = s.applyOrderScope(ctx, query)
|
||||
if err := query.First(&order).Error; err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -73,8 +71,7 @@ func (s *OrderStore) GetByIDWithItems(ctx context.Context, id uint) (*model.Orde
|
||||
func (s *OrderStore) GetByOrderNo(ctx context.Context, orderNo string) (*model.Order, error) {
|
||||
var order model.Order
|
||||
query := s.db.WithContext(ctx).Where("order_no = ?", orderNo)
|
||||
// 应用数据权限过滤(使用 seller_shop_id 字段)
|
||||
query = middleware.ApplySellerShopFilter(ctx, query)
|
||||
query = s.applyOrderScope(ctx, query)
|
||||
if err := query.First(&order).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -91,17 +88,7 @@ func (s *OrderStore) List(ctx context.Context, opts *store.QueryOptions, filters
|
||||
|
||||
query := s.db.WithContext(ctx).Model(&model.Order{})
|
||||
|
||||
// 应用数据权限过滤
|
||||
// 代理用户:可以查看作为买家或操作者的订单
|
||||
// 平台用户/超管:可以查看所有订单
|
||||
subordinateShopIDs := middleware.GetSubordinateShopIDs(ctx)
|
||||
if len(subordinateShopIDs) > 0 {
|
||||
// 代理用户:WHERE (buyer_type = 'agent' AND buyer_id IN ?) OR operator_id IN ?
|
||||
query = query.Where(
|
||||
s.db.Where("buyer_type = ? AND buyer_id IN ?", model.BuyerTypeAgent, subordinateShopIDs).
|
||||
Or("operator_id IN ?", subordinateShopIDs),
|
||||
)
|
||||
}
|
||||
query = s.applyOrderScope(ctx, query)
|
||||
|
||||
if v, ok := filters["payment_status"]; ok {
|
||||
query = query.Where("payment_status = ?", v)
|
||||
@@ -210,6 +197,19 @@ func (s *OrderStore) UpdatePaymentStatus(ctx context.Context, id uint, status in
|
||||
return s.db.WithContext(ctx).Model(&model.Order{}).Where("id = ?", id).Updates(updates).Error
|
||||
}
|
||||
|
||||
func (s *OrderStore) applyOrderScope(ctx context.Context, query *gorm.DB) *gorm.DB {
|
||||
shopIDs := middleware.GetSubordinateShopIDs(ctx)
|
||||
if len(shopIDs) == 0 {
|
||||
return query
|
||||
}
|
||||
|
||||
return query.Where(
|
||||
s.db.Where("buyer_type = ? AND buyer_id IN ?", model.BuyerTypeAgent, shopIDs).
|
||||
Or("seller_shop_id IN ?", shopIDs).
|
||||
Or(s.db.Where("seller_shop_id IS NULL AND operator_type = ? AND operator_id IN ?", model.OperatorAccountTypeAgent, shopIDs)),
|
||||
)
|
||||
}
|
||||
|
||||
func (s *OrderStore) GenerateOrderNo() string {
|
||||
now := time.Now()
|
||||
randomNum := rand.Intn(1000000)
|
||||
|
||||
Reference in New Issue
Block a user