fix: upload goods

master
howell 3 years ago
parent 087a5ccbf7
commit 8fec701bd5

@ -33,3 +33,16 @@ func (o Proxy) UpdateStatus(c *gin.Context) {
back.Suc(c, "ok", "") back.Suc(c, "ok", "")
} }
} }
func (o Proxy) UploadSku(c *gin.Context) {
var args jyy.ArgsUploadSku
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
if err := jyy.Logic.UploadSku(args); err != nil {
back.Fail(c, err.Error())
} else {
back.Suc(c, "ok", "")
}
}

@ -1,6 +1,9 @@
package jyy package jyy
import ( import (
"path/filepath"
"recook/internal/static_path"
"recook/internal/v2/lib/excel"
"recook/internal/v2/model/recook/goods" "recook/internal/v2/model/recook/goods"
"git.oa00.com/go/mysql" "git.oa00.com/go/mysql"
@ -50,3 +53,26 @@ func (o logic) UpdateStatus(args ArgsPublish) error {
} }
return nil return nil
} }
type ArgsUploadSku struct {
Path string `json:"path"`
}
type GoodsFile struct {
GoodsID uint `excel:"name:goods_id"`
}
func (o logic) UploadSku(args ArgsUploadSku) error {
path := filepath.Join(static_path.Dir.Root, args.Path)
f1, err := excel.OpenFile(path)
if err != nil {
return err
}
var gl []GoodsFile
f1.FromExcel(&gl, f1.GetSheetName(f1.GetActiveSheetIndex()))
ids := make([]uint, 0)
for _, v := range gl {
ids = append(ids, v.GoodsID)
}
return mysql.Db.Table((&goods.RecookGoodsInfoModel{}).TableName()).Where("id in (?) and ", ids).Where("third_party_type != 3").Update("is_sale", 1).Error
}

@ -830,6 +830,7 @@ func routerManage(manageRouter *gin.RouterGroup) {
{ {
saleRouter.POST("update", proxy.UpdateSale) saleRouter.POST("update", proxy.UpdateSale)
saleRouter.POST("publish", proxy.UpdateStatus) saleRouter.POST("publish", proxy.UpdateStatus)
saleRouter.POST("upload", proxy.UploadSku)
} }
} }
} }

Loading…
Cancel
Save