- 重构新京西活动,平台接口定为笼统的SyncAct,京平台支持添加,删除商品,暂不支持修改
This commit is contained in:
@@ -48,6 +48,13 @@ type ActMap struct {
|
||||
SyncStatus int `orm:"default(2)" json:"syncStatus"`
|
||||
}
|
||||
|
||||
func (*ActMap) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"ActID", "VendorID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
// 不建表
|
||||
type Act2 struct {
|
||||
MapID int `orm:"column(map_id)"`
|
||||
|
||||
@@ -66,32 +73,6 @@ type ActOrderRule struct {
|
||||
DeductPrice int64 `orm:"" json:"deductPrice"` // 减的价格
|
||||
}
|
||||
|
||||
// type ActStore struct {
|
||||
// ModelIDCULD
|
||||
|
||||
// ActID int `orm:"column(act_id)" json:"actID"`
|
||||
// StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
// }
|
||||
|
||||
type ActStoreMap struct {
|
||||
ModelIDCULD
|
||||
|
||||
ActID int `orm:"column(act_id)" json:"actID"`
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48)" json:"vendorActID"`
|
||||
SyncStatus int `orm:"default(2)" json:"syncStatus"`
|
||||
}
|
||||
|
||||
type ActStore2 struct {
|
||||
MapID int `orm:"column(map_id)"`
|
||||
|
||||
ActStoreMap
|
||||
|
||||
VendorStoreID string `orm:"column(vendor_store_id)" json:"vendorStoreID"`
|
||||
}
|
||||
|
||||
type ActStoreSku struct {
|
||||
ModelIDCULD
|
||||
|
||||
@@ -111,13 +92,14 @@ type ActStoreSku struct {
|
||||
|
||||
func (*ActStoreSku) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"ActID", "SkuID", "StoreID", "DeletedAt"},
|
||||
[]string{"ActID", "StoreID", "SkuID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
type ActStoreSkuMap struct {
|
||||
ModelIDCULD
|
||||
|
||||
BindID int `orm:"column(bind_id)" json:"bindID"`
|
||||
ActID int `orm:"column(act_id)" json:"actID"`
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID"`
|
||||
@@ -128,6 +110,19 @@ type ActStoreSkuMap struct {
|
||||
ActualActPrice int64 `orm:"" json:"actualActPrice"` // 单品级活动用,创建活动时商品的活动价格
|
||||
}
|
||||
|
||||
func (*ActStoreSkuMap) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"ActID", "BindID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
func (*ActStoreSkuMap) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"ActID", "StoreID", "SkuID", "VendorID", "DeletedAt"},
|
||||
}
|
||||
}
|
||||
|
||||
// 不建表
|
||||
type ActStoreSku2 struct {
|
||||
MapID int `orm:"column(map_id)"`
|
||||
|
||||
|
||||
@@ -32,38 +32,6 @@ func GetActVendorInfo(db *DaoDB, actID int, vendorIDs []int) (actMap map[int]*mo
|
||||
return actMap, err
|
||||
}
|
||||
|
||||
func GetActStoreVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs []int) (actStoreMap map[int][]*model.ActStore2, err error) {
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
t1.id map_id,
|
||||
t2.vendor_store_id
|
||||
FROM act_store_map t1
|
||||
JOIN store_map t2 ON t2.store_id = t1.store_id AND t2.vendor_id = t1.vendor_id AND t2.deleted_at = ?
|
||||
WHERE t1.deleted_at = ? AND t1.act_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
actID,
|
||||
}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND t1.vendor_id IN (" + GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t1.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
var actStoreList []*model.ActStore2
|
||||
if err = GetRows(db, &actStoreList, sql, sqlParams...); err == nil {
|
||||
actStoreMap = make(map[int][]*model.ActStore2)
|
||||
for _, v := range actStoreList {
|
||||
actStoreMap[v.VendorID] = append(actStoreMap[v.VendorID], v)
|
||||
}
|
||||
}
|
||||
return actStoreMap, err
|
||||
}
|
||||
|
||||
func GetActStoreSkuVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs []int) (actStoreSkuMap map[int][]*model.ActStoreSku2, err error) {
|
||||
sql := `
|
||||
SELECT t1.*,
|
||||
@@ -79,15 +47,14 @@ func GetActStoreSkuVendorInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs
|
||||
ELSE
|
||||
''
|
||||
END vendor_sku_id
|
||||
FROM act_store_sku t1
|
||||
JOIN act_store_sku_map t2 ON t2.act_id = t1.act_id AND t2.sku_id = t1.sku_id AND t2.store_id = t1.store_id AND t2.deleted_at = ?
|
||||
FROM act_store_sku_map t2
|
||||
JOIN act_store_sku t1 ON t1.id = t2.bind_id
|
||||
JOIN store_map t3 ON t3.store_id = t1.store_id AND t3.vendor_id = t2.vendor_id AND t3.deleted_at = ?
|
||||
JOIN sku t4 ON t4.id = t1.sku_id AND t4.deleted_at = ?
|
||||
JOIN store_sku_bind t5 ON t5.sku_id = t1.sku_id AND t5.store_id = t1.store_id AND t5.deleted_at = ?
|
||||
WHERE t1.deleted_at = ? AND t1.act_id = ?
|
||||
WHERE t2.deleted_at = ? AND t2.act_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
|
||||
@@ -11,6 +11,11 @@ import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
type KVUpdateItem struct {
|
||||
Item interface{}
|
||||
KVs map[string]interface{}
|
||||
}
|
||||
|
||||
// 这里面的函数要求实体是IDCUDL的,即含有ID, UpdatedAt, LastOperator, DeletedAt字段
|
||||
|
||||
func GetEntitiesByKV(db *DaoDB, item interface{}, conditions map[string]interface{}, isIncludeDeleted bool) (err error) {
|
||||
@@ -57,6 +62,29 @@ func UpdateEntityByKV(db *DaoDB, item interface{}, kvs map[string]interface{}, c
|
||||
return num, err
|
||||
}
|
||||
|
||||
func BatchUpdateEntityByKV(db *DaoDB, items []*KVUpdateItem) (num int64, err error) {
|
||||
if len(items) > 0 {
|
||||
Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
for _, v := range items {
|
||||
num2, err2 := UpdateEntityByKV(db, v.Item, v.KVs, nil)
|
||||
if err = err2; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
num += num2
|
||||
}
|
||||
Commit(db)
|
||||
}
|
||||
return num, nil
|
||||
}
|
||||
|
||||
func UpdateEntityLogically(db *DaoDB, item interface{}, kvs map[string]interface{}, userName string, conditions map[string]interface{}) (num int64, err error) {
|
||||
if conditions != nil && refutil.IsFieldExist(item, model.FieldDeletedAt) {
|
||||
conditions = utils.MergeMaps(conditions, map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user