refactor platform domain states and permissions

This commit is contained in:
david
2026-07-29 14:25:38 +08:00
parent d4799cd320
commit 35a52c4b06
42 changed files with 507 additions and 364 deletions

View File

@@ -105,14 +105,14 @@ var keywordSafeColumns = map[string]bool{
"channel": true, "settlement_no": true, "subject_type": true,
"content_type": true, "publish_status": true, "template_code": true,
"ticket_no": true, "category": true, "priority": true,
"platform_role_code": true, "data_scope": true, "menu_code": true,
"platform_role_code": true, "location_scope": true, "group_code": true,
"path": true, "resource_type": true,
"owner_type": true, "owner_identity": true, "payment_no": true,
"record_no": true, "request_no": true, "refund_no": true,
"cash_no": true, "trade_no": true, "trade_type": true,
"pay_channel": true, "payment_type": true,
"contract_no": true, "creator_type": true, "from_status": true,
"to_status": true, "confirm_type": true, "product_type_name": true,
"contract_no": true, "creator_type": true,
"confirm_type": true, "product_type_name": true,
}
func ApplyKeywordFilter(ctx *gin.Context, query *gorm.DB, model any) *gorm.DB {
@@ -191,7 +191,7 @@ func UpdateAllowedByIdentity(ctx *gin.Context, model any, values map[string]any,
return
}
result := impl.DBService.Model(model).Where("identity = ?", ctx.Param("identity")).Updates(values)
result := ActiveRecords(impl.DBService.Model(model)).Where("identity = ?", ctx.Param("identity")).Updates(values)
if result.Error != nil {
infra.Response.Error(ctx, result.Error)
return
@@ -204,7 +204,7 @@ func UpdateAllowedByIdentity(ctx *gin.Context, model any, values map[string]any,
}
func UpdateByIdentity(ctx *gin.Context, model any, values map[string]any) {
result := impl.DBService.Model(model).Where("identity = ?", ctx.Param("identity")).Updates(values)
result := ActiveRecords(impl.DBService.Model(model)).Where("identity = ?", ctx.Param("identity")).Updates(values)
if result.Error != nil {
infra.Response.Error(ctx, result.Error)
return

View File

@@ -0,0 +1,31 @@
package common
import (
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
)
// ValidateOrganizationIDs verifies that an optional delivery point and staff
// member belong to the requested gas organization.
func ValidateOrganizationIDs(gasID, deliveryID, staffID uint64) bool {
var delivery models.DeliveryBasic
if deliveryID != 0 {
if err := impl.DBService.First(&delivery, deliveryID).Error; err != nil {
return false
}
if gasID != 0 && delivery.GasBasicID != 0 && delivery.GasBasicID != gasID {
return false
}
}
if staffID == 0 {
return true
}
var staff models.StaffAccount
if err := impl.DBService.First(&staff, staffID).Error; err != nil {
return false
}
if deliveryID != 0 && staff.DeliveryBasicID != deliveryID {
return false
}
return gasID == 0 || staff.GasBasicID == 0 || staff.GasBasicID == gasID
}

View File

@@ -1,13 +1,16 @@
package common
// 公共实体状态。所有嵌入 models.Entity 的模型统一使用这些整数值
// 通用记录状态。仅用于 models.Entity.Status
const (
StatusDraft = 0 // 草稿
StatusEnable = 1 // 启用
StatusDisable = 2 // 停用
StatusArchived = 3 // 已归档
StatusFrozen = 4 // 已冻结
)
// 领域业务状态。必须写入各模型的专用状态字段,禁止写入 Entity.Status。
const (
StatusPending = 10 // 待处理
StatusActive = 11 // 生效中
StatusExpired = 12 // 已过期