获取某个商品平台价,商品名前缀
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
"git.rosy.net.cn/jx-callback/globals/api/apimanager"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
@@ -42,6 +43,13 @@ const (
|
||||
CopyStoreSkuModeUpdatePrice = "updatePrice" // 增量复制价格
|
||||
)
|
||||
|
||||
//通用写入Excel
|
||||
type ExcelParam struct {
|
||||
DataList interface{}
|
||||
SheetName string
|
||||
TitleList []string
|
||||
}
|
||||
|
||||
// UpdateStoreSku用,API调用时
|
||||
type StoreSkuBindSkuInfo struct {
|
||||
SkuID int `json:"skuID"`
|
||||
@@ -117,6 +125,15 @@ type SheetParam struct {
|
||||
SkuRow int
|
||||
}
|
||||
|
||||
type DataVendorStoreSkuPrice struct {
|
||||
StoreID int `json:"门店ID"`
|
||||
StoreName string `json:"门店名"`
|
||||
SkuID int `json:"商品ID"`
|
||||
SkuNameID int `json:"商品NameID"`
|
||||
SkuName string `json:"商品名"`
|
||||
VendorPrice int64 `json:"平台价"`
|
||||
}
|
||||
|
||||
type DataSuccess struct {
|
||||
NameID int `json:"商品NameID"`
|
||||
Name string `json:"商品名称"`
|
||||
@@ -151,7 +168,15 @@ var (
|
||||
"18180948107": 1, // 徐
|
||||
// "13684045763": 1, // 周
|
||||
}
|
||||
dataLock DataLock
|
||||
dataLock DataLock
|
||||
titleListVendorStoreSkuPrice = []string{
|
||||
"门店ID",
|
||||
"门店名",
|
||||
"商品ID",
|
||||
"商品NameID",
|
||||
"商品名",
|
||||
"平台价",
|
||||
}
|
||||
titleListSuccess = []string{
|
||||
"商品NameID",
|
||||
"商品名称",
|
||||
@@ -2484,3 +2509,129 @@ func IsChineseChar(str string) bool {
|
||||
func GetStoreCategories(ctx *jxcontext.Context, storeID, parentID int) (catList []*model.SkuCategory, err error) {
|
||||
return dao.GetStoreSkuCategories(dao.GetDB(), storeID, parentID)
|
||||
}
|
||||
|
||||
func GetVendorStoreSkuPrice(ctx *jxcontext.Context, vendorIDs []int, skuID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
storeSkuListJD []DataVendorStoreSkuPrice
|
||||
storeSkuListMT []DataVendorStoreSkuPrice
|
||||
storeSkuListEB []DataVendorStoreSkuPrice
|
||||
excelParamList []ExcelParam
|
||||
)
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
for _, v := range vendorIDs {
|
||||
vendorID := v
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||
handlerStore := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IStoreHandler)
|
||||
for _, v := range apimanager.CurAPIManager.GetAppOrgCodeList(vendorID) {
|
||||
vendorStoreIDs, err2 := handlerStore.GetAllStoresVendorID(ctx, v)
|
||||
err = err2
|
||||
task := tasksch.NewParallelTask("获取各平台所有门店某商品价格", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorStoreID := batchItemList[0].(string)
|
||||
var inStoreSkuList []*partner.StoreSkuInfo
|
||||
var storeDetail *dao.StoreDetail
|
||||
inStoreSku := &partner.StoreSkuInfo{
|
||||
SkuID: skuID,
|
||||
}
|
||||
inStoreSkuList = append(inStoreSkuList, inStoreSku)
|
||||
db := dao.GetDB()
|
||||
storeDetail, err = dao.GetStoreDetailByVendorStoreID(db, vendorStoreID, vendorID)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
outStoreSkuList, err := handler.GetStoreSkusBareInfo(ctx, v, task, 0, vendorStoreID, inStoreSkuList)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
if len(outStoreSkuList) > 0 {
|
||||
if storeDetail != nil {
|
||||
skuNameList, err := dao.GetSkus(db, []int{outStoreSkuList[0].SkuID}, nil, nil, nil)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
if len(skuNameList) > 0 {
|
||||
data := DataVendorStoreSkuPrice{
|
||||
StoreID: storeDetail.ID,
|
||||
StoreName: storeDetail.Name,
|
||||
SkuID: outStoreSkuList[0].SkuID,
|
||||
SkuNameID: outStoreSkuList[0].NameID,
|
||||
SkuName: skuNameList[0].Name,
|
||||
VendorPrice: outStoreSkuList[0].VendorPrice,
|
||||
}
|
||||
retVal = []DataVendorStoreSkuPrice{data}
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, vendorStoreIDs)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
storeSkuList, _ := task.GetResult(0)
|
||||
for _, v := range storeSkuList {
|
||||
if vendorID == model.VendorIDJD {
|
||||
storeSkuListJD = append(storeSkuListJD, v.(DataVendorStoreSkuPrice))
|
||||
}
|
||||
if vendorID == model.VendorIDEBAI {
|
||||
storeSkuListEB = append(storeSkuListEB, v.(DataVendorStoreSkuPrice))
|
||||
}
|
||||
if vendorID == model.VendorIDMTWM {
|
||||
storeSkuListMT = append(storeSkuListMT, v.(DataVendorStoreSkuPrice))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
excelParam1 := ExcelParam{
|
||||
DataList: storeSkuListJD,
|
||||
TitleList: titleListVendorStoreSkuPrice,
|
||||
SheetName: "京东平台",
|
||||
}
|
||||
excelParam2 := ExcelParam{
|
||||
DataList: storeSkuListEB,
|
||||
TitleList: titleListVendorStoreSkuPrice,
|
||||
SheetName: "饿百平台",
|
||||
}
|
||||
excelParam3 := ExcelParam{
|
||||
DataList: storeSkuListMT,
|
||||
TitleList: titleListVendorStoreSkuPrice,
|
||||
SheetName: "美团平台",
|
||||
}
|
||||
excelParamList = append(excelParamList, excelParam1, excelParam2, excelParam3)
|
||||
case 1:
|
||||
WriteToExcelNormal(task, "各平台"+utils.Int2Str(skuID)+"商品所有门店价格", excelParamList)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
taskSeq := tasksch.NewSeqTask2("获取各平台所有门店某商品价格-序列任务", ctx, isContinueWhenError, taskSeqFunc, 2)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = taskSeq.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func WriteToExcelNormal(task *tasksch.SeqTask, fileName string, excelParam []ExcelParam) (err error) {
|
||||
var sheetList []*excel.Obj2ExcelSheetConfig
|
||||
for _, v := range excelParam {
|
||||
if v.DataList != nil {
|
||||
excelConf := &excel.Obj2ExcelSheetConfig{
|
||||
Title: v.SheetName,
|
||||
Data: v.DataList,
|
||||
CaptionList: v.TitleList,
|
||||
}
|
||||
sheetList = append(sheetList, excelConf)
|
||||
}
|
||||
}
|
||||
downloadURL, fileNameResult, err := jxutils.UploadExeclAndPushMsg(sheetList, fileName)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s failed error:%v", fileNameResult, err)
|
||||
} else {
|
||||
noticeMsg := fmt.Sprintf("[详情点我]path=%s \n", downloadURL)
|
||||
task.SetNoticeMsg(noticeMsg)
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL:%s", fileNameResult, downloadURL)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user