This commit is contained in:
eson 2023-06-21 18:59:27 +08:00
parent 28cc8a19ba
commit d987601afd
14 changed files with 152 additions and 63 deletions

14
constants/faq.go Normal file
View File

@ -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

View File

@ -1,7 +1,6 @@
package config
import {{.authImport}}
import "fusenapi/server/faq/internal/types"
type Config struct {
rest.RestConf

View File

@ -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
}

View File

@ -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)
}

View File

@ -1,4 +1,4 @@
Name: faq
Name: wetset
Host: 0.0.0.0
Port: 8888
SourceMysql: ""

View File

@ -1,7 +1,7 @@
package config
import (
"fusenapi/server/faq/internal/types"
"fusenapi/server/webset/internal/types"
"github.com/zeromicro/go-zero/rest"
)

View File

@ -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"
)

View File

@ -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{

View 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)
}

View File

@ -3,7 +3,7 @@ package svc
import (
"errors"
"fmt"
"fusenapi/server/faq/internal/config"
"fusenapi/server/webset/internal/config"
"net/http"
"fusenapi/initalize"

View File

@ -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 {
}

View File

@ -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 {

View File

@ -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);
}

25
server_api/webset.api Normal file
View File

@ -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"`
}