|
|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fusenapi/constants"
|
|
|
|
|
"fusenapi/utils/auth"
|
|
|
|
|
"fusenapi/utils/basic"
|
|
|
|
|
@@ -29,53 +30,57 @@ func NewWetSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Wet
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var TagTexts = map[int]map[string]string{
|
|
|
|
|
1: {"title": "order", "icon": "faq/order.png", "icon_name": "orders"},
|
|
|
|
|
2: {"title": "Shipping", "icon": "faq/shipping.png", "icon_name": "delivery"},
|
|
|
|
|
3: {"title": "Payment", "icon": "faq/payment.png", "icon_name": "wallet"},
|
|
|
|
|
4: {"title": "Return", "icon": "faq/return.png", "icon_name": "freight"},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *WetSetSettingLogic) WetSetSetting(req *types.RequestFaq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
|
|
|
func (l *WetSetSettingLogic) WetSetSetting(req *types.RequestWebSet, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
|
|
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
|
|
|
|
// userinfo 传入值时, 一定不为null
|
|
|
|
|
|
|
|
|
|
switch req.Type {
|
|
|
|
|
case "faq":
|
|
|
|
|
typeConf := constants.TypeWebSet(req.Type)
|
|
|
|
|
|
|
|
|
|
result := make(map[string]interface{})
|
|
|
|
|
result["title"] = "Common Problem"
|
|
|
|
|
result["introduction"] = "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout."
|
|
|
|
|
|
|
|
|
|
lists := make([]map[string]interface{}, 0)
|
|
|
|
|
for tagID, tagText := range TagTexts {
|
|
|
|
|
faqs, err := l.svcCtx.AllModels.FsFaq.FindOneByTagId(l.ctx, tagID, int64(constants.STATUS_ON))
|
|
|
|
|
if err == gorm.ErrRecordNotFound {
|
|
|
|
|
return resp.SetStatus(basic.CodeDbRecordNotFoundErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// items := getFaqItems(tagID)
|
|
|
|
|
for k, item := range items {
|
|
|
|
|
content := strings.Split(item.Content, "\n")
|
|
|
|
|
items[k].Content = content
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res := make(map[string]interface{})
|
|
|
|
|
res["title"] = tagText["title"]
|
|
|
|
|
res["icon"] = tagText["icon"]
|
|
|
|
|
res["icon_name"] = tagText["icon_name"]
|
|
|
|
|
res["items"] = items
|
|
|
|
|
|
|
|
|
|
lists = append(lists, res)
|
|
|
|
|
//如果是这三个配置项 则读取缓存
|
|
|
|
|
var result map[string]interface{}
|
|
|
|
|
data, err := l.svcCtx.AllModels.FsWebSet.FindValueByKey(l.ctx, string(typeConf))
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err == gorm.ErrRecordNotFound {
|
|
|
|
|
return resp.SetStatus(basic.CodeDbRecordNotFoundErr)
|
|
|
|
|
}
|
|
|
|
|
result["list"] = lists
|
|
|
|
|
|
|
|
|
|
return resp.SetStatus(basic.CodeOK, result)
|
|
|
|
|
case "clause":
|
|
|
|
|
case "policy":
|
|
|
|
|
default:
|
|
|
|
|
return resp.SetStatus(basic.CodeDbSqlErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//读取配置项
|
|
|
|
|
err = json.Unmarshal([]byte(*data.Value), &result)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return resp.SetStatus(basic.CodeJsonErr)
|
|
|
|
|
}
|
|
|
|
|
//组装配置项的内容数据
|
|
|
|
|
for k, v := range result["list"].(map[string]interface{}) {
|
|
|
|
|
//按空格分隔内容
|
|
|
|
|
result["list"].(map[string]interface{})[k].(map[string]interface{})["content"] = strings.Split(v.(string), "\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: 缓存
|
|
|
|
|
if typeConf == constants.CLAUSE_CONFIG || typeConf == constants.FAQ_CONFIG || typeConf == constants.POLICY_CONFIG {
|
|
|
|
|
// cache := redis.NewClient(&redis.Options{
|
|
|
|
|
// Addr: "localhost:6379",
|
|
|
|
|
// Password: "", // no password set
|
|
|
|
|
// DB: 0, // use default DB
|
|
|
|
|
// })
|
|
|
|
|
// if cache.Exists(ctx.Query("type")).Val() > 0 {
|
|
|
|
|
// result = cache.HGetAll(ctx.Query("type")).Val()
|
|
|
|
|
// } else {
|
|
|
|
|
// //读取配置项
|
|
|
|
|
// model := WebSet{Key: typeStr}
|
|
|
|
|
// db.First(&model)
|
|
|
|
|
// result = json.Unmarshal([]byte(model.Value), &result)
|
|
|
|
|
// //组装配置项的内容数据
|
|
|
|
|
// for k, v := range result["list"].(map[string]interface{}) {
|
|
|
|
|
// //按空格分隔内容
|
|
|
|
|
// result["list"].(map[string]interface{})[k].(map[string]interface{})["content"] = strings.Split(v.(string), "\n")
|
|
|
|
|
// }
|
|
|
|
|
// cache.HMSet(ctx.Query("type"), result)
|
|
|
|
|
// }
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resp.SetStatus(basic.CodeOK)
|
|
|
|
|
}
|
|
|
|
|
|