fusenapi/server/webset/internal/logic/wetsetsettinglogic.go
2023-06-21 18:59:27 +08:00

82 lines
2.2 KiB
Go

package logic
import (
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"strings"
"context"
"fusenapi/server/webset/internal/svc"
"fusenapi/server/webset/internal/types"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type WetSetSettingLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewWetSetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WetSetSettingLogic {
return &WetSetSettingLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
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) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
switch req.Type {
case "faq":
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)
}
result["list"] = lists
return resp.SetStatus(basic.CodeOK, result)
case "clause":
case "policy":
default:
return resp.SetStatus(basic.CodeDbSqlErr)
}
return resp.SetStatus(basic.CodeOK)
}