修复platform的支付问题

This commit is contained in:
2026-09-16 10:35:55 +08:00
parent 71a14c46f9
commit 19687658e1
7 changed files with 415 additions and 148 deletions
+29 -5
View File
@@ -6,6 +6,7 @@ import (
"server/models"
"server/pkg/jwtutil"
"server/services"
beego "github.com/beego/beego/v2/server/web"
)
@@ -40,15 +41,24 @@ func (c *BackendModulesController) jsonErr(httpStatus, bizCode int, msg string)
_ = c.ServeJSON()
}
// moduleWithEnabled 带套餐开通标记的模块输出
type moduleWithEnabled struct {
models.SystemModules
Enabled bool `json:"enabled"`
}
// GetTenantList GET /backend/modules/getTenantList
// 返回当前 backend 账号可见的模块。当前实现:返回 status=1 且 is_show=1 的全部模块。
// 返回当前 backend 账号可见的模块(status=1 且 is_show=1),并根据租户绑定的套餐标记每个模块是否已开通。
// 前端可据此排序(已开通在前)、置灰未开通卡片、阻止跳转。
func (c *BackendModulesController) GetTenantList() {
if _, err := c.backendModulesClaims(); err != nil {
claims, err := c.backendModulesClaims()
if err != nil {
c.jsonErr(401, 401, err.Error())
return
}
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).
Filter("is_show", 1).
@@ -58,12 +68,26 @@ func (c *BackendModulesController) GetTenantList() {
c.jsonErr(500, 500, "获取失败:"+err.Error())
return
}
// 查询当前租户套餐包含的模块 code 集合(含默认套餐回退)
tid := uint64(claims.TenantId)
allowedCodes := services.GetTenantModuleCodes(tid)
enhanced := make([]moduleWithEnabled, 0, len(rows))
for _, m := range rows {
enabled := true
if len(allowedCodes) > 0 {
enabled = allowedCodes[m.Code]
}
enhanced = append(enhanced, moduleWithEnabled{SystemModules: m, Enabled: enabled})
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "获取成功",
"data": map[string]interface{}{
"list": rows,
"total": len(rows),
"list": enhanced,
"total": len(enhanced),
},
}
_ = c.ServeJSON()
+31 -2
View File
@@ -71,10 +71,23 @@ var channelSecretKeys = map[string][]string{
}
func channelRowDTO(row *models.PlatformPaymentChannel) map[string]interface{} {
hasConfig := (row.ConfigJSON != nil && *row.ConfigJSON != "" && *row.ConfigJSON != "{}") || row.MerchantNo != ""
if row.Channel == payment.ChannelCloudPay {
hasConfig = true
}
status := "unconfigured"
if row.Enabled == 1 {
status = "enabled"
} else if hasConfig {
status = "disabled"
}
return map[string]interface{}{
"id": row.ID, "channel": row.Channel, "name": row.Name,
"merchant_no": row.MerchantNo, "callback_url": row.CallbackURL,
"enabled": row.Enabled == 1,
"status": status,
"has_config": hasConfig,
"remark": row.Remark,
"last_test_time": row.LastTestTime, "last_test_result": row.LastTestResult,
"create_time": row.CreateTime, "update_time": row.UpdateTime,
@@ -223,13 +236,29 @@ func (c *PlatformPaymentController) SaveChannel() {
extraJSON = string(b)
}
merchantNo := strings.TrimSpace(p.MerchantNo)
if merchantNo == "" && merged != nil {
switch channel {
case payment.ChannelPayPal:
merchantNo = merged.Get("client_id")
case payment.ChannelWechat:
merchantNo = merged.Get("mch_id")
case payment.ChannelAlipay:
merchantNo = merged.Get("app_id")
case payment.ChannelUnionPay, payment.ChannelCloudPay:
merchantNo = merged.Get("mer_id")
}
}
now := time.Now()
updates := orm.Params{
"config_json": enc,
"merchant_no": strings.TrimSpace(p.MerchantNo),
"remark": strings.TrimSpace(p.Remark),
"merchant_no": merchantNo,
"update_time": now,
}
if p.Remark != "" {
updates["remark"] = strings.TrimSpace(p.Remark)
}
if p.Name != "" {
updates["name"] = strings.TrimSpace(p.Name)
}