logo search
This commit is contained in:
parent
cd4ca1c1e0
commit
48a63dad45
32
model/gmodel/fs_preprocess_logo_gen.go
Normal file
32
model/gmodel/fs_preprocess_logo_gen.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// fs_preprocess_logo logo数据表
|
||||||
|
type FsPreprocessLogo struct {
|
||||||
|
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 自增的唯一id
|
||||||
|
LocationCode *string `gorm:"index;default:'';" json:"location_code"` //
|
||||||
|
RestaurantName *string `gorm:"index;default:'';" json:"restaurant_name"` //
|
||||||
|
ResourceUrl *string `gorm:"default:'';" json:"resource_url"` //
|
||||||
|
RestaurantType *string `gorm:"default:'';" json:"restaurant_type"` //
|
||||||
|
Address *string `gorm:"default:'';" json:"address"` //
|
||||||
|
ZipCode *string `gorm:"default:'';" json:"zip_code"` //
|
||||||
|
Phone *string `gorm:"default:'';" json:"phone"` //
|
||||||
|
Website *string `gorm:"default:'';" json:"website"` //
|
||||||
|
IsBranch *int64 `gorm:"default:0;" json:"is_branch"` // 是否分店
|
||||||
|
Metadata *[]byte `gorm:"default:'';" json:"metadata"` //
|
||||||
|
Source *string `gorm:"index;default:'';" json:"source"` //
|
||||||
|
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||||
|
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||||
|
}
|
||||||
|
type FsPreprocessLogoModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsPreprocessLogoModel(db *gorm.DB) *FsPreprocessLogoModel {
|
||||||
|
return &FsPreprocessLogoModel{db: db, name: "fs_preprocess_logo"}
|
||||||
|
}
|
27
model/gmodel/fs_preprocess_logo_logic.go
Normal file
27
model/gmodel/fs_preprocess_logo_logic.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: 使用model的属性做你想做的
|
||||||
|
|
||||||
|
// 搜索建议
|
||||||
|
func (p *FsPreprocessLogoModel) PreLogoSearchSuggestions(ctx context.Context, zipcode string, keywordsStr string, count int) (resp []FsPreprocessLogo, err error) {
|
||||||
|
keywords := regexp.MustCompile(`\s+`).Split(keywordsStr, -1)
|
||||||
|
for i, v := range keywords {
|
||||||
|
keywords[i] = "+" + v + v
|
||||||
|
}
|
||||||
|
sqlstr := fmt.Sprintf("SELECT * FROM fs_preprocess_logo WHERE MATCH(restaurant_name) AGAINST('?' IN BOOLEAN MODE) limit %d;", count)
|
||||||
|
|
||||||
|
tx := p.db.WithContext(ctx).Model(&FsPreprocessLogo{}).Raw(sqlstr, strings.Join(keywords, " "))
|
||||||
|
err = tx.Scan(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
|
||||||
|
}
|
|
@ -53,7 +53,6 @@ type AllModelsGen struct {
|
||||||
FsGuest *FsGuestModel // fs_guest 游客表
|
FsGuest *FsGuestModel // fs_guest 游客表
|
||||||
FsLog *FsLogModel // fs_log 日志表
|
FsLog *FsLogModel // fs_log 日志表
|
||||||
FsLogoCartoon *FsLogoCartoonModel // fs_logo_cartoon logo底图表
|
FsLogoCartoon *FsLogoCartoonModel // fs_logo_cartoon logo底图表
|
||||||
FsLogoPreprocess *FsLogoPreprocessModel // fs_logo_preprocess
|
|
||||||
FsMapLibrary *FsMapLibraryModel // fs_map_library 贴图库
|
FsMapLibrary *FsMapLibraryModel // fs_map_library 贴图库
|
||||||
FsMenu *FsMenuModel // fs_menu 后台菜单
|
FsMenu *FsMenuModel // fs_menu 后台菜单
|
||||||
FsMerchantCategory *FsMerchantCategoryModel // fs_merchant_category 商户类型表
|
FsMerchantCategory *FsMerchantCategoryModel // fs_merchant_category 商户类型表
|
||||||
|
@ -68,6 +67,7 @@ type AllModelsGen struct {
|
||||||
FsOrderTradeEvent *FsOrderTradeEventModel // fs_order_trade_event 订单交易事件表
|
FsOrderTradeEvent *FsOrderTradeEventModel // fs_order_trade_event 订单交易事件表
|
||||||
FsPay *FsPayModel // fs_pay 支付记录
|
FsPay *FsPayModel // fs_pay 支付记录
|
||||||
FsPayEvent *FsPayEventModel // fs_pay_event 支付回调事件日志
|
FsPayEvent *FsPayEventModel // fs_pay_event 支付回调事件日志
|
||||||
|
FsPreprocessLogo *FsPreprocessLogoModel // fs_preprocess_logo logo数据表
|
||||||
FsProduct *FsProductModel // fs_product 产品表
|
FsProduct *FsProductModel // fs_product 产品表
|
||||||
FsProductCollection *FsProductCollectionModel // fs_product_collection 产品收藏表
|
FsProductCollection *FsProductCollectionModel // fs_product_collection 产品收藏表
|
||||||
FsProductCopy1 *FsProductCopy1Model // fs_product_copy1 产品表
|
FsProductCopy1 *FsProductCopy1Model // fs_product_copy1 产品表
|
||||||
|
@ -167,7 +167,6 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
||||||
FsGuest: NewFsGuestModel(gdb),
|
FsGuest: NewFsGuestModel(gdb),
|
||||||
FsLog: NewFsLogModel(gdb),
|
FsLog: NewFsLogModel(gdb),
|
||||||
FsLogoCartoon: NewFsLogoCartoonModel(gdb),
|
FsLogoCartoon: NewFsLogoCartoonModel(gdb),
|
||||||
FsLogoPreprocess: NewFsLogoPreprocessModel(gdb),
|
|
||||||
FsMapLibrary: NewFsMapLibraryModel(gdb),
|
FsMapLibrary: NewFsMapLibraryModel(gdb),
|
||||||
FsMenu: NewFsMenuModel(gdb),
|
FsMenu: NewFsMenuModel(gdb),
|
||||||
FsMerchantCategory: NewFsMerchantCategoryModel(gdb),
|
FsMerchantCategory: NewFsMerchantCategoryModel(gdb),
|
||||||
|
@ -182,6 +181,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
||||||
FsOrderTradeEvent: NewFsOrderTradeEventModel(gdb),
|
FsOrderTradeEvent: NewFsOrderTradeEventModel(gdb),
|
||||||
FsPay: NewFsPayModel(gdb),
|
FsPay: NewFsPayModel(gdb),
|
||||||
FsPayEvent: NewFsPayEventModel(gdb),
|
FsPayEvent: NewFsPayEventModel(gdb),
|
||||||
|
FsPreprocessLogo: NewFsPreprocessLogoModel(gdb),
|
||||||
FsProduct: NewFsProductModel(gdb),
|
FsProduct: NewFsProductModel(gdb),
|
||||||
FsProductCollection: NewFsProductCollectionModel(gdb),
|
FsProductCollection: NewFsProductCollectionModel(gdb),
|
||||||
FsProductCopy1: NewFsProductCopy1Model(gdb),
|
FsProductCopy1: NewFsProductCopy1Model(gdb),
|
||||||
|
|
35
server/info/internal/handler/prelogosearchhandler.go
Normal file
35
server/info/internal/handler/prelogosearchhandler.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/info/internal/logic"
|
||||||
|
"fusenapi/server/info/internal/svc"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PreLogoSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.PreLogoSearchRequest
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewPreLogoSearchLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.PreLogoSearch(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"fusenapi/server/info/internal/logic"
|
||||||
|
"fusenapi/server/info/internal/svc"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PreLogoSearchSuggestionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.PreLogoSearchRequest
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewPreLogoSearchSuggestionsLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.PreLogoSearchSuggestions(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -62,6 +62,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/info/restaurant/list",
|
Path: "/api/info/restaurant/list",
|
||||||
Handler: RestaurantListHandler(serverCtx),
|
Handler: RestaurantListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/info/prelogo/search/suggestions",
|
||||||
|
Handler: PreLogoSearchSuggestionsHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/api/info/prelogo/search",
|
||||||
|
Handler: PreLogoSearchHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/api/info/contact/us",
|
Path: "/api/info/contact/us",
|
||||||
|
|
50
server/info/internal/logic/prelogosearchlogic.go
Normal file
50
server/info/internal/logic/prelogosearchlogic.go
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/info/internal/svc"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PreLogoSearchLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPreLogoSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PreLogoSearchLogic {
|
||||||
|
return &PreLogoSearchLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *PreLogoSearchLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *PreLogoSearchLogic) PreLogoSearch(req *types.PreLogoSearchRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
|
// userinfo 传入值时, 一定不为null
|
||||||
|
if !userinfo.IsOnlooker() {
|
||||||
|
return resp.SetStatus(basic.CodeSearchAuthErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.ZipCode) < 4 {
|
||||||
|
return resp.SetStatus(basic.CodeSearchZipCodeErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.SetStatus(basic.CodeOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *PreLogoSearchLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
57
server/info/internal/logic/prelogosearchsuggestionslogic.go
Normal file
57
server/info/internal/logic/prelogosearchsuggestionslogic.go
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/info/internal/svc"
|
||||||
|
"fusenapi/server/info/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PreLogoSearchSuggestionsLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPreLogoSearchSuggestionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PreLogoSearchSuggestionsLogic {
|
||||||
|
return &PreLogoSearchSuggestionsLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *PreLogoSearchSuggestionsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *PreLogoSearchSuggestionsLogic) PreLogoSearchSuggestions(req *types.PreLogoSearchRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
|
// userinfo 传入值时, 一定不为null
|
||||||
|
if !userinfo.IsOnlooker() {
|
||||||
|
return resp.SetStatus(basic.CodeSearchAuthErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.ZipCode) < 4 {
|
||||||
|
return resp.SetStatus(basic.CodeSearchZipCodeErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := l.svcCtx.AllModels.FsPreprocessLogo.PreLogoSearchSuggestions(l.ctx, req.ZipCode, req.Keywords, 5)
|
||||||
|
if err != nil {
|
||||||
|
return resp.SetStatus(basic.CodeApiErr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.SetStatus(basic.CodeOK, map[string]any{
|
||||||
|
"result": result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *PreLogoSearchSuggestionsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
|
@ -12,6 +12,11 @@ type ContactUsRequest struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PreLogoSearchRequest struct {
|
||||||
|
ZipCode string `json:"zip_code"` // 邮编
|
||||||
|
Keywords string `json:"keywords"` // 关键字
|
||||||
|
}
|
||||||
|
|
||||||
type UserInfoRequest struct {
|
type UserInfoRequest struct {
|
||||||
Module []string `json:"module"`
|
Module []string `json:"module"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,10 +60,9 @@ type (
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PreLogoSearchRequest {
|
PreLogoSearchRequest {
|
||||||
ZipCode string `json:"zip_code"` // 邮编
|
ZipCode string `json:"zip_code"` // 邮编
|
||||||
Keywords int64 `json:"keywords"` // 关键字
|
Keywords string `json:"keywords"` // 关键字
|
||||||
}
|
}
|
||||||
|
|
||||||
UserInfoRequest {
|
UserInfoRequest {
|
||||||
|
|
|
@ -115,6 +115,9 @@ var (
|
||||||
CodeErrOrderCreatePrePaymentTimeout = &StatusResponse{5310, "create payment failed, timeout"}
|
CodeErrOrderCreatePrePaymentTimeout = &StatusResponse{5310, "create payment failed, timeout"}
|
||||||
CodeErrOrderDeleteStatusIllegality = &StatusResponse{5311, "delete order failed, status is illegality"}
|
CodeErrOrderDeleteStatusIllegality = &StatusResponse{5311, "delete order failed, status is illegality"}
|
||||||
CodeErrOrderInvoiceStatusIllegality = &StatusResponse{5312, "get order invoice failed, pay status is illegality"}
|
CodeErrOrderInvoiceStatusIllegality = &StatusResponse{5312, "get order invoice failed, pay status is illegality"}
|
||||||
|
|
||||||
|
CodeSearchAuthErr = &StatusResponse{5400, "search requires accepting cookies"} // 访客最少要接受cookies
|
||||||
|
CodeSearchZipCodeErr = &StatusResponse{5401, "zipcode error"} // 邮编错误
|
||||||
)
|
)
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user