You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
865 B
42 lines
865 B
package jst
|
|
|
|
import (
|
|
"recook/internal/v2/lib/db"
|
|
"sync"
|
|
)
|
|
|
|
var once sync.Once
|
|
var expressCache = make(map[string]string)
|
|
|
|
type ExpressModel struct {
|
|
db.BaseModel
|
|
Id uint `gorm:"column:id;primary_key"`
|
|
Name string `gorm:"column:name"`
|
|
LcID string `gorm:"column:lc_id"`
|
|
}
|
|
|
|
// TableName sets the insert table name for this struct type.
|
|
func (o *ExpressModel) TableName() string {
|
|
return "jst_express"
|
|
}
|
|
|
|
// GetJSTExpressCode 获取jst快递编号.
|
|
func (o *ExpressModel) GetJSTExpressCode(name string) string {
|
|
once.Do(func() {
|
|
var list []ExpressModel
|
|
o.GetDb().Find(&list)
|
|
for _, v := range list {
|
|
expressCache[v.Name] = v.LcID
|
|
}
|
|
})
|
|
if len(name) == 0 {
|
|
return ""
|
|
}
|
|
return expressCache[name]
|
|
}
|
|
|
|
func (o *ExpressModel) FindByLcID(by string) (result ExpressModel) {
|
|
o.GetDb().Table(o.TableName()).First(&result, "lc_id = ?", by)
|
|
return
|
|
}
|