补充退款列表应当让本店铺的人看见
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m30s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m30s
This commit is contained in:
@@ -33,7 +33,7 @@ func (s *RefundStore) Create(ctx context.Context, req *model.RefundRequest) erro
|
||||
return s.db.WithContext(ctx).Create(req).Error
|
||||
}
|
||||
|
||||
// GetByID 根据 ID 查询退款申请(含数据权限过滤)
|
||||
// GetByID 根据 ID 查询退款申请详情(含读取数据权限过滤)。
|
||||
func (s *RefundStore) GetByID(ctx context.Context, id uint) (*model.RefundRequest, error) {
|
||||
var req model.RefundRequest
|
||||
query := s.db.WithContext(ctx).
|
||||
@@ -41,7 +41,22 @@ func (s *RefundStore) GetByID(ctx context.Context, id uint) (*model.RefundReques
|
||||
Select("tb_refund_request.*, tb_shop.shop_name AS shop_name").
|
||||
Joins("LEFT JOIN tb_shop ON tb_shop.id = tb_refund_request.shop_id AND tb_shop.deleted_at IS NULL").
|
||||
Where("tb_refund_request.id = ?", id)
|
||||
query = applyRefundScope(ctx, query)
|
||||
query = applyRefundReadScope(ctx, query)
|
||||
if err := query.First(&req).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
// GetByIDForOperation 根据 ID 查询退款申请(含写操作数据权限过滤)。
|
||||
func (s *RefundStore) GetByIDForOperation(ctx context.Context, id uint) (*model.RefundRequest, error) {
|
||||
var req model.RefundRequest
|
||||
query := s.db.WithContext(ctx).
|
||||
Model(&model.RefundRequest{}).
|
||||
Select("tb_refund_request.*, tb_shop.shop_name AS shop_name").
|
||||
Joins("LEFT JOIN tb_shop ON tb_shop.id = tb_refund_request.shop_id AND tb_shop.deleted_at IS NULL").
|
||||
Where("tb_refund_request.id = ?", id)
|
||||
query = applyRefundOperationScope(ctx, query)
|
||||
if err := query.First(&req).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -70,7 +85,7 @@ func (s *RefundStore) List(ctx context.Context, opts *store.QueryOptions, filter
|
||||
Model(&model.RefundRequest{}).
|
||||
Select("tb_refund_request.*, tb_shop.shop_name AS shop_name").
|
||||
Joins("LEFT JOIN tb_shop ON tb_shop.id = tb_refund_request.shop_id AND tb_shop.deleted_at IS NULL")
|
||||
query = applyRefundScope(ctx, query)
|
||||
query = applyRefundReadScope(ctx, query)
|
||||
|
||||
if filters != nil {
|
||||
if filters.Status != nil {
|
||||
@@ -113,9 +128,25 @@ func (s *RefundStore) List(ctx context.Context, opts *store.QueryOptions, filter
|
||||
return requests, total, nil
|
||||
}
|
||||
|
||||
// applyRefundScope 应用退款单专属数据权限。
|
||||
// 退款申请对代理按创建人隔离,避免上级代理通过店铺层级看到下级申请。
|
||||
func applyRefundScope(ctx context.Context, query *gorm.DB) *gorm.DB {
|
||||
// applyRefundReadScope 应用退款单读取数据权限。
|
||||
// 代理仅可查看直接所属店铺的申请,不包含下级代理店铺。
|
||||
func applyRefundReadScope(ctx context.Context, query *gorm.DB) *gorm.DB {
|
||||
switch middleware.GetUserTypeFromContext(ctx) {
|
||||
case constants.UserTypeSuperAdmin, constants.UserTypePlatform:
|
||||
return query
|
||||
case constants.UserTypeAgent:
|
||||
shopID := middleware.GetShopIDFromContext(ctx)
|
||||
if shopID == 0 {
|
||||
return query.Where("1 = 0")
|
||||
}
|
||||
return query.Where("tb_refund_request.shop_id = ?", shopID)
|
||||
default:
|
||||
return query.Where("1 = 0")
|
||||
}
|
||||
}
|
||||
|
||||
// applyRefundOperationScope 应用退款单写操作数据权限。
|
||||
func applyRefundOperationScope(ctx context.Context, query *gorm.DB) *gorm.DB {
|
||||
switch middleware.GetUserTypeFromContext(ctx) {
|
||||
case constants.UserTypeSuperAdmin, constants.UserTypePlatform:
|
||||
return query
|
||||
|
||||
Reference in New Issue
Block a user