faq
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/faq/internal/svc"
|
||||
"fusenapi/server/faq/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WetSetSettingLogic) WetSetSetting(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
Name: faq
|
||||
Name: wetset
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
SourceMysql: ""
|
||||
@@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fusenapi/server/faq/internal/types"
|
||||
"fusenapi/server/webset/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
@@ -4,7 +4,7 @@ package handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fusenapi/server/faq/internal/svc"
|
||||
"fusenapi/server/webset/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/faq/internal/logic"
|
||||
"fusenapi/server/faq/internal/svc"
|
||||
"fusenapi/server/faq/internal/types"
|
||||
"fusenapi/server/webset/internal/logic"
|
||||
"fusenapi/server/webset/internal/svc"
|
||||
"fusenapi/server/webset/internal/types"
|
||||
)
|
||||
|
||||
func WetSetSettingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
@@ -53,7 +53,7 @@ func WetSetSettingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||
}
|
||||
|
||||
var req types.Request
|
||||
var req types.RequestFaq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
81
server/webset/internal/logic/wetsetsettinglogic.go
Normal file
81
server/webset/internal/logic/wetsetsettinglogic.go
Normal file
@@ -0,0 +1,81 @@
|
||||
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)
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package svc
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/server/faq/internal/config"
|
||||
"fusenapi/server/webset/internal/config"
|
||||
"net/http"
|
||||
|
||||
"fusenapi/initalize"
|
||||
@@ -5,6 +5,16 @@ import (
|
||||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type RequestFaq struct {
|
||||
Type string `form:"type"`
|
||||
}
|
||||
|
||||
type DataWetSet struct {
|
||||
Title string `json:"title"`
|
||||
Introduction string `json:"introduction"`
|
||||
List interface{} `json:"list"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"fusenapi/server/faq/internal/config"
|
||||
"fusenapi/server/faq/internal/handler"
|
||||
"fusenapi/server/faq/internal/svc"
|
||||
"fusenapi/server/webset/internal/config"
|
||||
"fusenapi/server/webset/internal/handler"
|
||||
"fusenapi/server/webset/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/faq.yaml", "the config file")
|
||||
var configFile = flag.String("f", "etc/wetset.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
@@ -30,7 +30,7 @@ func main() {
|
||||
server.Start()
|
||||
}
|
||||
|
||||
// var testConfigFile = flag.String("f", "../etc/faq.yaml", "the config file")
|
||||
// var testConfigFile = flag.String("f", "../etc/wetset.yaml", "the config file")
|
||||
// var cnf config.Config
|
||||
|
||||
// func GetTestServer() *rest.Server {
|
||||
Reference in New Issue
Block a user