- add jxcontext.Context to all public API.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
@@ -44,11 +45,11 @@ func InitServiceInfo(version, buildDate, gitCommit string) {
|
||||
Init()
|
||||
}
|
||||
|
||||
func GetServiceInfo() interface{} {
|
||||
func GetServiceInfo(ctx *jxcontext.Context) interface{} {
|
||||
return serviceInfo
|
||||
}
|
||||
|
||||
func GetQiniuUploadToken(suffix string) (upTokenInfo map[string]interface{}, err error) {
|
||||
func GetQiniuUploadToken(ctx *jxcontext.Context, suffix string) (upTokenInfo map[string]interface{}, err error) {
|
||||
putPolicy := storage.PutPolicy{
|
||||
Scope: globals.QiniuBucket,
|
||||
Expires: qiniuTokenExpires,
|
||||
@@ -61,7 +62,7 @@ func GetQiniuUploadToken(suffix string) (upTokenInfo map[string]interface{}, err
|
||||
return upTokenInfo, err
|
||||
}
|
||||
|
||||
func GetPlaces(keyword string, includeDisabled bool, params map[string]interface{}) ([]*model.Place, error) {
|
||||
func GetPlaces(ctx *jxcontext.Context, keyword string, includeDisabled bool, params map[string]interface{}) ([]*model.Place, error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM place t1
|
||||
@@ -94,7 +95,7 @@ func GetPlaces(keyword string, includeDisabled bool, params map[string]interface
|
||||
return places, dao.GetRows(nil, &places, sql, sqlParams)
|
||||
}
|
||||
|
||||
func UpdatePlaces(places []map[string]interface{}, userName string) (num int64, err error) {
|
||||
func UpdatePlaces(ctx *jxcontext.Context, places []map[string]interface{}, userName string) (num int64, err error) {
|
||||
if len(places) == 0 {
|
||||
return 0, ErrMissingInput
|
||||
}
|
||||
@@ -111,9 +112,9 @@ func UpdatePlaces(places []map[string]interface{}, userName string) (num int64,
|
||||
return num, err
|
||||
}
|
||||
|
||||
func UpdatePlace(placeCode int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
func UpdatePlace(ctx *jxcontext.Context, placeCode int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
payload["code"] = placeCode
|
||||
return UpdatePlaces([]map[string]interface{}{payload}, userName)
|
||||
return UpdatePlaces(ctx, []map[string]interface{}{payload}, userName)
|
||||
}
|
||||
|
||||
/////
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||
@@ -20,7 +21,7 @@ func init() {
|
||||
}
|
||||
|
||||
func TestGetQiniuUploadToken(t *testing.T) {
|
||||
token, err := GetQiniuUploadToken("")
|
||||
token, err := GetQiniuUploadToken(jxcontext.AdminCtx, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ var (
|
||||
)
|
||||
|
||||
// parentID 为-1表示所有
|
||||
func GetVendorCategories(vendorID int, parentID string) (vendorCats []*model.SkuVendorCategory, err error) {
|
||||
func GetVendorCategories(ctx *jxcontext.Context, vendorID int, parentID string) (vendorCats []*model.SkuVendorCategory, err error) {
|
||||
cond := map[string]interface{}{
|
||||
model.FieldVendorID: vendorID,
|
||||
}
|
||||
@@ -32,7 +33,7 @@ func GetVendorCategories(vendorID int, parentID string) (vendorCats []*model.Sku
|
||||
}
|
||||
|
||||
// parentID 为-1表示所有
|
||||
func GetCategories(parentID int) (cats []*model.SkuCategory, err error) {
|
||||
func GetCategories(ctx *jxcontext.Context, parentID int) (cats []*model.SkuCategory, err error) {
|
||||
params := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
@@ -45,7 +46,7 @@ func GetCategories(parentID int) (cats []*model.SkuCategory, err error) {
|
||||
return cats, dao.GetRows(nil, &cats, sql, params)
|
||||
}
|
||||
|
||||
func AddCategory(cat *model.SkuCategory, userName string) (outCat *model.SkuCategory, err error) {
|
||||
func AddCategory(ctx *jxcontext.Context, cat *model.SkuCategory, userName string) (outCat *model.SkuCategory, err error) {
|
||||
dao.WrapAddIDCULDEntity(cat, userName)
|
||||
cat.JdSyncStatus = model.SyncFlagNewMask
|
||||
cat.JdID = jxutils.GenFakeID()
|
||||
@@ -61,25 +62,25 @@ func AddCategory(cat *model.SkuCategory, userName string) (outCat *model.SkuCate
|
||||
}
|
||||
if err = dao.CreateEntity(nil, cat); err == nil {
|
||||
outCat = cat
|
||||
_, err = CurVendorSync.SyncCategory(nil, cat.ID, false, userName)
|
||||
_, err = CurVendorSync.SyncCategory(ctx, nil, cat.ID, false, userName)
|
||||
}
|
||||
return outCat, err
|
||||
}
|
||||
|
||||
func UpdateCategory(categoryID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
func UpdateCategory(ctx *jxcontext.Context, categoryID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
cat := &model.SkuCategory{}
|
||||
cat.ID = categoryID
|
||||
valid := dao.NormalMakeMapByStructObject(payload, cat, userName)
|
||||
if len(valid) > 0 {
|
||||
db := dao.GetDB()
|
||||
if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, cat, valid, userName, nil, model.FieldJdSyncStatus); err == nil {
|
||||
_, err = CurVendorSync.SyncCategory(db, categoryID, false, userName)
|
||||
_, err = CurVendorSync.SyncCategory(ctx, db, categoryID, false, userName)
|
||||
}
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func ReorderCategories(parentID int, categoryIDs []int, userName string) (err error) {
|
||||
func ReorderCategories(ctx *jxcontext.Context, parentID int, categoryIDs []int, userName string) (err error) {
|
||||
var cats []*model.SkuCategory
|
||||
parentCat := &model.SkuCategory{}
|
||||
parentCat.ID = parentID
|
||||
@@ -107,14 +108,14 @@ func ReorderCategories(parentID int, categoryIDs []int, userName string) (err er
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
_, err = CurVendorSync.SyncReorderCategories(db, parentID, false, userName)
|
||||
_, err = CurVendorSync.SyncReorderCategories(ctx, db, parentID, false, userName)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteCategory(categoryID int, userName string) (num int64, err error) {
|
||||
func DeleteCategory(ctx *jxcontext.Context, categoryID int, userName string) (num int64, err error) {
|
||||
cat := &model.SkuCategory{}
|
||||
cat.ID = categoryID
|
||||
var countInfos []*struct{ Ct int }
|
||||
@@ -140,13 +141,13 @@ func DeleteCategory(categoryID int, userName string) (num int64, err error) {
|
||||
return 0, errors.New("还有商品类别使用此类别,不能删除")
|
||||
}
|
||||
if num, err = dao.DeleteEntityLogically(db, cat, utils.Params2Map(model.FieldJdSyncStatus, model.SyncFlagDeletedMask), userName, nil); err == nil && num == 1 {
|
||||
_, err = CurVendorSync.SyncCategory(db, cat.ID, false, userName)
|
||||
_, err = CurVendorSync.SyncCategory(ctx, db, cat.ID, false, userName)
|
||||
}
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *SkuNamesInfo, err error) {
|
||||
func GetSkuNames(ctx *jxcontext.Context, keyword string, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *SkuNamesInfo, err error) {
|
||||
db := dao.GetDB()
|
||||
sql := `
|
||||
FROM sku_name t1
|
||||
@@ -311,7 +312,7 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize
|
||||
return skuNamesInfo, err
|
||||
}
|
||||
|
||||
func AddSkuName(skuNameExt *model.SkuNameExt, userName string) (outSkuNameExt *model.SkuNameExt, err error) {
|
||||
func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName string) (outSkuNameExt *model.SkuNameExt, err error) {
|
||||
if skuNameExt.CategoryID == 0 {
|
||||
return nil, errors.New("CategoryID不能为空")
|
||||
}
|
||||
@@ -351,7 +352,7 @@ func AddSkuName(skuNameExt *model.SkuNameExt, userName string) (outSkuNameExt *m
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
tmpInfo, err := GetSkuNames("", utils.Params2Map("nameID", skuNameExt.SkuName.ID), 0, 1)
|
||||
tmpInfo, err := GetSkuNames(ctx, "", utils.Params2Map("nameID", skuNameExt.SkuName.ID), 0, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -359,11 +360,11 @@ func AddSkuName(skuNameExt *model.SkuNameExt, userName string) (outSkuNameExt *m
|
||||
return nil, ErrEntityNotExist
|
||||
}
|
||||
outSkuNameExt = tmpInfo.SkuNames[0]
|
||||
_, err = CurVendorSync.SyncSku(db, outSkuNameExt.SkuName.ID, -1, false, userName)
|
||||
_, err = CurVendorSync.SyncSku(ctx, db, outSkuNameExt.SkuName.ID, -1, false, userName)
|
||||
return outSkuNameExt, err
|
||||
}
|
||||
|
||||
func UpdateSkuName(nameID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
var err2 error
|
||||
skuName := &model.SkuName{}
|
||||
skuName.ID = nameID
|
||||
@@ -403,7 +404,7 @@ func UpdateSkuName(nameID int, payload map[string]interface{}, userName string)
|
||||
}, model.FieldJdSyncStatus)
|
||||
if err = err2; err == nil {
|
||||
dao.Commit(db)
|
||||
_, err2 = CurVendorSync.SyncSku(db, nameID, -1, false, userName)
|
||||
_, err2 = CurVendorSync.SyncSku(ctx, db, nameID, -1, false, userName)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -416,7 +417,7 @@ func UpdateSkuName(nameID int, payload map[string]interface{}, userName string)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func DeleteSkuName(nameID int, userName string) (num int64, err error) {
|
||||
func DeleteSkuName(ctx *jxcontext.Context, nameID int, userName string) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
@@ -438,7 +439,7 @@ func DeleteSkuName(nameID int, userName string) (num int64, err error) {
|
||||
if err2 == nil {
|
||||
dao.Commit(db)
|
||||
if num2 > 0 {
|
||||
_, err = CurVendorSync.SyncSku(db, skuName.ID, -1, false, userName)
|
||||
_, err = CurVendorSync.SyncSku(ctx, db, skuName.ID, -1, false, userName)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
@@ -447,18 +448,18 @@ func DeleteSkuName(nameID int, userName string) (num int64, err error) {
|
||||
return num, err
|
||||
}
|
||||
|
||||
func AddSku(nameID int, sku *model.Sku, userName string) (outSkuNameExt *model.SkuNameExt, err error) {
|
||||
func AddSku(ctx *jxcontext.Context, nameID int, sku *model.Sku, userName string) (outSkuNameExt *model.SkuNameExt, err error) {
|
||||
db := dao.GetDB()
|
||||
dao.WrapAddIDCULDEntity(sku, userName)
|
||||
sku.JdSyncStatus = model.SyncFlagNewMask
|
||||
sku.NameID = nameID
|
||||
sku.JdID = jxutils.GenFakeID()
|
||||
if err = dao.CreateEntity(db, sku); err == nil {
|
||||
result, err2 := GetSkuNames("", utils.Params2Map("skuID", sku.ID), 0, 0)
|
||||
result, err2 := GetSkuNames(ctx, "", utils.Params2Map("skuID", sku.ID), 0, 0)
|
||||
if err = err2; err == nil {
|
||||
if result.TotalCount == 1 {
|
||||
outSkuNameExt = result.SkuNames[0]
|
||||
_, err = CurVendorSync.SyncSku(db, outSkuNameExt.SkuName.ID, sku.ID, false, userName)
|
||||
_, err = CurVendorSync.SyncSku(ctx, db, outSkuNameExt.SkuName.ID, sku.ID, false, userName)
|
||||
} else {
|
||||
err = ErrEntityNotExist
|
||||
}
|
||||
@@ -467,7 +468,7 @@ func AddSku(nameID int, sku *model.Sku, userName string) (outSkuNameExt *model.S
|
||||
return outSkuNameExt, err
|
||||
}
|
||||
|
||||
func UpdateSku(skuID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
func UpdateSku(ctx *jxcontext.Context, skuID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
sku := &model.Sku{}
|
||||
sku.ID = skuID
|
||||
valid := dao.NormalMakeMapByStructObject(payload, sku, userName)
|
||||
@@ -475,7 +476,7 @@ func UpdateSku(skuID int, payload map[string]interface{}, userName string) (num
|
||||
db := dao.GetDB()
|
||||
if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, sku, valid, userName, nil, model.FieldJdSyncStatus); err == nil {
|
||||
if num == 1 {
|
||||
_, err = CurVendorSync.SyncSku(db, -1, sku.ID, false, userName)
|
||||
_, err = CurVendorSync.SyncSku(ctx, db, -1, sku.ID, false, userName)
|
||||
} else {
|
||||
err = ErrEntityNotExist
|
||||
}
|
||||
@@ -484,7 +485,7 @@ func UpdateSku(skuID int, payload map[string]interface{}, userName string) (num
|
||||
return num, err
|
||||
}
|
||||
|
||||
func DeleteSku(skuID int, userName string) (num int64, err error) {
|
||||
func DeleteSku(ctx *jxcontext.Context, skuID int, userName string) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
sku := &model.Sku{}
|
||||
sku.ID = skuID
|
||||
@@ -493,7 +494,7 @@ func DeleteSku(skuID int, userName string) (num int64, err error) {
|
||||
model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
}, userName, nil); err == nil {
|
||||
if num == 1 {
|
||||
_, err = CurVendorSync.SyncSku(db, -1, sku.ID, false, userName)
|
||||
_, err = CurVendorSync.SyncSku(ctx, db, -1, sku.ID, false, userName)
|
||||
} else {
|
||||
err = ErrEntityNotExist
|
||||
}
|
||||
@@ -501,7 +502,7 @@ func DeleteSku(skuID int, userName string) (num int64, err error) {
|
||||
return num, err
|
||||
}
|
||||
|
||||
func AddSkuNamePlace(nameID, placeCode int, userName string) (outPlaceBind *model.SkuNamePlaceBind, err error) {
|
||||
func AddSkuNamePlace(ctx *jxcontext.Context, nameID, placeCode int, userName string) (outPlaceBind *model.SkuNamePlaceBind, err error) {
|
||||
db := dao.GetDB()
|
||||
placeBind := &model.SkuNamePlaceBind{
|
||||
NameID: nameID,
|
||||
@@ -509,19 +510,19 @@ func AddSkuNamePlace(nameID, placeCode int, userName string) (outPlaceBind *mode
|
||||
}
|
||||
dao.WrapAddIDCULEntity(placeBind, userName)
|
||||
if err = dao.CreateEntity(db, placeBind); err == nil {
|
||||
_, err = CurVendorSync.SyncSku(db, nameID, -1, false, userName)
|
||||
_, err = CurVendorSync.SyncSku(ctx, db, nameID, -1, false, userName)
|
||||
}
|
||||
return placeBind, err
|
||||
}
|
||||
|
||||
func DeleteSkuNamePlace(nameID, placeCode int, userName string) (num int64, err error) {
|
||||
func DeleteSkuNamePlace(ctx *jxcontext.Context, nameID, placeCode int, userName string) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
placeBind := &model.SkuNamePlaceBind{}
|
||||
placeBind.NameID = nameID
|
||||
placeBind.PlaceCode = placeCode
|
||||
if num, err = dao.DeleteEntity(db, placeBind, model.FieldNameID, model.FieldPlaceCode); err == nil {
|
||||
if num == 1 {
|
||||
_, err = CurVendorSync.SyncSku(db, nameID, -1, false, userName)
|
||||
_, err = CurVendorSync.SyncSku(ctx, db, nameID, -1, false, userName)
|
||||
} else {
|
||||
err = ErrEntityNotExist
|
||||
}
|
||||
@@ -529,7 +530,7 @@ func DeleteSkuNamePlace(nameID, placeCode int, userName string) (num int64, err
|
||||
return num, err
|
||||
}
|
||||
|
||||
func GetVendorSku(vendorID int, vendorSkuID string) (skuNameInfo *model.SkuNameExt, err error) {
|
||||
func GetVendorSku(ctx *jxcontext.Context, vendorID int, vendorSkuID string) (skuNameInfo *model.SkuNameExt, err error) {
|
||||
if handler := CurVendorSync.GetMultiStoreHandler(vendorID); handler != nil {
|
||||
return handler.ReadSku(vendorSkuID)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
@@ -41,7 +42,7 @@ var (
|
||||
)
|
||||
|
||||
// todo 门店绑定信息可以考虑以数组形式返回,而不是现在这样
|
||||
func GetStores(keyword string, params map[string]interface{}, offset, pageSize int) (retVal *StoresInfo, err error) {
|
||||
func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interface{}, offset, pageSize int) (retVal *StoresInfo, err error) {
|
||||
sqlWhere := `
|
||||
FROM store t1
|
||||
LEFT JOIN place city ON t1.city_code = city.code AND city.level = 2
|
||||
@@ -165,7 +166,7 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func GetVendorStore(vendorStoreID string, vendorID int) (retVal *StoreExt, err error) {
|
||||
func GetVendorStore(ctx *jxcontext.Context, vendorStoreID string, vendorID int) (retVal *StoreExt, err error) {
|
||||
if handler := CurVendorSync.GetStoreHandler(vendorID); handler != nil {
|
||||
result, err2 := handler.ReadStore(vendorStoreID)
|
||||
if err = err2; err == nil {
|
||||
@@ -186,7 +187,7 @@ func GetVendorStore(vendorStoreID string, vendorID int) (retVal *StoreExt, err e
|
||||
return nil, ErrCanNotFindVendor
|
||||
}
|
||||
|
||||
func UpdateStore(storeID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
store := &model.Store{}
|
||||
store.ID = storeID
|
||||
valid := dao.NormalMakeMapByStructObject(payload, store, userName)
|
||||
@@ -210,7 +211,7 @@ func UpdateStore(storeID int, payload map[string]interface{}, userName string) (
|
||||
}, model.FieldSyncStatus)
|
||||
if err = err2; err == nil {
|
||||
dao.Commit(db)
|
||||
_, err = CurVendorSync.SyncStore(db, -1, store.ID, false, userName)
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, -1, store.ID, false, userName)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@@ -220,7 +221,7 @@ func UpdateStore(storeID int, payload map[string]interface{}, userName string) (
|
||||
return num, err
|
||||
}
|
||||
|
||||
func CreateStore(store *model.Store, userName string) (id int, err error) {
|
||||
func CreateStore(ctx *jxcontext.Context, store *model.Store, userName string) (id int, err error) {
|
||||
existingID := store.ID
|
||||
dao.WrapAddIDCULDEntity(store, userName)
|
||||
store.ID = existingID
|
||||
@@ -230,7 +231,7 @@ func CreateStore(store *model.Store, userName string) (id int, err error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
func GetStoreVendorMaps(db *dao.DaoDB, storeID int, vendorID int) (storeMaps []*model.StoreMap, err error) {
|
||||
func GetStoreVendorMaps(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, vendorID int) (storeMaps []*model.StoreMap, err error) {
|
||||
cond := map[string]interface{}{
|
||||
model.FieldStoreID: storeID,
|
||||
}
|
||||
@@ -240,7 +241,7 @@ func GetStoreVendorMaps(db *dao.DaoDB, storeID int, vendorID int) (storeMaps []*
|
||||
return storeMaps, dao.GetEntitiesByKV(db, &storeMaps, cond, false)
|
||||
}
|
||||
|
||||
func AddStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, storeMap *model.StoreMap, userName string) (outStoreMap *model.StoreMap, err error) {
|
||||
func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeMap *model.StoreMap, userName string) (outStoreMap *model.StoreMap, err error) {
|
||||
if handler := CurVendorSync.GetMultiStoreHandler(vendorID); handler != nil {
|
||||
store, err2 := handler.ReadStore(storeMap.VendorStoreID)
|
||||
if err = err2; err == nil {
|
||||
@@ -263,7 +264,7 @@ func AddStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, storeMap *model.Sto
|
||||
if err = dao.CreateEntity(db, storeMap); err == nil {
|
||||
dao.Commit(db)
|
||||
outStoreMap = storeMap
|
||||
_, err = CurVendorSync.SyncStore(db, storeMap.VendorID, storeID, false, userName)
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, storeMap.VendorID, storeID, false, userName)
|
||||
}
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
@@ -275,7 +276,7 @@ func AddStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, storeMap *model.Sto
|
||||
return outStoreMap, err
|
||||
}
|
||||
|
||||
func DeleteStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, userName string) (num int64, err error) {
|
||||
func DeleteStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, userName string) (num int64, err error) {
|
||||
if db == nil {
|
||||
db = dao.GetDB()
|
||||
}
|
||||
@@ -287,12 +288,12 @@ func DeleteStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, userName string)
|
||||
model.FieldStoreID: storeID,
|
||||
model.FieldVendorID: vendorID,
|
||||
}); err == nil && num > 0 {
|
||||
_, err = CurVendorSync.SyncStore(db, vendorID, storeID, false, userName)
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func UpdateStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
if db == nil {
|
||||
db = dao.GetDB()
|
||||
}
|
||||
@@ -323,7 +324,7 @@ func UpdateStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, payload map[stri
|
||||
}
|
||||
if err == nil && num > 0 {
|
||||
if valid["status"] != nil {
|
||||
_, err = CurVendorSync.SyncStore(db, vendorID, storeID, false, userName)
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -331,11 +332,11 @@ func UpdateStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, payload map[stri
|
||||
return num, err
|
||||
}
|
||||
|
||||
func DeleteStore(db *dao.DaoDB, storeID int, userName string) (num int64, err error) {
|
||||
func DeleteStore(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, userName string) (num int64, err error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
func TmpGetJxBadCommentsNo(storeID int) (count int, err error) {
|
||||
func TmpGetJxBadCommentsNo(ctx *jxcontext.Context, storeID int) (count int, err error) {
|
||||
db := dao.GetDB()
|
||||
var ctInfo struct {
|
||||
Ct int
|
||||
@@ -346,7 +347,7 @@ func TmpGetJxBadCommentsNo(storeID int) (count int, err error) {
|
||||
return count, err
|
||||
}
|
||||
|
||||
func TmpGetJxBadCommentsByStoreId(storeID, page, size, commentType int) (retVal map[string]interface{}, err error) {
|
||||
func TmpGetJxBadCommentsByStoreId(ctx *jxcontext.Context, storeID, page, size, commentType int) (retVal map[string]interface{}, err error) {
|
||||
db := dao.GetDB()
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS *
|
||||
@@ -376,7 +377,7 @@ func TmpGetJxBadCommentsByStoreId(storeID, page, size, commentType int) (retVal
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func GetStoreCourierMaps(db *dao.DaoDB, storeID int, vendorID int) (storeCourierMaps []*model.StoreCourierMap, err error) {
|
||||
func GetStoreCourierMaps(ctx *jxcontext.Context, db *dao.DaoDB, storeID int, vendorID int) (storeCourierMaps []*model.StoreCourierMap, err error) {
|
||||
cond := map[string]interface{}{
|
||||
model.FieldStoreID: storeID,
|
||||
}
|
||||
@@ -386,7 +387,7 @@ func GetStoreCourierMaps(db *dao.DaoDB, storeID int, vendorID int) (storeCourier
|
||||
return storeCourierMaps, dao.GetEntitiesByKV(db, &storeCourierMaps, cond, false)
|
||||
}
|
||||
|
||||
func AddStoreCourierMap(db *dao.DaoDB, storeID, vendorID int, storeCourierMap *model.StoreCourierMap, userName string) (outStoreCourierMap *model.StoreCourierMap, err error) {
|
||||
func AddStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, storeCourierMap *model.StoreCourierMap, userName string) (outStoreCourierMap *model.StoreCourierMap, err error) {
|
||||
if handler := partner.GetDeliveryPlatformFromVendorID(vendorID); handler != nil {
|
||||
dao.WrapAddIDCULDEntity(storeCourierMap, userName)
|
||||
storeCourierMap.StoreID = storeID
|
||||
@@ -404,7 +405,7 @@ func AddStoreCourierMap(db *dao.DaoDB, storeID, vendorID int, storeCourierMap *m
|
||||
if err = dao.CreateEntity(db, storeCourierMap); err == nil {
|
||||
dao.Commit(db)
|
||||
outStoreCourierMap = storeCourierMap
|
||||
_, err = CurVendorSync.SyncStore(db, storeCourierMap.VendorID, storeID, false, userName)
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, storeCourierMap.VendorID, storeID, false, userName)
|
||||
}
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
@@ -415,7 +416,7 @@ func AddStoreCourierMap(db *dao.DaoDB, storeID, vendorID int, storeCourierMap *m
|
||||
return outStoreCourierMap, err
|
||||
}
|
||||
|
||||
func DeleteStoreCourierMap(db *dao.DaoDB, storeID, vendorID int, userName string) (num int64, err error) {
|
||||
func DeleteStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, userName string) (num int64, err error) {
|
||||
if db == nil {
|
||||
db = dao.GetDB()
|
||||
}
|
||||
@@ -426,12 +427,12 @@ func DeleteStoreCourierMap(db *dao.DaoDB, storeID, vendorID int, userName string
|
||||
model.FieldStoreID: storeID,
|
||||
model.FieldVendorID: vendorID,
|
||||
}); err == nil && num > 0 {
|
||||
_, err = CurVendorSync.SyncStore(db, vendorID, storeID, false, userName)
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
func UpdateStoreCourierMap(db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
func UpdateStoreCourierMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
if db == nil {
|
||||
db = dao.GetDB()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
@@ -60,7 +61,7 @@ type tStoreSkuBindAndSpec struct {
|
||||
RealSkuID int `orm:"column(real_sku_id)"`
|
||||
}
|
||||
|
||||
func GetStoreSkus(storeID int, isFocus bool, keyword string, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) {
|
||||
func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword string, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) {
|
||||
db := dao.GetDB()
|
||||
sql := `
|
||||
FROM sku_name t1
|
||||
@@ -229,21 +230,21 @@ func GetStoreSkus(storeID int, isFocus bool, keyword string, params map[string]i
|
||||
return skuNamesInfo, err
|
||||
}
|
||||
|
||||
func UpdateStoreSku(storeID int, skuBindInfo *StoreSkuBindInfo, userName string) (num int64, err error) {
|
||||
return UpdateStoreSkus(storeID, []*StoreSkuBindInfo{skuBindInfo}, userName)
|
||||
func UpdateStoreSku(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBindInfo, userName string) (num int64, err error) {
|
||||
return UpdateStoreSkus(ctx, storeID, []*StoreSkuBindInfo{skuBindInfo}, userName)
|
||||
}
|
||||
|
||||
func UpdateStoreSkus(storeID int, skuBindInfos []*StoreSkuBindInfo, userName string) (num int64, err error) {
|
||||
skuIDs, err := updateStoreSkusWithoutSync(storeID, skuBindInfos, userName)
|
||||
func UpdateStoreSkus(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, userName string) (num int64, err error) {
|
||||
skuIDs, err := updateStoreSkusWithoutSync(ctx, storeID, skuBindInfos, userName)
|
||||
if err == nil {
|
||||
db := dao.GetDB()
|
||||
_, err = CurVendorSync.SyncStoresSkus(db, nil, []int{storeID}, skuIDs, false, userName)
|
||||
_, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, []int{storeID}, skuIDs, false, userName)
|
||||
return int64(len(skuIDs)), err
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
|
||||
func updateStoreSkusWithoutSync(storeID int, skuBindInfos []*StoreSkuBindInfo, userName string) (needSyncSkus []int, err error) {
|
||||
func updateStoreSkusWithoutSync(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, userName string) (needSyncSkus []int, err error) {
|
||||
var num int64
|
||||
db := dao.GetDB()
|
||||
needSyncIDMap := make(map[int]int)
|
||||
@@ -371,9 +372,9 @@ func updateStoreSkusWithoutSync(storeID int, skuBindInfos []*StoreSkuBindInfo, u
|
||||
return skuIDs, err
|
||||
}
|
||||
|
||||
func UpdateStoresSkus(storeIDs []int, skuBindInfos []*StoreSkuBindInfo, userName string) (num int64, err error) {
|
||||
func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, userName string) (num int64, err error) {
|
||||
for _, storeID := range storeIDs {
|
||||
skuIDs, err2 := updateStoreSkusWithoutSync(storeID, skuBindInfos, userName)
|
||||
skuIDs, err2 := updateStoreSkusWithoutSync(ctx, storeID, skuBindInfos, userName)
|
||||
if err = err2; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -386,11 +387,11 @@ func UpdateStoresSkus(storeIDs []int, skuBindInfos []*StoreSkuBindInfo, userName
|
||||
}
|
||||
}
|
||||
db := dao.GetDB()
|
||||
_, err = CurVendorSync.SyncStoresSkus(db, nil, storeIDs, skuIDs, false, userName)
|
||||
_, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, storeIDs, skuIDs, false, userName)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func updateStoreSkusSaleWithoutSync(storeID int, skuBindSkuInfos []*StoreSkuBindSkuInfo, userName string) (needSyncSkus []int, err error) {
|
||||
func updateStoreSkusSaleWithoutSync(ctx *jxcontext.Context, storeID int, skuBindSkuInfos []*StoreSkuBindSkuInfo, userName string) (needSyncSkus []int, err error) {
|
||||
var num int64
|
||||
db := dao.GetDB()
|
||||
needSyncIDMap := make(map[int]int)
|
||||
@@ -428,9 +429,9 @@ func updateStoreSkusSaleWithoutSync(storeID int, skuBindSkuInfos []*StoreSkuBind
|
||||
return needSyncSkus, err
|
||||
}
|
||||
|
||||
func UpdateStoresSkusSale(storeIDs []int, skuBindSkuInfos []*StoreSkuBindSkuInfo, userName string) (num int64, err error) {
|
||||
func UpdateStoresSkusSale(ctx *jxcontext.Context, storeIDs []int, skuBindSkuInfos []*StoreSkuBindSkuInfo, userName string) (num int64, err error) {
|
||||
for _, storeID := range storeIDs {
|
||||
skuIDs, err2 := updateStoreSkusSaleWithoutSync(storeID, skuBindSkuInfos, userName)
|
||||
skuIDs, err2 := updateStoreSkusSaleWithoutSync(ctx, storeID, skuBindSkuInfos, userName)
|
||||
if err = err2; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -441,11 +442,11 @@ func UpdateStoresSkusSale(storeIDs []int, skuBindSkuInfos []*StoreSkuBindSkuInfo
|
||||
skuIDs = append(skuIDs, v.SkuID)
|
||||
}
|
||||
db := dao.GetDB()
|
||||
_, err = CurVendorSync.SyncStoresSkus(db, nil, storeIDs, skuIDs, false, userName)
|
||||
_, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, storeIDs, skuIDs, false, userName)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func CopyStoreSkus(fromStoreID, toStoreID int, copyMode string, params map[string]interface{}, userName string) (num int64, err error) {
|
||||
func CopyStoreSkus(ctx *jxcontext.Context, fromStoreID, toStoreID int, copyMode string, params map[string]interface{}, userName string) (num int64, err error) {
|
||||
if copyMode != CopyStoreSkuModeFresh && copyMode != CopyStoreSkuModeUpdate {
|
||||
return 0, fmt.Errorf("不支持的拷贝模式:%s", copyMode)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
@@ -119,7 +120,7 @@ func (v *VendorSync) GetSingleStoreHandler(vendorID int) partner.ISingleStoreHan
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *VendorSync) syncCategories(parentTask tasksch.ITask, multiStoresHandler partner.IMultipleStoresHandler, db *dao.DaoDB, cats []*model.SkuCategory, userName string) (err error) {
|
||||
func (v *VendorSync) syncCategories(ctx *jxcontext.Context, multiStoresHandler partner.IMultipleStoresHandler, db *dao.DaoDB, cats []*model.SkuCategory, userName string) (err error) {
|
||||
syncStatusFieldName := multiStoresHandler.GetFieldSyncStatusName()
|
||||
task := tasksch.RunParallelTask("syncCategories", nil, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
cat := batchItemList[0].(*model.SkuCategory)
|
||||
@@ -139,14 +140,14 @@ func (v *VendorSync) syncCategories(parentTask tasksch.ITask, multiStoresHandler
|
||||
}
|
||||
return nil, err
|
||||
}, cats)
|
||||
parentTask.AddChild(task)
|
||||
ctx.SetTaskOrAddChild(task)
|
||||
_, err = task.GetResult(0)
|
||||
return err
|
||||
}
|
||||
|
||||
func (v *VendorSync) SyncCategory(db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) {
|
||||
func (v *VendorSync) SyncCategory(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) {
|
||||
globals.SugarLogger.Debug(v.MultiStoreVendorIDs)
|
||||
hint, err = v.LoopMultiStoresVendors(db, "SyncCategory", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
hint, err = v.LoopMultiStoresVendors(ctx, db, "SyncCategory", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
multiStoresHandler := v.GetMultiStoreHandler(batchItemList[0].(int))
|
||||
var cats []*model.SkuCategory
|
||||
cond := make(map[string]interface{})
|
||||
@@ -157,7 +158,7 @@ func (v *VendorSync) SyncCategory(db *dao.DaoDB, categoryID int, isAsync bool, u
|
||||
}
|
||||
err := dao.GetEntitiesByKV(db, &cats, cond, true)
|
||||
if err == nil {
|
||||
err = v.syncCategories(t, multiStoresHandler, db, cats, userName)
|
||||
err = v.syncCategories(ctx, multiStoresHandler, db, cats, userName)
|
||||
}
|
||||
if err != nil || categoryID > 0 {
|
||||
return nil, err
|
||||
@@ -165,15 +166,15 @@ func (v *VendorSync) SyncCategory(db *dao.DaoDB, categoryID int, isAsync bool, u
|
||||
cond[model.FieldLevel] = 2
|
||||
err = dao.GetEntitiesByKV(db, &cats, cond, true)
|
||||
if err == nil {
|
||||
err = v.syncCategories(t, multiStoresHandler, db, cats, userName)
|
||||
err = v.syncCategories(ctx, multiStoresHandler, db, cats, userName)
|
||||
}
|
||||
return nil, err
|
||||
})
|
||||
return "", err
|
||||
}
|
||||
|
||||
func (v *VendorSync) SyncReorderCategories(db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) {
|
||||
hint, err = v.LoopMultiStoresVendors(db, "SyncReorderCategories", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
func (v *VendorSync) SyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) {
|
||||
hint, err = v.LoopMultiStoresVendors(ctx, db, "SyncReorderCategories", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
multiStoresHandler := v.GetMultiStoreHandler(batchItemList[0].(int))
|
||||
err2 := multiStoresHandler.ReorderCategories(db, categoryID, userName)
|
||||
if err2 == nil {
|
||||
@@ -186,9 +187,9 @@ func (v *VendorSync) SyncReorderCategories(db *dao.DaoDB, categoryID int, isAsyn
|
||||
return "", err
|
||||
}
|
||||
|
||||
func (v *VendorSync) SyncStore(db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) {
|
||||
func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("SyncStore, storeID:%d", storeID)
|
||||
hint, err = v.LoopStoreMap(db, "SyncStore", isAsync, userName, storeID, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
hint, err = v.LoopStoreMap(ctx, db, "SyncStore", isAsync, userName, storeID, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
if (vendorID == -1 || vendorID == storeMap.VendorID) && (storeMap.SyncStatus != 0) {
|
||||
if handler := v.GetStoreHandler(storeMap.VendorID); handler != nil {
|
||||
@@ -203,9 +204,9 @@ func (v *VendorSync) SyncStore(db *dao.DaoDB, vendorID, storeID int, isAsync boo
|
||||
return "", err
|
||||
}
|
||||
|
||||
func (v *VendorSync) SyncSku(db *dao.DaoDB, nameID, skuID int, isAsync bool, userName string) (hint string, err error) {
|
||||
func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuID int, isAsync bool, userName string) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("SyncSku, nameID:%d, skuID:%d, userName:%s", nameID, skuID, userName)
|
||||
hint, err = v.LoopMultiStoresVendors(db, "SyncSku", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
hint, err = v.LoopMultiStoresVendors(ctx, db, "SyncSku", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
multiStoresHandler := v.GetMultiStoreHandler(batchItemList[0].(int))
|
||||
syncStatusFieldName := multiStoresHandler.GetFieldSyncStatusName()
|
||||
var skuList []*model.Sku
|
||||
@@ -248,9 +249,9 @@ func (v *VendorSync) SyncSku(db *dao.DaoDB, nameID, skuID int, isAsync bool, use
|
||||
}
|
||||
|
||||
//
|
||||
func (v *VendorSync) SyncStoresSkus(db *dao.DaoDB, vendorIDs []int, storeIDs []int, skuIDs []int, isAsync bool, userName string) (hint string, err error) {
|
||||
func (v *VendorSync) SyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, skuIDs []int, isAsync bool, userName string) (hint string, err error) {
|
||||
globals.SugarLogger.Debug("SyncStoresSkus")
|
||||
hint, err = v.LoopStoreVendors(db, vendorIDs, "SyncStoresSkus", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
hint, err = v.LoopStoreVendors(ctx, db, vendorIDs, "SyncStoresSkus", isAsync, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
handler := v.GetStoreHandler(batchItemList[0].(int))
|
||||
_, err = handler.SyncStoresSkus(db, storeIDs, skuIDs, false, userName)
|
||||
return nil, err
|
||||
@@ -258,10 +259,11 @@ func (v *VendorSync) SyncStoresSkus(db *dao.DaoDB, vendorIDs []int, storeIDs []i
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func (v *VendorSync) LoopStoreMap(db *dao.DaoDB, taskName string, isAsync bool, userName string, storeID int, handler tasksch.WorkFunc) (hint string, err error) {
|
||||
storeMaps, err := GetStoreVendorMaps(db, storeID, -1)
|
||||
func (v *VendorSync) LoopStoreMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync bool, userName string, storeID int, handler tasksch.WorkFunc) (hint string, err error) {
|
||||
storeMaps, err := GetStoreVendorMaps(ctx, db, storeID, -1)
|
||||
if err == nil {
|
||||
task := tasksch.RunManagedParallelTask(taskName, nil, userName, handler, storeMaps)
|
||||
ctx.SetTaskOrAddChild(task)
|
||||
hint = task.ID
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
@@ -270,18 +272,19 @@ func (v *VendorSync) LoopStoreMap(db *dao.DaoDB, taskName string, isAsync bool,
|
||||
return hint, makeSyncError(err)
|
||||
}
|
||||
|
||||
func (v *VendorSync) LoopMultiStoresVendors(db *dao.DaoDB, taskName string, isAsync bool, userName string, handler tasksch.WorkFunc) (hint string, err error) {
|
||||
func (v *VendorSync) LoopMultiStoresVendors(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync bool, userName string, handler tasksch.WorkFunc) (hint string, err error) {
|
||||
if taskName == "" {
|
||||
taskName = "LoopMultiStoresVendors"
|
||||
}
|
||||
task := tasksch.RunManagedParallelTask(taskName, nil, userName, handler, v.MultiStoreVendorIDs)
|
||||
ctx.SetTaskOrAddChild(task)
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return task.ID, makeSyncError(err)
|
||||
}
|
||||
|
||||
func (v *VendorSync) LoopStoreVendors(db *dao.DaoDB, vendorIDs []int, taskName string, isAsync bool, userName string, handler tasksch.WorkFunc) (hint string, err error) {
|
||||
func (v *VendorSync) LoopStoreVendors(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, taskName string, isAsync bool, userName string, handler tasksch.WorkFunc) (hint string, err error) {
|
||||
if taskName == "" {
|
||||
taskName = "LoopStoreVendors"
|
||||
}
|
||||
@@ -306,13 +309,14 @@ func (v *VendorSync) LoopStoreVendors(db *dao.DaoDB, vendorIDs []int, taskName s
|
||||
allHandlers = allHandlers[:count]
|
||||
}
|
||||
task := tasksch.RunManagedParallelTask(taskName, nil, userName, handler, allHandlers)
|
||||
ctx.SetTaskOrAddChild(task)
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return task.ID, err
|
||||
}
|
||||
|
||||
func (v *VendorSync) LoopSingleStoreVendors(db *dao.DaoDB, taskName string, isAsync bool, userName string, handler tasksch.WorkFunc) (hint string, err error) {
|
||||
func (v *VendorSync) LoopSingleStoreVendors(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync bool, userName string, handler tasksch.WorkFunc) (hint string, err error) {
|
||||
if taskName == "" {
|
||||
taskName = "LoopSingleStoreVendors"
|
||||
}
|
||||
@@ -322,6 +326,7 @@ func (v *VendorSync) LoopSingleStoreVendors(db *dao.DaoDB, taskName string, isAs
|
||||
FROM store_map
|
||||
WHERE vendor_id IN (`+dao.GenQuestionMarks(len(v.SingleStoreVendorIDs))+")", v.SingleStoreVendorIDs); err == nil {
|
||||
task := tasksch.RunManagedParallelTask(taskName, nil, userName, handler, storeMaps)
|
||||
ctx.SetTaskOrAddChild(task)
|
||||
hint = task.ID
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
@@ -330,7 +335,7 @@ func (v *VendorSync) LoopSingleStoreVendors(db *dao.DaoDB, taskName string, isAs
|
||||
return hint, makeSyncError(err)
|
||||
}
|
||||
|
||||
func (v *VendorSync) RefreshSkuIDs(nameID, skuID int, userName string) (err error) {
|
||||
func (v *VendorSync) RefreshSkuIDs(ctx *jxcontext.Context, nameID, skuID int, userName string) (err error) {
|
||||
sql := `
|
||||
SELECT t1.id
|
||||
FROM sku t1
|
||||
@@ -351,7 +356,7 @@ func (v *VendorSync) RefreshSkuIDs(nameID, skuID int, userName string) (err erro
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetRows(db, &ids, sql, sqlParams); err == nil {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(ids, false))
|
||||
_, err = v.LoopMultiStoresVendors(db, "RefreshSkuIDs", false, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
_, err = v.LoopMultiStoresVendors(ctx, db, "RefreshSkuIDs", false, userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
multiStoresHandler := v.GetMultiStoreHandler(batchItemList[0].(int))
|
||||
err := multiStoresHandler.SyncSkusIDMap(db, ids, userName)
|
||||
globals.SugarLogger.Debug(err)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
@@ -17,7 +18,7 @@ type StoreUserInfo struct {
|
||||
MembersStr string `json:"-"`
|
||||
}
|
||||
|
||||
func GetStoreUsers(storeID int) (storeUserInfos []*StoreUserInfo, err error) {
|
||||
func GetStoreUsers(ctx *jxcontext.Context, storeID int) (storeUserInfos []*StoreUserInfo, err error) {
|
||||
sql := `
|
||||
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"parentID":', t2.parentid, ',"openID":"', IF(t2.openid IS NULL, "", t2.openid), '","tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||
@@ -37,7 +38,7 @@ func GetStoreUsers(storeID int) (storeUserInfos []*StoreUserInfo, err error) {
|
||||
return storeUserInfos, err
|
||||
}
|
||||
|
||||
func GetUserInfo(mobile string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
func GetUserInfo(ctx *jxcontext.Context, mobile string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
sql := `
|
||||
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"openID":"', IF(t2.openid IS NULL, "", t2.openid), '","tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||
@@ -56,7 +57,7 @@ func GetUserInfo(mobile string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
return storeUserInfo, err
|
||||
}
|
||||
|
||||
func GetSelfInfo(openID string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
func GetSelfInfo(ctx *jxcontext.Context, openID string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
sql := `
|
||||
SELECT t1.id, t1.jxstoreid, t1.openid, t1.tel, t1.nickname, t1.parentid, t3.tel parent_mobile,
|
||||
CONCAT("[", GROUP_CONCAT(CONCAT('{"id":', t2.id, ',"openID":"', IF(t2.openid IS NULL, "", t2.openid), '","tel":"', t2.tel, '","nickname":"', IF(t2.nickname IS NULL, "", t2.nickname), '"}')), "]") members_str
|
||||
@@ -76,7 +77,7 @@ func GetSelfInfo(openID string) (storeUserInfo *StoreUserInfo, err error) {
|
||||
return storeUserInfo, err
|
||||
}
|
||||
|
||||
func UnbindMobile(mobile string) (num int64, err error) {
|
||||
func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error) {
|
||||
return dao.UpdateEntityByKV(nil, &legacymodel.WeiXins{}, map[string]interface{}{
|
||||
"JxStoreID": nil,
|
||||
"ParentID": -1,
|
||||
@@ -85,7 +86,7 @@ func UnbindMobile(mobile string) (num int64, err error) {
|
||||
})
|
||||
}
|
||||
|
||||
func BindMobile2Store(mobile string, storeID int) (num int64, err error) {
|
||||
func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
user, err2 := verifyMobileIsBlank(db, mobile)
|
||||
if err = err2; err == nil || err == orm.ErrNoRows {
|
||||
@@ -102,7 +103,7 @@ func BindMobile2Store(mobile string, storeID int) (num int64, err error) {
|
||||
return num, err
|
||||
}
|
||||
|
||||
func AddMobile2Mobile(parentMobile, mobile string) (num int64, err error) {
|
||||
func AddMobile2Mobile(ctx *jxcontext.Context, parentMobile, mobile string) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
parentUser := &legacymodel.WeiXins{}
|
||||
parentUser.Tel = parentMobile
|
||||
@@ -129,7 +130,7 @@ func AddMobile2Mobile(parentMobile, mobile string) (num int64, err error) {
|
||||
return num, err
|
||||
}
|
||||
|
||||
func ChangeMobile(curMobile, expectedMobile string) (num int64, err error) {
|
||||
func ChangeMobile(ctx *jxcontext.Context, curMobile, expectedMobile string) (num int64, err error) {
|
||||
return dao.UpdateEntityByKV(nil, &legacymodel.WeiXins{}, map[string]interface{}{
|
||||
"Tel": expectedMobile,
|
||||
}, map[string]interface{}{
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
@@ -25,7 +26,7 @@ type tUploadFileInfo struct {
|
||||
StoreID int
|
||||
}
|
||||
|
||||
func SendFilesToStores(files []*multipart.FileHeader, isAsync bool, userName string) (hint string, err error) {
|
||||
func SendFilesToStores(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync bool, userName string) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("SendFilesToStores, fileCount:%d isAsync:%t, userName:%s", len(files), isAsync, userName)
|
||||
if len(files) == 0 {
|
||||
return "", errors.New("没有文件上传!")
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
@@ -132,7 +133,7 @@ func init() {
|
||||
gob.Register([]*SkuPrice{})
|
||||
}
|
||||
|
||||
func CreateJdPromotion(isIDJd bool, isAsync bool, params *PromotionParams, userName string) (hint string, err error) {
|
||||
func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params *PromotionParams, userName string) (hint string, err error) {
|
||||
if len(params.SkuPrices) == 0 {
|
||||
return "", ErrEmptySkus
|
||||
}
|
||||
@@ -306,7 +307,7 @@ func CreateJdPromotion(isIDJd bool, isAsync bool, params *PromotionParams, userN
|
||||
return rootTask.ID, err
|
||||
}
|
||||
|
||||
func CreatePromotionByExcel(isAsync bool, promotionType int, fileHeader *multipart.FileHeader, userName string) (hint string, err error) {
|
||||
func CreatePromotionByExcel(ctx *jxcontext.Context, isAsync bool, promotionType int, fileHeader *multipart.FileHeader, userName string) (hint string, err error) {
|
||||
file, err := fileHeader.Open()
|
||||
if err != nil {
|
||||
return hint, err
|
||||
@@ -353,7 +354,7 @@ func CreatePromotionByExcel(isAsync bool, promotionType int, fileHeader *multipa
|
||||
}
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(promotionParams, false))
|
||||
// globals.SugarLogger.Debug(isAsync)
|
||||
return CreateJdPromotion(true, isAsync, promotionParams, userName)
|
||||
return CreateJdPromotion(ctx, true, isAsync, promotionParams, userName)
|
||||
}
|
||||
|
||||
func excelStr2Time(timeStr string) (tm time.Time, err error) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/KenmyZhang/aliyun-communicate"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
@@ -21,7 +22,7 @@ type tMobileInfo struct {
|
||||
Mobile string
|
||||
}
|
||||
|
||||
func SendAdvertingByGoodsOrder(advertising string, days int, isAsync bool, userName string) (hint string, err error) {
|
||||
func SendAdvertingByGoodsOrder(ctx *jxcontext.Context, advertising string, days int, isAsync bool, userName string) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("SendAdvertingByGoodsOrder advertising:%s, days:%d, isAsync:%t, userName:%s", advertising, days, isAsync, userName)
|
||||
|
||||
if days == 0 {
|
||||
|
||||
Reference in New Issue
Block a user