From d987601afd020eea335f7e0415a94f0cf5ab28f4 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 21 Jun 2023 18:59:27 +0800 Subject: [PATCH] faq --- constants/faq.go | 14 ++++ goctl_template/api/config.tpl | 1 - model/gmodel/fs_faq_logic.go | 9 +++ .../faq/internal/logic/wetsetsettinglogic.go | 34 -------- .../etc/faq.yaml => webset/etc/wetset.yaml} | 2 +- .../{faq => webset}/internal/config/config.go | 2 +- .../internal/handler/routes.go | 2 +- .../internal/handler/wetsetsettinghandler.go | 8 +- .../internal/logic/wetsetsettinglogic.go | 81 +++++++++++++++++++ .../internal/svc/servicecontext.go | 2 +- .../{faq => webset}/internal/types/types.go | 10 +++ server/{faq/faq.go => webset/wetset.go} | 10 +-- server_api/faq.api | 15 ---- server_api/webset.api | 25 ++++++ 14 files changed, 152 insertions(+), 63 deletions(-) create mode 100644 constants/faq.go delete mode 100644 server/faq/internal/logic/wetsetsettinglogic.go rename server/{faq/etc/faq.yaml => webset/etc/wetset.yaml} (90%) rename server/{faq => webset}/internal/config/config.go (78%) rename server/{faq => webset}/internal/handler/routes.go (90%) rename server/{faq => webset}/internal/handler/wetsetsettinghandler.go (93%) create mode 100644 server/webset/internal/logic/wetsetsettinglogic.go rename server/{faq => webset}/internal/svc/servicecontext.go (96%) rename server/{faq => webset}/internal/types/types.go (87%) rename server/{faq/faq.go => webset/wetset.go} (74%) delete mode 100644 server_api/faq.api create mode 100644 server_api/webset.api diff --git a/constants/faq.go b/constants/faq.go new file mode 100644 index 00000000..6529b365 --- /dev/null +++ b/constants/faq.go @@ -0,0 +1,14 @@ +package constants + +type TypeFaq int64 + +const STATUS_ON TypeFaq = 1 +const STATUS_OFF TypeFaq = 0 + +/** + * 定义类型 + */ +const TAG_ORDER TypeFaq = 1 +const TAG_SHIPPING TypeFaq = 2 +const TAG_PAYMENT TypeFaq = 3 +const TAG_RETURN TypeFaq = 4 diff --git a/goctl_template/api/config.tpl b/goctl_template/api/config.tpl index 78514f2e..dff7003f 100644 --- a/goctl_template/api/config.tpl +++ b/goctl_template/api/config.tpl @@ -1,7 +1,6 @@ package config import {{.authImport}} -import "fusenapi/server/faq/internal/types" type Config struct { rest.RestConf diff --git a/model/gmodel/fs_faq_logic.go b/model/gmodel/fs_faq_logic.go index f35dfc56..84a89336 100755 --- a/model/gmodel/fs_faq_logic.go +++ b/model/gmodel/fs_faq_logic.go @@ -1 +1,10 @@ package gmodel + +import "context" + +func (m *FsFaqModel) FindOneByTagId(ctx context.Context, tagId int, STATUS_ON int64) (faqs []*FsFaq, err error) { + err = m.db.WithContext(ctx). + Select("id", "tag_id", "tag_name", "title", "content"). + Where("tag_id = ? AND status = ?", tagId, STATUS_ON).Order("sort DESC").Find(&faqs).Error + return faqs, err +} diff --git a/server/faq/internal/logic/wetsetsettinglogic.go b/server/faq/internal/logic/wetsetsettinglogic.go deleted file mode 100644 index 3806422d..00000000 --- a/server/faq/internal/logic/wetsetsettinglogic.go +++ /dev/null @@ -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) -} diff --git a/server/faq/etc/faq.yaml b/server/webset/etc/wetset.yaml similarity index 90% rename from server/faq/etc/faq.yaml rename to server/webset/etc/wetset.yaml index c5603f5c..5a728a3f 100644 --- a/server/faq/etc/faq.yaml +++ b/server/webset/etc/wetset.yaml @@ -1,4 +1,4 @@ -Name: faq +Name: wetset Host: 0.0.0.0 Port: 8888 SourceMysql: "" diff --git a/server/faq/internal/config/config.go b/server/webset/internal/config/config.go similarity index 78% rename from server/faq/internal/config/config.go rename to server/webset/internal/config/config.go index 4f528866..670228c0 100644 --- a/server/faq/internal/config/config.go +++ b/server/webset/internal/config/config.go @@ -1,7 +1,7 @@ package config import ( - "fusenapi/server/faq/internal/types" + "fusenapi/server/webset/internal/types" "github.com/zeromicro/go-zero/rest" ) diff --git a/server/faq/internal/handler/routes.go b/server/webset/internal/handler/routes.go similarity index 90% rename from server/faq/internal/handler/routes.go rename to server/webset/internal/handler/routes.go index b328b683..700ccc93 100644 --- a/server/faq/internal/handler/routes.go +++ b/server/webset/internal/handler/routes.go @@ -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" ) diff --git a/server/faq/internal/handler/wetsetsettinghandler.go b/server/webset/internal/handler/wetsetsettinghandler.go similarity index 93% rename from server/faq/internal/handler/wetsetsettinghandler.go rename to server/webset/internal/handler/wetsetsettinghandler.go index d898c341..2e843a97 100644 --- a/server/faq/internal/handler/wetsetsettinghandler.go +++ b/server/webset/internal/handler/wetsetsettinghandler.go @@ -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{ diff --git a/server/webset/internal/logic/wetsetsettinglogic.go b/server/webset/internal/logic/wetsetsettinglogic.go new file mode 100644 index 00000000..00a2ec50 --- /dev/null +++ b/server/webset/internal/logic/wetsetsettinglogic.go @@ -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) +} diff --git a/server/faq/internal/svc/servicecontext.go b/server/webset/internal/svc/servicecontext.go similarity index 96% rename from server/faq/internal/svc/servicecontext.go rename to server/webset/internal/svc/servicecontext.go index 78519b9a..291cebf9 100644 --- a/server/faq/internal/svc/servicecontext.go +++ b/server/webset/internal/svc/servicecontext.go @@ -3,7 +3,7 @@ package svc import ( "errors" "fmt" - "fusenapi/server/faq/internal/config" + "fusenapi/server/webset/internal/config" "net/http" "fusenapi/initalize" diff --git a/server/faq/internal/types/types.go b/server/webset/internal/types/types.go similarity index 87% rename from server/faq/internal/types/types.go rename to server/webset/internal/types/types.go index 705841f7..2674ac6f 100644 --- a/server/faq/internal/types/types.go +++ b/server/webset/internal/types/types.go @@ -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 { } diff --git a/server/faq/faq.go b/server/webset/wetset.go similarity index 74% rename from server/faq/faq.go rename to server/webset/wetset.go index 2ba13d77..d667e463 100644 --- a/server/faq/faq.go +++ b/server/webset/wetset.go @@ -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 { diff --git a/server_api/faq.api b/server_api/faq.api deleted file mode 100644 index 3d3002d0..00000000 --- a/server_api/faq.api +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "v1" - -info ( - title: // TODO: add title - desc: // TODO: add description - author: "" - email: "" -) - -import "basic.api" - -service faq { - @handler WetSetSettingHandler - get /web-set/setting(request) returns (response); -} \ No newline at end of file diff --git a/server_api/webset.api b/server_api/webset.api new file mode 100644 index 00000000..ee93a856 --- /dev/null +++ b/server_api/webset.api @@ -0,0 +1,25 @@ +syntax = "v1" + +info ( + title: // TODO: add title + desc: // TODO: add description + author: "" + email: "" +) + +import "basic.api" + +service wetset { + @handler WetSetSettingHandler + get /web-set/setting(RequestFaq) returns (response); +} + +type RequestFaq { + Type string `form:"type"` +} + +type DataWetSet { + Title string `json:"title"` + Introduction string `json:"introduction"` + List interface{} `json:"list"` +} \ No newline at end of file