faq
This commit is contained in:
parent
28cc8a19ba
commit
d987601afd
14
constants/faq.go
Normal file
14
constants/faq.go
Normal 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
|
|
@ -1,7 +1,6 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import {{.authImport}}
|
import {{.authImport}}
|
||||||
import "fusenapi/server/faq/internal/types"
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
rest.RestConf
|
rest.RestConf
|
||||||
|
|
|
@ -1 +1,10 @@
|
||||||
package gmodel
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
Host: 0.0.0.0
|
||||||
Port: 8888
|
Port: 8888
|
||||||
SourceMysql: ""
|
SourceMysql: ""
|
|
@ -1,7 +1,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/faq/internal/types"
|
"fusenapi/server/webset/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
|
@ -4,7 +4,7 @@ package handler
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"fusenapi/server/faq/internal/svc"
|
"fusenapi/server/webset/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
"fusenapi/server/faq/internal/logic"
|
"fusenapi/server/webset/internal/logic"
|
||||||
"fusenapi/server/faq/internal/svc"
|
"fusenapi/server/webset/internal/svc"
|
||||||
"fusenapi/server/faq/internal/types"
|
"fusenapi/server/webset/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WetSetSettingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
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}
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
var req types.Request
|
var req types.RequestFaq
|
||||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/server/faq/internal/config"
|
"fusenapi/server/webset/internal/config"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"fusenapi/initalize"
|
"fusenapi/initalize"
|
|
@ -5,6 +5,16 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"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 {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,15 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"fusenapi/server/faq/internal/config"
|
"fusenapi/server/webset/internal/config"
|
||||||
"fusenapi/server/faq/internal/handler"
|
"fusenapi/server/webset/internal/handler"
|
||||||
"fusenapi/server/faq/internal/svc"
|
"fusenapi/server/webset/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/conf"
|
"github.com/zeromicro/go-zero/core/conf"
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -30,7 +30,7 @@ func main() {
|
||||||
server.Start()
|
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
|
// var cnf config.Config
|
||||||
|
|
||||||
// func GetTestServer() *rest.Server {
|
// func GetTestServer() *rest.Server {
|
|
@ -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
25
server_api/webset.api
Normal 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"`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user