hsun преди 1 година
родител
ревизия
6ef9ce5b62
променени са 2 файла, в които са добавени 34 реда и са изтрити 24 реда
  1. 3 4
      controllers/report_share.go
  2. 31 20
      models/business_conf.go

+ 3 - 4
controllers/report_share.go

@@ -2,7 +2,6 @@ package controllers
 
 import (
 	"hongze/hongze_api/models"
-	"hongze/hongze_api/utils"
 	"html"
 )
 
@@ -42,13 +41,13 @@ func (this *ReportShareController) Detail() {
 	resp := new(models.ReportShareDetailResp)
 	// 免责声明
 	conf, e := models.GetBusinessConf()
-	if e != nil && e.Error() != utils.ErrNoRow() {
+	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
 		return
 	}
-	if conf != nil {
-		resp.Disclaimer = html.UnescapeString(conf.Disclaimer)
+	if conf[models.BusinessConfDisclaimer] != "" {
+		resp.Disclaimer = html.UnescapeString(conf[models.BusinessConfDisclaimer])
 	}
 
 	resp.Report = report

+ 31 - 20
models/business_conf.go

@@ -2,32 +2,43 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"html"
+	"time"
+)
+
+const (
+	BusinessConfDisclaimer = "Disclaimer"
 )
 
 // BusinessConf 商户配置表
 type BusinessConf struct {
-	Id                 int    `orm:"column(id);pk"`
-	CompanyName        string `description:"公司名称"`
-	CompanyWatermark   string `description:"公司水印"`
-	WatermarkChart     int    `description:"是否在研报图表使用水印"`
-	CnPptCoverImgs     string `description:"中文PPT封面图(多图)"`
-	CnPptBackgroundImg string `description:"中文PPT背景图"`
-	CnPptBottomImg     string `description:"中文PPT封底图"`
-	Disclaimer         string `description:"免责声明"`
-	EnPptCoverImgs     string `description:"英文PPT封面图(多图)"`
-	EnPptBackgroundImg string `description:"英文PPT背景图"`
-	EnPptBottomImg     string `description:"英文PPT封底图"`
-	UseXf              int    `description:"是否使用科大讯飞:0-否;1-是"`
-	XfAppid            string `description:"科大讯飞Appid"`
-	XfApiKey           string `description:"科大讯飞ApiKey"`
-	XfApiSecret        string `description:"科大讯飞ApiSecret"`
-	XfVcn              string `description:"科大讯飞Vcn"`
+	Id         int    `orm:"column(id);pk"`
+	ConfKey    string `description:"配置Key"`
+	ConfVal    string `description:"配置值"`
+	ValType    int    `description:"1-字符串;2-数值;3-字符串数组;4-富文本;"`
+	Necessary  int    `description:"是否必填:0-否;1-是"`
+	Remark     string `description:"备注"`
+	CreateTime time.Time
 }
 
 // GetBusinessConf 获取商家配置
-func GetBusinessConf() (item *BusinessConf, err error) {
-	o := orm.NewOrmUsingDB("eta")
-	sql := `SELECT * FROM business_conf LIMIT 1`
-	err = o.Raw(sql).QueryRow(&item)
+func GetBusinessConf() (list map[string]string, err error) {
+	list = make(map[string]string)
+
+	var items []*BusinessConf
+	o := orm.NewOrm()
+	sql := `SELECT * FROM business_conf`
+	_, err = o.Raw(sql).QueryRows(&items)
+	if err != nil {
+		return
+	}
+
+	for _, v := range items {
+		if v.ValType == 4 {
+			list[v.ConfKey] = html.UnescapeString(v.ConfVal)
+			continue
+		}
+		list[v.ConfKey] = v.ConfVal
+	}
 	return
 }