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.
68 lines
1.8 KiB
68 lines
1.8 KiB
package service
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"shop-api/global"
|
|
"shop-api/model"
|
|
"shop-api/utils/track"
|
|
)
|
|
|
|
func GetSysDictDataLabel(typeCode, value string) string {
|
|
var res string
|
|
|
|
cacheKey := "bkb-admin_sys_dict_labels"
|
|
labelKey := fmt.Sprintf("%s_%s", typeCode, value)
|
|
res = RedisHashGet(cacheKey, labelKey)
|
|
if res == "" {
|
|
_ = global.MG_DB.Model(&model.SysDictData{}).Select("label").Where("type_code=? AND `value`=?", typeCode, value).Scan(&res).Error
|
|
go RedisHashSet(cacheKey, labelKey, res)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func GetSysDictDataListByTypeCode(typeCode string) (list []model.SysDictDataView, err error) {
|
|
var lists []model.SysDictDataView
|
|
err = global.MG_DB.Model(&model.SysDictData{}).Where("type_code=? AND `status`='1'", typeCode).Order("sort asc").Find(&lists).Error
|
|
return lists, err
|
|
}
|
|
|
|
func checkSysDictData(typeCode, value string) bool {
|
|
if GetSysDictDataLabel(typeCode, value) != "" {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func BatchAddCourier() error {
|
|
list, err := track.ListCouriers()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
clist := make([]model.Courier, 0)
|
|
for _, v := range list.Couriers {
|
|
c := model.Courier{
|
|
Name: v.CourierName,
|
|
Code: v.CourierCode,
|
|
CountryIso2: v.CourierCountryIso2,
|
|
Phone: v.CourierPhone,
|
|
Url: v.CourierURL,
|
|
Type: v.CourierType,
|
|
Logo: v.CourierLogo,
|
|
}
|
|
clist = append(clist, c)
|
|
}
|
|
return global.MG_DB.Create(&clist).Error
|
|
}
|
|
|
|
func getSysDictDataValue(typeCode, label string) string {
|
|
var res string
|
|
cacheKey := "bkb-admin_sys_dict_values"
|
|
labelKey := fmt.Sprintf("%s_%s", typeCode, label)
|
|
res = RedisHashGet(cacheKey, labelKey)
|
|
if res == "" {
|
|
_ = global.MG_DB.Model(&model.SysDictData{}).Select("label").Where("type_code = ? AND `label` = ?", typeCode, label).Scan(&res).Error
|
|
go RedisHashSet(cacheKey, labelKey, res)
|
|
}
|
|
return res
|
|
}
|
|
|