- skuName place bind man.

This commit is contained in:
gazebo
2018-09-12 23:15:54 +08:00
parent ecd19c55b3
commit f14112c030
14 changed files with 173 additions and 68 deletions

View File

@@ -180,8 +180,18 @@ func CreateEntity(db *DaoDB, item interface{}) (err error) {
return err
}
// 如果logicDeletedBy不为空表示逻辑删除否则物理删除
func DeleteEntity(db *DaoDB, item interface{}, conditions map[string]interface{}, logicDeletedBy string, kvs map[string]interface{}) (num int64, err error) {
func DeleteEntity(db *DaoDB, item interface{}, cols ...string) (num int64, err error) {
if db == nil {
db = GetDB()
}
err = utils.CallFuncLogError(func() error {
num, err = db.db.Delete(item, cols...)
return err
}, reflect.TypeOf(item).Name())
return num, err
}
func DeleteEntityLogically(db *DaoDB, item interface{}, conditions map[string]interface{}, logicDeletedBy string, kvs map[string]interface{}) (num int64, err error) {
if db == nil {
db = GetDB()
}
@@ -194,17 +204,13 @@ func DeleteEntity(db *DaoDB, item interface{}, conditions map[string]interface{}
qs = qs.Filter(k, v)
}
}
if logicDeletedBy != "" {
qs = qs.Filter(model.FieldDeletedAt, utils.DefaultTimeValue)
updateValues := map[string]interface{}{
model.FieldDeletedAt: time.Now(),
model.FieldUpdatedAt: time.Now(),
model.FieldLastOperator: logicDeletedBy,
}
num, err = qs.Update(utils.MergeMaps(updateValues, kvs))
} else {
num, err = qs.Delete()
qs = qs.Filter(model.FieldDeletedAt, utils.DefaultTimeValue)
updateValues := map[string]interface{}{
model.FieldDeletedAt: time.Now(),
model.FieldUpdatedAt: time.Now(),
model.FieldLastOperator: logicDeletedBy,
}
num, err = qs.Update(utils.MergeMaps(updateValues, kvs))
return err
}, reflect.TypeOf(item).Name())
return num, err

View File

@@ -27,7 +27,7 @@ func TestSelectEntities(t *testing.T) {
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 = ?
WHERE t1.name_id = ?
`, 40)
globals.SugarLogger.Debug(utils.Format4Output(places, false))

View File

@@ -12,7 +12,7 @@ func GetPlaceByCode(db *DaoDB, code int) (place *model.Place, err error) {
place = &model.Place{
Code: code,
}
err = db.db.Read(place, "Code")
err = GetEntity(db, place, "Code")
return place, err
}
@@ -25,7 +25,7 @@ func GetPlaceByName(db *DaoDB, name string, level int, parentCode int) (place *m
Level: int8(level),
ParentCode: parentCode,
}
if err = db.db.Read(place, "Name", "Level", "ParentCode"); err == orm.ErrNoRows {
if err = GetEntity(db, 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

View File

@@ -4,17 +4,17 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
)
func GetSellCities(db *DaoDB, skuNameID int, vendorID int) (cities []*model.Place, err error) {
func GetSellCities(db *DaoDB, nameID 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 = ?
WHERE t1.name_id = ?
`
if vendorID == model.VendorIDJD {
sql += "AND t3.jd_code <> 0\n"
}
return cities, GetRows(db, &cities, sql, skuNameID)
return cities, GetRows(db, &cities, sql, nameID)
}

View File

@@ -11,6 +11,7 @@ const (
FieldCreatedAt = "CreatedAt"
FieldUpdatedAt = "UpdatedAt"
FieldLastOperator = "LastOperator"
FieldStatus = "Status"
FieldSyncStatus = "SyncStatus"
FieldJdSyncStatus = "JdSyncStatus"
@@ -18,6 +19,7 @@ const (
FieldStoreID = "StoreID"
FieldVendorStoreID = "VendorStoreID"
FieldNameID = "NameID"
FieldPlaceCode = "PlaceCode"
)
type ModelIDCUL struct {

View File

@@ -102,13 +102,14 @@ type SkuCategory struct {
ElmCategoryID int64 `orm:"column(elm_category_id)" json:"elmCategoryID"` // 这个是指对应的饿了么商品类别
EbaiCategoryID int64 `orm:"column(ebai_category_id)" json:"ebaiCategoryID"` // 这个是指对应的饿百商品类别
JdID int64 `orm:"column(jd_id);index" json:"jdID"` // 这个是指商家自己的商品类别在京东平台上的ID
JdID int64 `orm:"column(jd_id)" json:"jdID"` // 这个是指商家自己的商品类别在京东平台上的ID
JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`
}
func (*SkuCategory) TableUnique() [][]string {
return [][]string{
[]string{"Name", "DeletedAt"},
[]string{"JdID", "DeletedAt"},
}
}
@@ -116,11 +117,11 @@ type SkuName struct {
ModelIDCULD
Prefix string `orm:"size(255)" json:"prefix"`
Name string `orm:"size(255)" json:"name"`
Name string `orm:"size(255);index" json:"name"`
Comment string `orm:"size(255)" json:"comment"`
BrandID int `orm:"column(brand_id);default(0)" json:"brandID"` // 此属性暂时没有使用
CategoryID int `orm:"column(category_id)" json:"categoryID"` // 标准类别
BrandID int `orm:"column(brand_id);default(0)" json:"brandID"` // 此属性暂时没有使用
CategoryID int `orm:"column(category_id);index" json:"categoryID"` // 标准类别
IsGlobal int8 `orm:"default(1)" json:"isGlobal"` // 是否是全部全国可见如果否的话可见性由SkuPlace决定
Unit string `orm:"size(8)" json:"unit"`
@@ -159,42 +160,12 @@ func (*Sku) TableUnique() [][]string {
type SkuNamePlaceBind struct {
ModelIDCUL
SkuNameID int `orm:"column(sku_name_id)"`
NameID int `orm:"column(name_id)"`
PlaceCode int
}
func (*SkuNamePlaceBind) TableUnique() [][]string {
return [][]string{
[]string{"SkuNameID", "PlaceCode"},
}
}
// 以下为门店相关数据
type StoreSkuCategoryMap struct {
ModelIDCUL
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 {
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 `orm:"column(elm_id);index"`
EbaiID int64 `orm:"column(ebai_id);index"`
}
func (*StoreSkuBind) TableUnique() [][]string {
return [][]string{
[]string{"StoreID", "SkuID"},
[]string{"NameID", "PlaceCode"},
}
}

View File

@@ -0,0 +1,30 @@
package model
type StoreSkuCategoryMap struct {
ModelIDCUL
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 {
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 `orm:"column(elm_id);index"`
EbaiID int64 `orm:"column(ebai_id);index"`
}
func (*StoreSkuBind) TableUnique() [][]string {
return [][]string{
[]string{"StoreID", "SkuID"},
}
}