根据skuid批量关注
This commit is contained in:
@@ -2734,3 +2734,88 @@ func WriteToExcelNormal(task *tasksch.SeqTask, fileName string, excelParam []Exc
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FocusStoreSkusByExcel(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
if len(files) == 0 {
|
||||||
|
return "", errors.New("没有文件上传!")
|
||||||
|
}
|
||||||
|
fileHeader := files[0]
|
||||||
|
file, err := fileHeader.Open()
|
||||||
|
hint, err = FocusStoreSkusByExcelBin(ctx, file, isAsync, isContinueWhenError)
|
||||||
|
file.Close()
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
var (
|
||||||
|
skuMap = make(map[int]int)
|
||||||
|
skuNameMap = make(map[int]int)
|
||||||
|
skuBindInfos []*StoreSkuBindInfo
|
||||||
|
db = dao.GetDB()
|
||||||
|
storeIDs []int
|
||||||
|
skuIDs []int
|
||||||
|
price int
|
||||||
|
)
|
||||||
|
sheetParam := &SheetParam{
|
||||||
|
OutSkuIDCol: 1,
|
||||||
|
SkuPriceCol: 3,
|
||||||
|
SkuRow: 1,
|
||||||
|
}
|
||||||
|
xlsx, err := excelize.OpenReader(reader)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
rows, _ := xlsx.GetRows(xlsx.GetSheetName(1))
|
||||||
|
for rowNum, row := range rows {
|
||||||
|
if rowNum < sheetParam.SkuRow {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
GetCellForFocusStoreSkus(db, rowNum, row, sheetParam, skuMap)
|
||||||
|
}
|
||||||
|
for k, _ := range skuMap {
|
||||||
|
skuIDs = append(skuIDs, k)
|
||||||
|
}
|
||||||
|
skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil)
|
||||||
|
if err != nil && len(skuList) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, v := range skuList {
|
||||||
|
if v.Unit == model.SpecialUnit {
|
||||||
|
price = model.SpecialSpecQuality / int(utils.Float64TwoInt64(float64(v.SpecQuality))) * skuMap[v.ID]
|
||||||
|
}
|
||||||
|
if skuNameMap[v.NameID] < price {
|
||||||
|
skuNameMap[v.NameID] = price
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for k, v := range skuNameMap {
|
||||||
|
skuBindInfo := &StoreSkuBindInfo{
|
||||||
|
NameID: k,
|
||||||
|
UnitPrice: v,
|
||||||
|
IsFocus: 1,
|
||||||
|
IsSale: 1,
|
||||||
|
}
|
||||||
|
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||||
|
}
|
||||||
|
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||||
|
for _, v := range storeList {
|
||||||
|
storeIDs = append(storeIDs, v.ID)
|
||||||
|
}
|
||||||
|
hint, err = UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCellForFocusStoreSkus(db *dao.DaoDB, rowNum int, row []string, sheetParam *SheetParam, skuMap map[int]int) {
|
||||||
|
var (
|
||||||
|
skuID int
|
||||||
|
price int
|
||||||
|
)
|
||||||
|
for k, cell := range row {
|
||||||
|
if k == sheetParam.OutSkuIDCol {
|
||||||
|
skuID = int(utils.Str2Int64(cell))
|
||||||
|
}
|
||||||
|
if k == sheetParam.SkuPriceCol {
|
||||||
|
price = int(utils.Float64TwoInt64(utils.Str2Float64(cell) * 100))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
skuMap[skuID] = price
|
||||||
|
}
|
||||||
|
|||||||
@@ -535,6 +535,23 @@ func (c *StoreSkuController) RefreshJxPriceByExcel() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 根据Excel中SkuID批量关注商品
|
||||||
|
// @Description 根据Excel中SkuID批量关注商品
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param isAsync formData bool true "是否异步,缺省是同步"
|
||||||
|
// @Param isContinueWhenError formData bool true "单个同步失败是否继续,缺省false"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /FocusStoreSkusByExcel [post]
|
||||||
|
func (c *StoreSkuController) FocusStoreSkusByExcel() {
|
||||||
|
c.callFocusStoreSkusByExcel(func(params *tStoreSkuFocusStoreSkusByExcelParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
r := c.Ctx.Request
|
||||||
|
files := r.MultipartForm.File["userfiles"]
|
||||||
|
retVal, err = cms.FocusStoreSkusByExcel(params.Ctx, files, params.IsAsync, params.IsContinueWhenError)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// @Title 得到门店的分类列表
|
// @Title 得到门店的分类列表
|
||||||
// @Description 得到门店的分类列表(按商品销量)
|
// @Description 得到门店的分类列表(按商品销量)
|
||||||
// @Param token header string false "认证token"
|
// @Param token header string false "认证token"
|
||||||
|
|||||||
@@ -1611,6 +1611,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "FocusStoreSkusByExcel",
|
||||||
|
Router: `/FocusStoreSkusByExcel`,
|
||||||
|
AllowHTTPMethods: []string{"post"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetMissingStoreSkuFromOrder",
|
Method: "GetMissingStoreSkuFromOrder",
|
||||||
|
|||||||
Reference in New Issue
Block a user