- all db orm use beego orm, don't use gorm anymore.
This commit is contained in:
@@ -4,117 +4,116 @@ import (
|
||||
"reflect"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||
"github.com/jinzhu/gorm"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
func GetRows(db *gorm.DB, inPtr interface{}, sql string, values ...interface{}) (err error) {
|
||||
if db == nil {
|
||||
db = gormdb.GetDB()
|
||||
}
|
||||
topTypeInfo := reflect.TypeOf(inPtr)
|
||||
if topTypeInfo.Kind() != reflect.Ptr {
|
||||
panic("SelectEntities inPtr should be slice ptr (*[]Type)")
|
||||
}
|
||||
typeInfo := topTypeInfo.Elem()
|
||||
if typeInfo.Kind() != reflect.Slice {
|
||||
panic("SelectEntities inPtr should be slice ptr (*[]Type)")
|
||||
}
|
||||
elmType := typeInfo.Elem()
|
||||
type DaoDB struct {
|
||||
db orm.Ormer
|
||||
}
|
||||
|
||||
valueInfo := reflect.ValueOf(inPtr)
|
||||
rows, err := db.Raw(sql, values...).Rows()
|
||||
if err == nil {
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var value reflect.Value
|
||||
if elmType.Kind() == reflect.Ptr {
|
||||
value = reflect.New(elmType.Elem())
|
||||
} else {
|
||||
value = reflect.New(elmType)
|
||||
// func GetRows(db *gorm.DB, inPtr interface{}, sql string, values ...interface{}) (err error) {
|
||||
// if db == nil {
|
||||
// db = gormdb.GetDB()
|
||||
// }
|
||||
// topTypeInfo := reflect.TypeOf(inPtr)
|
||||
// if topTypeInfo.Kind() != reflect.Ptr {
|
||||
// panic("SelectEntities inPtr should be slice ptr (*[]Type)")
|
||||
// }
|
||||
// typeInfo := topTypeInfo.Elem()
|
||||
// if typeInfo.Kind() != reflect.Slice {
|
||||
// panic("SelectEntities inPtr should be slice ptr (*[]Type)")
|
||||
// }
|
||||
// elmType := typeInfo.Elem()
|
||||
|
||||
// valueInfo := reflect.ValueOf(inPtr)
|
||||
// rows, err := db.Raw(sql, values...).Rows()
|
||||
// if err == nil {
|
||||
// defer rows.Close()
|
||||
// for rows.Next() {
|
||||
// var value reflect.Value
|
||||
// if elmType.Kind() == reflect.Ptr {
|
||||
// value = reflect.New(elmType.Elem())
|
||||
// } else {
|
||||
// value = reflect.New(elmType)
|
||||
// }
|
||||
// db.ScanRows(rows, value.Interface())
|
||||
// if elmType.Kind() != reflect.Ptr {
|
||||
// value = value.Elem()
|
||||
// }
|
||||
// valueInfo.Elem().Set(reflect.Append(valueInfo.Elem(), value))
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
func GetDB() *DaoDB {
|
||||
return &DaoDB{db: orm.NewOrm()}
|
||||
}
|
||||
|
||||
func GetRow(db *DaoDB, inPtr interface{}, sql string, values ...interface{}) (err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
return db.db.Raw(sql, values).QueryRow(inPtr)
|
||||
}
|
||||
|
||||
func GetRows(db *DaoDB, inPtr interface{}, sql string, values ...interface{}) (err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
_, err = db.db.Raw(sql, values).QueryRows(inPtr)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetEntity(db *DaoDB, item interface{}, cols ...string) error {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
return db.db.Read(item, cols...)
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateEntity(db *DaoDB, item interface{}, cols ...string) error {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
_, err2 := db.db.Update(item, cols...)
|
||||
return err2
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateEntityByKV(db *DaoDB, item interface{}, kvs map[string]interface{}, conditions map[string]interface{}) error {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
qs := db.db.QueryTable(item)
|
||||
if conditions == nil {
|
||||
qs = qs.Filter("id", jxutils.GetObjFieldByName(item, "ID"))
|
||||
} else {
|
||||
for k, v := range conditions {
|
||||
qs = qs.Filter(k, v)
|
||||
}
|
||||
db.ScanRows(rows, value.Interface())
|
||||
if elmType.Kind() != reflect.Ptr {
|
||||
value = value.Elem()
|
||||
}
|
||||
valueInfo.Elem().Set(reflect.Append(valueInfo.Elem(), value))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetEntity(db *gorm.DB, item interface{}) error {
|
||||
if db == nil {
|
||||
db = gormdb.GetDB()
|
||||
}
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
return db.First(item).Error
|
||||
_, err2 := qs.Update(kvs)
|
||||
return err2
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateEntity(db *gorm.DB, item interface{}, values map[string]interface{}) error {
|
||||
func CreateEntity(db *DaoDB, item interface{}) error {
|
||||
if db == nil {
|
||||
db = gormdb.GetDB()
|
||||
db = GetDB()
|
||||
}
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
return db.Model(item).Updates(values).Error
|
||||
_, err2 := db.db.Insert(item) // todo 这里需要将ID赋值么?
|
||||
return err2
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return err
|
||||
}
|
||||
|
||||
func CreateEntity(db *gorm.DB, item interface{}) error {
|
||||
if db == nil {
|
||||
db = gormdb.GetDB()
|
||||
}
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
return db.Create(item).Error
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return err
|
||||
}
|
||||
|
||||
func GetSellCities(skuNameID int, vendorID int, db *gorm.DB) (cities []*model.Place, err error) {
|
||||
cities = []*model.Place{}
|
||||
sql := `
|
||||
SELECT DISTINCT t3.*
|
||||
FROM sku_name_place_bind t1
|
||||
JOIN place t2 ON t1.place_code = t2.code
|
||||
JOIN place t3 ON (t2.level = 2 AND t2.code = t3.code) OR (t2.level = 1 AND t2.code = t3.parent_code)
|
||||
WHERE t1.sku_name_id = ?
|
||||
`
|
||||
if vendorID == model.VendorIDJD {
|
||||
sql += "AND t3.jd_code <> 0\n"
|
||||
}
|
||||
return cities, GetRows(nil, &cities, sql, skuNameID)
|
||||
}
|
||||
|
||||
func GetPlaceByCode(db *gorm.DB, code int) (place *model.Place, err error) {
|
||||
if db == nil {
|
||||
db = gormdb.GetDB()
|
||||
}
|
||||
place = new(model.Place)
|
||||
err = db.Where("code = ?", code).First(place).Error
|
||||
return place, err
|
||||
}
|
||||
|
||||
func GetPlaceByName(db *gorm.DB, name string, level int, parentCode int) (place *model.Place, err error) {
|
||||
if db == nil {
|
||||
db = gormdb.GetDB()
|
||||
}
|
||||
place = new(model.Place)
|
||||
if err = db.Where("parent_code = ? AND level = ? AND name = ?", parentCode, level, name).First(place).Error; err == gorm.ErrRecordNotFound {
|
||||
err = db.Where("parent_code = ? AND level = ? AND name LIKE ?", parentCode, level, "%"+name+"%").First(place).Error
|
||||
}
|
||||
return place, err
|
||||
}
|
||||
|
||||
func GetPlaceByJdCode(db *gorm.DB, jdCode int) (place *model.Place, err error) {
|
||||
if db == nil {
|
||||
db = gormdb.GetDB()
|
||||
}
|
||||
place = new(model.Place)
|
||||
err = db.Where("jd_code = ?", jdCode).First(place).Error
|
||||
return place, err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
@@ -18,7 +17,6 @@ func init() {
|
||||
|
||||
globals.Init()
|
||||
beegodb.Init()
|
||||
gormdb.Init()
|
||||
api.Init()
|
||||
}
|
||||
|
||||
|
||||
43
business/model/dao/place.go
Normal file
43
business/model/dao/place.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
func GetPlaceByCode(db *DaoDB, code int) (place *model.Place, err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
place = &model.Place{
|
||||
Code: code,
|
||||
}
|
||||
err = db.db.Read(place, "Code")
|
||||
return place, err
|
||||
}
|
||||
|
||||
func GetPlaceByName(db *DaoDB, name string, level int, parentCode int) (place *model.Place, err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
place = &model.Place{
|
||||
Name: name,
|
||||
Level: int8(level),
|
||||
ParentCode: parentCode,
|
||||
}
|
||||
if err = db.db.Read(place, "Name", "Level", "ParentCode"); err == orm.ErrNoRows {
|
||||
err = db.db.Raw("SELECT * FROM place WHERE parent_code = ? AND level = ? AND name LIKE ?", parentCode, level, "%"+name+"%").QueryRow(place)
|
||||
}
|
||||
return place, err
|
||||
}
|
||||
|
||||
func GetPlaceByJdCode(db *DaoDB, jdCode int) (place *model.Place, err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
place = &model.Place{
|
||||
JdCode: jdCode,
|
||||
}
|
||||
err = db.db.Read(place, "JdCode")
|
||||
return place, err
|
||||
}
|
||||
20
business/model/dao/sku.go
Normal file
20
business/model/dao/sku.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetSellCities(db *DaoDB, skuNameID int, vendorID int) (cities []*model.Place, err error) {
|
||||
cities = []*model.Place{}
|
||||
sql := `
|
||||
SELECT DISTINCT t3.*
|
||||
FROM sku_name_place_bind t1
|
||||
JOIN place t2 ON t1.place_code = t2.code
|
||||
JOIN place t3 ON (t2.level = 2 AND t2.code = t3.code) OR (t2.level = 1 AND t2.code = t3.parent_code)
|
||||
WHERE t1.sku_name_id = ?
|
||||
`
|
||||
if vendorID == model.VendorIDJD {
|
||||
sql += "AND t3.jd_code <> 0\n"
|
||||
}
|
||||
return cities, GetRows(db, &cities, sql, skuNameID)
|
||||
}
|
||||
34
business/model/dtask.go
Normal file
34
business/model/dtask.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type DurableTask struct {
|
||||
ID int `orm:"column(id)" json:"id"`
|
||||
CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
|
||||
UpdatedAt time.Time `orm:"auto_now;type(datetime)" json:"updatedAt"`
|
||||
|
||||
TaskID string `orm:"size(48)"` // 用于标识任务
|
||||
Description string `orm:"size(255)"`
|
||||
CreatedBy string `orm:"size(48)"`
|
||||
FinishedAt time.Time
|
||||
Status int
|
||||
|
||||
TotalItem int
|
||||
FinishedItem int
|
||||
}
|
||||
|
||||
type DurableTaskItem struct {
|
||||
ID int `orm:"column(id)" json:"id"`
|
||||
CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
|
||||
UpdatedAt time.Time `orm:"auto_now;type(datetime)" json:"updatedAt"`
|
||||
|
||||
TaskID string `orm:"size(48)"` // 用于标识任务
|
||||
TaskIndex int
|
||||
ObjHint string `orm:"size(48)"`
|
||||
FuncName string `orm:"size(48)"`
|
||||
Params string `orm:"size(2000)"` // 序列化后的参数
|
||||
FinishedAt time.Time
|
||||
Status int
|
||||
}
|
||||
@@ -1,33 +1,33 @@
|
||||
package model
|
||||
|
||||
type WeiXins struct {
|
||||
ID int
|
||||
JxStoreID int `gorm:"column:jxstoreid"`
|
||||
OpenID string `gorm:"column:openid;type:varchar(70);index"`
|
||||
Tel string `gorm:"type:varchar(15);index"`
|
||||
ParentID int `gorm:"column:parentid"`
|
||||
NickName string `gorm:"column:nickname;type:varchar(30)"`
|
||||
ID int `orm:"column(id)"`
|
||||
JxStoreID int `orm:"column(jxstoreid)"`
|
||||
OpenID string `orm:"column(openid);size(70);index"`
|
||||
Tel string `orm:"size(15);index"`
|
||||
ParentID int `orm:"column(parentid)"`
|
||||
NickName string `orm:"column(nickname);size(30)"`
|
||||
}
|
||||
|
||||
func (WeiXins) TableName() string {
|
||||
func (*WeiXins) TableName() string {
|
||||
return "weixins"
|
||||
}
|
||||
|
||||
type JxBackendUser struct {
|
||||
UID int `gorm:"PRIMARY_KEY"`
|
||||
UName string `gorm:"column:uname;type:varchar(64);unique_index"`
|
||||
UPass string `gorm:"column:upass;type:varchar(64)"`
|
||||
Tel string `gorm:"type:varchar(32);index"`
|
||||
Position string `gorm:"type:varchar(255)"`
|
||||
Enabled int8 `gorm:"default:1"`
|
||||
SkuWidget int `gorm:"default:0"`
|
||||
StoreWidget int `gorm:"default:0"`
|
||||
UserWidget int `gorm:"default:0"`
|
||||
BillinfoWidget int `gorm:"default:0"`
|
||||
GroupWidget int `gorm:"default:0"`
|
||||
CategoryWidget int `gorm:"default:0"`
|
||||
UID int `orm:"pk;column(uid)"`
|
||||
UName string `orm:"column(uname);size(64);index"`
|
||||
UPass string `orm:"column(upass);size(64)"`
|
||||
Tel string `orm:"size(32);index"`
|
||||
Position string `orm:"size(255)"`
|
||||
Enabled int8 `orm:"default(1)"`
|
||||
SkuWidget int `orm:"default(0)"`
|
||||
StoreWidget int `orm:"default(0)"`
|
||||
UserWidget int `orm:"default(0)"`
|
||||
BillinfoWidget int `orm:"default(0)"`
|
||||
GroupWidget int `orm:"default(0)"`
|
||||
CategoryWidget int `orm:"default(0)"`
|
||||
}
|
||||
|
||||
func (JxBackendUser) TableName() string {
|
||||
func (*JxBackendUser) TableName() string {
|
||||
return "jxbackenduser"
|
||||
}
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type ModelO struct {
|
||||
ID int `gorm:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt *time.Time `sql:"index"`
|
||||
LastOperator string `gorm:"type:varchar(32)" json:"lastOperator"` // 最后操作员
|
||||
}
|
||||
|
||||
type ModelIDCU struct {
|
||||
ID int `gorm:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type ModelIDCUO struct {
|
||||
ID int `gorm:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
LastOperator string `gorm:"type:varchar(32)" json:"lastOperator"` // 最后操作员
|
||||
type ModelIDCUL struct {
|
||||
ID int `orm:"column(id)" json:"id"`
|
||||
CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
|
||||
UpdatedAt time.Time `orm:"auto_now;type(datetime)" json:"updatedAt"`
|
||||
LastOperator string `orm:"size(32)" json:"lastOperator"` // 最后操作员
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// https://github.com/videni/pcr
|
||||
const (
|
||||
CityLevelProvince = 1
|
||||
@@ -10,15 +8,15 @@ const (
|
||||
)
|
||||
|
||||
type Place struct {
|
||||
ID int `json:"-"`
|
||||
Code int `gorm:"unique_index" json:"code"` // 国家标准代码
|
||||
Name string `gorm:"type:varchar(16);index" json:"name"` // 如果是直辖市,省的概念不加“市”来区别
|
||||
ParentCode int `json:"parentCode"` // 上级代码
|
||||
PostCode string `gorm:"type:varchar(8);index" json:"postCode"`
|
||||
Level int8 `json:"level"` // 城市级别,参见相关常量定义
|
||||
TelCode string `gorm:"type:varchar(8);index" json:"telCode"`
|
||||
JdCode int `gorm:"index" json:"jdCode"` // 对应的京东代码
|
||||
Enabled int8 `json:"enabled"` // 是否启用
|
||||
MtpsPrice int `json:"mtpsPrice"` // 分为单位
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
ModelIDCUL
|
||||
|
||||
Code int `orm:"unique" json:"code"` // 国家标准代码
|
||||
Name string `orm:"size(16);index" json:"name"` // 如果是直辖市,省的概念不加“市”来区别
|
||||
ParentCode int `json:"parentCode"` // 上级代码
|
||||
PostCode string `orm:"size(8);index" json:"postCode"`
|
||||
Level int8 `json:"level"` // 城市级别,参见相关常量定义
|
||||
TelCode string `orm:"size(8);index" json:"telCode"`
|
||||
JdCode int `orm:"index" json:"jdCode"` // 对应的京东代码
|
||||
Enabled int8 `json:"enabled"` // 是否启用
|
||||
MtpsPrice int `json:"mtpsPrice"` // 分为单位
|
||||
}
|
||||
|
||||
@@ -49,89 +49,123 @@ var (
|
||||
|
||||
// 这个指的是厂商(比如京东到家,饿百)自已的商品分类,与商家自己的商品分类是两回事
|
||||
type SkuVendorCategory struct {
|
||||
ModelIDCUO
|
||||
VendorCategoryID string `gorm:"type:varchar(48);unique_index:unique_index_id_vendor_id" json:"vendorCategoryID"`
|
||||
VendorID int `gorm:"unique_index:unique_index_id_vendor_id" json:"vendorID"`
|
||||
Name string `gorm:"type:varchar(255);index" json:"name"`
|
||||
ModelIDCUL
|
||||
|
||||
VendorCategoryID string `orm:"size(48);column(vendor_category_id)" json:"vendorCategoryID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
Name string `orm:"size(255);index" json:"name"`
|
||||
IsLeaf int8 `json:"isLeaf"`
|
||||
Level int `json:"level"`
|
||||
ParentID string `gorm:"type:varchar(255);index" json:"parentID"` // 父ID,引用的是VendorCategoryID而不是ID
|
||||
ParentID string `orm:"column(parent_id);size(255);index" json:"parentID"` // 父ID,引用的是VendorCategoryID而不是ID
|
||||
}
|
||||
|
||||
func (*SkuVendorCategory) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorCategoryID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
// 基础数据,除了商家商品类别外,基本都以京东到家为准
|
||||
type SkuCategory struct {
|
||||
ModelIDCUO
|
||||
Name string `gorm:"type:varchar(255);unique_index"`
|
||||
ParentID int
|
||||
ModelIDCUL
|
||||
|
||||
Name string `orm:"size(255);unique"`
|
||||
ParentID int `orm:"column(parent_id)"`
|
||||
Level int8
|
||||
Type int8 // 类别类型
|
||||
Seq int
|
||||
|
||||
JdID int64 `gorm:"index"` // 这个是指商家自己的商品类别在京东平台上的ID
|
||||
JdCategoryID int // 这个是指对应的京东商品类别
|
||||
JdID int64 `orm:"column(jd_id);index"` // 这个是指商家自己的商品类别在京东平台上的ID
|
||||
JdCategoryID int `orm:"column(jd_category_id)"` // 这个是指对应的京东商品类别
|
||||
|
||||
// ElmID int64 `gorm:"index"` // 饿了么是单店模式,不需要
|
||||
ElmCategoryID int64 // 这个是指对应的饿了么商品类别
|
||||
ElmCategoryID int64 `orm:"column(elm_category_id)"` // 这个是指对应的饿了么商品类别
|
||||
EbaiCategoryID int64 `orm:"column(ebai_category_id)"` // 这个是指对应的饿百商品类别
|
||||
|
||||
// EbaiID int64 `gorm:"index"` // 饿百是单店模式,不需要
|
||||
EbaiCategoryID int64 // 这个是指对应的饿百商品类别
|
||||
|
||||
// MtID string `gorm:"type:varchar(48);index"`
|
||||
// DidiID string `gorm:"type:varchar(48);index"`
|
||||
// MtID string `orm:"size(48);index"`
|
||||
// DidiID string `orm:"size(48);index"`
|
||||
}
|
||||
|
||||
type SkuName struct {
|
||||
ModelIDCUO
|
||||
Prefix string `gorm:"type:varchar(255)"`
|
||||
Name string `gorm:"type:varchar(255)"`
|
||||
Comment string `gorm:"type:varchar(255)"`
|
||||
ModelIDCUL
|
||||
|
||||
BrandID int `gorm:"default:0"` // 此属性暂时没有使用
|
||||
CategoryID int // 标准类别
|
||||
Prefix string `orm:"size(255)"`
|
||||
Name string `orm:"size(255)"`
|
||||
Comment string `orm:"size(255)"`
|
||||
|
||||
BrandID int `orm:"column(brand_id);default(0)"` // 此属性暂时没有使用
|
||||
CategoryID int `orm:"column(category_id)"` // 标准类别
|
||||
Status int
|
||||
|
||||
IsGlobal int8 `gorm:"default:1"` // 是否是全部(全国)可见,如果否的话,可见性由SkuPlace决定
|
||||
Unit string `gorm:"type:varchar(8)"`
|
||||
IsGlobal int8 `orm:"default(1)"` // 是否是全部(全国)可见,如果否的话,可见性由SkuPlace决定
|
||||
Unit string `orm:"size(8)"`
|
||||
Price int // 单位为分,标准价,不为份的就为实际标准价,为份的为每市斤价,实际还要乘质量。todo 为份的确定必须有质量
|
||||
Img string `gorm:"type:varchar(255)"`
|
||||
ElmImgHashCode string `gorm:"type:varchar(64)"`
|
||||
Img string `orm:"size(255)"`
|
||||
ElmImgHashCode string `orm:"size(64)"`
|
||||
}
|
||||
|
||||
type Sku struct {
|
||||
ModelIDCUO
|
||||
CategoryID int // 特殊类别,一般用于秒杀,特价之类的特殊类别
|
||||
NameID int `gorm:"index:unique_index_name_Id_quality"` // todo 这个索引应该要求唯一
|
||||
SpecQuality float32 `gorm:"index:unique_index_name_Id_quality"`
|
||||
SpecUnit string `gorm:"type:varchar(8)"` // 质量或容量
|
||||
Weight int // 重量/质量,单位为克,当相应的SkuName的SpecUnit为g或kg时,必须等于SpecQuality
|
||||
// func (*SkuName) TableUnique() [][]string {
|
||||
// return [][]string{
|
||||
// []string{"Name", "Prefix", "Unit"},
|
||||
// }
|
||||
// }
|
||||
|
||||
JdID int64
|
||||
type Sku struct {
|
||||
ModelIDCUL
|
||||
|
||||
CategoryID int `orm:"column(category_id)"` // 特殊类别,一般用于秒杀,特价之类的特殊类别
|
||||
NameID int `orm:"column(name_id)"` // todo 这个索引应该要求唯一
|
||||
SpecQuality float32
|
||||
SpecUnit string `orm:"size(8)"` // 质量或容量
|
||||
Weight int // 重量/质量,单位为克,当相应的SkuName的SpecUnit为g或kg时,必须等于SpecQuality
|
||||
|
||||
JdID int64 `orm:"column(jd_id)"`
|
||||
}
|
||||
|
||||
func (*Sku) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"NameID", "SpecQuality", "SpecUnit"},
|
||||
}
|
||||
}
|
||||
|
||||
type SkuNamePlaceBind struct {
|
||||
ModelIDCUO
|
||||
SkuNameID int `gorm:"unique_index:unique_sku_name_id_sku_place_id"`
|
||||
PlaceCode int `gorm:"unique_index:unique_sku_name_id_sku_place_id"`
|
||||
ModelIDCUL
|
||||
|
||||
SkuNameID int `orm:"column(sku_name_id)"`
|
||||
PlaceCode int
|
||||
}
|
||||
|
||||
func (*SkuNamePlaceBind) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"SkuNameID", "PlaceCode"},
|
||||
}
|
||||
}
|
||||
|
||||
// 以下为门店相关数据
|
||||
type StoreSkuCategoryMap struct {
|
||||
ModelIDCUO
|
||||
StoreID int
|
||||
SkuCategoryID int
|
||||
ModelIDCUL
|
||||
|
||||
ElmID int64 `gorm:"index"`
|
||||
EbaiID int64 `gorm:"index"`
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
SkuCategoryID int `orm:"column(sku_category_id)"`
|
||||
|
||||
ElmID int64 `orm:"column(elm_id);index"`
|
||||
EbaiID int64 `orm:"column(ebai_id);index"`
|
||||
}
|
||||
|
||||
type StoreSkuBind struct {
|
||||
ModelIDCUO
|
||||
StoreID int `gorm:"unique_index:unique_store_id_sku_id"`
|
||||
SkuID int `gorm:"unique_index:unique_store_id_sku_id"`
|
||||
SubStoreID int
|
||||
ModelIDCUL
|
||||
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
SkuID int `orm:"column(sku_id)"`
|
||||
SubStoreID int `orm:"column(sub_store_id)"`
|
||||
Price int // 单位为分,不用int64的原因是这里不需要累加
|
||||
Status int
|
||||
|
||||
ElmID int64 `gorm:"index"`
|
||||
EbaiID int64 `gorm:"index"`
|
||||
ElmID int64 `orm:"column(elm_id);index"`
|
||||
EbaiID int64 `orm:"column(ebai_id);index"`
|
||||
}
|
||||
|
||||
func (*StoreSkuBind) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"StoreID", "SkuID"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,41 +18,50 @@ const (
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
ModelIDCUO
|
||||
Name string `gorm:"type:varchar(255);unique_index" json:"name"`
|
||||
CityCode int `json:"cityCode"` // todo ?
|
||||
DistrictCode int `json:"districtCode"` // todo ?
|
||||
Address string `gorm:"type:varchar(255)" json:"address"`
|
||||
Tel1 string `gorm:"type:varchar(32)" json:"tel1"`
|
||||
Tel2 string `gorm:"type:varchar(32)" json:"tel2"`
|
||||
OpenTime1 int16 `json:"openTime1"` // 930就表示9点半,用两个的原因是为了支持中午休息,1与2的时间段不能交叉,为0表示没有
|
||||
CloseTime1 int16 `json:"closeTime1"` // 格式同上
|
||||
OpenTime2 int16 `json:"openTime2"` // 格式同上
|
||||
CloseTime2 int16 `json:"closeTime2"` // 格式同上
|
||||
Lng int `json:"lng"` // 乘了10的6次方
|
||||
Lat int `json:"lat"` // 乘了10的6次方
|
||||
DeliveryRangeType int8 `json:"deliveryRangeType"` // 参见相关常量定义
|
||||
DeliveryRange string `gorm:"type:varchar(2048)" json:"deliveryRange"` // 如果DeliveryRangeType为DeliveryRangeTypePolygon,则为逗号分隔坐标,分号分隔的坐标点(坐标与Lng和Lat一样,都是整数),比如 121361504,31189308;121420555,31150238。否则为半径,单位为米
|
||||
ModelIDCUL
|
||||
|
||||
Name string `orm:"size(255);unique" json:"name"`
|
||||
CityCode int `orm:"default(0);null" json:"cityCode"` // todo ?
|
||||
DistrictCode int `orm:"default(0);null" json:"districtCode"` // todo ?
|
||||
Address string `orm:"size(255)" json:"address"`
|
||||
Tel1 string `orm:"size(32);index" json:"tel1"`
|
||||
Tel2 string `orm:"size(32);index" json:"tel2"`
|
||||
OpenTime1 int16 `json:"openTime1"` // 930就表示9点半,用两个的原因是为了支持中午休息,1与2的时间段不能交叉,为0表示没有
|
||||
CloseTime1 int16 `json:"closeTime1"` // 格式同上
|
||||
OpenTime2 int16 `json:"openTime2"` // 格式同上
|
||||
CloseTime2 int16 `json:"closeTime2"` // 格式同上
|
||||
Lng int `json:"lng"` // 乘了10的6次方
|
||||
Lat int `json:"lat"` // 乘了10的6次方
|
||||
DeliveryRangeType int8 `json:"deliveryRangeType"` // 参见相关常量定义
|
||||
DeliveryRange string `orm:"size(2048)" json:"deliveryRange"` // 如果DeliveryRangeType为DeliveryRangeTypePolygon,则为逗号分隔坐标,分号分隔的坐标点(坐标与Lng和Lat一样,都是整数),比如 121361504,31189308;121420555,31150238。否则为半径,单位为米
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
type StoreSub struct {
|
||||
ModelIDCUO
|
||||
StoreID int `gorm:"unique_index:unique_index1"`
|
||||
Index int `gorm:"unique_index:unique_index1"` // 子店序号,为0表示主店
|
||||
Name string `gorm:"type:varchar(255)"`
|
||||
Address string `gorm:"type:varchar(255)"`
|
||||
ModelIDCUL
|
||||
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
Index int // 子店序号,为0表示主店
|
||||
Name string `orm:"size(255);index"`
|
||||
Address string `orm:"size(255)"`
|
||||
Status int // 取值同Store.Status
|
||||
Mobile1 string `gorm:"type:varchar(32)"`
|
||||
Mobile2 string `gorm:"type:varchar(32)"`
|
||||
Mobile3 string `gorm:"type:varchar(32)"`
|
||||
Mobile1 string `orm:"size(32)"`
|
||||
Mobile2 string `orm:"size(32)"`
|
||||
Mobile3 string `orm:"size(32)"`
|
||||
}
|
||||
|
||||
func (*StoreSub) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"StoreID", "Index"},
|
||||
}
|
||||
}
|
||||
|
||||
type StoreMap struct {
|
||||
ModelIDCUO
|
||||
StoreID int `gorm:"unique_index:storemap1"`
|
||||
VendorID int `gorm:"unique_index:storemap1"`
|
||||
VendorStoreID string `gorm:"type:varchar(48);unique_index"`
|
||||
ModelIDCUL
|
||||
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
VendorID int `orm:"column(vendor_id)"`
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)"`
|
||||
Status int // 取值同Store.Status
|
||||
|
||||
AutoPickup int8 // 是否自动拣货
|
||||
@@ -60,10 +69,25 @@ type StoreMap struct {
|
||||
DeliveryCompetition int8 // 是否支持配送竞争
|
||||
}
|
||||
|
||||
func (*StoreMap) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"StoreID", "VendorID"},
|
||||
[]string{"VendorStoreID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
type StoreCourierMap struct {
|
||||
ModelIDCUO
|
||||
StoreID int `gorm:"unique_index:storemap1"`
|
||||
VendorID int `gorm:"unique_index:storemap1"`
|
||||
VendorStoreID string `gorm:"type:varchar(48);unique_index"`
|
||||
ModelIDCUL
|
||||
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
VendorID int `orm:"column(vendor_id)"`
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)"`
|
||||
Status int
|
||||
}
|
||||
|
||||
func (*StoreCourierMap) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"StoreID", "VendorID"},
|
||||
[]string{"VendorStoreID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package model
|
||||
|
||||
type TaskLog struct {
|
||||
ModelIDCU
|
||||
TaskID string `gorm:"type:varchar(48)"` // 用于标识任务
|
||||
CreatedBy string `gorm:"type:varchar(48)"`
|
||||
Status int
|
||||
}
|
||||
|
||||
type TaskLogItem struct {
|
||||
ModelIDCU
|
||||
TaskID string `gorm:"type:varchar(48)"` // 用于标识任务
|
||||
ID1 int
|
||||
VendorID1 string `gorm:"type:varchar(48)"`
|
||||
ID2 int
|
||||
VendorID2 string `gorm:"type:varchar(48)"`
|
||||
ID3 int
|
||||
VendorID3 string `gorm:"type:varchar(48)"`
|
||||
Payload string `gorm:"type:varchar(2000)"`
|
||||
StatusJD int8
|
||||
StatusElm int8
|
||||
StatusEbai int8
|
||||
}
|
||||
Reference in New Issue
Block a user