更新密码找回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

-34
View File
@@ -14,9 +14,6 @@ import (
beego "github.com/beego/beego/v2/server/web"
)
// PlatformProductController 平台端「产品定价」管理
//
// 产品(名称 / 编码 / 价格 / 关联功能 / 上下架)+ 功能节点树 -> 租户端购买展示与下单。
type PlatformProductController struct {
beego.Controller
}
@@ -52,8 +49,6 @@ func (c *PlatformProductController) readBody(target interface{}) bool {
return true
}
// ============================ 产品 ============================
type productFeaturePayload struct {
ID uint64 `json:"id"`
Pid uint64 `json:"pid"`
@@ -73,7 +68,6 @@ type productPayload struct {
Features []productFeaturePayload `json:"features"`
}
// loadProductFeatures 批量加载产品功能节点(扁平,含 pid,前端按 pid 组装树)
func loadProductFeatures(productIDs []uint64) map[uint64][]models.PlatformProductFeature {
result := map[uint64][]models.PlatformProductFeature{}
if len(productIDs) == 0 {
@@ -111,7 +105,6 @@ func productToMap(p models.PlatformProduct, features []models.PlatformProductFea
}
}
// GetProductList GET /platform/product/list
func (c *PlatformProductController) GetProductList() {
keyword := strings.TrimSpace(c.GetString("keyword"))
status := strings.TrimSpace(c.GetString("status"))
@@ -144,7 +137,6 @@ func (c *PlatformProductController) GetProductList() {
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 {
@@ -162,9 +154,6 @@ func (c *PlatformProductController) GetProductDetail() {
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 {
@@ -174,7 +163,6 @@ func saveProductFeatures(productID uint64, items []productFeaturePayload) error
return nil
}
// 第一遍:按输入顺序建节点,记录 oldID(库中已有ID或前端临时ID) -> newID
oldToNew := map[uint64]uint64{}
type pending struct {
item productFeaturePayload
@@ -201,15 +189,12 @@ func saveProductFeatures(productID uint64, items []productFeaturePayload) error
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 {
@@ -218,7 +203,6 @@ func saveProductFeatures(productID uint64, items []productFeaturePayload) error
if newPid, ok := oldToNew[pid]; ok {
pid = newPid
}
// 父节点已被删除或指向自身时降级为顶级
if pid == p.newID {
pid = 0
}
@@ -231,7 +215,6 @@ func saveProductFeatures(productID uint64, items []productFeaturePayload) error
return nil
}
// CreateProduct POST /platform/product/create
func (c *PlatformProductController) CreateProduct() {
var p productPayload
if !c.readBody(&p) {
@@ -281,7 +264,6 @@ func (c *PlatformProductController) CreateProduct() {
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 {
@@ -341,7 +323,6 @@ func (c *PlatformProductController) EditProduct() {
c.jsonOK(nil, "编辑成功")
}
// DeleteProduct DELETE /platform/product/delete/:id(软删)
func (c *PlatformProductController) DeleteProduct() {
id := parseUint64Param(c.Ctx.Input.Param(":id"))
if id == 0 {
@@ -365,9 +346,6 @@ func (c *PlatformProductController) DeleteProduct() {
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"))
@@ -387,8 +365,6 @@ func (c *PlatformProductController) GetProductOrders() {
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 {
@@ -414,9 +390,6 @@ func (c *PlatformProductController) ActivateProductOrder() {
c.jsonOK(nil, "开通成功")
}
// CloseProductOrder POST /platform/product/order/close/:id
// 关闭已开通的单品功能:订单置为已关闭,租户端对应模块权益即时回收(菜单/卡片恢复锁定)。
// 仅允许关闭单品订单(package_id=0);误操作可在购买订单列表重新「手动开通」。
func (c *PlatformProductController) CloseProductOrder() {
id := parseUint64Param(c.Ctx.Input.Param(":id"))
if id == 0 {
@@ -453,18 +426,13 @@ func (c *PlatformProductController) CloseProductOrder() {
c.jsonOK(nil, "功能已关闭")
}
// activateProductOrder 订单开通:绑定套餐(产品配置了套餐时)并置为已开通。
// 单品功能默认 1 年有效期(ProductOrderDurationDays),到期后租户端权益自动失效,需续费。
func activateProductOrder(order *models.PlatformProductOrder, operator string) error {
now := time.Now()
if order.PackageID > 0 && order.Tid > 0 {
// 套餐订单:绑定/续费套餐,有效期由套餐自身到期时间管理
if _, err := services.ApplyPackageToTenant(order.Tid, order.PackageID, true); err != nil {
return fmt.Errorf("开通失败:%v", err)
}
} else if order.ProductID > 0 {
// 单品功能:有效期精确到日(自然日 0 点),到期日当天 0 点起即失效;
// 未到期续费从原到期日顺延 1 年,已过期重新开通从开通当日 0 点起算 1 年
base := services.DayStart(now)
if cur := services.ProductOrderExpireAt(order); cur != nil && cur.After(base) {
base = *cur
@@ -474,7 +442,6 @@ func activateProductOrder(order *models.PlatformProductOrder, operator string) e
}
order.Status = models.ProductOrderStatusActivated
if order.ActivateTime == nil {
// 开通时间精确到日(自然日 0 点),与有效期的计算粒度保持一致
day := services.DayStart(now)
order.ActivateTime = &day
}
@@ -486,7 +453,6 @@ func activateProductOrder(order *models.PlatformProductOrder, operator string) e
}
_, err := models.Orm.Update(order, fields...)
if err == nil && order.Tid > 0 {
// 开通后立即刷新模块权益缓存,避免「已购买却仍被拦」的窗口期
services.InvalidateTenantModuleCodes(order.Tid)
}
return err