Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark

This commit is contained in:
gazebo
2019-11-26 17:17:06 +08:00
2 changed files with 150 additions and 22 deletions

View File

@@ -42,6 +42,11 @@ type SheetParam struct {
SkuRow int
}
type DataStoreSkusSuccessLock struct {
dataStoreSkusSuccessList []DataStoreSkusSuccess
locker sync.RWMutex
}
type DataSuccessLock struct {
dataSuccessList []DataSuccess
locker sync.RWMutex
@@ -52,8 +57,18 @@ type DataFailedLock struct {
locker sync.RWMutex
}
type DataStoreSkusSuccess struct {
StoreID int `json:"门店ID"`
NameID int `json:"商品编码"`
Name string `json:"商品名称"`
Unit string `json:"单位"`
OrgPrice float64 `json:"原价"`
NowPrice float64 `json:"现价"`
MixPrice float64 `json:"涨跌"`
}
type DataSuccess struct {
NameID string `json:"商品nameID"`
NameID string `json:"商品编码"`
Name string `json:"商品名称"`
Unit string `json:"单位"`
OrgPrice float64 `json:"原价"`
@@ -150,8 +165,17 @@ var (
SkuRow: 1,
},
}
titleListStoreSkusSuccess = []string{
"门店ID",
"商品编码",
"商品名称",
"单位",
"原价",
"现价",
"涨跌",
}
titleListSuccess = []string{
"商品nameID",
"商品编码",
"商品名称",
"单位",
"原价",
@@ -168,8 +192,9 @@ var (
"商品名称",
"订货数量",
}
dataSuccess DataSuccessLock
dataFailed DataFailedLock
dataSuccess DataSuccessLock
dataFailed DataFailedLock
dataStoreSkusSuccess DataStoreSkusSuccessLock
)
const (
@@ -190,6 +215,12 @@ func (d *DataFailedLock) AppendData2(dataFailed DataFailed) {
d.dataFailedList = append(d.dataFailedList, dataFailed)
}
func (d *DataStoreSkusSuccessLock) AppendData3(dataStoreSkusSuccess DataStoreSkusSuccess) {
d.locker.Lock()
defer d.locker.Unlock()
d.dataStoreSkusSuccessList = append(d.dataStoreSkusSuccessList, dataStoreSkusSuccess)
}
func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) {
if len(files) == 0 {
return "", errors.New("没有文件上传!")
@@ -507,7 +538,7 @@ func updateWeiMobGoods(costPrice, salePrice float64, unit string, isCompare bool
}
} else {
outPutData := DataSuccess{
NameID: goodsDetail.SkuMap.SingleSku.OuterSkuCode,
NameID: goodsDetail.OuterGoodsCode,
Name: goodsDetail.Title,
Unit: unit,
OrgPrice: goodsDetail.SkuMap.SingleSku.SalePrice,
@@ -708,7 +739,7 @@ func WriteToExcel(task *tasksch.SeqTask, dataSuccess []DataSuccess, dataFailed [
}
sheetList2 = append(sheetList2, excelConf2)
if excelConf1 != nil {
downloadURL1, fileName1, err = UploadExeclAndPushMsg(sheetList1, "已更新商品")
downloadURL1, fileName1, err = UploadExeclAndPushMsg(sheetList1, "微盟已更新商品")
} else {
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
}
@@ -741,14 +772,13 @@ func UpdateJxPriceByWeimob(ctx *jxcontext.Context, storeIDs []int, isAsync, isCo
storeSkuBindInfoList []interface{}
skuBindInfos []*cms.StoreSkuBindInfo
)
//获取微盟所有上架商品
queryParameter := &weimobapi.QueryGoodsListRequestVo{
GoodsStatus: weimobapi.GoodsTypeNormal,
}
db := dao.GetDB()
dataFailed.dataFailedList = dataFailed.dataFailedList[0:0]
dataStoreSkusSuccess.dataStoreSkusSuccessList = dataStoreSkusSuccess.dataStoreSkusSuccessList[0:0]
//获取微盟所有商品
param := &weimobapi.QueryGoodsListParam{
PageNum: 1,
PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds,
QueryParameter: queryParameter,
PageNum: 1,
PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds,
}
goodsList, err := GetWeiMobGoodsList(param)
if err != nil {
@@ -763,14 +793,53 @@ func UpdateJxPriceByWeimob(ctx *jxcontext.Context, storeIDs []int, isAsync, isCo
if err != nil {
baseapi.SugarLogger.Errorf("QueryGoodsDetail error:%v", err)
}
if goodsDetail.OuterGoodsCode != "" && goodsDetail.IsPutAway == weimobapi.GoodsTypeNormal {
nameID := int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))
unitPrice := int(utils.Float64TwoInt64(goodsDetail.SkuMap.SingleSku.CostPrice * 100))
storeSkuBindInfo := &cms.StoreSkuBindInfo{
NameID: nameID,
UnitPrice: unitPrice,
nameID := int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))
unitPrice := int(utils.Float64TwoInt64(goodsDetail.SkuMap.SingleSku.CostPrice * 100))
goodsID := goodsDetail.OuterGoodsCode
skuList, err := dao.GetStoreSkusByNameIDs(db, storeIDs, nameID)
if len(skuList) > 0 {
if goodsDetail.OuterGoodsCode != "" {
if goodsDetail.IsPutAway == weimobapi.GoodsTypeNormal {
storeSkuBindInfo := &cms.StoreSkuBindInfo{
NameID: nameID,
UnitPrice: unitPrice,
}
retVal = []*cms.StoreSkuBindInfo{storeSkuBindInfo}
for _, v := range skuList {
outPutData := DataStoreSkusSuccess{
StoreID: v.StoreID,
NameID: nameID,
Name: v.Name,
Unit: v.Unit,
OrgPrice: utils.Str2Float64(utils.Int64ToStr(v.UnitPrice)) / 100,
NowPrice: goodsDetail.SkuMap.SingleSku.CostPrice,
MixPrice: Float64Round((utils.Str2Float64(utils.Int64ToStr(v.UnitPrice)) / 100) - goodsDetail.SkuMap.SingleSku.CostPrice),
}
dataStoreSkusSuccess.AppendData3(outPutData)
}
} else { //如果微盟为下架
outPutData := DataFailed{
GoodsID: goodsID,
GoodsName: goodsDetail.Title,
Comment: "微盟已下架",
}
dataFailed.AppendData2(outPutData)
}
} else {
outPutData := DataFailed{
GoodsID: goodsID,
GoodsName: goodsDetail.Title,
Comment: "微盟上没有该商品的spu编码",
}
dataFailed.AppendData2(outPutData)
}
retVal = []*cms.StoreSkuBindInfo{storeSkuBindInfo}
} else {
outPutData := DataFailed{
GoodsID: goodsID,
GoodsName: goodsDetail.Title,
Comment: "京西未关注该商品",
}
dataFailed.AppendData2(outPutData)
}
return retVal, err
}
@@ -782,10 +851,12 @@ func UpdateJxPriceByWeimob(ctx *jxcontext.Context, storeIDs []int, isAsync, isCo
skuBindInfos = append(skuBindInfos, v.(*cms.StoreSkuBindInfo))
}
cms.UpdateStoresSkus(ctx, storeIDs, skuBindInfos, isAsync, isContinueWhenError)
case 2:
WriteToExcel3(task, dataStoreSkusSuccess.dataStoreSkusSuccessList, dataFailed.dataFailedList)
}
return result, err
}
taskSeq := tasksch.NewSeqTask2("根据微盟商品更新京西价", ctx, isContinueWhenError, taskSeqFunc, 2)
taskSeq := tasksch.NewSeqTask2("根据微盟商品更新京西价", ctx, isContinueWhenError, taskSeqFunc, 3)
tasksch.HandleTask(taskSeq, nil, true).Run()
if !isAsync {
_, err = taskSeq.GetResult(0)
@@ -796,6 +867,42 @@ func UpdateJxPriceByWeimob(ctx *jxcontext.Context, storeIDs []int, isAsync, isCo
return hint, err
}
func WriteToExcel3(task *tasksch.SeqTask, dataSuccess []DataStoreSkusSuccess, dataFailed []DataFailed) (err error) {
var sheetList1 []*excel.Obj2ExcelSheetConfig
var sheetList2 []*excel.Obj2ExcelSheetConfig
var downloadURL1, downloadURL2, fileName1, fileName2 string
excelConf1 := &excel.Obj2ExcelSheetConfig{
Title: "sheet1",
Data: dataSuccess,
CaptionList: titleListStoreSkusSuccess,
}
sheetList1 = append(sheetList1, excelConf1)
excelConf2 := &excel.Obj2ExcelSheetConfig{
Title: "sheet1",
Data: dataFailed,
CaptionList: titleListFailed,
}
sheetList2 = append(sheetList2, excelConf2)
if excelConf1 != nil {
downloadURL1, fileName1, err = UploadExeclAndPushMsg(sheetList1, "京西已更新商品")
} else {
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
}
if excelConf2 != nil {
downloadURL2, fileName2, err = UploadExeclAndPushMsg(sheetList2, "缺少商品_京西")
} else {
baseapi.SugarLogger.Debug("WriteToExcel: dataFailed is nil!")
}
if err != nil {
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName1, fileName2, err)
} else {
noticeMsg := fmt.Sprintf("[详情点我]path1=%s, path2=%s \n", globals.BackstageHost, downloadURL1, downloadURL2)
task.SetNoticeMsg(noticeMsg)
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s ,%s success, downloadURL1:%s ,downloadURL2:%s", fileName1, fileName2, downloadURL1, downloadURL2)
}
return err
}
func GetWeimobOrders(ctx *jxcontext.Context, fromTime, toTime string, params map[string]interface{}) (result []*OrderList, err error) {
if fromTime != "" && toTime != "" {
fromTimeParam := utils.Str2Time(fromTime).UnixNano() / 1e6
@@ -940,7 +1047,7 @@ func GetWeimobOrdersExcel(ctx *jxcontext.Context, OrderNo string) (result *Weimo
}
downloadURL1, downloadURL2, err := WriteToExcel2(ctx, DataFineList, DataHairyList)
result = &WeimobOrderSkusExcelResult{
DownloadUrlFine: downloadURL1,
DownloadUrlFine: downloadURL1,
DownloadUrlHairy: downloadURL2,
}
return result, err

View File

@@ -640,3 +640,24 @@ func UpdateStoreSkuBindSyncStatus(db *DaoDB, vendorIDs []int, storeID int) (num
}
return ExecuteSQL(db, sql, sqlParams...)
}
func GetStoreSkusByNameIDs(db *DaoDB, storeIDs []int, nameID int) (skuList []*StoreSkuSyncInfo, err error) {
sql := `
SELECT a.*,c.unit,c.name
FROM store_sku_bind a
JOIN sku b ON a.sku_id = b.id
JOIN sku_name c ON b.name_id = c.id
WHERE b.name_id = ?
`
sqlParams := []interface{}{
nameID,
}
if len(storeIDs) > 0 {
sql += " AND a.store_id in (" + GenQuestionMarks(len(storeIDs)) + ")"
sqlParams = append(sqlParams, storeIDs)
}
sql += " AND a.status != ?"
sqlParams = append(sqlParams, model.SkuStatusDeleted)
err = GetRows(db, &skuList, sql, sqlParams...)
return skuList, err
}