From a1efff61a47b3e8c8c70ed07c4c0b4dda659cb6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 12 Nov 2019 18:06:35 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B0=B8=E8=BE=89excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/yonghui/yonghui.go | 478 +++++++++++++++++++++++----- controllers/yonghui.go | 2 +- 2 files changed, 392 insertions(+), 88 deletions(-) diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index dcb52a49b..8ce9b113b 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -1,118 +1,369 @@ package yonghui import ( + "errors" "fmt" "mime/multipart" + "strconv" "unicode" + "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/baseapi/utils" + "github.com/360EntSecGroup-Skylar/excelize" + "git.rosy.net.cn/baseapi/platformapi/jdapi" "git.rosy.net.cn/baseapi/platformapi/weimobapi" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" - "github.com/360EntSecGroup-Skylar/excelize" + "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" + + "git.rosy.net.cn/jx-callback/globals/api" ) var ( sheetNames = []string{"蔬菜", "水果", "肉禽", "净配", "水产", "干货", "MINI肉禽价格"} + sheet1Name = "蔬菜" + sheet2Name = "水果" + sheet3Name = "肉禽" + sheet4Name = "净配" + sheet5Name = "水产" + sheet6Name = "干货" + sheet7Name = "MINI肉禽价格" ) //sheet1 蔬菜 var ( - sheet1SkuIdCol = 0 - sheet1SkuPriceCol = 14 - sheet1OrgSkuIdCol = 5 - sheet1OrgSkuPriceCol = 8 + sheet1SkuIDCol = 0 //商品的spu编码 + sheet1SkuPriceCol = 14 //对应商品的成本价 + sheet1OrgSkuIdCol = 5 //原料的spu编码 + sheet1OrgSkuPriceCol = 8 //对应原料的成本价 + sheet1SkuRow = 2 ) -func SendFilesToStores(ctx *jxcontext.Context, files []*multipart.FileHeader) (hint string, err error) { +//sheet2 水果 +var ( + sheet2SkuIDCol = 0 + sheet2SkuPriceCol = 14 + sheet2OrgSkuIdCol = 5 + sheet2OrgSkuPriceCol = 8 + sheet2SkuRow = 2 +) + +//sheet3 肉禽 +var ( + sheet3SkuIDCol = 0 + sheet3SkuPriceCol = 12 + sheet3OrgSkuIdCol = 4 + sheet3OrgSkuPriceCol = 7 + sheet3SkuRow = 1 +) + +//sheet4 净配 +var ( + sheet4SkuIDCol = 0 + sheet4SkuPriceCol = 12 + sheet4OrgSkuIdCol = 4 + sheet4OrgSkuPriceCol = 7 + sheet4SkuRow = 1 +) + +//sheet5 水产 +var ( + sheet5SkuIDCol = 1 + sheet5SkuPriceCol = 15 + sheet5OrgSkuIdCol = 6 + sheet5OrgSkuPriceCol = 9 + sheet5SkuRow = 1 +) + +//sheet6 干货 +var ( + sheet6SkuIDCol = 0 + sheet6SkuPriceCol = 13 + sheet6OrgSkuIdCol = 4 + sheet6OrgSkuPriceCol = 7 + sheet6SkuRow = 2 +) + +//sheet7 MINI肉禽价格 +var ( + sheet7SkuIDCol = 1 + sheet7SkuPriceCol = 5 + sheet7SkuRow = 1 +) + +const ( + parallelCount = 5 +) + +func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync bool) (hint string, err error) { var ( - // skuId string - // skuPrice string - skuMap = make(map[string]string) + skuMap = make(map[string]float64) + errMsg string + // costPrice float64 //成本价 + // goodsIDListForPutAway []int64 + // goodsList []*weimobapi.GoodsInfo ) + // db := dao.GetDB() + if len(files) == 0 { + return "", errors.New("没有文件上传!") + } + //读取excel文件 + xlsx, err := excelize.OpenFile(files[0].Filename) + // xlsx, err := excelize.OpenFile("111.xlsx") + if err != nil { + return "", err + } + taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { + switch step { + case 0: + taskFunc1 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + v := batchItemList[0].(string) + rows, _ := xlsx.GetRows(v) + for rowNum, row := range rows { + switch v { + case sheet1Name: + if rowNum < sheet1SkuRow { + continue + } + GetCellIntoMap(sheet1SkuIDCol, sheet1SkuPriceCol, sheet1OrgSkuIdCol, sheet1OrgSkuPriceCol, skuMap, true, row, v, rowNum) + case sheet2Name: + if rowNum < sheet2SkuRow { + continue + } + GetCellIntoMap(sheet2SkuIDCol, sheet2SkuPriceCol, sheet2OrgSkuIdCol, sheet2OrgSkuPriceCol, skuMap, true, row, v, rowNum) + case sheet3Name: + if rowNum < sheet3SkuRow { + continue + } + GetCellIntoMap(sheet3SkuIDCol, sheet3SkuPriceCol, sheet3OrgSkuIdCol, sheet3OrgSkuPriceCol, skuMap, true, row, v, rowNum) + case sheet4Name: + if rowNum < sheet4SkuRow { + continue + } + GetCellIntoMap(sheet4SkuIDCol, sheet4SkuPriceCol, sheet4OrgSkuIdCol, sheet4OrgSkuPriceCol, skuMap, true, row, v, rowNum) + case sheet5Name: + if rowNum < sheet5SkuRow { + continue + } + GetCellIntoMap(sheet5SkuIDCol, sheet5SkuPriceCol, sheet5OrgSkuIdCol, sheet5OrgSkuPriceCol, skuMap, true, row, v, rowNum) + case sheet6Name: + if rowNum < sheet6SkuRow { + continue + } + GetCellIntoMap(sheet6SkuIDCol, sheet6SkuPriceCol, sheet6OrgSkuIdCol, sheet6OrgSkuPriceCol, skuMap, true, row, v, rowNum) + case sheet7Name: + if rowNum < sheet7SkuRow { + continue + } + GetCellIntoMap(sheet7SkuIDCol, sheet7SkuPriceCol, 0, 0, skuMap, false, row, v, rowNum) + default: + return retVal, errors.New("未找到配置的sheet页,请检查excel内容排版格式是否发生变化!\n") + } + } + return retVal, err + } + taskParallel1 := tasksch.NewParallelTask("读取Excel", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc1, sheetNames) + tasksch.HandleTask(taskParallel1, task, true).Run() + _, err = taskParallel1.GetResult(0) + // case 1: + // //获取微盟所有商品 + // goodsList = GetGoodsInfoAndDetail() + // //找出excel上有,微盟没有的,有就列出报错,不进行更新 + // goodsInfoAndDetailMap := GetGoodsInfoAndDetailMap(goodsList) + // for k, _ := range skuMap { + // //表示excel上有,微盟上没有 + // if goodsInfoAndDetailMap[k] == nil { + // errMsg += fmt.Sprintf("在微盟上未找到该商品!excel商品ID : [%v]\n", k) + // } + // } + // if errMsg != "" { + // return "", errors.New(errMsg) + // } + // case 2: + // //找出微盟上有,excel上没有的,有就更新,没有就下架 + // taskFunc2 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + // goods := batchItemList[0].(*weimobapi.GoodsInfo) + // goodsDetail := goods.GoodsDetailInfo + // spuCode := goodsDetail.OuterGoodsCode + // if spuCode != "" { + // //如果微盟商品里找得到excel中的商品 + // if skuMap[spuCode] != 0 { + // //获取京西库商品 + // skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil) + // if len(skuList) == 0 { + // errMsg += fmt.Sprintf("在京西库中未找到该商品!name_id : [%v] \n", goodsDetail.SkuMap.SingleSku.OuterSkuCode) + // } else { + // if skuList[0].Unit != "份" { + // costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap[spuCode]) + // } else { + // costPrice = skuMap[spuCode] + // } + // if errMsg == "" { + // _, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode], goodsDetail) + // } + // } + // } else { + // //下架微盟商品 + // goodsIDListForPutAway = append(goodsIDListForPutAway, goodsDetail.GoodsID) + // } + // } + // return retVal, err + // } + // taskParallel2 := tasksch.NewParallelTask("获取微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc2, goodsList) + // tasksch.HandleTask(taskParallel2, task, true).Run() + // _, err = taskParallel2.GetResult(0) + // case 3: + // //批量下架微盟商品 + // if errMsg == "" { + // if len(goodsIDListForPutAway) <= 50 { //api要求最多传50个 + // PutAwayWeiMobSku(goodsIDListForPutAway) + // } else { + // for i := 0; i < len(goodsIDListForPutAway)/50+1; i++ { + // var int64Slice []int64 + // if len(goodsIDListForPutAway) > 50*(i+1) { + // int64Slice = goodsIDListForPutAway[i*50 : (i+1)*50+1] + // } else { + // int64Slice = goodsIDListForPutAway[i*50 : len(goodsIDListForPutAway)] + // } + // PutAwayWeiMobSku(int64Slice) + // } + // } + // } + } + return result, err + } + taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 4) + tasksch.HandleTask(taskSeq, nil, true).Run() + for k, v := range skuMap { + fmt.Println(k, v) + } + if errMsg != "" { + baseapi.SugarLogger.Debugf(errMsg) + } + return "", err +} + +func PutAwayWeiMobSku(goodsIDListForPutAway []int64) { + err := api.WeimobAPI.UpdateGoodsShelfStatus(goodsIDListForPutAway, false) + if err != nil { + baseapi.SugarLogger.Errorf("UpdateGoodsShelfStatus error:%v", err) + } +} + +func GetGoodsInfoAndDetailMap(goodsList []*weimobapi.GoodsInfo) (goodsMap map[string]*weimobapi.GoodsInfo) { + goodsMap = make(map[string]*weimobapi.GoodsInfo) + for _, v := range goodsList { + goodsMap[v.GoodsDetailInfo.OuterGoodsCode] = v + } + return goodsMap +} + +func GetGoodsInfoAndDetail() []*weimobapi.GoodsInfo { + goodsList, err := GetWeiMobGoodsList() + if err != nil { + baseapi.SugarLogger.Errorf("GetWeiMobGoodsList error:%v", err) + } + for _, v := range goodsList { + goodsDetail, err := api.WeimobAPI.QueryGoodsDetail(v.GoodsID) + if err != nil { + baseapi.SugarLogger.Errorf("QueryGoodsDetail error:%v", err) + } + v.GoodsDetailInfo = goodsDetail + } + return goodsList +} + +func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.GoodsDetailInfo) (goodsID int64, skuMap map[string]int64, err error) { + var ( + skuListParam []*weimobapi.SkuList + deliveryTypeListSlice []int64 + skuListInfo = goodsDetail.SkuList[0] + categoryList []*weimobapi.CategoryList + categoryID int + ) + + //查询配送方式 + deliveryTypeList, err := api.WeimobAPI.FindDeliveryTypeList(goodsDetail.GoodsID) + if err != nil { + baseapi.SugarLogger.Errorf("FindDeliveryTypeList error:%v", err) + } + for _, deliveryType := range deliveryTypeList { + if deliveryType.Selected { + deliveryTypeListSlice = append(deliveryTypeListSlice, deliveryType.DeliveryID) + } + } + //查询运费模板 + freightTemplateListInfo, err := api.WeimobAPI.FindFreightTemplateList(goodsDetail.GoodsID) + if err != nil { + baseapi.SugarLogger.Errorf("FindFreightTemplateList error:%v", err) + } + //寻找分类子ID + categoryList = goodsDetail.CategoryList + if len(categoryList) > 0 { + for k, v := range categoryList { + if k < len(categoryList)-1 { + continue + } + categoryID = v.CategoryID + } + } else { + return 0, nil, errors.New(fmt.Sprintf("未查询到此商品的分类信息!goodsID : [%v] ,", goodsDetail.GoodsID)) + } + b2CSku := &weimobapi.B2CSku{ + Weight: skuListInfo.B2CSku.Weight, + Volume: skuListInfo.B2CSku.Volume, + } + b2CGoods := &weimobapi.B2CGoods{ + B2CGoodsType: goodsDetail.B2CGoods.B2CGoodsType, + DeliveryTypeIDList: deliveryTypeListSlice, + FreightTemplateID: freightTemplateListInfo.DefaultFreightTemplate.TemplateID, + } + skuList := &weimobapi.SkuList{ + SalePrice: salePrice, + CostPrice: costPrice, + SkuID: skuListInfo.SkuID, + EditStockNum: skuListInfo.EditStockNum, + OuterSkuCode: skuListInfo.OuterSkuCode, + B2CSku: b2CSku, + } + skuListParam = append(skuListParam, skuList) + goods := &weimobapi.Goods{ + B2CGoods: b2CGoods, + SkuList: skuListParam, + Title: goodsDetail.Title, + IsMultiSku: goodsDetail.IsMultiSku, + IsPutAway: goodsDetail.IsPutAway, + GoodsImageURL: goodsDetail.GoodsImageURL, + GoodsID: goodsDetail.GoodsID, + CategoryID: categoryID, + OuterGoodsCode: goodsDetail.OuterGoodsCode, + PointDeductRatio: goodsDetail.PointDeductRatio, + } + updateGoodsParam := &weimobapi.UpdateGoodsParam{ + Goods: goods, + } + return api.WeimobAPI.UpdateGoods3(updateGoodsParam) +} + +func GetWeiMobGoodsList() (goodsList []*weimobapi.GoodsInfo, err error) { param := &weimobapi.QueryGoodsListParam{ PageNum: 1, PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds, } - // if len(files) == 0 { - // return "", errors.New("没有文件上传!") - // } - xlsx, err := excelize.OpenFile("111.xlsx") - if err != nil { - fmt.Println(err) - return - } - for _, v := range sheetNames { - // goodsParam := &weimobapi.GoodsParameter{} - rows, _ := xlsx.GetRows(v) - switch v { - case "蔬菜": - for _, row := range rows { - for k, _ := range row { - if k == sheet1SkuIdCol { - - } - // if !IsChineseChar(colCell) { - - // } - } - fmt.Println() - } + for { + goodsInfoList, _, err := api.WeimobAPI.QueryGoodsList(param) + if err != nil { + return nil, err } + if len(goodsInfoList) > 0 { + goodsList = append(goodsList, goodsInfoList...) + } + if len(goodsInfoList) < param.PageSize { + break + } + param.PageNum++ } - - // xlFile, err := xlsx.OpenFile("111.xlsx") - // if err != nil { - // errors.New(err.Error()) - // } - // excelize - // for _, sheet := range xlFile.Sheets { - // if sheet.Name == "蔬菜" { - // for j := 0; j < len(sheet.Rows); j++ { - // cells := sheet.Rows[j].Cells - // for i := 0; i < len(cells); i++ { - // cell := cells[i] - // if i == 0 { - // if _, err := strconv.Atoi(cell.String()); err != nil || cell.String() == "" { - // continue - // } - // skuId = cell.String() - // } - // if i == 14 { - // skuPrice = cell.String() - // } - // skuMap[skuId] = skuPrice - // } - // } - // } - // } - for k, v := range skuMap { - fmt.Println(k) - fmt.Println(v) - } - - GetWeiMoGoodsList(param) - return "", err -} - -func GetWeiMoGoodsList(param *weimobapi.QueryGoodsListParam) { - // for { - // skuList, _, err2 := getAPI("").QuerySkuInfos(param) - // if err = err2; err != nil { - // return nil, err - // } - // if len(skuList) > 0 { - // batchSkuNameList := make([]*partner.SkuNameInfo, len(skuList)) - // for k, v := range skuList { - // batchSkuNameList[k] = vendorSku2Jx(v) - // } - // setSkuNameListPic(batchSkuNameList) - // skuNameList = append(skuNameList, batchSkuNameList...) - // } - // if len(skuList) < param.PageSize { - // break - // } - // param.PageNum++ - // } + return goodsList, err } func IsChineseChar(str string) bool { @@ -123,3 +374,56 @@ func IsChineseChar(str string) bool { } return false } + +func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuMap map[string]float64, isHaveOrg bool, row []string, sheetName string, rowNum int) { + var ( + skuID string + orgSkuID string + skuPrice float64 + orgSkuPrice float64 + ) + for k, cell := range row { + if !IsChineseChar(cell) && cell != "" { + if k == skuIDCol { + skuID = cell + } + if k == skuPriceCol { + skuPrice = Float64Round(utils.Str2Float64(cell)) + } + if isHaveOrg { + if k == orgSkuIDCol { + orgSkuID = "0" + cell + } + if k == orgSkuPriceCol { + orgSkuPrice = Float64Round(utils.Str2Float64(cell)) + } + } + } + } + if skuMap[skuID] != 0 && skuMap[skuID] != skuPrice { + if skuPrice > skuMap[skuID] { + skuMap[skuID] = skuPrice + } + // fmt.Sprintf("读取excel表格出错!有商品ID重复且价格不同,sheetName : [%v] ,行数 : [%v] , 商品编码 :[%v] , 价格:[%v]\n", sheetName, rowNum, skuID, skuPrice) + } else { + skuMap[skuID] = skuPrice + } + if isHaveOrg { + if skuMap[orgSkuID] != 0 && skuMap[orgSkuID] != orgSkuPrice { + if orgSkuPrice > skuMap[orgSkuID] { + skuMap[orgSkuID] = orgSkuPrice + } + // fmt.Sprintf("读取excel表格出错!有商品ID重复且价格不同,sheetName : [%v] ,行数 : [%v], 商品编码 :[%v] , 价格:[%v]\n", sheetName, rowNum, orgSkuID, orgSkuPrice) + } else { + skuMap[orgSkuID] = orgSkuPrice + } + } +} + +func Float64Round(f float64) (flt float64) { + flt, err := strconv.ParseFloat(fmt.Sprintf("%.2f", f), 64) + if err != nil { + flt = 0 + } + return flt +} diff --git a/controllers/yonghui.go b/controllers/yonghui.go index 3e75306ff..52d38a43c 100644 --- a/controllers/yonghui.go +++ b/controllers/yonghui.go @@ -21,7 +21,7 @@ func (c *YongHuiController) LoadExcelByYongHui() { c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) { r := c.Ctx.Request files := r.MultipartForm.File["userfiles"] - retVal, err = yonghui.SendFilesToStores(params.Ctx, files) + retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync) return retVal, "", err }) } From 6eabd6b488cba56e02f29966f9a00e216c50f303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 12 Nov 2019 18:22:00 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E8=AF=BB=E5=8F=96excle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/yonghui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/yonghui.go b/controllers/yonghui.go index 52d38a43c..edff47114 100644 --- a/controllers/yonghui.go +++ b/controllers/yonghui.go @@ -20,7 +20,7 @@ type YongHuiController struct { func (c *YongHuiController) LoadExcelByYongHui() { c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) { r := c.Ctx.Request - files := r.MultipartForm.File["userfiles"] + files := r.MultipartForm.File["file"] retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync) return retVal, "", err }) From c39acd3d4f142c525d95f4ab17c33479f748ef2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 12 Nov 2019 18:30:06 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=BC=BA=E7=9C=81?= =?UTF-8?q?=E5=80=BC=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 4 ++-- controllers/yonghui.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index afcdbb84d..a7e1d0607 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -626,7 +626,7 @@ func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, if fromDate != "" && toDate != "" { fromDateParam = utils.Str2Time(fromDate) toDateParam = utils.Str2Time(toDate) - actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", -1, nil, nil, nil, 0, 0, 0, time.Time{}, time.Time{}, time.Time{}, time.Time{}) + actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", -1, nil, nil, nil, 0, 0, 0, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue) if len(actList.Data) > 0 { actBeginAt := actList.Data[0].BeginAt actEndAt := actList.Data[0].EndAt @@ -656,7 +656,7 @@ func (c *OrderManager) RefreshHistoryOrdersEarningPrice(ctx *jxcontext.Context, return "", errors.New(fmt.Sprintf("未查询到相关结算活动,活动ID:[%d]", actID)) } } else if fromDate == "" && toDate == "" { - actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", -1, nil, nil, nil, 0, 0, 0, time.Time{}, time.Time{}, time.Time{}, time.Time{}) + actList, _ := dao.QueryActs(db, actID, 0, math.MaxInt32, 0, "", -1, nil, nil, nil, 0, 0, 0, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue) if len(actList.Data) > 0 { orderList, _ = dao.QueryOrders(db, vendorOrderID, actID, vendorIDs, storeID, actList.Data[0].BeginAt, actList.Data[0].EndAt) } else { diff --git a/controllers/yonghui.go b/controllers/yonghui.go index edff47114..52d38a43c 100644 --- a/controllers/yonghui.go +++ b/controllers/yonghui.go @@ -20,7 +20,7 @@ type YongHuiController struct { func (c *YongHuiController) LoadExcelByYongHui() { c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) { r := c.Ctx.Request - files := r.MultipartForm.File["file"] + files := r.MultipartForm.File["userfiles"] retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync) return retVal, "", err }) From d40182a22078ca9804295c534f316615e571309e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 13 Nov 2019 08:15:37 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E8=AF=BB=E5=8F=96excel=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/yonghui/yonghui.go | 1 + controllers/yonghui.go | 35 +++++++++++++++++++++------ routers/commentsRouter_controllers.go | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 8ce9b113b..3c5bbf6fa 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -107,6 +107,7 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i if len(files) == 0 { return "", errors.New("没有文件上传!") } + //读取excel文件 xlsx, err := excelize.OpenFile(files[0].Filename) // xlsx, err := excelize.OpenFile("111.xlsx") diff --git a/controllers/yonghui.go b/controllers/yonghui.go index 52d38a43c..958ebeb95 100644 --- a/controllers/yonghui.go +++ b/controllers/yonghui.go @@ -1,6 +1,9 @@ package controllers import ( + "fmt" + "io" + "git.rosy.net.cn/jx-callback/business/jxstore/yonghui" "github.com/astaxie/beego" ) @@ -12,16 +15,32 @@ type YongHuiController struct { // @Title 读取永辉excel文件 // @Description 读取永辉excel文件 -// @Param token header string true "认证token" +// @Param token header string false "认证token" // @Param isAsync query bool false "是否异步,缺省是同步" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult -// @router /LoadExcelByYongHui [post] +// @router /LoadExcelByYongHui [post,get] func (c *YongHuiController) LoadExcelByYongHui() { - c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) { - r := c.Ctx.Request - files := r.MultipartForm.File["userfiles"] - retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync) - return retVal, "", err - }) + if c.Ctx.Input.IsGet() { + w := c.Ctx.ResponseWriter + // 上传页面 + w.Header().Add("Content-Type", "text/html") + w.WriteHeader(200) + html := ` +
+ Send this file: + +
+ ` + io.WriteString(w, html) + } else if c.Ctx.Input.IsPost() { + c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) { + r := c.Ctx.Request + files := r.MultipartForm.File["userfiles"] + fmt.Println(r) + fmt.Println(r.MultipartForm) + retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync) + return retVal, "", err + }) + } } diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 004fe4213..02a5aeba7 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -2002,7 +2002,7 @@ func init() { beego.ControllerComments{ Method: "LoadExcelByYongHui", Router: `/LoadExcelByYongHui`, - AllowHTTPMethods: []string{"post"}, + AllowHTTPMethods: []string{"post","get"}, MethodParams: param.Make(), Filters: nil, Params: nil}) From be69ca429cc09a8c3d642b0b824b1225364ce865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 13 Nov 2019 08:19:50 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E8=AF=BB=E5=8F=96excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/yonghui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/yonghui.go b/controllers/yonghui.go index 958ebeb95..3aa519f6c 100644 --- a/controllers/yonghui.go +++ b/controllers/yonghui.go @@ -36,9 +36,9 @@ func (c *YongHuiController) LoadExcelByYongHui() { } else if c.Ctx.Input.IsPost() { c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) { r := c.Ctx.Request - files := r.MultipartForm.File["userfiles"] fmt.Println(r) fmt.Println(r.MultipartForm) + files := r.MultipartForm.File["userfiles"] retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync) return retVal, "", err }) From 95c37a847e3172eb6652545b9de08c3f10206a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 13 Nov 2019 09:57:20 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B0=B8=E8=BE=89Excel?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/yonghui/yonghui.go | 177 ++++++++++++++++------------ controllers/yonghui.go | 3 - 2 files changed, 101 insertions(+), 79 deletions(-) diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 3c5bbf6fa..898a456aa 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -15,6 +15,7 @@ import ( "git.rosy.net.cn/baseapi/platformapi/weimobapi" "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/api" ) @@ -97,13 +98,13 @@ const ( func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync bool) (hint string, err error) { var ( - skuMap = make(map[string]float64) - errMsg string - // costPrice float64 //成本价 - // goodsIDListForPutAway []int64 - // goodsList []*weimobapi.GoodsInfo + skuMap = make(map[string]float64) + errMsg string + costPrice float64 //成本价 + goodsIDListForPutAway []int64 + goodsList []*weimobapi.GoodsInfo ) - // db := dao.GetDB() + db := dao.GetDB() if len(files) == 0 { return "", errors.New("没有文件上传!") } @@ -127,117 +128,141 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i continue } GetCellIntoMap(sheet1SkuIDCol, sheet1SkuPriceCol, sheet1OrgSkuIdCol, sheet1OrgSkuPriceCol, skuMap, true, row, v, rowNum) + if len(skuMap) < 1 { + errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) + } case sheet2Name: if rowNum < sheet2SkuRow { continue } GetCellIntoMap(sheet2SkuIDCol, sheet2SkuPriceCol, sheet2OrgSkuIdCol, sheet2OrgSkuPriceCol, skuMap, true, row, v, rowNum) + if len(skuMap) < 1 { + errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) + } case sheet3Name: if rowNum < sheet3SkuRow { continue } GetCellIntoMap(sheet3SkuIDCol, sheet3SkuPriceCol, sheet3OrgSkuIdCol, sheet3OrgSkuPriceCol, skuMap, true, row, v, rowNum) + if len(skuMap) < 1 { + errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) + } case sheet4Name: if rowNum < sheet4SkuRow { continue } GetCellIntoMap(sheet4SkuIDCol, sheet4SkuPriceCol, sheet4OrgSkuIdCol, sheet4OrgSkuPriceCol, skuMap, true, row, v, rowNum) + if len(skuMap) < 1 { + errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) + } case sheet5Name: if rowNum < sheet5SkuRow { continue } GetCellIntoMap(sheet5SkuIDCol, sheet5SkuPriceCol, sheet5OrgSkuIdCol, sheet5OrgSkuPriceCol, skuMap, true, row, v, rowNum) + if len(skuMap) < 1 { + errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) + } case sheet6Name: if rowNum < sheet6SkuRow { continue } GetCellIntoMap(sheet6SkuIDCol, sheet6SkuPriceCol, sheet6OrgSkuIdCol, sheet6OrgSkuPriceCol, skuMap, true, row, v, rowNum) + if len(skuMap) < 1 { + errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) + } case sheet7Name: if rowNum < sheet7SkuRow { continue } GetCellIntoMap(sheet7SkuIDCol, sheet7SkuPriceCol, 0, 0, skuMap, false, row, v, rowNum) + if len(skuMap) < 1 { + errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) + } default: return retVal, errors.New("未找到配置的sheet页,请检查excel内容排版格式是否发生变化!\n") } } + if errMsg != "" { + return "", errors.New(errMsg) + } return retVal, err } taskParallel1 := tasksch.NewParallelTask("读取Excel", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc1, sheetNames) tasksch.HandleTask(taskParallel1, task, true).Run() _, err = taskParallel1.GetResult(0) - // case 1: - // //获取微盟所有商品 - // goodsList = GetGoodsInfoAndDetail() - // //找出excel上有,微盟没有的,有就列出报错,不进行更新 - // goodsInfoAndDetailMap := GetGoodsInfoAndDetailMap(goodsList) - // for k, _ := range skuMap { - // //表示excel上有,微盟上没有 - // if goodsInfoAndDetailMap[k] == nil { - // errMsg += fmt.Sprintf("在微盟上未找到该商品!excel商品ID : [%v]\n", k) - // } - // } - // if errMsg != "" { - // return "", errors.New(errMsg) - // } - // case 2: - // //找出微盟上有,excel上没有的,有就更新,没有就下架 - // taskFunc2 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - // goods := batchItemList[0].(*weimobapi.GoodsInfo) - // goodsDetail := goods.GoodsDetailInfo - // spuCode := goodsDetail.OuterGoodsCode - // if spuCode != "" { - // //如果微盟商品里找得到excel中的商品 - // if skuMap[spuCode] != 0 { - // //获取京西库商品 - // skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil) - // if len(skuList) == 0 { - // errMsg += fmt.Sprintf("在京西库中未找到该商品!name_id : [%v] \n", goodsDetail.SkuMap.SingleSku.OuterSkuCode) - // } else { - // if skuList[0].Unit != "份" { - // costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap[spuCode]) - // } else { - // costPrice = skuMap[spuCode] - // } - // if errMsg == "" { - // _, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode], goodsDetail) - // } - // } - // } else { - // //下架微盟商品 - // goodsIDListForPutAway = append(goodsIDListForPutAway, goodsDetail.GoodsID) - // } - // } - // return retVal, err - // } - // taskParallel2 := tasksch.NewParallelTask("获取微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc2, goodsList) - // tasksch.HandleTask(taskParallel2, task, true).Run() - // _, err = taskParallel2.GetResult(0) - // case 3: - // //批量下架微盟商品 - // if errMsg == "" { - // if len(goodsIDListForPutAway) <= 50 { //api要求最多传50个 - // PutAwayWeiMobSku(goodsIDListForPutAway) - // } else { - // for i := 0; i < len(goodsIDListForPutAway)/50+1; i++ { - // var int64Slice []int64 - // if len(goodsIDListForPutAway) > 50*(i+1) { - // int64Slice = goodsIDListForPutAway[i*50 : (i+1)*50+1] - // } else { - // int64Slice = goodsIDListForPutAway[i*50 : len(goodsIDListForPutAway)] - // } - // PutAwayWeiMobSku(int64Slice) - // } - // } - // } + case 1: + //获取微盟所有商品 + goodsList = GetGoodsInfoAndDetail() + //找出excel上有,微盟没有的,有就列出报错,不进行更新 + goodsInfoAndDetailMap := GetGoodsInfoAndDetailMap(goodsList) + delete(skuMap, "") + for k, v := range skuMap { + fmt.Printf("key %v, value %v\n", k, v) + //表示excel上有,微盟上没有 + if goodsInfoAndDetailMap[k] == nil { + errMsg += fmt.Sprintf("在微盟上未找到该商品!excel商品ID : [%v]\n", k) + } + } + fmt.Println(len(skuMap)) + if errMsg != "" { + return "", errors.New(errMsg) + } + case 2: + //找出微盟上有,excel上没有的,有就更新,没有就下架 + taskFunc2 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + goods := batchItemList[0].(*weimobapi.GoodsInfo) + goodsDetail := goods.GoodsDetailInfo + spuCode := goodsDetail.OuterGoodsCode + if spuCode != "" { + //如果微盟商品里找得到excel中的商品 + if skuMap[spuCode] != 0 { + //获取京西库商品 + skuList, _ := dao.GetSkus(db, nil, []int{int(utils.Str2Int64(goodsDetail.SkuMap.SingleSku.OuterSkuCode))}, nil, nil) + if len(skuList) == 0 { + errMsg += fmt.Sprintf("在京西库中未找到该商品!name_id : [%v] \n", goodsDetail.SkuMap.SingleSku.OuterSkuCode) + } else { + if skuList[0].Unit != "份" { + costPrice = Float64Round(0.5 / goodsDetail.SkuMap.SingleSku.B2CSku.Weight * skuMap[spuCode]) + } else { + costPrice = skuMap[spuCode] + } + if errMsg == "" { + _, _, err = updateWeiMobGoods(costPrice, skuMap[spuCode], goodsDetail) + } + } + } else { + //下架微盟商品 + goodsIDListForPutAway = append(goodsIDListForPutAway, goodsDetail.GoodsID) + } + } + return retVal, err + } + taskParallel2 := tasksch.NewParallelTask("获取微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc2, goodsList) + tasksch.HandleTask(taskParallel2, task, true).Run() + _, err = taskParallel2.GetResult(0) + case 3: + //批量下架微盟商品 + if errMsg == "" { + if len(goodsIDListForPutAway) <= 50 { //api要求最多传50个 + PutAwayWeiMobSku(goodsIDListForPutAway) + } else { + for i := 0; i < len(goodsIDListForPutAway)/50+1; i++ { + var int64Slice []int64 + if len(goodsIDListForPutAway) > 50*(i+1) { + int64Slice = goodsIDListForPutAway[i*50 : (i+1)*50+1] + } else { + int64Slice = goodsIDListForPutAway[i*50 : len(goodsIDListForPutAway)] + } + PutAwayWeiMobSku(int64Slice) + } + } + } } return result, err } - taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 4) + taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 2) tasksch.HandleTask(taskSeq, nil, true).Run() - for k, v := range skuMap { - fmt.Println(k, v) - } if errMsg != "" { baseapi.SugarLogger.Debugf(errMsg) } @@ -401,7 +426,7 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM } } } - if skuMap[skuID] != 0 && skuMap[skuID] != skuPrice { + if skuMap[skuID] != 0 && skuMap[skuID] != skuPrice && skuID != "" { if skuPrice > skuMap[skuID] { skuMap[skuID] = skuPrice } @@ -410,7 +435,7 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM skuMap[skuID] = skuPrice } if isHaveOrg { - if skuMap[orgSkuID] != 0 && skuMap[orgSkuID] != orgSkuPrice { + if skuMap[orgSkuID] != 0 && skuMap[orgSkuID] != orgSkuPrice && orgSkuID != "" { if orgSkuPrice > skuMap[orgSkuID] { skuMap[orgSkuID] = orgSkuPrice } diff --git a/controllers/yonghui.go b/controllers/yonghui.go index 3aa519f6c..d714ea019 100644 --- a/controllers/yonghui.go +++ b/controllers/yonghui.go @@ -1,7 +1,6 @@ package controllers import ( - "fmt" "io" "git.rosy.net.cn/jx-callback/business/jxstore/yonghui" @@ -36,8 +35,6 @@ func (c *YongHuiController) LoadExcelByYongHui() { } else if c.Ctx.Input.IsPost() { c.callLoadExcelByYongHui(func(params *tYonghuiLoadExcelByYongHuiParams) (retVal interface{}, errCode string, err error) { r := c.Ctx.Request - fmt.Println(r) - fmt.Println(r.MultipartForm) files := r.MultipartForm.File["userfiles"] retVal, err = yonghui.LoadExcelByYongHui(params.Ctx, files, params.IsAsync) return retVal, "", err From 3c46efe89d6f64dcd6cbb256edb4e709af00e7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 13 Nov 2019 09:59:20 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B0=B8=E8=BE=89Excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/yonghui/yonghui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 898a456aa..020926bfa 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -261,7 +261,7 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i } return result, err } - taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 2) + taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 4) tasksch.HandleTask(taskSeq, nil, true).Run() if errMsg != "" { baseapi.SugarLogger.Debugf(errMsg) From 705aa5153c1347733a13464c79d9b2814d328b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 13 Nov 2019 17:06:18 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B0=B8=E8=BE=89Excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/yonghui/yonghui.go | 330 +++++++++++----------------- 1 file changed, 131 insertions(+), 199 deletions(-) diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 020926bfa..980d8675a 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -20,80 +20,21 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" ) -var ( - sheetNames = []string{"蔬菜", "水果", "肉禽", "净配", "水产", "干货", "MINI肉禽价格"} - sheet1Name = "蔬菜" - sheet2Name = "水果" - sheet3Name = "肉禽" - sheet4Name = "净配" - sheet5Name = "水产" - sheet6Name = "干货" - sheet7Name = "MINI肉禽价格" -) +type SheetParam struct { + SkuIDCol int + SkuPriceCol int + OrgSkuIdCol int + OrgSkuPriceCol int + SkuRow int +} -//sheet1 蔬菜 var ( - sheet1SkuIDCol = 0 //商品的spu编码 - sheet1SkuPriceCol = 14 //对应商品的成本价 - sheet1OrgSkuIdCol = 5 //原料的spu编码 - sheet1OrgSkuPriceCol = 8 //对应原料的成本价 - sheet1SkuRow = 2 -) - -//sheet2 水果 -var ( - sheet2SkuIDCol = 0 - sheet2SkuPriceCol = 14 - sheet2OrgSkuIdCol = 5 - sheet2OrgSkuPriceCol = 8 - sheet2SkuRow = 2 -) - -//sheet3 肉禽 -var ( - sheet3SkuIDCol = 0 - sheet3SkuPriceCol = 12 - sheet3OrgSkuIdCol = 4 - sheet3OrgSkuPriceCol = 7 - sheet3SkuRow = 1 -) - -//sheet4 净配 -var ( - sheet4SkuIDCol = 0 - sheet4SkuPriceCol = 12 - sheet4OrgSkuIdCol = 4 - sheet4OrgSkuPriceCol = 7 - sheet4SkuRow = 1 -) - -//sheet5 水产 -var ( - sheet5SkuIDCol = 1 - sheet5SkuPriceCol = 15 - sheet5OrgSkuIdCol = 6 - sheet5OrgSkuPriceCol = 9 - sheet5SkuRow = 1 -) - -//sheet6 干货 -var ( - sheet6SkuIDCol = 0 - sheet6SkuPriceCol = 13 - sheet6OrgSkuIdCol = 4 - sheet6OrgSkuPriceCol = 7 - sheet6SkuRow = 2 -) - -//sheet7 MINI肉禽价格 -var ( - sheet7SkuIDCol = 1 - sheet7SkuPriceCol = 5 - sheet7SkuRow = 1 + sheetMap = make(map[string]*SheetParam) ) const ( - parallelCount = 5 + parallelCount = 5 + UpdateGoodsShelfStatusCount = 50 //微盟下架商品api限制一次50个 ) func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync bool) (hint string, err error) { @@ -101,8 +42,8 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i skuMap = make(map[string]float64) errMsg string costPrice float64 //成本价 - goodsIDListForPutAway []int64 goodsList []*weimobapi.GoodsInfo + goodsIDListForPutAway []int64 ) db := dao.GetDB() if len(files) == 0 { @@ -115,105 +56,62 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i if err != nil { return "", err } + initSheetMap() taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { switch step { case 0: - taskFunc1 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - v := batchItemList[0].(string) - rows, _ := xlsx.GetRows(v) + for k, _ := range sheetMap { + sheetParam := sheetMap[k] + rows, _ := xlsx.GetRows(k) for rowNum, row := range rows { - switch v { - case sheet1Name: - if rowNum < sheet1SkuRow { - continue - } - GetCellIntoMap(sheet1SkuIDCol, sheet1SkuPriceCol, sheet1OrgSkuIdCol, sheet1OrgSkuPriceCol, skuMap, true, row, v, rowNum) - if len(skuMap) < 1 { - errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) - } - case sheet2Name: - if rowNum < sheet2SkuRow { - continue - } - GetCellIntoMap(sheet2SkuIDCol, sheet2SkuPriceCol, sheet2OrgSkuIdCol, sheet2OrgSkuPriceCol, skuMap, true, row, v, rowNum) - if len(skuMap) < 1 { - errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) - } - case sheet3Name: - if rowNum < sheet3SkuRow { - continue - } - GetCellIntoMap(sheet3SkuIDCol, sheet3SkuPriceCol, sheet3OrgSkuIdCol, sheet3OrgSkuPriceCol, skuMap, true, row, v, rowNum) - if len(skuMap) < 1 { - errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) - } - case sheet4Name: - if rowNum < sheet4SkuRow { - continue - } - GetCellIntoMap(sheet4SkuIDCol, sheet4SkuPriceCol, sheet4OrgSkuIdCol, sheet4OrgSkuPriceCol, skuMap, true, row, v, rowNum) - if len(skuMap) < 1 { - errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) - } - case sheet5Name: - if rowNum < sheet5SkuRow { - continue - } - GetCellIntoMap(sheet5SkuIDCol, sheet5SkuPriceCol, sheet5OrgSkuIdCol, sheet5OrgSkuPriceCol, skuMap, true, row, v, rowNum) - if len(skuMap) < 1 { - errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) - } - case sheet6Name: - if rowNum < sheet6SkuRow { - continue - } - GetCellIntoMap(sheet6SkuIDCol, sheet6SkuPriceCol, sheet6OrgSkuIdCol, sheet6OrgSkuPriceCol, skuMap, true, row, v, rowNum) - if len(skuMap) < 1 { - errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) - } - case sheet7Name: - if rowNum < sheet7SkuRow { - continue - } - GetCellIntoMap(sheet7SkuIDCol, sheet7SkuPriceCol, 0, 0, skuMap, false, row, v, rowNum) - if len(skuMap) < 1 { - errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", v) - } - default: - return retVal, errors.New("未找到配置的sheet页,请检查excel内容排版格式是否发生变化!\n") + if rowNum < sheetParam.SkuRow { + continue + } + GetCellIntoMap(sheetParam.SkuIDCol, sheetParam.SkuPriceCol, sheetParam.OrgSkuIdCol, sheetParam.OrgSkuPriceCol, skuMap, row, k, rowNum) + if len(skuMap) < 1 { + errMsg += fmt.Sprintf("读取Excel数据失败,Excel格式排版可能发生了变化!sheetName: [%v]", k) } } if errMsg != "" { return "", errors.New(errMsg) } - return retVal, err } - taskParallel1 := tasksch.NewParallelTask("读取Excel", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc1, sheetNames) - tasksch.HandleTask(taskParallel1, task, true).Run() - _, err = taskParallel1.GetResult(0) case 1: //获取微盟所有商品 - goodsList = GetGoodsInfoAndDetail() + goodsList, err = GetWeiMobGoodsList() + if err != nil { + baseapi.SugarLogger.Errorf("GetWeiMobGoodsList error:%v", err) + } + taskFunc2 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + v := batchItemList[0].(*weimobapi.GoodsInfo) + goodsDetail, err := api.WeimobAPI.QueryGoodsDetail(v.GoodsID) + if err != nil { + baseapi.SugarLogger.Errorf("QueryGoodsDetail error:%v", err) + } + v.GoodsDetailInfo = goodsDetail + return retVal, err + } + taskParallel2 := tasksch.NewParallelTask("获取微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc2, goodsList) + tasksch.HandleTask(taskParallel2, task, true).Run() + _, err = taskParallel2.GetResult(0) //找出excel上有,微盟没有的,有就列出报错,不进行更新 goodsInfoAndDetailMap := GetGoodsInfoAndDetailMap(goodsList) - delete(skuMap, "") - for k, v := range skuMap { - fmt.Printf("key %v, value %v\n", k, v) + for k, _ := range skuMap { //表示excel上有,微盟上没有 if goodsInfoAndDetailMap[k] == nil { errMsg += fmt.Sprintf("在微盟上未找到该商品!excel商品ID : [%v]\n", k) } } - fmt.Println(len(skuMap)) if errMsg != "" { return "", errors.New(errMsg) } case 2: //找出微盟上有,excel上没有的,有就更新,没有就下架 - taskFunc2 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + taskFunc3 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { goods := batchItemList[0].(*weimobapi.GoodsInfo) goodsDetail := goods.GoodsDetailInfo spuCode := goodsDetail.OuterGoodsCode + goodsIDListForPutAway := []int64{} if spuCode != "" { //如果微盟商品里找得到excel中的商品 if skuMap[spuCode] != 0 { @@ -236,27 +134,32 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i goodsIDListForPutAway = append(goodsIDListForPutAway, goodsDetail.GoodsID) } } + retVal = goodsIDListForPutAway return retVal, err } - taskParallel2 := tasksch.NewParallelTask("获取微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc2, goodsList) - tasksch.HandleTask(taskParallel2, task, true).Run() - _, err = taskParallel2.GetResult(0) + taskParallel3 := tasksch.NewParallelTask("根据获取的微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc3, goodsList) + tasksch.HandleTask(taskParallel3, task, true).Run() + goodsIDListForPutAwayInterface, err2 := taskParallel3.GetResult(0) + if err = err2; err != nil { + return "", err + } + // 批量下架微盟商品 + for _, v := range goodsIDListForPutAwayInterface { + goodsIDListForPutAway = append(goodsIDListForPutAway, v.(int64)) + } case 3: - //批量下架微盟商品 if errMsg == "" { - if len(goodsIDListForPutAway) <= 50 { //api要求最多传50个 - PutAwayWeiMobSku(goodsIDListForPutAway) - } else { - for i := 0; i < len(goodsIDListForPutAway)/50+1; i++ { - var int64Slice []int64 - if len(goodsIDListForPutAway) > 50*(i+1) { - int64Slice = goodsIDListForPutAway[i*50 : (i+1)*50+1] - } else { - int64Slice = goodsIDListForPutAway[i*50 : len(goodsIDListForPutAway)] - } - PutAwayWeiMobSku(int64Slice) + taskFunc4 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + int64Slice := []int64{} + for _, v := range batchItemList { + int64Slice = append(int64Slice, v.(int64)) } + PutAwayWeiMobSku(int64Slice) + return retVal, err } + taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway) + tasksch.HandleTask(taskParallel4, task, true).Run() + _, err = taskParallel4.GetResult(0) } } return result, err @@ -284,28 +187,13 @@ func GetGoodsInfoAndDetailMap(goodsList []*weimobapi.GoodsInfo) (goodsMap map[st return goodsMap } -func GetGoodsInfoAndDetail() []*weimobapi.GoodsInfo { - goodsList, err := GetWeiMobGoodsList() - if err != nil { - baseapi.SugarLogger.Errorf("GetWeiMobGoodsList error:%v", err) - } - for _, v := range goodsList { - goodsDetail, err := api.WeimobAPI.QueryGoodsDetail(v.GoodsID) - if err != nil { - baseapi.SugarLogger.Errorf("QueryGoodsDetail error:%v", err) - } - v.GoodsDetailInfo = goodsDetail - } - return goodsList -} - func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.GoodsDetailInfo) (goodsID int64, skuMap map[string]int64, err error) { var ( - skuListParam []*weimobapi.SkuList - deliveryTypeListSlice []int64 - skuListInfo = goodsDetail.SkuList[0] categoryList []*weimobapi.CategoryList + skuListInfo = goodsDetail.SkuList[0] + skuListParam []*weimobapi.SkuList categoryID int + deliveryTypeListSlice []int64 ) //查询配送方式 @@ -326,12 +214,7 @@ func updateWeiMobGoods(costPrice, salePrice float64, goodsDetail *weimobapi.Good //寻找分类子ID categoryList = goodsDetail.CategoryList if len(categoryList) > 0 { - for k, v := range categoryList { - if k < len(categoryList)-1 { - continue - } - categoryID = v.CategoryID - } + categoryID = categoryList[len(categoryList)-1].CategoryID } else { return 0, nil, errors.New(fmt.Sprintf("未查询到此商品的分类信息!goodsID : [%v] ,", goodsDetail.GoodsID)) } @@ -401,7 +284,7 @@ func IsChineseChar(str string) bool { return false } -func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuMap map[string]float64, isHaveOrg bool, row []string, sheetName string, rowNum int) { +func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuMap map[string]float64, row []string, sheetName string, rowNum int) { var ( skuID string orgSkuID string @@ -410,23 +293,21 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM ) for k, cell := range row { if !IsChineseChar(cell) && cell != "" { - if k == skuIDCol { + if k == skuIDCol && skuIDCol >= 0 { skuID = cell } - if k == skuPriceCol { + if k == skuPriceCol && skuPriceCol >= 0 { skuPrice = Float64Round(utils.Str2Float64(cell)) } - if isHaveOrg { - if k == orgSkuIDCol { - orgSkuID = "0" + cell - } - if k == orgSkuPriceCol { - orgSkuPrice = Float64Round(utils.Str2Float64(cell)) - } + if k == orgSkuIDCol && orgSkuIDCol >= 0 { + orgSkuID = "0" + cell + } + if k == orgSkuPriceCol && orgSkuPriceCol >= 0 { + orgSkuPrice = Float64Round(utils.Str2Float64(cell)) } } } - if skuMap[skuID] != 0 && skuMap[skuID] != skuPrice && skuID != "" { + if skuMap[skuID] != 0 && skuMap[skuID] != skuPrice { if skuPrice > skuMap[skuID] { skuMap[skuID] = skuPrice } @@ -434,16 +315,15 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM } else { skuMap[skuID] = skuPrice } - if isHaveOrg { - if skuMap[orgSkuID] != 0 && skuMap[orgSkuID] != orgSkuPrice && orgSkuID != "" { - if orgSkuPrice > skuMap[orgSkuID] { - skuMap[orgSkuID] = orgSkuPrice - } - // fmt.Sprintf("读取excel表格出错!有商品ID重复且价格不同,sheetName : [%v] ,行数 : [%v], 商品编码 :[%v] , 价格:[%v]\n", sheetName, rowNum, orgSkuID, orgSkuPrice) - } else { + if skuMap[orgSkuID] != 0 && skuMap[orgSkuID] != orgSkuPrice { + if orgSkuPrice > skuMap[orgSkuID] { skuMap[orgSkuID] = orgSkuPrice } + // fmt.Sprintf("读取excel表格出错!有商品ID重复且价格不同,sheetName : [%v] ,行数 : [%v], 商品编码 :[%v] , 价格:[%v]\n", sheetName, rowNum, orgSkuID, orgSkuPrice) + } else if orgSkuPriceCol >= 0 && orgSkuIDCol >= 0 { + skuMap[orgSkuID] = orgSkuPrice } + delete(skuMap, "") } func Float64Round(f float64) (flt float64) { @@ -453,3 +333,55 @@ func Float64Round(f float64) (flt float64) { } return flt } + +func initSheetMap() { + sheetMap["蔬菜"] = &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 14, + OrgSkuIdCol: 5, + OrgSkuPriceCol: 8, + SkuRow: 2, + } + sheetMap["水果"] = &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 14, + OrgSkuIdCol: 5, + OrgSkuPriceCol: 8, + SkuRow: 2, + } + sheetMap["肉禽"] = &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 12, + OrgSkuIdCol: 4, + OrgSkuPriceCol: 7, + SkuRow: 1, + } + sheetMap["净配"] = &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 12, + OrgSkuIdCol: 4, + OrgSkuPriceCol: 7, + SkuRow: 1, + } + sheetMap["水产"] = &SheetParam{ + SkuIDCol: 1, + SkuPriceCol: 15, + OrgSkuIdCol: 6, + OrgSkuPriceCol: 9, + SkuRow: 1, + } + sheetMap["干货"] = &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 13, + OrgSkuIdCol: 4, + OrgSkuPriceCol: 7, + SkuRow: 2, + } + sheetMap["MINI肉禽价格"] = &SheetParam{ + SkuIDCol: 1, + SkuPriceCol: 5, + OrgSkuIdCol: -1, + OrgSkuPriceCol: -1, + SkuRow: 1, + } +} From 8df7f897fa70dc5e1df911bf29cec4b402d754e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 13 Nov 2019 18:11:58 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B0=B8=E8=BE=89Excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/yonghui/yonghui.go | 133 ++++++++++++---------------- 1 file changed, 57 insertions(+), 76 deletions(-) diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 980d8675a..1bfa564f0 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -3,8 +3,8 @@ package yonghui import ( "errors" "fmt" + "math" "mime/multipart" - "strconv" "unicode" "git.rosy.net.cn/baseapi" @@ -29,7 +29,51 @@ type SheetParam struct { } var ( - sheetMap = make(map[string]*SheetParam) + sheetMap = map[string]*SheetParam{ + "蔬菜": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 14, + OrgSkuIdCol: 5, + OrgSkuPriceCol: 8, + SkuRow: 2, + }, "水果": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 14, + OrgSkuIdCol: 5, + OrgSkuPriceCol: 8, + SkuRow: 2, + }, "肉禽": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 12, + OrgSkuIdCol: 4, + OrgSkuPriceCol: 7, + SkuRow: 1, + }, "净配": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 12, + OrgSkuIdCol: 4, + OrgSkuPriceCol: 7, + SkuRow: 1, + }, "水产": &SheetParam{ + SkuIDCol: 1, + SkuPriceCol: 15, + OrgSkuIdCol: 6, + OrgSkuPriceCol: 9, + SkuRow: 1, + }, "干货": &SheetParam{ + SkuIDCol: 0, + SkuPriceCol: 13, + OrgSkuIdCol: 4, + OrgSkuPriceCol: 7, + SkuRow: 2, + }, "MINI肉禽价格": &SheetParam{ + SkuIDCol: 1, + SkuPriceCol: 5, + OrgSkuIdCol: -1, + OrgSkuPriceCol: -1, + SkuRow: 1, + }, + } ) const ( @@ -43,23 +87,20 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i errMsg string costPrice float64 //成本价 goodsList []*weimobapi.GoodsInfo - goodsIDListForPutAway []int64 + goodsIDListForPutAway []interface{} ) db := dao.GetDB() if len(files) == 0 { return "", errors.New("没有文件上传!") } - - //读取excel文件 - xlsx, err := excelize.OpenFile(files[0].Filename) - // xlsx, err := excelize.OpenFile("111.xlsx") - if err != nil { - return "", err - } - initSheetMap() taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { switch step { case 0: + //读取excel文件 + xlsx, err := excelize.OpenFile(files[0].Filename) + if err != nil { + return "", err + } for k, _ := range sheetMap { sheetParam := sheetMap[k] rows, _ := xlsx.GetRows(k) @@ -111,7 +152,6 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i goods := batchItemList[0].(*weimobapi.GoodsInfo) goodsDetail := goods.GoodsDetailInfo spuCode := goodsDetail.OuterGoodsCode - goodsIDListForPutAway := []int64{} if spuCode != "" { //如果微盟商品里找得到excel中的商品 if skuMap[spuCode] != 0 { @@ -131,10 +171,9 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i } } else { //下架微盟商品 - goodsIDListForPutAway = append(goodsIDListForPutAway, goodsDetail.GoodsID) + retVal = []int64{goodsDetail.GoodsID} } } - retVal = goodsIDListForPutAway return retVal, err } taskParallel3 := tasksch.NewParallelTask("根据获取的微盟所有商品并更新", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx, taskFunc3, goodsList) @@ -144,9 +183,7 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i return "", err } // 批量下架微盟商品 - for _, v := range goodsIDListForPutAwayInterface { - goodsIDListForPutAway = append(goodsIDListForPutAway, v.(int64)) - } + goodsIDListForPutAway = goodsIDListForPutAwayInterface case 3: if errMsg == "" { taskFunc4 := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { @@ -297,13 +334,13 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM skuID = cell } if k == skuPriceCol && skuPriceCol >= 0 { - skuPrice = Float64Round(utils.Str2Float64(cell)) + skuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0)) } if k == orgSkuIDCol && orgSkuIDCol >= 0 { orgSkuID = "0" + cell } if k == orgSkuPriceCol && orgSkuPriceCol >= 0 { - orgSkuPrice = Float64Round(utils.Str2Float64(cell)) + orgSkuPrice = Float64Round(utils.Str2Float64WithDefault(cell, 0)) } } } @@ -327,61 +364,5 @@ func GetCellIntoMap(skuIDCol, skuPriceCol, orgSkuIDCol, orgSkuPriceCol int, skuM } func Float64Round(f float64) (flt float64) { - flt, err := strconv.ParseFloat(fmt.Sprintf("%.2f", f), 64) - if err != nil { - flt = 0 - } - return flt -} - -func initSheetMap() { - sheetMap["蔬菜"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 14, - OrgSkuIdCol: 5, - OrgSkuPriceCol: 8, - SkuRow: 2, - } - sheetMap["水果"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 14, - OrgSkuIdCol: 5, - OrgSkuPriceCol: 8, - SkuRow: 2, - } - sheetMap["肉禽"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 12, - OrgSkuIdCol: 4, - OrgSkuPriceCol: 7, - SkuRow: 1, - } - sheetMap["净配"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 12, - OrgSkuIdCol: 4, - OrgSkuPriceCol: 7, - SkuRow: 1, - } - sheetMap["水产"] = &SheetParam{ - SkuIDCol: 1, - SkuPriceCol: 15, - OrgSkuIdCol: 6, - OrgSkuPriceCol: 9, - SkuRow: 1, - } - sheetMap["干货"] = &SheetParam{ - SkuIDCol: 0, - SkuPriceCol: 13, - OrgSkuIdCol: 4, - OrgSkuPriceCol: 7, - SkuRow: 2, - } - sheetMap["MINI肉禽价格"] = &SheetParam{ - SkuIDCol: 1, - SkuPriceCol: 5, - OrgSkuIdCol: -1, - OrgSkuPriceCol: -1, - SkuRow: 1, - } + return math.Round(f*100) / 100 } From 32eb1a6dbe040e8c375612e669c7bfcdd4b407f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 13 Nov 2019 18:18:12 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B0=B8=E8=BE=89Excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/yonghui/yonghui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 1bfa564f0..1d96e02c8 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -191,7 +191,7 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i for _, v := range batchItemList { int64Slice = append(int64Slice, v.(int64)) } - PutAwayWeiMobSku(int64Slice) + // PutAwayWeiMobSku(int64Slice) return retVal, err } taskParallel4 := tasksch.NewParallelTask("下架微盟商品", tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetBatchSize(UpdateGoodsShelfStatusCount), ctx, taskFunc4, goodsIDListForPutAway) From e15e7ed9e2541d0a2182dfeb1e29b8b8d4c11bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 14 Nov 2019 11:45:16 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=8F=AF=E5=94=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 30 +++++++++++++++++++++++++++++ business/jxstore/misc/misc.go | 29 ++++++++++++++++++++++++++++ business/jxstore/yonghui/yonghui.go | 8 +++++++- business/model/dao/store_sku.go | 27 ++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 750931e3e..844e3ec09 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -3,6 +3,7 @@ package cms import ( "errors" "fmt" + "time" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -653,3 +654,32 @@ func (v *VendorSync) SyncSkuNames(ctx *jxcontext.Context, nameIDs []int, isForce } return v.SyncSkus(ctx, db, nameIDs, nil, isAsync, isContinueWhenError, ctx.GetUserName()) } + +func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (err error) { + var ( + storeIDs []int + skuIDs []int + vendorIDs = []int{0, 1, 3} + ) + db := dao.GetDB() + now := time.Now().Hour()*100 + time.Now().Minute() + storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db) + for _, v := range storeSkuList { + if (now >= v.TimeBegin1 && now <= v.TimeEnd1) || (now >= v.TimeBegin2 && now <= v.TimeEnd2) { + skuIDs = append(skuIDs, v.StoreSkuBind.SkuID) + storeIDs = append(storeIDs, v.StoreSkuBind.StoreID) + v.StoreSkuBind.Status = model.SkuStatusDontSale + setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagSaleMask) + dao.UpdateEntity(db, &v.StoreSkuBind) + } else { + v.StoreSkuBind.Status = model.SkuStatusNormal + setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagSaleMask) + dao.UpdateEntity(db, &v.StoreSkuBind) + } + } + v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError) + if err != nil { + return err + } + return nil +} diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 807ba34a5..84c8c83a9 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -46,6 +46,32 @@ var ( "19:00:00", "22:00:00", } + ChangeStoreSkuSaleStatusList = []string{ + "0:00:00", + "1:00:00", + "2:00:00", + "3:00:00", + "4:00:00", + "5:00:00", + "6:00:00", + "7:00:00", + "8:00:00", + "9:00:00", + "10:00:00", + "11:00:00", + "12:00:00", + "13:00:00", + "14:00:00", + "15:00:00", + "16:00:00", + "17:00:00", + "18:00:00", + "19:00:00", + "20:00:00", + "21:00:00", + "22:00:00", + "23:00:00", + } openRemoteStoreTimeList = []string{ "23:30:00", } @@ -117,6 +143,9 @@ func Init() { }, []string{ "04:05:06", }) + ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() { + cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, false, false) + }, ChangeStoreSkuSaleStatusList) } } diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 1d96e02c8..08722141e 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -203,10 +203,16 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i } taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 4) tasksch.HandleTask(taskSeq, nil, true).Run() + if !isAsync { + _, err = taskSeq.GetResult(0) + hint = "1" + } else { + hint = taskSeq.GetID() + } if errMsg != "" { baseapi.SugarLogger.Debugf(errMsg) } - return "", err + return hint, err } func PutAwayWeiMobSku(goodsIDListForPutAway []int64) { diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 310e2ad7b..2bc996ed9 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -107,6 +107,14 @@ type StoreSkuNameInfo struct { UnitPrice int64 } +type StoreSkuBindWithSaleTime struct { + StoreSkuBind model.StoreSkuBind + TimeBegin1 int + TimeEnd1 int + TimeBegin2 int + TimeEnd2 int +} + // todo 应该通过需要同步的skuid来驱动同步分类,而不是当前这种分开的逻辑 // 单门店模式厂商适用 // 从store_sku_bind中,得到所有依赖的商家分类信息 @@ -584,3 +592,22 @@ func (s *StoreSkuSyncInfo) GetSeq() int { } return int(s.VendorPrice) } + +func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*StoreSkuBindWithSaleTime, err error) { + sql := ` + SELECT t1.*, + IF(t2.open_time1 <= t1.status_sale_begin,t2.open_time1,0) time_begin1, + IF(t2.open_time1 <= t1.status_sale_begin,t1.status_sale_begin,0) time_end1, + IF(t2.close_time1 >= t1.status_sale_end,t1.status_sale_end,0) time_begin2, + IF(t2.close_time1 >= t1.status_sale_end,t2.close_time1,0) time_end2 + FROM store_sku_bind t1 + JOIN store t2 ON t1.store_id = t2.id + WHERE t1.status_sale_begin <> 0 AND t1.status_sale_end <> 0 + AND t1.status != ? + ` + sqlParams := []interface{}{ + model.SkuStatusDeleted, + } + err = GetRows(db, &storeSkuBindList, sql, sqlParams...) + return storeSkuBindList, err +} From bcc534289a8a06b5b8830243b8bec0a8588954c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 14 Nov 2019 18:03:34 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=8F=AF=E5=94=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync.go | 51 +++++++++++++++++--------- business/jxstore/cms/sync_store_sku.go | 29 ++++++++++++++- business/jxstore/misc/misc.go | 12 +----- business/model/dao/store_sku.go | 38 +++++++++---------- business/model/store_sku.go | 3 ++ 5 files changed, 83 insertions(+), 50 deletions(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 844e3ec09..ab204b4bd 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -3,7 +3,6 @@ package cms import ( "errors" "fmt" - "time" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -657,29 +656,47 @@ func (v *VendorSync) SyncSkuNames(ctx *jxcontext.Context, nameIDs []int, isForce func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (err error) { var ( - storeIDs []int - skuIDs []int - vendorIDs = []int{0, 1, 3} + storeIDs []int + skuIDs []int ) + vendorIDs := partner.GetPurchasePlatformVendorIDs() db := dao.GetDB() - now := time.Now().Hour()*100 + time.Now().Minute() storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db) for _, v := range storeSkuList { - if (now >= v.TimeBegin1 && now <= v.TimeEnd1) || (now >= v.TimeBegin2 && now <= v.TimeEnd2) { - skuIDs = append(skuIDs, v.StoreSkuBind.SkuID) - storeIDs = append(storeIDs, v.StoreSkuBind.StoreID) - v.StoreSkuBind.Status = model.SkuStatusDontSale - setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagSaleMask) - dao.UpdateEntity(db, &v.StoreSkuBind) - } else { - v.StoreSkuBind.Status = model.SkuStatusNormal - setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagSaleMask) - dao.UpdateEntity(db, &v.StoreSkuBind) - } + storeIDs = append(storeIDs, v.StoreID) + skuIDs = append(skuIDs, v.SkuID) + setStoreSkuBindStatus(v, model.SyncFlagSaleMask) + dao.UpdateEntity(db, v) + } + if len(storeSkuList) > 0 { + v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError) + } else { + return errors.New("未查询到设置了可售时间的商品!") } - v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError) if err != nil { return err } return nil } + +func GetTimeMixByInt(begin1, end1, begin2, end2 int) (beginAt, endAt int) { + if (begin1 > begin2 && begin1 > end2) || (begin2 > end1 && end2 > end1) { + return 0, 0 + } + if begin1 > begin2 { + beginAt = begin1 + if end1 > end2 { + endAt = end2 + } else { + endAt = end1 + } + } else { + beginAt = begin2 + if end1 > end2 { + endAt = end2 + } else { + endAt = end1 + } + } + return beginAt, endAt +} diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index d63cf40d9..94765a658 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -299,6 +299,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo } else { skus, err = dao.GetStoreSkus(db, vendorID, storeID, skuIDs) } + if err != nil || len(skus) == 0 { return err } @@ -328,8 +329,13 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo if reorderHandler != nil { reorderSkuMap = make(map[string][]*dao.StoreSkuSyncInfo) } - + now := time.Now().Hour()*100 + time.Now().Minute() for _, sku := range skus { + if isUpdateSkuSaleStatus(sku, now) { + sku.MergedStatus = model.SkuStatusDontSale + } else { + sku.MergedStatus = model.SkuStatusNormal + } var bareSku *partner.StoreSkuInfo isNeedReorder := false if isStoreSkuSyncNeedDelete(sku) { @@ -795,3 +801,24 @@ func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, st return "" } + +func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, now int) bool { + //商品可售时间的差集与门店营业时间的交集为不可售,其余为原本状态 + openTime := sku.OpenTime + closeTime := sku.CloseTime + saleBeginTime := sku.StatusSaleBegin + saleEndTime := sku.StatusSaleEnd + beginAt1, endAt1 := GetTimeMixByInt(0, saleBeginTime, openTime, closeTime) + beginAt2, endAt2 := GetTimeMixByInt(saleEndTime, 2400, openTime, closeTime) + if beginAt1 != 0 && endAt1 != 0 { + if now > beginAt1 && now < endAt1 { + return true + } + } + if beginAt2 != 0 && endAt2 != 0 { + if now > beginAt2 && now < endAt2 { + return true + } + } + return false +} diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 84c8c83a9..82d5bf82d 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -47,13 +47,6 @@ var ( "22:00:00", } ChangeStoreSkuSaleStatusList = []string{ - "0:00:00", - "1:00:00", - "2:00:00", - "3:00:00", - "4:00:00", - "5:00:00", - "6:00:00", "7:00:00", "8:00:00", "9:00:00", @@ -68,9 +61,6 @@ var ( "18:00:00", "19:00:00", "20:00:00", - "21:00:00", - "22:00:00", - "23:00:00", } openRemoteStoreTimeList = []string{ "23:30:00", @@ -144,7 +134,7 @@ func Init() { "04:05:06", }) ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() { - cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, false, false) + cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, true, false) }, ChangeStoreSkuSaleStatusList) } } diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 2bc996ed9..d42ba9b30 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -79,9 +79,13 @@ type StoreSkuSyncInfo struct { StoreCatSyncStatus int8 VendorCatID string `orm:"column(vendor_cat_id)"` - VendorPrice int64 - MergedStatus int - SkuName string + VendorPrice int64 + MergedStatus int + SkuName string + StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围 + StatusSaleEnd int `json:"statusSaleEnd"` + OpenTime int //门店营业时间 + CloseTime int } type MissingStoreSkuInfo struct { @@ -107,14 +111,6 @@ type StoreSkuNameInfo struct { UnitPrice int64 } -type StoreSkuBindWithSaleTime struct { - StoreSkuBind model.StoreSkuBind - TimeBegin1 int - TimeEnd1 int - TimeBegin2 int - TimeEnd2 int -} - // todo 应该通过需要同步的skuid来驱动同步分类,而不是当前这种分开的逻辑 // 单门店模式厂商适用 // 从store_sku_bind中,得到所有依赖的商家分类信息 @@ -224,7 +220,9 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty boo fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID]) sql := ` SELECT t1.id bind_id, t1.sku_id, t1.price, t1.unit_price, t1.status store_sku_status, %s.%s_id vendor_sku_id, - t1.%s_sync_status store_sku_sync_status, t1.store_id, t1.deleted_at bind_deleted_at, + t1.%s_sync_status store_sku_sync_status, t1.store_id, t1.deleted_at bind_deleted_at,t1.status_sale_begin,t1.status_sale_end, + IF(t6.open_time2 <> 0 AND t6.close_time2 <>0,IF(t6.open_time1 < t6.open_time2,t6.open_time1,t6.open_time2),t6.open_time1) open_time, + IF(t6.open_time2 <> 0 AND t6.close_time2 <>0,IF(t6.close_time1 > t6.close_time2,t6.close_time1,t6.close_time2),t6.close_time1) close_time, t2.*, t3.id name_id, t3.prefix, t3.name, t3.unit, t3.upc, IF(t11.%s <> '', t11.%s, t3.img) img, @@ -257,6 +255,7 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty boo LEFT JOIN data_resource t11 ON t11.main_url = t3.img LEFT JOIN data_resource t12 ON t12.main_url = t3.img2 LEFT JOIN data_resource t13 ON t13.main_url = t3.desc_img + LEFT JOIN store t6 ON t6.id = t1.store_id ` sqlParams := []interface{}{ utils.DefaultTimeValue, @@ -593,20 +592,17 @@ func (s *StoreSkuSyncInfo) GetSeq() int { return int(s.VendorPrice) } -func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*StoreSkuBindWithSaleTime, err error) { +func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*model.StoreSkuBind, err error) { sql := ` - SELECT t1.*, - IF(t2.open_time1 <= t1.status_sale_begin,t2.open_time1,0) time_begin1, - IF(t2.open_time1 <= t1.status_sale_begin,t1.status_sale_begin,0) time_end1, - IF(t2.close_time1 >= t1.status_sale_end,t1.status_sale_end,0) time_begin2, - IF(t2.close_time1 >= t1.status_sale_end,t2.close_time1,0) time_end2 + SELECT t1.* FROM store_sku_bind t1 - JOIN store t2 ON t1.store_id = t2.id WHERE t1.status_sale_begin <> 0 AND t1.status_sale_end <> 0 - AND t1.status != ? + AND t1.status = ? + AND t1.deleted_at = ? ` sqlParams := []interface{}{ - model.SkuStatusDeleted, + model.SkuStatusNormal, + utils.DefaultTimeValue, } err = GetRows(db, &storeSkuBindList, sql, sqlParams...) return storeSkuBindList, err diff --git a/business/model/store_sku.go b/business/model/store_sku.go index 9147b3646..c7d54ed89 100644 --- a/business/model/store_sku.go +++ b/business/model/store_sku.go @@ -112,6 +112,9 @@ type StoreSkuBind struct { // WscPrice int `json:"wscPrice"` AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"` + + StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围 + StatusSaleEnd int `json:"statusSaleEnd"` } func (*StoreSkuBind) TableUnique() [][]string { From 7305f1a6af90bba033b140d8738eb811caa8282a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 15 Nov 2019 09:47:10 +0800 Subject: [PATCH 13/17] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=8F=AF=E5=94=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 22 ++++++++----- business/jxstore/cms/sync.go | 14 ++++----- business/jxstore/cms/sync_store_sku.go | 25 ++++++++++++--- business/jxstore/cms/sync_store_sku_test.go | 12 +++++++ business/jxutils/jxutils.go | 4 +++ business/model/dao/store_sku.go | 35 ++++++++++++++++++--- 6 files changed, 87 insertions(+), 25 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 88c6833da..30257ce9c 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -116,13 +116,15 @@ type StoreSkuBindSkuInfo struct { // UpdateStoreSku用,API调用时 type StoreSkuBindInfo struct { - StoreID int `json:"storeID"` - NameID int `json:"nameID"` - UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价 - IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注 - IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售 - SubStoreID int `json:"subStoreID,omitempty"` - Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"` + StoreID int `json:"storeID"` + NameID int `json:"nameID"` + UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价 + IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注 + IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售 + SubStoreID int `json:"subStoreID,omitempty"` + StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围 + StatusSaleEnd int `json:"statusSaleEnd"` + Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"` } type tStoreSkuBindAndSpec struct { @@ -1076,6 +1078,12 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs updateFieldMap["Price"] = 1 updateFieldMap["JxPrice"] = 1 } + if skuBindInfo.StatusSaleBegin != 0 && skuBindInfo.StatusSaleEnd != 0 { + updateFieldMap["StatusSaleBegin"] = skuBindInfo.StatusSaleBegin + updateFieldMap["StatusSaleEnd"] = skuBindInfo.StatusSaleEnd + skuBind.StatusSaleBegin = skuBindInfo.StatusSaleBegin + skuBind.StatusSaleEnd = skuBindInfo.StatusSaleEnd + } // todo 这里应该是不需处理这个信息的吧? // if inSkuBind != nil && inSkuBind.EbaiID != 0 { // skuBind.EbaiID = inSkuBind.EbaiID diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index ab204b4bd..2b5e3cf7a 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -659,20 +659,18 @@ func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, i storeIDs []int skuIDs []int ) - vendorIDs := partner.GetPurchasePlatformVendorIDs() db := dao.GetDB() storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db) + if len(storeSkuList) < 1 || err != nil { + return errors.New(fmt.Sprintf("未查询到设置了可售时间的商品 GetStoresSkusInfoBySaleTime!err : %v", err)) + } for _, v := range storeSkuList { storeIDs = append(storeIDs, v.StoreID) skuIDs = append(skuIDs, v.SkuID) - setStoreSkuBindStatus(v, model.SyncFlagSaleMask) - dao.UpdateEntity(db, v) - } - if len(storeSkuList) > 0 { - v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError) - } else { - return errors.New("未查询到设置了可售时间的商品!") } + vendorIDs := partner.GetPurchasePlatformVendorIDs() + dao.UpdateStoreSkuBindSyncStatus(db, vendorIDs) + v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError) if err != nil { return err } diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 94765a658..647f65dc1 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -329,9 +329,9 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo if reorderHandler != nil { reorderSkuMap = make(map[string][]*dao.StoreSkuSyncInfo) } - now := time.Now().Hour()*100 + time.Now().Minute() + now := jxutils.OperationTime2HourMinuteFormat(time.Now()) for _, sku := range skus { - if isUpdateSkuSaleStatus(sku, now) { + if isUpdateSkuSaleStatus(sku, storeDetail, now) { sku.MergedStatus = model.SkuStatusDontSale } else { sku.MergedStatus = model.SkuStatusNormal @@ -802,12 +802,27 @@ func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, st return "" } -func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, now int) bool { +func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, storeDetail *dao.StoreDetail, now int) bool { //商品可售时间的差集与门店营业时间的交集为不可售,其余为原本状态 - openTime := sku.OpenTime - closeTime := sku.CloseTime + var openTime int + var closeTime int saleBeginTime := sku.StatusSaleBegin saleEndTime := sku.StatusSaleEnd + if storeDetail.OpenTime2 != 0 && storeDetail.CloseTime2 != 0 { + if storeDetail.OpenTime1 < storeDetail.OpenTime2 { + openTime = int(storeDetail.OpenTime1) + } else { + openTime = int(storeDetail.OpenTime2) + } + if storeDetail.CloseTime1 > storeDetail.CloseTime2 { + closeTime = int(storeDetail.CloseTime1) + } else { + closeTime = int(storeDetail.CloseTime2) + } + } else { + openTime = int(storeDetail.OpenTime1) + closeTime = int(storeDetail.CloseTime1) + } beginAt1, endAt1 := GetTimeMixByInt(0, saleBeginTime, openTime, closeTime) beginAt2, endAt2 := GetTimeMixByInt(saleEndTime, 2400, openTime, closeTime) if beginAt1 != 0 && endAt1 != 0 { diff --git a/business/jxstore/cms/sync_store_sku_test.go b/business/jxstore/cms/sync_store_sku_test.go index acd9abfcf..0df67e1a0 100644 --- a/business/jxstore/cms/sync_store_sku_test.go +++ b/business/jxstore/cms/sync_store_sku_test.go @@ -1,6 +1,7 @@ package cms import ( + "fmt" "testing" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" @@ -30,3 +31,14 @@ func TestFreeBatchStoreSkuInfo(t *testing.T) { t.Fatal(err) } } + +func TestGetTimeMixByInt(t *testing.T) { + var ( + time1 = 1100 + time2 = 2300 + time3 = 1200 + time4 = 2400 + ) + a, b := GetTimeMixByInt(time1, time2, time3, time4) + fmt.Println(a, b) +} diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index b0469f187..d43e503d0 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -688,6 +688,10 @@ func OperationTimeStr4VendorStore(v *model.VendorStoreSnapshot) (str string) { return str } +func OperationTime2HourMinuteFormat(time time.Time) (i int) { + return time.Hour()*100 + time.Minute() +} + // 得到饿百订单的取货码 func GetEbaiOrderGetCode(order *model.GoodsOrder) (getCode string) { if order.VendorID == model.VendorIDEBAI && len(order.VendorOrderID2) >= 4 { diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index d42ba9b30..b20942a45 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -1,7 +1,9 @@ package dao import ( + "errors" "fmt" + "strings" "time" "git.rosy.net.cn/baseapi/utils" @@ -84,8 +86,6 @@ type StoreSkuSyncInfo struct { SkuName string StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围 StatusSaleEnd int `json:"statusSaleEnd"` - OpenTime int //门店营业时间 - CloseTime int } type MissingStoreSkuInfo struct { @@ -221,8 +221,6 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty boo sql := ` SELECT t1.id bind_id, t1.sku_id, t1.price, t1.unit_price, t1.status store_sku_status, %s.%s_id vendor_sku_id, t1.%s_sync_status store_sku_sync_status, t1.store_id, t1.deleted_at bind_deleted_at,t1.status_sale_begin,t1.status_sale_end, - IF(t6.open_time2 <> 0 AND t6.close_time2 <>0,IF(t6.open_time1 < t6.open_time2,t6.open_time1,t6.open_time2),t6.open_time1) open_time, - IF(t6.open_time2 <> 0 AND t6.close_time2 <>0,IF(t6.close_time1 > t6.close_time2,t6.close_time1,t6.close_time2),t6.close_time1) close_time, t2.*, t3.id name_id, t3.prefix, t3.name, t3.unit, t3.upc, IF(t11.%s <> '', t11.%s, t3.img) img, @@ -255,7 +253,6 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty boo LEFT JOIN data_resource t11 ON t11.main_url = t3.img LEFT JOIN data_resource t12 ON t12.main_url = t3.img2 LEFT JOIN data_resource t13 ON t13.main_url = t3.desc_img - LEFT JOIN store t6 ON t6.id = t1.store_id ` sqlParams := []interface{}{ utils.DefaultTimeValue, @@ -607,3 +604,31 @@ func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*model.StoreSkuB err = GetRows(db, &storeSkuBindList, sql, sqlParams...) return storeSkuBindList, err } + +func UpdateStoreSkuBindSyncStatus(db *DaoDB, vendorIDs []int) (num int64, err error) { + sql := ` + UPDATE store_sku_bind + SET + ` + fmtParams := []interface{}{} + sqlParams := []interface{}{} + if len(vendorIDs) > 0 { + for _, v := range vendorIDs { + fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[v]) + sql += ` %s_sync_status = ?,` + fmtParams = append(fmtParams, fieldPrefix) + sqlParams = append(sqlParams, model.SyncFlagSaleMask) + } + } else { + return 0, errors.New("取平台ID名有错误!partner.GetPurchasePlatformVendorIDs()") + } + sql = sql[0:strings.LastIndex(sql, ",")] + sql = fmt.Sprintf(sql, fmtParams...) + sql += ` WHERE status = ? + AND deleted_at = ? + AND status_sale_begin <> 0 + AND status_sale_end <> 0 + ` + sqlParams = append(sqlParams, model.StoreSkuBindStatusNormal, utils.DefaultTimeValue) + return ExecuteSQL(db, sql, sqlParams...) +} From a929498359b171a16b0dd0313df11b4b2b8ec86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 15 Nov 2019 10:03:57 +0800 Subject: [PATCH 14/17] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=8F=AF=E5=94=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sync_store_sku.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 647f65dc1..e21dc6c50 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -826,12 +826,12 @@ func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, storeDetail *dao.StoreDeta beginAt1, endAt1 := GetTimeMixByInt(0, saleBeginTime, openTime, closeTime) beginAt2, endAt2 := GetTimeMixByInt(saleEndTime, 2400, openTime, closeTime) if beginAt1 != 0 && endAt1 != 0 { - if now > beginAt1 && now < endAt1 { + if now >= beginAt1 && now < endAt1 { return true } } if beginAt2 != 0 && endAt2 != 0 { - if now > beginAt2 && now < endAt2 { + if now >= beginAt2 && now < endAt2 { return true } } From 4d013ad28b42acb1d15fc162cd32f8315e03473d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 15 Nov 2019 11:58:53 +0800 Subject: [PATCH 15/17] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=8F=AF=E5=94=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store.go | 3 +++ business/jxstore/cms/store_sku.go | 17 +++++++++++++---- business/jxstore/cms/sync.go | 6 +++--- business/jxstore/cms/sync_store_sku.go | 18 +++++++++--------- business/jxstore/misc/misc.go | 2 +- business/jxutils/jxutils.go | 4 ++-- business/model/dao/store_sku.go | 10 +++++++--- business/model/store_sku.go | 4 ++-- 8 files changed, 40 insertions(+), 24 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 5f2160e21..fa19987ba 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -777,6 +777,9 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa dao.Commit(db) } notifyStoreOperatorChanged(store, valid["operatorPhone"]) + if (valid["openTime1"] != 0 && valid["closeTime1"] != 0) && (valid["openTime2"] != 0) && (valid["closeTime2"] != 0) { + err = CurVendorSync.ChangeStoreSkuSaleStatus(ctx, true, false, storeID) + } } } else { globals.SugarLogger.Debugf("UpdateStore track:%s, store:%s", ctx.GetTrackInfo(), utils.Format4Output(store, true)) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 30257ce9c..6bdf996ad 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -122,8 +122,8 @@ type StoreSkuBindInfo struct { IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注 IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售 SubStoreID int `json:"subStoreID,omitempty"` - StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围 - StatusSaleEnd int `json:"statusSaleEnd"` + StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围 + StatusSaleEnd int16 `json:"statusSaleEnd"` Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"` } @@ -1079,8 +1079,17 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs updateFieldMap["JxPrice"] = 1 } if skuBindInfo.StatusSaleBegin != 0 && skuBindInfo.StatusSaleEnd != 0 { - updateFieldMap["StatusSaleBegin"] = skuBindInfo.StatusSaleBegin - updateFieldMap["StatusSaleEnd"] = skuBindInfo.StatusSaleEnd + if skuBindInfo.StatusSaleBegin < 0 || skuBindInfo.StatusSaleBegin > 2359 || + skuBindInfo.StatusSaleEnd < 0 || skuBindInfo.StatusSaleEnd > 2359 { + dao.Rollback(db) + return nil, fmt.Errorf("更改商品:%s, 可售时间不合法!时间范围:[%v] 至 [%v]", allBinds[0].Name, skuBindInfo.StatusSaleBegin, skuBindInfo.StatusSaleEnd) + } + if skuBindInfo.StatusSaleBegin >= skuBindInfo.StatusSaleEnd { + dao.Rollback(db) + return nil, fmt.Errorf("更改商品:%s, 可售时间不允许交叉!时间范围:[%v] 至 [%v]", allBinds[0].Name, skuBindInfo.StatusSaleBegin, skuBindInfo.StatusSaleEnd) + } + updateFieldMap["StatusSaleBegin"] = int(skuBindInfo.StatusSaleBegin) + updateFieldMap["StatusSaleEnd"] = int(skuBindInfo.StatusSaleEnd) skuBind.StatusSaleBegin = skuBindInfo.StatusSaleBegin skuBind.StatusSaleEnd = skuBindInfo.StatusSaleEnd } diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index a333fcb43..5e54a5a35 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -654,13 +654,13 @@ func (v *VendorSync) SyncSkuNames(ctx *jxcontext.Context, nameIDs []int, isForce return v.SyncSkus(ctx, db, nameIDs, nil, isAsync, isContinueWhenError, ctx.GetUserName()) } -func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (err error) { +func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, isContinueWhenError bool, storeID int) (err error) { var ( storeIDs []int skuIDs []int ) db := dao.GetDB() - storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db) + storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db, storeID) if len(storeSkuList) < 1 || err != nil { return errors.New(fmt.Sprintf("未查询到设置了可售时间的商品 GetStoresSkusInfoBySaleTime!err : %v", err)) } @@ -677,7 +677,7 @@ func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, i return nil } -func GetTimeMixByInt(begin1, end1, begin2, end2 int) (beginAt, endAt int) { +func GetTimeMixByInt(begin1, end1, begin2, end2 int16) (beginAt, endAt int16) { if (begin1 > begin2 && begin1 > end2) || (begin2 > end1 && end2 > end1) { return 0, 0 } diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 90c041aad..b3c85f20c 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -802,26 +802,26 @@ func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, st return "" } -func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, storeDetail *dao.StoreDetail, now int) bool { +func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, storeDetail *dao.StoreDetail, now int16) bool { //商品可售时间的差集与门店营业时间的交集为不可售,其余为原本状态 - var openTime int - var closeTime int + var openTime int16 + var closeTime int16 saleBeginTime := sku.StatusSaleBegin saleEndTime := sku.StatusSaleEnd if storeDetail.OpenTime2 != 0 && storeDetail.CloseTime2 != 0 { if storeDetail.OpenTime1 < storeDetail.OpenTime2 { - openTime = int(storeDetail.OpenTime1) + openTime = storeDetail.OpenTime1 } else { - openTime = int(storeDetail.OpenTime2) + openTime = storeDetail.OpenTime2 } if storeDetail.CloseTime1 > storeDetail.CloseTime2 { - closeTime = int(storeDetail.CloseTime1) + closeTime = storeDetail.CloseTime1 } else { - closeTime = int(storeDetail.CloseTime2) + closeTime = storeDetail.CloseTime2 } } else { - openTime = int(storeDetail.OpenTime1) - closeTime = int(storeDetail.CloseTime1) + openTime = storeDetail.OpenTime1 + closeTime = storeDetail.CloseTime1 } beginAt1, endAt1 := GetTimeMixByInt(0, saleBeginTime, openTime, closeTime) beginAt2, endAt2 := GetTimeMixByInt(saleEndTime, 2400, openTime, closeTime) diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 82d5bf82d..504976fe4 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -134,7 +134,7 @@ func Init() { "04:05:06", }) ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() { - cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, true, false) + cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, true, false, 0) }, ChangeStoreSkuSaleStatusList) } } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index d43e503d0..386c2e465 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -688,8 +688,8 @@ func OperationTimeStr4VendorStore(v *model.VendorStoreSnapshot) (str string) { return str } -func OperationTime2HourMinuteFormat(time time.Time) (i int) { - return time.Hour()*100 + time.Minute() +func OperationTime2HourMinuteFormat(time time.Time) (i int16) { + return int16(time.Hour()*100 + time.Minute()) } // 得到饿百订单的取货码 diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index b20942a45..9d3496866 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -84,8 +84,8 @@ type StoreSkuSyncInfo struct { VendorPrice int64 MergedStatus int SkuName string - StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围 - StatusSaleEnd int `json:"statusSaleEnd"` + StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围 + StatusSaleEnd int16 `json:"statusSaleEnd"` } type MissingStoreSkuInfo struct { @@ -589,7 +589,7 @@ func (s *StoreSkuSyncInfo) GetSeq() int { return int(s.VendorPrice) } -func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*model.StoreSkuBind, err error) { +func GetStoresSkusInfoBySaleTime(db *DaoDB, storeID int) (storeSkuBindList []*model.StoreSkuBind, err error) { sql := ` SELECT t1.* FROM store_sku_bind t1 @@ -601,6 +601,10 @@ func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*model.StoreSkuB model.SkuStatusNormal, utils.DefaultTimeValue, } + if storeID > 0 { + sql += ` AND t1.store_id = ?` + sqlParams = append(sqlParams, storeID) + } err = GetRows(db, &storeSkuBindList, sql, sqlParams...) return storeSkuBindList, err } diff --git a/business/model/store_sku.go b/business/model/store_sku.go index c7d54ed89..382a97b61 100644 --- a/business/model/store_sku.go +++ b/business/model/store_sku.go @@ -113,8 +113,8 @@ type StoreSkuBind struct { AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"` - StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围 - StatusSaleEnd int `json:"statusSaleEnd"` + StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围 + StatusSaleEnd int16 `json:"statusSaleEnd"` } func (*StoreSkuBind) TableUnique() [][]string { From 449f55d87ac62363acc2f0d9edd80fd5e372fd33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 15 Nov 2019 13:46:10 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E8=90=A5=E4=B8=9A=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index fa19987ba..ffbcb936a 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -777,7 +777,7 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa dao.Commit(db) } notifyStoreOperatorChanged(store, valid["operatorPhone"]) - if (valid["openTime1"] != 0 && valid["closeTime1"] != 0) && (valid["openTime2"] != 0) && (valid["closeTime2"] != 0) { + if valid["openTime1"] != 0 || valid["closeTime1"] != 0 || valid["openTime2"] != 0 || valid["closeTime2"] != 0 { err = CurVendorSync.ChangeStoreSkuSaleStatus(ctx, true, false, storeID) } } From a8b954cd893070aa4d75ed0a45d852f3012cfb1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 15 Nov 2019 13:52:56 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=8F=AF=E5=94=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store.go | 2 +- business/jxstore/cms/sync.go | 4 ++-- business/jxstore/misc/misc.go | 2 +- business/model/dao/store_sku.go | 6 +++++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index ffbcb936a..1bdc89d63 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -778,7 +778,7 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa } notifyStoreOperatorChanged(store, valid["operatorPhone"]) if valid["openTime1"] != 0 || valid["closeTime1"] != 0 || valid["openTime2"] != 0 || valid["closeTime2"] != 0 { - err = CurVendorSync.ChangeStoreSkuSaleStatus(ctx, true, false, storeID) + err = CurVendorSync.ChangeStoreSkuSaleStatus(ctx, storeID, true, false) } } } else { diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 5e54a5a35..33c10fdf4 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -654,7 +654,7 @@ func (v *VendorSync) SyncSkuNames(ctx *jxcontext.Context, nameIDs []int, isForce return v.SyncSkus(ctx, db, nameIDs, nil, isAsync, isContinueWhenError, ctx.GetUserName()) } -func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, isContinueWhenError bool, storeID int) (err error) { +func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, storeID int, isAsync, isContinueWhenError bool) (err error) { var ( storeIDs []int skuIDs []int @@ -669,7 +669,7 @@ func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, i skuIDs = append(skuIDs, v.SkuID) } vendorIDs := partner.GetPurchasePlatformVendorIDs() - dao.UpdateStoreSkuBindSyncStatus(db, vendorIDs) + dao.UpdateStoreSkuBindSyncStatus(db, vendorIDs, storeID) v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError) if err != nil { return err diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 504976fe4..b6b83280b 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -134,7 +134,7 @@ func Init() { "04:05:06", }) ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() { - cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, true, false, 0) + cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, 0, true, false) }, ChangeStoreSkuSaleStatusList) } } diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 9d3496866..a8fcb9fe0 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -609,7 +609,7 @@ func GetStoresSkusInfoBySaleTime(db *DaoDB, storeID int) (storeSkuBindList []*mo return storeSkuBindList, err } -func UpdateStoreSkuBindSyncStatus(db *DaoDB, vendorIDs []int) (num int64, err error) { +func UpdateStoreSkuBindSyncStatus(db *DaoDB, vendorIDs []int, storeID int) (num int64, err error) { sql := ` UPDATE store_sku_bind SET @@ -634,5 +634,9 @@ func UpdateStoreSkuBindSyncStatus(db *DaoDB, vendorIDs []int) (num int64, err er AND status_sale_end <> 0 ` sqlParams = append(sqlParams, model.StoreSkuBindStatusNormal, utils.DefaultTimeValue) + if storeID > 0 { + sql += ` AND store_id = ?` + sqlParams = append(sqlParams, storeID) + } return ExecuteSQL(db, sql, sqlParams...) }