更新密码找回uniapp

This commit is contained in:
hero920103 committed 2026-11-16 17:22:50 +08:00
1 parent 7f9a66da0f
commit 3fdda89833
1304 files changed
+3503 -26132

No files matched your search

+1 -61
View File
@@ -15,13 +15,6 @@ import (
beego "github.com/beego/beego/v2/server/web"
)
// PlatformTenantPackageController 平台端「租户套餐」管理
//
// 两块能力:
// 1. 功能套餐(yz_system_tenant_package + yz_system_tenant_package_module):
// 勾选套餐包含的功能模块(erp / oa / crm / cms ...),租户绑定后按其开通功能。
// 2. 用户数配额(yz_system_tenant_user_quota_package + yz_system_tenant_quota_order):
// 每个租户有用户数上限(默认 20),支持按单个用户或按加购套餐增购。
type PlatformTenantPackageController struct {
beego.Controller
}
@@ -32,9 +25,6 @@ func (c *PlatformTenantPackageController) jsonErr(httpStatus, bizCode int, msg s
_ = c.ServeJSON()
}
// requirePlatform 套餐与配额是平台侧经营数据,全部路由都挂在 /platform 下。
// 此前每个方法各自解析令牌、且没有一个判端——租户令牌即可改自己的套餐上限和
// 用户数配额,等于把计费开关交给了付费方。失败时已写好响应,调用方必须立即 return。
func (c *PlatformTenantPackageController) requirePlatform() bool {
if _, err := identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndPlatform); err != nil {
code := identity.Status(err)
@@ -56,7 +46,6 @@ func (c *PlatformTenantPackageController) jsonOK(data interface{}, msg string) {
_ = c.ServeJSON()
}
// currentOperator 解析当前平台账号名(用于增购记录留痕;取不到时返回空串,不阻断请求)
func (c *PlatformTenantPackageController) currentOperator() string {
claims, err := identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndPlatform)
if err != nil || claims == nil {
@@ -83,8 +72,6 @@ func parseUint64Param(raw string) uint64 {
return v
}
// ============================ 功能套餐 ============================
type tenantPackageModuleItem struct {
ModuleCode string `json:"module_code"`
ModuleName string `json:"module_name"`
@@ -104,7 +91,6 @@ type tenantPackagePayload struct {
UserQuota *int `json:"user_quota"`
ExtraUserPrice *float64 `json:"extra_user_price"`
IsDefault *int8 `json:"is_default"`
// AllowRepurchase 是否允许重复购买:1允许(默认) 0仅可购买一次(体验套餐)
AllowRepurchase *int8 `json:"allow_repurchase"`
Sort *int `json:"sort"`
Status *int8 `json:"status"`
@@ -112,7 +98,6 @@ type tenantPackagePayload struct {
Modules []string `json:"modules"`
}
// normalizePackageDuration 套餐有效时长(天)规范化:<=0 时按 365(年付)
func normalizePackageDuration(v *int) int {
if v == nil || *v <= 0 {
return services.DefaultPackageDurationDays
@@ -120,7 +105,6 @@ func normalizePackageDuration(v *int) int {
return *v
}
// loadPackageModules 批量加载套餐模块(packageID -> 模块列表)
func loadPackageModules(packageIDs []uint64) map[uint64][]tenantPackageModuleItem {
result := map[uint64][]tenantPackageModuleItem{}
if len(packageIDs) == 0 {
@@ -143,7 +127,6 @@ func loadPackageModules(packageIDs []uint64) map[uint64][]tenantPackageModuleIte
return result
}
// GetPackageList GET /platform/tenantPackage/list
func (c *PlatformTenantPackageController) GetPackageList() {
if !c.requirePlatform() {
return
@@ -172,7 +155,6 @@ func (c *PlatformTenantPackageController) GetPackageList() {
}
moduleMap := loadPackageModules(ids)
// 每个套餐的租户数
tenantCount := map[uint64]int{}
if len(ids) > 0 {
var tenants []models.SystemTenant
@@ -222,7 +204,6 @@ func moduleCodes(items []tenantPackageModuleItem) []string {
return codes
}
// GetPackageSelectList GET /platform/tenantPackage/select/list
func (c *PlatformTenantPackageController) GetPackageSelectList() {
if !c.requirePlatform() {
return
@@ -267,7 +248,6 @@ func (c *PlatformTenantPackageController) GetPackageSelectList() {
c.jsonOK(list, "获取成功")
}
// GetPackageDetail GET /platform/tenantPackage/detail/:id
func (c *PlatformTenantPackageController) GetPackageDetail() {
if !c.requirePlatform() {
return
@@ -292,8 +272,6 @@ func (c *PlatformTenantPackageController) GetPackageDetail() {
c.jsonOK(tenantPackageDTO{SystemTenantPackage: row, Modules: modules}, "获取成功")
}
// GetPurchaseURL GET /platform/tenantPackage/purchaseUrl
// 套餐购买链接:租户端未开通功能卡片「购买」按钮的跳转地址
func (c *PlatformTenantPackageController) GetPurchaseURL() {
if !c.requirePlatform() {
return
@@ -301,7 +279,6 @@ func (c *PlatformTenantPackageController) GetPurchaseURL() {
c.jsonOK(map[string]interface{}{"purchase_url": services.GetPackagePurchaseURL()}, "获取成功")
}
// SavePurchaseURL POST /platform/tenantPackage/purchaseUrl
func (c *PlatformTenantPackageController) SavePurchaseURL() {
if !c.requirePlatform() {
return
@@ -319,8 +296,6 @@ func (c *PlatformTenantPackageController) SavePurchaseURL() {
c.jsonOK(nil, "保存成功")
}
// GetModuleOptions GET /platform/tenantPackage/moduleOptions
// 可加入套餐的功能模块清单(取 yz_system_modules 中启用且未删除的模块)
func (c *PlatformTenantPackageController) GetModuleOptions() {
if !c.requirePlatform() {
return
@@ -351,7 +326,6 @@ func (c *PlatformTenantPackageController) GetModuleOptions() {
c.jsonOK(map[string]interface{}{"list": list, "total": len(list)}, "获取成功")
}
// savePackageModules 覆盖式保存套餐模块
func savePackageModules(packageID uint64, modules []string) error {
if _, err := models.Orm.QueryTable(new(models.SystemTenantPackageModule)).
Filter("package_id", packageID).
@@ -389,7 +363,6 @@ func savePackageModules(packageID uint64, modules []string) error {
return nil
}
// CreatePackage POST /platform/tenantPackage/create
func (c *PlatformTenantPackageController) CreatePackage() {
if !c.requirePlatform() {
return
@@ -436,7 +409,6 @@ func (c *PlatformTenantPackageController) CreatePackage() {
if row.UserQuota <= 0 {
row.UserQuota = services.DefaultTenantUserQuota
}
// 体验套餐(不允许重复购买)不涉及用户数增购,增购价恒为 0
if row.AllowRepurchase == 0 {
row.ExtraUserPrice = 0
}
@@ -455,7 +427,6 @@ func (c *PlatformTenantPackageController) CreatePackage() {
c.jsonOK(map[string]interface{}{"id": uint64(id)}, "创建成功")
}
// EditPackage POST /platform/tenantPackage/edit/:id
func (c *PlatformTenantPackageController) EditPackage() {
if !c.requirePlatform() {
return
@@ -521,7 +492,6 @@ func (c *PlatformTenantPackageController) EditPackage() {
update["allow_repurchase"] = *p.AllowRepurchase
}
// 体验套餐(不允许重复购买)不涉及用户数增购,增购价恒为 0
allowRepurchase := int8(1)
if p.AllowRepurchase != nil {
allowRepurchase = *p.AllowRepurchase
@@ -557,7 +527,6 @@ func (c *PlatformTenantPackageController) EditPackage() {
c.jsonOK(nil, "编辑成功")
}
// clearOtherDefaultPackages 保证全局只有一个默认套餐
func clearOtherDefaultPackages(keepID uint64) {
_, _ = models.Orm.QueryTable(new(models.SystemTenantPackage)).
Filter("id__ne", keepID).
@@ -565,8 +534,6 @@ func clearOtherDefaultPackages(keepID uint64) {
Update(map[string]interface{}{"is_default": 0})
}
// DeletePackage DELETE /platform/tenantPackage/delete/:id(软删)
// 注意:基础套餐(code=basic)为系统内置兜底套餐(套餐到期自动降级目标),任何情况下不允许删除。
func (c *PlatformTenantPackageController) DeletePackage() {
if !c.requirePlatform() {
return
@@ -584,7 +551,6 @@ func (c *PlatformTenantPackageController) DeletePackage() {
c.jsonErr(400, 400, "基础套餐为系统内置套餐,不允许删除")
return
}
// 有租户正在使用该套餐时不允许删除
used, _ := models.Orm.QueryTable(new(models.SystemTenant)).Filter("package_id", id).Count()
if used > 0 {
c.jsonErr(400, 400, fmt.Sprintf("该套餐已被 %d 个租户使用,请先调整租户套餐", used))
@@ -621,8 +587,6 @@ func valueInt(v *int, def int) int {
return *v
}
// ============================ 用户数加购套餐 ============================
type quotaPackagePayload struct {
Name string `json:"name"`
UserCount *int `json:"user_count"`
@@ -632,7 +596,6 @@ type quotaPackagePayload struct {
Remark string `json:"remark"`
}
// GetQuotaPackageList GET /platform/tenantQuotaPackage/list
func (c *PlatformTenantPackageController) GetQuotaPackageList() {
if !c.requirePlatform() {
return
@@ -650,7 +613,6 @@ func (c *PlatformTenantPackageController) GetQuotaPackageList() {
c.jsonOK(map[string]interface{}{"list": rows, "total": len(rows)}, "获取成功")
}
// CreateQuotaPackage POST /platform/tenantQuotaPackage/create
func (c *PlatformTenantPackageController) CreateQuotaPackage() {
if !c.requirePlatform() {
return
@@ -686,7 +648,6 @@ func (c *PlatformTenantPackageController) CreateQuotaPackage() {
c.jsonOK(map[string]interface{}{"id": uint64(id)}, "创建成功")
}
// EditQuotaPackage POST /platform/tenantQuotaPackage/edit/:id
func (c *PlatformTenantPackageController) EditQuotaPackage() {
if !c.requirePlatform() {
return
@@ -738,7 +699,6 @@ func (c *PlatformTenantPackageController) EditQuotaPackage() {
c.jsonOK(nil, "编辑成功")
}
// DeleteQuotaPackage DELETE /platform/tenantQuotaPackage/delete/:id(软删)
func (c *PlatformTenantPackageController) DeleteQuotaPackage() {
if !c.requirePlatform() {
return
@@ -764,16 +724,12 @@ func (c *PlatformTenantPackageController) DeleteQuotaPackage() {
c.jsonOK(nil, "删除成功")
}
// ============================ 租户套餐 / 用户数配额 ============================
type setTenantPackagePayload struct {
Tid uint64 `json:"tid"`
PackageID uint64 `json:"package_id"`
SyncQuota *bool `json:"sync_quota"`
}
// SetTenantPackage POST /platform/tenant/setPackage
// 为租户绑定套餐;sync_quota 为 true(默认)时按套餐包含用户数与现有上限取较大值同步。
func (c *PlatformTenantPackageController) SetTenantPackage() {
if !c.requirePlatform() {
return
@@ -798,8 +754,6 @@ func (c *PlatformTenantPackageController) SetTenantPackage() {
c.jsonOK(map[string]interface{}{"user_quota": newQuota}, "套餐设置成功")
}
// GetTenantQuotaInfo GET /platform/tenant/quotaInfo?tid=1
// 返回租户套餐、用户数使用情况、可增购规格与单价
func (c *PlatformTenantPackageController) GetTenantQuotaInfo() {
if !c.requirePlatform() {
return
@@ -828,7 +782,6 @@ func (c *PlatformTenantPackageController) GetTenantQuotaInfo() {
moduleList = append(moduleList, tenantPackageModuleItem{ModuleCode: m.ModuleCode, ModuleName: m.ModuleName})
}
// 已开通单品功能:单品订单不改变租户套餐,需与套餐模块并集展示,避免“买了功能看不到”
productOrders, productModules := loadTenantProductEntitlements(tid)
c.jsonOK(map[string]interface{}{
@@ -850,7 +803,6 @@ func (c *PlatformTenantPackageController) GetTenantQuotaInfo() {
}, "获取成功")
}
// productEntitlement 已开通单品功能明细(租户详情「套餐与用户数」展示 / 关闭用)
type productEntitlement struct {
OrderID uint64 `json:"order_id"`
OrderNo string `json:"order_no"`
@@ -861,13 +813,9 @@ type productEntitlement struct {
Amount float64 `json:"amount"`
ActivateTime *time.Time `json:"activate_time"`
ExpireTime *time.Time `json:"expire_time"`
// Expired 是否已过有效期:到期后租户端权益自动失效,需续费
Expired bool `json:"expired"`
}
// loadTenantProductEntitlements 加载租户已开通的单品功能:
// - orders 订单明细(按开通时间倒序),供面板展示与「关闭功能」操作;
// - modules 去重后的模块列表,与套餐模块并集构成租户完整功能权益。
func loadTenantProductEntitlements(tid uint64) ([]productEntitlement, []tenantPackageModuleItem) {
orders := make([]productEntitlement, 0)
modules := make([]tenantPackageModuleItem, 0)
@@ -899,7 +847,6 @@ func loadTenantProductEntitlements(tid uint64) ([]productEntitlement, []tenantPa
productMap[p.ID] = p
}
// 模块 code -> 名称(大小写/空格不敏感,与租户端权益判定保持一致)
var moduleRows []models.SystemModules
_, _ = models.Orm.QueryTable(new(models.SystemModules)).
Filter("delete_time__isnull", true).
@@ -916,7 +863,6 @@ func loadTenantProductEntitlements(tid uint64) ([]productEntitlement, []tenantPa
if p, ok := productMap[r.ProductID]; ok {
code = strings.TrimSpace(p.ModuleCode)
if code == "" {
// 产品未显式关联模块时按产品编码兜底(与 GetTenantModuleCodes 一致)
code = strings.TrimSpace(p.Code)
}
name = p.Name
@@ -924,7 +870,6 @@ func loadTenantProductEntitlements(tid uint64) ([]productEntitlement, []tenantPa
normCode := services.NormalizeModuleCode(code)
expire := services.ProductOrderExpireAt(&r)
expired := services.ProductOrderExpired(&r, now)
// 权益模块只统计仍在有效期内的订单,与租户端 GetTenantModuleCodes 判定保持一致
if !expired && normCode != "" && !seen[normCode] {
seen[normCode] = true
moduleName := moduleNameMap[normCode]
@@ -933,7 +878,6 @@ func loadTenantProductEntitlements(tid uint64) ([]productEntitlement, []tenantPa
}
modules = append(modules, tenantPackageModuleItem{ModuleCode: code, ModuleName: moduleName})
}
// 明细保留全部已开通订单(含已过期):便于平台看到「已过期,待续费并关闭」
orders = append(orders, productEntitlement{
OrderID: r.ID,
OrderNo: r.OrderNo,
@@ -952,15 +896,13 @@ func loadTenantProductEntitlements(tid uint64) ([]productEntitlement, []tenantPa
type rechargeQuotaPayload struct {
Tid uint64 `json:"tid"`
Type int8 `json:"type"` // 1 单个增购 2 套餐增购
Type int8 `json:"type"`
QuotaPackageID uint64 `json:"quota_package_id"`
UserCount int `json:"user_count"`
UnitPrice float64 `json:"unit_price"`
Remark string `json:"remark"`
}
// RechargeTenantQuota POST /platform/tenant/rechargeQuota
// 用户数增购:单个增购(单价 x 人数)或 按加购套餐(如 5人/500元)
func (c *PlatformTenantPackageController) RechargeTenantQuota() {
if !c.requirePlatform() {
return
@@ -1009,7 +951,6 @@ func (c *PlatformTenantPackageController) RechargeTenantQuota() {
}
unitPrice := p.UnitPrice
if unitPrice <= 0 {
// 未传单价时取租户套餐的单个用户增购价
if info, err := services.GetTenantQuotaInfo(p.Tid); err == nil && info.ExtraUserPrice > 0 {
unitPrice = info.ExtraUserPrice
} else {
@@ -1048,7 +989,6 @@ func (c *PlatformTenantPackageController) RechargeTenantQuota() {
c.jsonOK(map[string]interface{}{"quota": after, "add": order.UserCount, "amount": order.Amount}, "增购成功")
}
// GetQuotaOrders GET /platform/tenant/quotaOrders?tid=1
func (c *PlatformTenantPackageController) GetQuotaOrders() {
if !c.requirePlatform() {
return