Merge branch 'master' of https://git.yunzer.cn/yunzerwebsite/yunzerwebsiteallinone
This commit is contained in:
@@ -113,10 +113,12 @@ func (c *BackendMenuController) GetBackendMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
// 套餐功能开通过滤:仅展示租户套餐已包含的功能模块对应的菜单(未包含的整块菜单不展示)
|
||||
backendMenus = filterMenusByTenantPackage(c.Ctx.Request.Header.Get("Authorization"), backendMenus, tid)
|
||||
// 套餐功能开通标记:未开通模块的菜单保留但标记 locked(前端展示锁定态与升级提示,不再 404)
|
||||
backendMenus, lockedMenuIDs := filterMenusByTenantPackageLocked(c.Ctx.Request.Header.Get("Authorization"), backendMenus, tid, true)
|
||||
menuTree := buildMenuTree(backendMenus, 0)
|
||||
markTreeLocked(menuTree, lockedMenuIDs)
|
||||
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": buildMenuTree(backendMenus, 0)}
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": menuTree}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
@@ -139,26 +141,51 @@ func backendJWTTenantID(auth string) uint64 {
|
||||
return uint64(claims.TenantId)
|
||||
}
|
||||
|
||||
// filterMenusByTenantPackage 按租户套餐包含的功能模块过滤菜单。
|
||||
// filterMenusByTenantPackage 按租户套餐包含的功能模块过滤菜单(剔除未开通模块,用于角色菜单分配等场景)。
|
||||
// tid 优先取 token 中的租户ID,其次用调用方传入的兜底值;两者都取不到时不处理(保持原行为)。
|
||||
func filterMenusByTenantPackage(authHeader string, menus []models.SystemMenu, tid uint64) []models.SystemMenu {
|
||||
filtered, _ := filterMenusByTenantPackageLocked(authHeader, menus, tid, false)
|
||||
return filtered
|
||||
}
|
||||
|
||||
// filterMenusByTenantPackageLocked 按租户套餐处理菜单。
|
||||
// markLocked=false:剔除未开通模块的菜单(原行为);markLocked=true:保留菜单并返回锁定菜单ID集合(含后代)。
|
||||
func filterMenusByTenantPackageLocked(authHeader string, menus []models.SystemMenu, tid uint64, markLocked bool) ([]models.SystemMenu, map[uint64]bool) {
|
||||
if jwtTid := backendJWTTenantID(authHeader); jwtTid > 0 {
|
||||
tid = jwtTid
|
||||
}
|
||||
if tid == 0 {
|
||||
return menus
|
||||
return menus, nil
|
||||
}
|
||||
allModules, err := services.ListEnabledModules()
|
||||
if err != nil || len(allModules) == 0 {
|
||||
return menus
|
||||
return menus, nil
|
||||
}
|
||||
allowed := services.GetTenantModuleCodes(tid)
|
||||
// 安全兜底:租户没有绑定套餐或套餐未配置任何功能模块时不做过滤,
|
||||
// 避免因套餐数据缺失导致租户端菜单整体消失。
|
||||
if len(allowed) == 0 {
|
||||
return menus
|
||||
return menus, nil
|
||||
}
|
||||
if markLocked {
|
||||
return services.MarkMenusLockedByTenantModules(menus, allModules, allowed)
|
||||
}
|
||||
return services.FilterMenusByTenantModules(menus, allModules, allowed), nil
|
||||
}
|
||||
|
||||
// markTreeLocked 将菜单树中位于锁定集合的节点标记为 locked
|
||||
func markTreeLocked(nodes []*menuNode, locked map[uint64]bool) {
|
||||
if len(nodes) == 0 || len(locked) == 0 {
|
||||
return
|
||||
}
|
||||
for _, n := range nodes {
|
||||
if locked[n.ID] {
|
||||
n.Locked = true
|
||||
}
|
||||
if len(n.Children) > 0 {
|
||||
markTreeLocked(n.Children, locked)
|
||||
}
|
||||
}
|
||||
return services.FilterMenusByTenantModules(menus, allModules, allowed)
|
||||
}
|
||||
|
||||
// parseRightsToSet 将角色 rights 解析为菜单 ID 集合(兼容 JSON 数组 / 逗号分隔)
|
||||
@@ -350,6 +377,7 @@ type menuNode struct {
|
||||
Views []int `json:"views,omitempty"`
|
||||
Type int8 `json:"type"`
|
||||
Permission string `json:"permission,omitempty"`
|
||||
Locked bool `json:"locked,omitempty"`
|
||||
Children []*menuNode `json:"children,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,18 @@ import (
|
||||
"server/models"
|
||||
"server/pkg/jwtutil"
|
||||
"server/services"
|
||||
"server/services"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// tenantModuleItem 模块列表返回项:在模块基础信息上补充套餐开通状态,
|
||||
// locked=true 表示该模块不在当前租户已购套餐内(前端置灰并提示购买套餐)。
|
||||
type tenantModuleItem struct {
|
||||
models.SystemModules
|
||||
Locked bool `json:"locked"`
|
||||
}
|
||||
|
||||
// BackendModulesController backend 模块接口(yz_system_modules)
|
||||
type BackendModulesController struct {
|
||||
beego.Controller
|
||||
@@ -51,6 +59,8 @@ type moduleWithEnabled struct {
|
||||
// 返回当前 backend 账号可见的模块(status=1 且 is_show=1),并根据租户绑定的套餐标记每个模块是否已开通。
|
||||
// 前端可据此排序(已开通在前)、置灰未开通卡片、阻止跳转。
|
||||
func (c *BackendModulesController) GetTenantList() {
|
||||
claims, err := c.backendModulesClaims()
|
||||
if err != nil {
|
||||
claims, err := c.backendModulesClaims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
@@ -58,6 +68,7 @@ func (c *BackendModulesController) GetTenantList() {
|
||||
}
|
||||
|
||||
var rows []models.SystemModules
|
||||
_, err = models.Orm.QueryTable(new(models.SystemModules)).
|
||||
_, err = models.Orm.QueryTable(new(models.SystemModules)).
|
||||
Filter("delete_time__isnull", true).
|
||||
Filter("status", 1).
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/jwtutil"
|
||||
"server/services/payment"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// BackendProductPurchaseController 租户端「产品购买」接口(只读产品 + 下单 + 订单状态)。
|
||||
// 注意:与 CMS 产品管理的 BackendProductController 区分开。
|
||||
// 租户身份来自 JWT:UserType=backend,TenantId 即租户ID。
|
||||
type BackendProductPurchaseController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *BackendProductPurchaseController) claims() (*jwtutil.Claims, error) {
|
||||
auth := c.Ctx.Request.Header.Get("Authorization")
|
||||
if auth == "" {
|
||||
return nil, errors.New("未登录")
|
||||
}
|
||||
parts := strings.SplitN(auth, " ", 2)
|
||||
if len(parts) != 2 || parts[0] != "Bearer" {
|
||||
return nil, errors.New("认证信息格式错误")
|
||||
}
|
||||
claims, err := jwtutil.ParseToken(parts[1])
|
||||
if err != nil {
|
||||
return nil, errors.New("无效的token")
|
||||
}
|
||||
if claims.UserType != "backend" {
|
||||
return nil, errors.New("无权访问")
|
||||
}
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func (c *BackendProductPurchaseController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
c.Ctx.Output.SetStatus(httpStatus)
|
||||
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *BackendProductPurchaseController) jsonOK(data interface{}, msg string) {
|
||||
if msg == "" {
|
||||
msg = "success"
|
||||
}
|
||||
resp := map[string]interface{}{"code": 200, "msg": msg}
|
||||
if data != nil {
|
||||
resp["data"] = data
|
||||
}
|
||||
c.Data["json"] = resp
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *BackendProductPurchaseController) tenantName(tid uint64) string {
|
||||
if tid == 0 {
|
||||
return ""
|
||||
}
|
||||
tenant := &models.SystemTenant{}
|
||||
if err := models.Orm.QueryTable(new(models.SystemTenant)).
|
||||
Filter("id", tid).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(tenant); err != nil {
|
||||
return ""
|
||||
}
|
||||
return tenant.TenantName
|
||||
}
|
||||
|
||||
// GetProductList GET /backend/product/list
|
||||
// 上架产品列表(含功能节点与启用档位),供购买页/产品列表展示
|
||||
func (c *BackendProductPurchaseController) GetProductList() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
var rows []models.PlatformProduct
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformProduct)).
|
||||
Filter("delete_time__isnull", true).
|
||||
Filter("status", 1).
|
||||
OrderBy("sort", "id").
|
||||
All(&rows); err != nil {
|
||||
c.jsonErr(500, 500, "获取失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
ids := make([]uint64, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
ids = append(ids, r.ID)
|
||||
}
|
||||
featureMap := loadProductFeatures(ids)
|
||||
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
list = append(list, productToMap(r, featureMap[r.ID]))
|
||||
}
|
||||
c.jsonOK(map[string]interface{}{"list": list, "total": len(list)}, "获取成功")
|
||||
}
|
||||
|
||||
// GetProductDetailByCode GET /backend/product/detail/:code
|
||||
// 按产品编码取详情(租户端 home 卡片按模块 code 跳转购买页时使用)
|
||||
func (c *BackendProductPurchaseController) GetProductDetailByCode() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
code := strings.TrimSpace(c.Ctx.Input.Param(":code"))
|
||||
if code == "" {
|
||||
c.jsonErr(400, 400, "产品编码不能为空")
|
||||
return
|
||||
}
|
||||
var row models.PlatformProduct
|
||||
if err := models.Orm.QueryTable(new(models.PlatformProduct)).
|
||||
Filter("code", code).
|
||||
Filter("delete_time__isnull", true).
|
||||
Filter("status", 1).
|
||||
One(&row); err != nil {
|
||||
c.jsonErr(404, 404, "产品不存在或未上架")
|
||||
return
|
||||
}
|
||||
c.jsonOK(productToMap(row, loadProductFeatures([]uint64{row.ID})[row.ID]), "获取成功")
|
||||
}
|
||||
|
||||
type createProductOrderPayload struct {
|
||||
ProductCode string `json:"product_code"`
|
||||
Channel string `json:"channel"`
|
||||
PayType string `json:"pay_type"`
|
||||
ReturnURL string `json:"return_url"`
|
||||
}
|
||||
|
||||
// CreateOrder POST /backend/product/order/create
|
||||
// 创建购买订单;channel 非空时同时创建支付单并返回拉起支付参数。
|
||||
func (c *BackendProductPurchaseController) CreateOrder() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
tid := uint64(claims.TenantId)
|
||||
if tid == 0 {
|
||||
c.jsonErr(401, 401, "未获取到租户信息")
|
||||
return
|
||||
}
|
||||
|
||||
body, _ := io.ReadAll(c.Ctx.Request.Body)
|
||||
var p createProductOrderPayload
|
||||
if err := json.Unmarshal(body, &p); err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
p.ProductCode = strings.TrimSpace(p.ProductCode)
|
||||
p.Channel = strings.TrimSpace(p.Channel)
|
||||
if p.ProductCode == "" {
|
||||
c.jsonErr(400, 400, "产品不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
var product models.PlatformProduct
|
||||
if err := models.Orm.QueryTable(new(models.PlatformProduct)).
|
||||
Filter("code", p.ProductCode).
|
||||
Filter("delete_time__isnull", true).
|
||||
Filter("status", 1).
|
||||
One(&product); err != nil {
|
||||
c.jsonErr(404, 404, "产品不存在或未上架")
|
||||
return
|
||||
}
|
||||
if product.Price <= 0 {
|
||||
c.jsonErr(400, 400, "该产品未配置价格,请联系平台")
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
order := &models.PlatformProductOrder{
|
||||
OrderNo: "PO" + strconv.FormatInt(now.UnixNano(), 10),
|
||||
Tid: tid,
|
||||
TenantName: c.tenantName(tid),
|
||||
ProductID: product.ID,
|
||||
ProductCode: product.Code,
|
||||
ProductName: product.Name,
|
||||
Amount: product.Price,
|
||||
Status: models.ProductOrderStatusPending,
|
||||
UpdateTime: &now,
|
||||
}
|
||||
|
||||
// 未选择支付渠道:仅落单,等待平台确认(线下转账/试用审批场景)
|
||||
if p.Channel == "" {
|
||||
if _, err := models.Orm.Insert(order); err != nil {
|
||||
c.jsonErr(500, 500, "下单失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
c.jsonOK(map[string]interface{}{
|
||||
"order_no": order.OrderNo,
|
||||
"pay_no": "",
|
||||
"amount": order.Amount,
|
||||
"offline": true,
|
||||
}, "下单成功,请等待平台开通")
|
||||
return
|
||||
}
|
||||
|
||||
amountFen := int64(order.Amount*100 + 0.5)
|
||||
subject := product.Name
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
payOrder, params, err := payment.CreatePayment(ctx, payment.CreateInput{
|
||||
OutTradeNo: order.OrderNo,
|
||||
OrderType: models.CommissionOrderTypeModuleShop,
|
||||
TenantID: strconv.FormatUint(tid, 10),
|
||||
TenantName: order.TenantName,
|
||||
Amount: amountFen,
|
||||
Channel: p.Channel,
|
||||
Subject: subject,
|
||||
ReturnURL: strings.TrimSpace(p.ReturnURL),
|
||||
ClientIP: c.Ctx.Input.IP(),
|
||||
PayType: p.PayType,
|
||||
})
|
||||
if err != nil {
|
||||
c.jsonErr(400, 400, "创建支付单失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
order.PayNo = payOrder.PayNo
|
||||
order.Channel = p.Channel
|
||||
if _, err := models.Orm.Insert(order); err != nil {
|
||||
c.jsonErr(500, 500, "下单失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
c.jsonOK(map[string]interface{}{
|
||||
"order_no": order.OrderNo,
|
||||
"pay_no": payOrder.PayNo,
|
||||
"amount": order.Amount,
|
||||
"channel": p.Channel,
|
||||
"pay_params": params,
|
||||
"offline": false,
|
||||
}, "下单成功")
|
||||
}
|
||||
|
||||
// GetOrderStatus GET /backend/product/order/status?order_no=xxx
|
||||
// 查询订单状态;在线支付时同步渠道状态,已支付则自动开通套餐。
|
||||
func (c *BackendProductPurchaseController) GetOrderStatus() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
orderNo := strings.TrimSpace(c.GetString("order_no"))
|
||||
if orderNo == "" {
|
||||
c.jsonErr(400, 400, "订单号不能为空")
|
||||
return
|
||||
}
|
||||
var order models.PlatformProductOrder
|
||||
if err := models.Orm.QueryTable(new(models.PlatformProductOrder)).
|
||||
Filter("order_no", orderNo).
|
||||
Filter("tid", uint64(claims.TenantId)).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&order); err != nil {
|
||||
c.jsonErr(404, 404, "订单不存在")
|
||||
return
|
||||
}
|
||||
|
||||
// 在线支付:同步渠道状态,支付成功后自动开通
|
||||
if order.Status == models.ProductOrderStatusPending && order.PayNo != "" {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
if payOrder, qerr := payment.QueryPayment(ctx, order.PayNo, true); qerr == nil && payOrder.Status == models.PayStatusPaid {
|
||||
now := time.Now()
|
||||
order.Status = models.ProductOrderStatusPaid
|
||||
order.UpdateTime = &now
|
||||
_, _ = models.Orm.Update(&order, "Status", "UpdateTime")
|
||||
}
|
||||
}
|
||||
if order.Status == models.ProductOrderStatusPaid {
|
||||
if err := activateProductOrder(&order, "支付成功自动开通"); err == nil {
|
||||
_ = models.Orm.Read(&order)
|
||||
}
|
||||
}
|
||||
|
||||
c.jsonOK(map[string]interface{}{
|
||||
"order_no": order.OrderNo,
|
||||
"status": order.Status,
|
||||
"amount": order.Amount,
|
||||
"product_name": order.ProductName,
|
||||
"pay_no": order.PayNo,
|
||||
"activate_time": order.ActivateTime,
|
||||
}, "获取成功")
|
||||
}
|
||||
|
||||
// GetMyOrders GET /backend/product/order/list 本租户购买记录
|
||||
func (c *BackendProductPurchaseController) GetMyOrders() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
return
|
||||
}
|
||||
var rows []models.PlatformProductOrder
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformProductOrder)).
|
||||
Filter("tid", uint64(claims.TenantId)).
|
||||
Filter("delete_time__isnull", true).
|
||||
OrderBy("-id").
|
||||
Limit(50).
|
||||
All(&rows); err != nil {
|
||||
c.jsonErr(500, 500, "获取失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
c.jsonOK(map[string]interface{}{"list": rows, "total": len(rows)}, "获取成功")
|
||||
}
|
||||
@@ -47,15 +47,18 @@ func (c *BackendTenantQuotaController) GetQuotaInfo() {
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
"data": map[string]interface{}{
|
||||
"tid": info.Tid,
|
||||
"package_id": info.EffectivePackageID,
|
||||
"package_name": info.PackageName,
|
||||
"quota": info.Quota,
|
||||
"used": info.Used,
|
||||
"remaining": info.Remaining,
|
||||
"extra_user_price": info.ExtraUserPrice,
|
||||
"module_codes": moduleCodes,
|
||||
"module_names": moduleNames,
|
||||
"tid": info.Tid,
|
||||
"package_id": info.EffectivePackageID,
|
||||
"package_name": info.PackageName,
|
||||
"quota": info.Quota,
|
||||
"used": info.Used,
|
||||
"remaining": info.Remaining,
|
||||
"extra_user_price": info.ExtraUserPrice,
|
||||
"duration_days": info.DurationDays,
|
||||
"package_expire_time": info.PackageExpireTime,
|
||||
"days_remaining": info.DaysRemaining,
|
||||
"module_codes": moduleCodes,
|
||||
"module_names": moduleNames,
|
||||
},
|
||||
}
|
||||
_ = c.ServeJSON()
|
||||
|
||||
@@ -0,0 +1,431 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/services"
|
||||
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// PlatformProductController 平台端「产品定价」管理
|
||||
//
|
||||
// 产品(名称 / 编码 / 价格 / 关联功能 / 上下架)+ 功能节点树 -> 租户端购买展示与下单。
|
||||
type PlatformProductController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (c *PlatformProductController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
c.Ctx.Output.SetStatus(httpStatus)
|
||||
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *PlatformProductController) jsonOK(data interface{}, msg string) {
|
||||
if msg == "" {
|
||||
msg = "success"
|
||||
}
|
||||
resp := map[string]interface{}{"code": 200, "msg": msg}
|
||||
if data != nil {
|
||||
resp["data"] = data
|
||||
}
|
||||
c.Data["json"] = resp
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func (c *PlatformProductController) readBody(target interface{}) bool {
|
||||
raw, err := io.ReadAll(c.Ctx.Request.Body)
|
||||
if err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return false
|
||||
}
|
||||
if err := json.Unmarshal(raw, target); err != nil {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ============================ 产品 ============================
|
||||
|
||||
type productFeaturePayload struct {
|
||||
ID uint64 `json:"id"`
|
||||
Pid uint64 `json:"pid"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Sort int `json:"sort"`
|
||||
}
|
||||
|
||||
type productPayload struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Price *float64 `json:"price"`
|
||||
ModuleCode string `json:"module_code"`
|
||||
Sort *int `json:"sort"`
|
||||
Status *int8 `json:"status"`
|
||||
Remark string `json:"remark"`
|
||||
Features []productFeaturePayload `json:"features"`
|
||||
}
|
||||
|
||||
// loadProductFeatures 批量加载产品功能节点(扁平,含 pid,前端按 pid 组装树)
|
||||
func loadProductFeatures(productIDs []uint64) map[uint64][]models.PlatformProductFeature {
|
||||
result := map[uint64][]models.PlatformProductFeature{}
|
||||
if len(productIDs) == 0 {
|
||||
return result
|
||||
}
|
||||
var rows []models.PlatformProductFeature
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformProductFeature)).
|
||||
Filter("product_id__in", productIDs).
|
||||
OrderBy("sort", "id").
|
||||
All(&rows); err != nil {
|
||||
return result
|
||||
}
|
||||
for _, r := range rows {
|
||||
result[r.ProductID] = append(result[r.ProductID], r)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func productToMap(p models.PlatformProduct, features []models.PlatformProductFeature) map[string]interface{} {
|
||||
if features == nil {
|
||||
features = []models.PlatformProductFeature{}
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"id": p.ID,
|
||||
"code": p.Code,
|
||||
"name": p.Name,
|
||||
"price": p.Price,
|
||||
"module_code": p.ModuleCode,
|
||||
"sort": p.Sort,
|
||||
"status": p.Status,
|
||||
"remark": p.Remark,
|
||||
"features": features,
|
||||
"create_time": p.CreateTime,
|
||||
"update_time": p.UpdateTime,
|
||||
}
|
||||
}
|
||||
|
||||
// GetProductList GET /platform/product/list
|
||||
func (c *PlatformProductController) GetProductList() {
|
||||
keyword := strings.TrimSpace(c.GetString("keyword"))
|
||||
status := strings.TrimSpace(c.GetString("status"))
|
||||
|
||||
qs := models.Orm.QueryTable(new(models.PlatformProduct)).Filter("delete_time__isnull", true)
|
||||
if keyword != "" {
|
||||
qs = qs.Filter("name__icontains", keyword)
|
||||
}
|
||||
if status == "0" || status == "1" {
|
||||
v, _ := strconv.Atoi(status)
|
||||
qs = qs.Filter("status", v)
|
||||
}
|
||||
|
||||
var rows []models.PlatformProduct
|
||||
if _, err := qs.OrderBy("sort", "id").All(&rows); err != nil {
|
||||
c.jsonErr(500, 500, "获取失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
ids := make([]uint64, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
ids = append(ids, r.ID)
|
||||
}
|
||||
featureMap := loadProductFeatures(ids)
|
||||
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for _, r := range rows {
|
||||
list = append(list, productToMap(r, featureMap[r.ID]))
|
||||
}
|
||||
c.jsonOK(map[string]interface{}{"list": list, "total": len(list)}, "获取成功")
|
||||
}
|
||||
|
||||
// GetProductDetail GET /platform/product/detail/:id
|
||||
func (c *PlatformProductController) GetProductDetail() {
|
||||
id := parseUint64Param(c.Ctx.Input.Param(":id"))
|
||||
if id == 0 {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
var row models.PlatformProduct
|
||||
if err := models.Orm.QueryTable(new(models.PlatformProduct)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&row); err != nil {
|
||||
c.jsonErr(404, 404, "产品不存在")
|
||||
return
|
||||
}
|
||||
c.jsonOK(productToMap(row, loadProductFeatures([]uint64{id})[id]), "获取成功")
|
||||
}
|
||||
|
||||
// saveProductFeatures 覆盖式保存功能节点(含父子关系 pid)
|
||||
// 前端传扁平数组,顶级节点 pid=0;子节点的 pid 指向父节点在库中的真实 ID,
|
||||
// 因此这里先按「前端临时序号 -> 库 ID」建立映射再落库。
|
||||
func saveProductFeatures(productID uint64, items []productFeaturePayload) error {
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformProductFeature)).
|
||||
Filter("product_id", productID).Delete(); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 第一遍:按输入顺序建节点,记录 oldID(库中已有ID或前端临时ID) -> newID
|
||||
oldToNew := map[uint64]uint64{}
|
||||
type pending struct {
|
||||
item productFeaturePayload
|
||||
newID uint64
|
||||
}
|
||||
created := make([]pending, 0, len(items))
|
||||
|
||||
for i, it := range items {
|
||||
title := strings.TrimSpace(it.Title)
|
||||
if title == "" {
|
||||
continue
|
||||
}
|
||||
sort := it.Sort
|
||||
if sort == 0 {
|
||||
sort = i + 1
|
||||
}
|
||||
row := &models.PlatformProductFeature{
|
||||
ProductID: productID,
|
||||
Title: title,
|
||||
Description: strings.TrimSpace(it.Description),
|
||||
Sort: sort,
|
||||
}
|
||||
id, err := models.Orm.Insert(row)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 前端用 id 字段标识节点:已存在节点传库中真实ID,新增节点传负数临时ID,
|
||||
// 统一建立「旧标识 -> 新ID」映射,供子节点回填 pid。
|
||||
if it.ID != 0 {
|
||||
oldToNew[it.ID] = uint64(id)
|
||||
}
|
||||
created = append(created, pending{item: it, newID: uint64(id)})
|
||||
}
|
||||
|
||||
// 第二遍:回填父级
|
||||
for _, p := range created {
|
||||
pid := p.item.Pid
|
||||
if pid == 0 {
|
||||
continue
|
||||
}
|
||||
if newPid, ok := oldToNew[pid]; ok {
|
||||
pid = newPid
|
||||
}
|
||||
// 父节点已被删除或指向自身时降级为顶级
|
||||
if pid == p.newID {
|
||||
pid = 0
|
||||
}
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformProductFeature)).
|
||||
Filter("id", p.newID).
|
||||
Update(map[string]interface{}{"pid": pid}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateProduct POST /platform/product/create
|
||||
func (c *PlatformProductController) CreateProduct() {
|
||||
var p productPayload
|
||||
if !c.readBody(&p) {
|
||||
return
|
||||
}
|
||||
p.Code = strings.TrimSpace(p.Code)
|
||||
p.Name = strings.TrimSpace(p.Name)
|
||||
if p.Name == "" {
|
||||
c.jsonErr(400, 400, "产品名称不能为空")
|
||||
return
|
||||
}
|
||||
if p.Code == "" {
|
||||
c.jsonErr(400, 400, "产品编码不能为空")
|
||||
return
|
||||
}
|
||||
cnt, _ := models.Orm.QueryTable(new(models.PlatformProduct)).
|
||||
Filter("code", p.Code).
|
||||
Filter("delete_time__isnull", true).
|
||||
Count()
|
||||
if cnt > 0 {
|
||||
c.jsonErr(400, 400, "产品编码已存在")
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
row := &models.PlatformProduct{
|
||||
Code: p.Code,
|
||||
Name: p.Name,
|
||||
Price: valueFloat(p.Price, 0),
|
||||
ModuleCode: strings.TrimSpace(p.ModuleCode),
|
||||
Sort: valueInt(p.Sort, 0),
|
||||
Status: valueInt8(p.Status, 1),
|
||||
Remark: strings.TrimSpace(p.Remark),
|
||||
UpdateTime: &now,
|
||||
}
|
||||
id, err := models.Orm.Insert(row)
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "创建失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
if p.Features != nil {
|
||||
if err := saveProductFeatures(uint64(id), p.Features); err != nil {
|
||||
c.jsonErr(500, 500, "功能节点保存失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
c.jsonOK(map[string]interface{}{"id": uint64(id)}, "创建成功")
|
||||
}
|
||||
|
||||
// EditProduct POST /platform/product/edit/:id
|
||||
func (c *PlatformProductController) EditProduct() {
|
||||
id := parseUint64Param(c.Ctx.Input.Param(":id"))
|
||||
if id == 0 {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
var p productPayload
|
||||
if !c.readBody(&p) {
|
||||
return
|
||||
}
|
||||
p.Code = strings.TrimSpace(p.Code)
|
||||
p.Name = strings.TrimSpace(p.Name)
|
||||
if p.Name == "" {
|
||||
c.jsonErr(400, 400, "产品名称不能为空")
|
||||
return
|
||||
}
|
||||
if p.Code != "" {
|
||||
cnt, _ := models.Orm.QueryTable(new(models.PlatformProduct)).
|
||||
Filter("code", p.Code).
|
||||
Filter("id__ne", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Count()
|
||||
if cnt > 0 {
|
||||
c.jsonErr(400, 400, "产品编码已存在")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
update := map[string]interface{}{
|
||||
"name": p.Name,
|
||||
"module_code": strings.TrimSpace(p.ModuleCode),
|
||||
"sort": valueInt(p.Sort, 0),
|
||||
"status": valueInt8(p.Status, 1),
|
||||
"remark": strings.TrimSpace(p.Remark),
|
||||
"update_time": now,
|
||||
}
|
||||
if p.Code != "" {
|
||||
update["code"] = p.Code
|
||||
}
|
||||
if p.Price != nil {
|
||||
update["price"] = *p.Price
|
||||
}
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformProduct)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(update); err != nil {
|
||||
c.jsonErr(500, 500, "编辑失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
if p.Features != nil {
|
||||
if err := saveProductFeatures(id, p.Features); err != nil {
|
||||
c.jsonErr(500, 500, "功能节点保存失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
c.jsonOK(nil, "编辑成功")
|
||||
}
|
||||
|
||||
// DeleteProduct DELETE /platform/product/delete/:id(软删)
|
||||
func (c *PlatformProductController) DeleteProduct() {
|
||||
id := parseUint64Param(c.Ctx.Input.Param(":id"))
|
||||
if id == 0 {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
now := time.Now()
|
||||
n, err := models.Orm.QueryTable(new(models.PlatformProduct)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
Update(map[string]interface{}{"delete_time": now, "update_time": now})
|
||||
if err != nil {
|
||||
c.jsonErr(500, 500, "删除失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
if n == 0 {
|
||||
c.jsonErr(404, 404, "产品不存在")
|
||||
return
|
||||
}
|
||||
_, _ = models.Orm.QueryTable(new(models.PlatformProductFeature)).Filter("product_id", id).Delete()
|
||||
c.jsonOK(nil, "删除成功")
|
||||
}
|
||||
|
||||
// ============================ 购买订单 ============================
|
||||
|
||||
// GetProductOrders GET /platform/product/orders?status=&keyword=
|
||||
func (c *PlatformProductController) GetProductOrders() {
|
||||
status := strings.TrimSpace(c.GetString("status"))
|
||||
keyword := strings.TrimSpace(c.GetString("keyword"))
|
||||
|
||||
qs := models.Orm.QueryTable(new(models.PlatformProductOrder)).Filter("delete_time__isnull", true)
|
||||
if status != "" {
|
||||
qs = qs.Filter("status", status)
|
||||
}
|
||||
if keyword != "" {
|
||||
qs = qs.Filter("product_name__icontains", keyword)
|
||||
}
|
||||
var rows []models.PlatformProductOrder
|
||||
if _, err := qs.OrderBy("-id").Limit(200).All(&rows); err != nil {
|
||||
c.jsonErr(500, 500, "获取失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
c.jsonOK(map[string]interface{}{"list": rows, "total": len(rows)}, "获取成功")
|
||||
}
|
||||
|
||||
// ActivateProductOrder POST /platform/product/order/activate/:id
|
||||
// 手动开通:将订单置为已支付并绑定套餐(支付回调失败/线下付款时使用)
|
||||
func (c *PlatformProductController) ActivateProductOrder() {
|
||||
id := parseUint64Param(c.Ctx.Input.Param(":id"))
|
||||
if id == 0 {
|
||||
c.jsonErr(400, 400, "参数错误")
|
||||
return
|
||||
}
|
||||
var order models.PlatformProductOrder
|
||||
if err := models.Orm.QueryTable(new(models.PlatformProductOrder)).
|
||||
Filter("id", id).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&order); err != nil {
|
||||
c.jsonErr(404, 404, "订单不存在")
|
||||
return
|
||||
}
|
||||
if order.Status == models.ProductOrderStatusActivated {
|
||||
c.jsonErr(400, 400, "订单已开通")
|
||||
return
|
||||
}
|
||||
if err := activateProductOrder(&order, "平台手动开通"); err != nil {
|
||||
c.jsonErr(400, 400, err.Error())
|
||||
return
|
||||
}
|
||||
c.jsonOK(nil, "开通成功")
|
||||
}
|
||||
|
||||
// activateProductOrder 订单开通:绑定套餐(产品配置了套餐时)并置为已开通
|
||||
func activateProductOrder(order *models.PlatformProductOrder, operator string) error {
|
||||
if order.PackageID > 0 && order.Tid > 0 {
|
||||
if _, err := services.ApplyPackageToTenant(order.Tid, order.PackageID, true); err != nil {
|
||||
return fmt.Errorf("开通失败:%v", err)
|
||||
}
|
||||
}
|
||||
now := time.Now()
|
||||
order.Status = models.ProductOrderStatusActivated
|
||||
order.ActivateTime = &now
|
||||
order.UpdateTime = &now
|
||||
order.Remark = strings.TrimSpace(order.Remark + " " + operator)
|
||||
_, err := models.Orm.Update(order, "Status", "ActivateTime", "Remark", "UpdateTime")
|
||||
return err
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -32,9 +33,12 @@ type tenantDTO struct {
|
||||
// 套餐与用户数配额
|
||||
PackageID uint64 `json:"package_id"`
|
||||
PackageName string `json:"package_name"`
|
||||
UserQuota int `json:"user_quota"`
|
||||
UserUsed int `json:"user_used"`
|
||||
Remark string `json:"remark"`
|
||||
// PackageExpireTime 套餐计费到期时间(NULL-永久有效);DaysRemaining 剩余天数
|
||||
PackageExpireTime *time.Time `json:"package_expire_time"`
|
||||
DaysRemaining int `json:"days_remaining"`
|
||||
UserQuota int `json:"user_quota"`
|
||||
UserUsed int `json:"user_used"`
|
||||
Remark string `json:"remark"`
|
||||
CreateTime *time.Time `json:"create_time,omitempty"`
|
||||
UpdateTime *time.Time `json:"update_time,omitempty"`
|
||||
DeleteTime *time.Time `json:"delete_time,omitempty"`
|
||||
@@ -82,6 +86,13 @@ func stringPtr(s string) *string {
|
||||
func toTenantDTO(t models.SystemTenant) tenantDTO {
|
||||
ct := t.CreateTime
|
||||
ut := t.UpdateTime
|
||||
daysRemaining := 0
|
||||
if t.PackageExpireTime != nil {
|
||||
daysRemaining = int(math.Ceil(time.Until(*t.PackageExpireTime).Hours() / 24))
|
||||
if daysRemaining < 0 {
|
||||
daysRemaining = 0
|
||||
}
|
||||
}
|
||||
return tenantDTO{
|
||||
ID: t.ID,
|
||||
TenantCode: t.TenantCode,
|
||||
@@ -93,6 +104,8 @@ func toTenantDTO(t models.SystemTenant) tenantDTO {
|
||||
Worktime: stringValue(t.Worktime),
|
||||
Status: t.Status,
|
||||
PackageID: t.PackageID,
|
||||
PackageExpireTime: t.PackageExpireTime,
|
||||
DaysRemaining: daysRemaining,
|
||||
UserQuota: t.UserQuota,
|
||||
Remark: stringValue(t.Remark),
|
||||
CreateTime: &ct,
|
||||
@@ -188,6 +201,11 @@ func (c *PlatformTenantController) GetTenantDetail() {
|
||||
|
||||
dto := toTenantDTO(t)
|
||||
if pkg, err := services.GetTenantPackage(t.ID); err == nil && pkg != nil {
|
||||
if pkg.ID != t.PackageID {
|
||||
// 套餐已因到期自动降级,原到期时间不再有效
|
||||
dto.PackageExpireTime = nil
|
||||
dto.DaysRemaining = 0
|
||||
}
|
||||
dto.PackageID = pkg.ID
|
||||
dto.PackageName = pkg.Name
|
||||
}
|
||||
@@ -293,7 +311,10 @@ func (c *PlatformTenantController) CreateTenant() {
|
||||
// 套餐与用户数上限:未指定套餐时使用默认套餐,用户数取其包含用户数(兜底 20)
|
||||
packageID := uint64(0)
|
||||
userQuota := services.DefaultTenantUserQuota
|
||||
if p.PackageID != nil && *p.PackageID > 0 {
|
||||
// 显式选择的套餐按套餐有效时长计费;未指定而兜底绑定默认套餐的不设置到期时间
|
||||
explicitPackage := p.PackageID != nil && *p.PackageID > 0
|
||||
var packageExpire *time.Time
|
||||
if explicitPackage {
|
||||
packageID = *p.PackageID
|
||||
}
|
||||
if packageID == 0 {
|
||||
@@ -309,8 +330,14 @@ func (c *PlatformTenantController) CreateTenant() {
|
||||
if err := models.Orm.QueryTable(new(models.SystemTenantPackage)).
|
||||
Filter("id", packageID).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&pkg); err == nil && pkg.UserQuota > 0 {
|
||||
userQuota = pkg.UserQuota
|
||||
One(&pkg); err == nil {
|
||||
if pkg.UserQuota > 0 {
|
||||
userQuota = pkg.UserQuota
|
||||
}
|
||||
if explicitPackage {
|
||||
e := services.PackageExpireFromNow(&pkg)
|
||||
packageExpire = &e
|
||||
}
|
||||
}
|
||||
}
|
||||
if p.UserQuota != nil && *p.UserQuota > 0 {
|
||||
@@ -321,17 +348,18 @@ func (c *PlatformTenantController) CreateTenant() {
|
||||
}
|
||||
|
||||
t := models.SystemTenant{
|
||||
TenantCode: p.TenantCode,
|
||||
TenantName: p.TenantName,
|
||||
ContactPerson: stringPtr(p.ContactPerson),
|
||||
ContactPhone: stringPtr(p.ContactPhone),
|
||||
ContactEmail: stringPtr(p.ContactEmail),
|
||||
Address: stringPtr(p.Address),
|
||||
Worktime: stringPtr(p.Worktime),
|
||||
Status: status,
|
||||
PackageID: packageID,
|
||||
UserQuota: userQuota,
|
||||
Remark: stringPtr(p.Remark),
|
||||
TenantCode: p.TenantCode,
|
||||
TenantName: p.TenantName,
|
||||
ContactPerson: stringPtr(p.ContactPerson),
|
||||
ContactPhone: stringPtr(p.ContactPhone),
|
||||
ContactEmail: stringPtr(p.ContactEmail),
|
||||
Address: stringPtr(p.Address),
|
||||
Worktime: stringPtr(p.Worktime),
|
||||
Status: status,
|
||||
PackageID: packageID,
|
||||
PackageExpireTime: packageExpire,
|
||||
UserQuota: userQuota,
|
||||
Remark: stringPtr(p.Remark),
|
||||
}
|
||||
|
||||
id, err := models.Orm.Insert(&t)
|
||||
@@ -381,17 +409,17 @@ func (c *PlatformTenantController) EditTenant() {
|
||||
if p.PackageID != nil {
|
||||
pkgID := *p.PackageID
|
||||
if pkgID > 0 {
|
||||
var pkg models.SystemTenantPackage
|
||||
if err := models.Orm.QueryTable(new(models.SystemTenantPackage)).
|
||||
Filter("id", pkgID).
|
||||
Filter("delete_time__isnull", true).
|
||||
One(&pkg); err != nil {
|
||||
c.Data["json"] = map[string]interface{}{"code": 400, "msg": "套餐不存在"}
|
||||
// 套餐切换/续费:按套餐有效时长重新计费(同套餐未到期在原到期时间上顺延),不动用户数上限
|
||||
if _, err := services.ApplyPackageToTenant(id, pkgID, false); err != nil {
|
||||
c.Data["json"] = map[string]interface{}{"code": 400, "msg": err.Error()}
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 解绑套餐:回退未绑定状态(视为默认套餐),清除计费到期时间
|
||||
update["package_id"] = 0
|
||||
update["package_expire_time"] = nil
|
||||
}
|
||||
update["package_id"] = pkgID
|
||||
}
|
||||
if p.UserQuota != nil {
|
||||
// 用户数上限只增不减:不允许调低到当前已开用户数以下
|
||||
|
||||
@@ -99,6 +99,7 @@ type tenantPackagePayload struct {
|
||||
Code string `json:"code"`
|
||||
Description string `json:"description"`
|
||||
Price *float64 `json:"price"`
|
||||
DurationDays *int `json:"duration_days"`
|
||||
UserQuota *int `json:"user_quota"`
|
||||
ExtraUserPrice *float64 `json:"extra_user_price"`
|
||||
IsDefault *int8 `json:"is_default"`
|
||||
@@ -108,6 +109,14 @@ type tenantPackagePayload struct {
|
||||
Modules []string `json:"modules"`
|
||||
}
|
||||
|
||||
// normalizePackageDuration 套餐有效时长(天)规范化:<=0 时按 365(年付)
|
||||
func normalizePackageDuration(v *int) int {
|
||||
if v == nil || *v <= 0 {
|
||||
return services.DefaultPackageDurationDays
|
||||
}
|
||||
return *v
|
||||
}
|
||||
|
||||
// loadPackageModules 批量加载套餐模块(packageID -> 模块列表)
|
||||
func loadPackageModules(packageIDs []uint64) map[uint64][]tenantPackageModuleItem {
|
||||
result := map[uint64][]tenantPackageModuleItem{}
|
||||
@@ -180,6 +189,7 @@ func (c *PlatformTenantPackageController) GetPackageList() {
|
||||
"code": r.Code,
|
||||
"description": r.Description,
|
||||
"price": r.Price,
|
||||
"duration_days": r.DurationDays,
|
||||
"user_quota": r.UserQuota,
|
||||
"extra_user_price": r.ExtraUserPrice,
|
||||
"is_default": r.IsDefault,
|
||||
@@ -235,6 +245,7 @@ func (c *PlatformTenantPackageController) GetPackageSelectList() {
|
||||
"code": r.Code,
|
||||
"description": r.Description,
|
||||
"price": r.Price,
|
||||
"duration_days": r.DurationDays,
|
||||
"user_quota": r.UserQuota,
|
||||
"extra_user_price": r.ExtraUserPrice,
|
||||
"is_default": r.IsDefault,
|
||||
@@ -267,6 +278,27 @@ func (c *PlatformTenantPackageController) GetPackageDetail() {
|
||||
c.jsonOK(tenantPackageDTO{SystemTenantPackage: row, Modules: modules}, "获取成功")
|
||||
}
|
||||
|
||||
// GetPurchaseURL GET /platform/tenantPackage/purchaseUrl
|
||||
// 套餐购买链接:租户端未开通功能卡片「购买」按钮的跳转地址
|
||||
func (c *PlatformTenantPackageController) GetPurchaseURL() {
|
||||
c.jsonOK(map[string]interface{}{"purchase_url": services.GetPackagePurchaseURL()}, "获取成功")
|
||||
}
|
||||
|
||||
// SavePurchaseURL POST /platform/tenantPackage/purchaseUrl
|
||||
func (c *PlatformTenantPackageController) SavePurchaseURL() {
|
||||
var p struct {
|
||||
PurchaseURL string `json:"purchase_url"`
|
||||
}
|
||||
if !c.readBody(&p) {
|
||||
return
|
||||
}
|
||||
if err := services.SavePackagePurchaseURL(p.PurchaseURL); err != nil {
|
||||
c.jsonErr(500, 500, "保存失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
c.jsonOK(nil, "保存成功")
|
||||
}
|
||||
|
||||
// GetModuleOptions GET /platform/tenantPackage/moduleOptions
|
||||
// 可加入套餐的功能模块清单(取 yz_system_modules 中启用且未删除的模块)
|
||||
func (c *PlatformTenantPackageController) GetModuleOptions() {
|
||||
@@ -365,6 +397,7 @@ func (c *PlatformTenantPackageController) CreatePackage() {
|
||||
Code: p.Code,
|
||||
Description: strings.TrimSpace(p.Description),
|
||||
Price: valueFloat(p.Price, 0),
|
||||
DurationDays: normalizePackageDuration(p.DurationDays),
|
||||
UserQuota: valueInt(p.UserQuota, services.DefaultTenantUserQuota),
|
||||
ExtraUserPrice: valueFloat(p.ExtraUserPrice, services.DefaultTenantExtraUserPrice),
|
||||
IsDefault: valueInt8(p.IsDefault, 0),
|
||||
@@ -436,6 +469,9 @@ func (c *PlatformTenantPackageController) EditPackage() {
|
||||
if p.Price != nil {
|
||||
update["price"] = *p.Price
|
||||
}
|
||||
if p.DurationDays != nil {
|
||||
update["duration_days"] = normalizePackageDuration(p.DurationDays)
|
||||
}
|
||||
if p.UserQuota != nil {
|
||||
quota := *p.UserQuota
|
||||
if quota <= 0 {
|
||||
@@ -718,6 +754,9 @@ func (c *PlatformTenantPackageController) GetTenantQuotaInfo() {
|
||||
"used": info.Used,
|
||||
"remaining": info.Remaining,
|
||||
"extra_user_price": info.ExtraUserPrice,
|
||||
"duration_days": info.DurationDays,
|
||||
"package_expire_time": info.PackageExpireTime,
|
||||
"days_remaining": info.DaysRemaining,
|
||||
"quota_packages": quotaPackages,
|
||||
}, "获取成功")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user