- remove partner.GetFieldIDName and partner.GetFieldSyncStatusName (use dao.GetXXXField instead)
- mtwm.UpdateStore - mtwm.SyncStoreCategory
This commit is contained in:
@@ -19,12 +19,12 @@ const (
|
||||
|
||||
var (
|
||||
VendorNames = map[int]string{
|
||||
VendorIDJD: "JD",
|
||||
VendorIDMTWM: "MT",
|
||||
VendorIDELM: "ELEME",
|
||||
VendorIDEBAI: "EBAI",
|
||||
VendorIDJD: "Jd",
|
||||
VendorIDMTWM: "Mtwm",
|
||||
VendorIDELM: "Elm",
|
||||
VendorIDEBAI: "Ebai",
|
||||
VendorIDDada: "Dada",
|
||||
VendorIDMTPS: "MTPS",
|
||||
VendorIDMTPS: "Mtps",
|
||||
}
|
||||
VendorChineseNames = map[int]string{
|
||||
VendorIDJD: "京东到家",
|
||||
|
||||
@@ -2,6 +2,7 @@ package dao
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -81,3 +82,51 @@ func GenQuestionMarks(count int) string {
|
||||
}
|
||||
return marks
|
||||
}
|
||||
|
||||
func ConvertStructFieldPrefix(prefix string) string {
|
||||
return prefix
|
||||
}
|
||||
|
||||
func ConvertJsonFieldPrefix(prefix string) string {
|
||||
return strings.ToLower(prefix)
|
||||
}
|
||||
|
||||
func ConvertDBFieldPrefix(prefix string) string {
|
||||
return strings.ToLower(prefix)
|
||||
}
|
||||
|
||||
func GetVendorThingIDStructField(prefix string) string {
|
||||
return ConvertStructFieldPrefix(prefix) + "ID"
|
||||
}
|
||||
|
||||
func GetVendorThingIDJsonField(prefix string) string {
|
||||
return ConvertJsonFieldPrefix(prefix) + "ID"
|
||||
}
|
||||
|
||||
func GetVendorThingIDDBField(prefix string) string {
|
||||
return ConvertDBFieldPrefix(prefix) + "_id"
|
||||
}
|
||||
|
||||
func GetSyncStatusStructField(prefix string) string {
|
||||
return ConvertStructFieldPrefix(prefix) + "SyncStatus"
|
||||
}
|
||||
|
||||
func GetSyncStatusJsonField(prefix string) string {
|
||||
return ConvertJsonFieldPrefix(prefix) + "SyncStatus"
|
||||
}
|
||||
|
||||
func GetSyncStatusDBField(prefix string) string {
|
||||
return ConvertDBFieldPrefix(prefix) + "_sync_status"
|
||||
}
|
||||
|
||||
func GetCategoryIDStructField(prefix string) string {
|
||||
return ConvertStructFieldPrefix(prefix) + "CategoryID"
|
||||
}
|
||||
|
||||
func GetCategoryIDJsonField(prefix string) string {
|
||||
return ConvertJsonFieldPrefix(prefix) + "CategoryID"
|
||||
}
|
||||
|
||||
func GetCategoryIDDBField(prefix string) string {
|
||||
return ConvertDBFieldPrefix(prefix) + "_category_id"
|
||||
}
|
||||
|
||||
30
business/model/dao/store.go
Normal file
30
business/model/dao/store.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type StoreDetail struct {
|
||||
model.Store
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
||||
VendorStatus int `json:"vendor_status"` // 取值同Store.Status
|
||||
DeliveryFee int `json:"deliveryFee"`
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
model.Place // district info
|
||||
}
|
||||
|
||||
func GetStoreDetail(db *DaoDB, storeID, vendorID int) (storeDetail *StoreDetail, err error) {
|
||||
sql := `
|
||||
SELECT t2.status vendor_status, t2.vendor_store_id, t2.sync_status, district.*, t1.*
|
||||
FROM store t1
|
||||
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ?
|
||||
LEFT JOIN place district ON t1.district_code = district.code
|
||||
WHERE t1.id = ? AND t1.deleted_at = ?
|
||||
`
|
||||
storeDetail = &StoreDetail{}
|
||||
if err = GetRow(db, storeDetail, sql, vendorID, utils.DefaultTimeValue, storeID, utils.DefaultTimeValue); err == nil {
|
||||
return storeDetail, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
87
business/model/dao/store_sku.go
Normal file
87
business/model/dao/store_sku.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type SkuStoreCatInfo struct {
|
||||
model.SkuCategory
|
||||
CatID int `orm:"column(cat_id)"` // 这个主要用于判断是否有store_sku_category_map
|
||||
VendorCatID string `orm:"column(vendor_cat_id)"`
|
||||
CatSyncStatus int8
|
||||
|
||||
ParentCatName string
|
||||
ParentCatID int `orm:"column(parent_cat_id)"` // 这个主要用于判断是否有父store_sku_category_map
|
||||
ParentVendorCatID string `orm:"column(parent_vendor_cat_id)"`
|
||||
ParentCatSyncStatus int8
|
||||
}
|
||||
|
||||
type StoreCatSyncInfo struct {
|
||||
CatName string
|
||||
Seq int `json:"seq"`
|
||||
model.StoreSkuCategoryMap
|
||||
|
||||
ParentCatName string
|
||||
ParentCatID int `orm:"column(parent_cat_id)"` // 这个主要用于判断是否有父store_sku_category_map
|
||||
ParentVendorCatID string `orm:"column(parent_vendor_cat_id)"`
|
||||
ParentCatSyncStatus int8
|
||||
}
|
||||
|
||||
func GetSkusCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int) (cats []*SkuStoreCatInfo, err error) {
|
||||
sql := `
|
||||
SELECT DISTINCT t4.*, t5.category_id cat_id, t5.%s_id vendor_cat_id, t5.%s_sync_status cat_sync_status, t4p.name parent_cat_name, t5p.category_id parent_cat_id, t5p.%s_id parent_vendor_cat_id, t5p.%s_sync_status parent_cat_sync_status
|
||||
FROM store_sku_bind t1
|
||||
JOIN sku t2 ON t1.sku_id = t2.id
|
||||
JOIN sku_name t3 ON t2.name_id = t3.id
|
||||
`
|
||||
if level == 2 {
|
||||
sql += `
|
||||
JOIN sku_category t4 ON (t3.category_id = t4.id OR t2.category_id = t4.id)
|
||||
`
|
||||
} else {
|
||||
sql += `
|
||||
JOIN sku_category t4c ON (t3.category_id = t4c.id OR t2.category_id = t4c.id)
|
||||
JOIN sku_category t4 ON t4.id = t4c.parent_id
|
||||
`
|
||||
}
|
||||
sql += `
|
||||
LEFT JOIN store_sku_category_map t5 ON t4.id = t5.category_id AND t5.store_id = t1.store_id AND t5.deleted_at = ?
|
||||
LEFT JOIN sku_category t4p ON t4.parent_id = t4p.id
|
||||
LEFT JOIN store_sku_category_map t5p ON t4p.id = t5p.category_id AND t5p.store_id = t1.store_id AND t5p.deleted_at = ?
|
||||
WHERE t1.store_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
storeID,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
filedPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID])
|
||||
sql = fmt.Sprintf(sql, filedPrefix, filedPrefix, filedPrefix, filedPrefix)
|
||||
if err = GetRows(db, &cats, sql, sqlParams...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cats, err
|
||||
}
|
||||
|
||||
func GetStoreCategories(db *DaoDB, vendorID, storeID int, level int) (cats []*StoreCatSyncInfo, err error) {
|
||||
filedPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID])
|
||||
sql := fmt.Sprintf(`
|
||||
SELECT t5.*, t4.name cat_name, t4.seq, t4p.name parent_cat_name, t5p.category_id parent_cat_id, t5p.%s_id parent_vendor_cat_id, t5p.%s_sync_status parent_cat_sync_status
|
||||
FROM store_sku_category_map t5
|
||||
JOIN sku_category t4 ON t5.category_id = t4.id
|
||||
JOIN sku_category t4p ON t4.parent_id = t4p.id
|
||||
JOIN store_sku_category_map t5p ON t4p.id = t5p.category_id AND t5p.deleted_at = ?
|
||||
WHERE t5.store_id = ? AND t5.level = ? AND t5.%s_sync_status <> 0
|
||||
`, filedPrefix, filedPrefix, filedPrefix)
|
||||
if err = GetRows(db, &cats, sql, utils.DefaultTimeValue, storeID, level); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cats, err
|
||||
}
|
||||
@@ -134,6 +134,7 @@ type SkuCategory struct {
|
||||
JdCategoryID int `orm:"column(jd_category_id)" json:"jdCategoryID"` // 这个是指对应的京东商品类别
|
||||
ElmCategoryID int64 `orm:"column(elm_category_id)" json:"elmCategoryID"` // 这个是指对应的饿了么商品类别
|
||||
EbaiCategoryID int64 `orm:"column(ebai_category_id)" json:"ebaiCategoryID"` // 这个是指对应的饿百商品类别
|
||||
MtwmCategoryID int64 `orm:"column(mtwm_category_id)" json:"mtwmCategoryID"` // 这个是指对应的美团外卖商品类别
|
||||
|
||||
JdID int64 `orm:"column(jd_id);null" json:"jdID"` // 这个是指商家自己的商品类别在京东平台上的ID
|
||||
JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`
|
||||
|
||||
@@ -165,9 +165,10 @@ type StoreMap struct {
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
||||
Status int `json:"status"` // 取值同Store.Status
|
||||
|
||||
PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格
|
||||
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
|
||||
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
|
||||
PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格
|
||||
AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货
|
||||
DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型
|
||||
DeliveryFee int `json:"deliveryFee"`
|
||||
DeliveryCompetition int8 `orm:"default(1)" json:"deliveryCompetition"` // 是否支持配送竞争
|
||||
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
|
||||
@@ -16,11 +16,13 @@ type StoreSkuCategoryMap struct {
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
CategoryID int `orm:"column(category_id)"`
|
||||
|
||||
ElmID int64 `orm:"column(elm_id);index"`
|
||||
EbaiID int64 `orm:"column(ebai_id);index"`
|
||||
ElmID int64 `orm:"column(elm_id);index"`
|
||||
EbaiID int64 `orm:"column(ebai_id);index"`
|
||||
MtwmID string `orm:"column(mtwm_id);size(16)"` // 美团外卖没有ID,保存名字
|
||||
|
||||
ElmSyncStatus int8
|
||||
EbaiSyncStatus int8
|
||||
MtwmSyncStatus int8
|
||||
}
|
||||
|
||||
func (*StoreSkuCategoryMap) TableUnique() [][]string {
|
||||
|
||||
Reference in New Issue
Block a user