logo search

This commit is contained in:
eson
2023-10-20 13:25:35 +08:00
parent cd4ca1c1e0
commit 48a63dad45
11 changed files with 259 additions and 6 deletions

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

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

View File

@@ -53,7 +53,6 @@ type AllModelsGen struct {
FsGuest *FsGuestModel // fs_guest 游客表
FsLog *FsLogModel // fs_log 日志表
FsLogoCartoon *FsLogoCartoonModel // fs_logo_cartoon logo底图表
FsLogoPreprocess *FsLogoPreprocessModel // fs_logo_preprocess
FsMapLibrary *FsMapLibraryModel // fs_map_library 贴图库
FsMenu *FsMenuModel // fs_menu 后台菜单
FsMerchantCategory *FsMerchantCategoryModel // fs_merchant_category 商户类型表
@@ -68,6 +67,7 @@ type AllModelsGen struct {
FsOrderTradeEvent *FsOrderTradeEventModel // fs_order_trade_event 订单交易事件表
FsPay *FsPayModel // fs_pay 支付记录
FsPayEvent *FsPayEventModel // fs_pay_event 支付回调事件日志
FsPreprocessLogo *FsPreprocessLogoModel // fs_preprocess_logo logo数据表
FsProduct *FsProductModel // fs_product 产品表
FsProductCollection *FsProductCollectionModel // fs_product_collection 产品收藏表
FsProductCopy1 *FsProductCopy1Model // fs_product_copy1 产品表
@@ -167,7 +167,6 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsGuest: NewFsGuestModel(gdb),
FsLog: NewFsLogModel(gdb),
FsLogoCartoon: NewFsLogoCartoonModel(gdb),
FsLogoPreprocess: NewFsLogoPreprocessModel(gdb),
FsMapLibrary: NewFsMapLibraryModel(gdb),
FsMenu: NewFsMenuModel(gdb),
FsMerchantCategory: NewFsMerchantCategoryModel(gdb),
@@ -182,6 +181,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsOrderTradeEvent: NewFsOrderTradeEventModel(gdb),
FsPay: NewFsPayModel(gdb),
FsPayEvent: NewFsPayEventModel(gdb),
FsPreprocessLogo: NewFsPreprocessLogoModel(gdb),
FsProduct: NewFsProductModel(gdb),
FsProductCollection: NewFsProductCollectionModel(gdb),
FsProductCopy1: NewFsProductCopy1Model(gdb),