From 52fbbb020b35aabaf829ad9275fa2a944ffee74c 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, 5 Feb 2020 14:39:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=90=A5=E6=9D=83=E9=99=90=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E5=8F=AF=E4=BF=AE=E6=94=B9=E5=B8=82=E5=9C=BA?= =?UTF-8?q?=E8=B4=9F=E8=B4=A3=E4=BA=BA=E7=94=B5=E8=AF=9D=E5=92=8C=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 103 +++++++++++++++++++++++----------- business/jxstore/cms/store.go | 4 +- controllers/act.go | 6 +- 3 files changed, 76 insertions(+), 37 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 219a31a09..ab59b78c4 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -1,11 +1,8 @@ package act import ( - "errors" "fmt" - "io" "math" - "mime/multipart" "time" "git.rosy.net.cn/baseapi/utils" @@ -599,7 +596,7 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, vendorOr _, err = SyncAct(ctx, task, actID, nil, false) return retVal, err }, neeSyncActIDs) - + tasksch.HandleTask(task, nil, true).Run() if !isAsync { hint = utils.Int2Str(act.ID) @@ -1319,18 +1316,18 @@ func SyncSpecialAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model return err } -func CreateActByExcel(ctx *jxcontext.Context, files []*multipart.FileHeader, vendorID int, vendorOrgCode string, mixType int, isFocus, isSync, isAsync, isContinueWhenError bool) (hint string, err error) { - if len(files) == 0 { - return "", errors.New("没有文件上传!") - } - fileHeader := files[0] - file, err := fileHeader.Open() - hint, err = CreateActByExcelBin(ctx, file, vendorID, vendorOrgCode, mixType, isFocus, isSync, isAsync, isContinueWhenError) - file.Close() +func CreateActByExcel(ctx *jxcontext.Context, files string, vendorID int, vendorOrgCode string, mixType int, isFocus, isSync, isAsync, isContinueWhenError bool) (hint string, err error) { + // if len(files) == 0 { + // return "", errors.New("没有文件上传!") + // } + // fileHeader := files[0] + // file, err := fileHeader.Open() + hint, err = CreateActByExcelBin(ctx, files, vendorID, vendorOrgCode, mixType, isFocus, isSync, isAsync, isContinueWhenError) + // file.Close() return hint, err } -func CreateActByExcelBin(ctx *jxcontext.Context, reader io.Reader, vendorID int, vendorOrgCode string, mixType int, isFocus, isSync, isAsync, isContinueWhenError bool) (hint string, err error) { +func CreateActByExcelBin(ctx *jxcontext.Context, reader string, vendorID int, vendorOrgCode string, mixType int, isFocus, isSync, isAsync, isContinueWhenError bool) (hint string, err error) { sheetParam := &SheetParamAct{ StoreIDCol: 0, SkuIDCol: 2, @@ -1346,13 +1343,16 @@ func CreateActByExcelBin(ctx *jxcontext.Context, reader io.Reader, vendorID int, } taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) { var ( - actObj = &model.Act{} - actStoreSkuList []*ActStoreSkuParam + actObj = &model.Act{} + actStoreSkuList []*ActStoreSkuParam + actStoreSkusResult []*ActStoreSkuParam + storeIDs []int ) switch step { case 0: //读取excel文件 - xlsx, err := excelize.OpenReader(reader) + xlsx, err := excelize.OpenFile("111.xlsx") + // xlsx, err := excelize.OpenReader(reader) if err != nil { return result, err } @@ -1361,9 +1361,23 @@ func CreateActByExcelBin(ctx *jxcontext.Context, reader io.Reader, vendorID int, if rowNum < 1 { continue } - err = loadExcelForCreateAct(rowNum, mixType, row, sheetParam, actObj, actStoreSkuList) + loadExcelForCreateAct(rowNum, mixType, row, sheetParam, actObj, actStoreSkuList, storeIDs) } case 1: + //叉乘 + if mixType == 2 { + for _, v := range storeIDs { + for _, vv := range actStoreSkuList { + actStoreSkus := &ActStoreSkuParam{} + actStoreSkus = vv + actStoreSkus.StoreID = v + actStoreSkusResult = append(actStoreSkusResult, actStoreSkus) + } + } + _, err = CreateAct(ctx, actObj, []int{vendorID}, vendorOrgCode, nil, actStoreSkusResult, isAsync) + } else if mixType == 1 { + _, err = CreateAct(ctx, actObj, []int{vendorID}, vendorOrgCode, nil, actStoreSkuList, isAsync) + } } return result, err } @@ -1378,7 +1392,8 @@ func CreateActByExcelBin(ctx *jxcontext.Context, reader io.Reader, vendorID int, return hint, err } -func loadExcelForCreateAct(rowNum, mixType int, row []string, sheetParam *SheetParamAct, actObj *model.Act, actStoreSkuList []*ActStoreSkuParam) (err error) { +func loadExcelForCreateAct(rowNum, mixType int, row []string, sheetParam *SheetParamAct, actObj *model.Act, actStoreSkuList []*ActStoreSkuParam, storeIDs []int) { + actStoreSku := &ActStoreSkuParam{} for k, cell := range row { if rowNum == 1 { if k == sheetParam.ActTypeCol { @@ -1386,31 +1401,55 @@ func loadExcelForCreateAct(rowNum, mixType int, row []string, sheetParam *SheetP for k, v := range model.ActTypeName { if cell == v { actType = k + break } } actObj.Type = actType } if k == sheetParam.ActPricePercentageCol { - actObj.PricePercentage = int(utils.Str2Int64(cell) * 10) + actObj.PricePercentage = int(utils.Str2Float64(cell) * 10) } if k == sheetParam.ActNameCol { actObj.Name = cell } - // if k == sheetParam.BeginTimeCol { - // actObj.BeginAt = cell - // } - // if k == sheetParam.EndTimeCol { - // actObj.EndAt = cell - // } + if k == sheetParam.BeginTimeCol { + begin, err := time.Parse("2006年1月2日 15:04:05", cell) + if err != nil { + begin = utils.ZeroTimeValue + } + actObj.BeginAt = begin + } + if k == sheetParam.EndTimeCol { + end, err := time.Parse("2006年1月2日 15:04:05", cell) + if err != nil { + end = utils.ZeroTimeValue + } + actObj.EndAt = end + } } - //一行一行 - if mixType == 1 { - + if k == sheetParam.StoreIDCol { + //一行一行 + if mixType == 1 { + actStoreSku.StoreID = int(utils.Str2Int64(cell)) + } else if mixType == 2 { + storeIDs = append(storeIDs, int(utils.Str2Int64(cell))) + } } - //叉乘 - if mixType == 2 { - + if k == sheetParam.SkuIDCol { + actStoreSku.SkuID = int(utils.Str2Int64(cell)) + } + if k == sheetParam.SkuPricePercentageCol { + actStoreSku.PricePercentage = int(utils.Str2Float64WithDefault(cell, 0) * 10) + } + if k == sheetParam.ActPriceCol { + actStoreSku.ActPrice = int64(utils.Str2Float64(cell) * 100) + } + if k == sheetParam.EarningPriceCol { + actStoreSku.EarningPrice = int64(utils.Str2Float64(cell) * 100) + } + if k == sheetParam.StockCol { + actStoreSku.Stock = int(utils.Str2Int64(cell)) } } - return err + actStoreSkuList = append(actStoreSkuList, actStoreSku) } diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index cb472378c..b23af14e8 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -208,8 +208,8 @@ var ( "运营负责人2", } roleMap = map[string]string{ - "marketManPhone": "市场负责人电话", - "marketManRole": "市场负责人组(角色,单人)", + // "marketManPhone": "市场负责人电话", + // "marketManRole": "市场负责人组(角色,单人)", "jxBrandFeeFactor": "京西品牌费因子", "marketAddFeeFactor": "市场附加费因子", "payeeName": "收款人姓名", diff --git a/controllers/act.go b/controllers/act.go index 38f7b5d7e..b4df2580a 100644 --- a/controllers/act.go +++ b/controllers/act.go @@ -346,9 +346,9 @@ func (c *ActController) ForceUpdateVendorPrice() { // @router /CreateActByExcel [post] func (c *ActController) CreateActByExcel() { c.callCreateActByExcel(func(params *tActCreateActByExcelParams) (retVal interface{}, errCode string, err error) { - r := c.Ctx.Request - files := r.MultipartForm.File["userfiles"] - retVal, err = act.CreateActByExcel(params.Ctx, files, params.VendorID, params.VendorOrgCode, params.MixType, params.IsFocus, params.IsSync, params.IsAsync, params.IsContinueWhenError) + // r := c.Ctx.Request + // files := r.MultipartForm.File["userfiles"] + retVal, err = act.CreateActByExcel(params.Ctx, "files", params.VendorID, params.VendorOrgCode, params.MixType, params.IsFocus, params.IsSync, params.IsAsync, params.IsContinueWhenError) return retVal, "", err }) }