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

This commit is contained in:
gazebo
2019-12-11 22:31:07 +08:00
4 changed files with 53 additions and 21 deletions

View File

@@ -97,7 +97,15 @@ func AddCategory(ctx *jxcontext.Context, cat *model.SkuCategory, userName string
dao.WrapAddIDCULDEntity(cat, userName)
cat.JdSyncStatus = model.SyncFlagNewMask
cat.JdID = 0
cat.Status = model.CategoryStatusEnable
cat.Name = strings.Trim(cat.Name, " ")
if cat.Img != "" {
_, err2 := datares.TryRegisterDataResource(ctx, cat.Name, cat.Img, model.ImgTypeLocal, false)
if err = err2; err != nil {
return nil, err
}
}
if cat.Seq <= 0 {
var maxSeq struct {
MaxSeq int
@@ -144,6 +152,22 @@ func UpdateCategory(ctx *jxcontext.Context, categoryID int, payload map[string]i
syncStatus = model.SyncFlagModifiedMask
valid[model.FieldJdSyncStatus] = int8(syncStatus) | cat.JdSyncStatus
}
if valid["status"] != nil {
if utils.Interface2Int64WithDefault(valid["status"], -1) == model.CategoryStatusDisabled {
if skuList, err2 := dao.GetSkuByCats(db, []int{categoryID}); err2 == nil && len(skuList) > 0 {
return 0, fmt.Errorf("暂不允许禁用分类下有商品的分类!")
}
}
}
if valid["img"] != nil {
if imgStr := utils.Interface2String(valid["img"]); imgStr != "" {
_, err2 := datares.TryRegisterDataResource(ctx, cat.Name, utils.Interface2String(valid["img"]), model.ImgTypeLocal, false)
if err = err2; err != nil {
return 0, err
}
}
}
dao.Begin(db)
defer func() {

View File

@@ -3,7 +3,9 @@ package cms
import (
"errors"
"fmt"
"io"
"math"
"mime/multipart"
"sort"
"strconv"
"strings"
@@ -2144,21 +2146,21 @@ func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error
return err
}
func RefreshJxPriceByExcel(ctx *jxcontext.Context, storeIDs []int, files string, isAsync, isContinueWhenError bool) (hint string, err error) {
// if len(files) == 0 {
// return "", errors.New("没有文件上传!")
// }
func RefreshJxPriceByExcel(ctx *jxcontext.Context, storeIDs []int, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) {
if len(files) == 0 {
return "", errors.New("没有文件上传!")
}
if len(storeIDs) == 0 {
return "", errors.New("请选择至少一个门店!")
}
// fileHeader := files[0]
// file, err := fileHeader.Open()
hint, err = RefreshJxPriceByExcelBin(ctx, storeIDs, files, true, true)
// file.Close()
fileHeader := files[0]
file, err := fileHeader.Open()
hint, err = RefreshJxPriceByExcelBin(ctx, storeIDs, file, true, true)
file.Close()
return hint, err
}
func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader string, isAsync, isContinueWhenError bool) (hint string, err error) {
func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
var (
storeSkuNamePriceList []*model.StoreSkuNamePrice
storeSkuNamePriceListUpdate []*model.StoreSkuNamePrice
@@ -2178,8 +2180,8 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader str
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
switch step {
case 0:
xlsx, err := excelize.OpenFile("111.xlsx")
// xlsx, err := excelize.OpenReader(reader)
// xlsx, err := excelize.OpenFile("111.xlsx")
xlsx, err := excelize.OpenReader(reader)
if err != nil {
return "", err
}

View File

@@ -18,6 +18,11 @@ const (
SkuStatusNormal = 1
)
const (
CategoryStatusDisabled = 0
CategoryStatusEnable = 1
)
var (
SpecUnitNames = []string{
"g",
@@ -140,9 +145,10 @@ type SkuCategory struct {
// ElmCategoryID int64 `orm:"column(elm_category_id)" json:"elmCategoryID"` // 这个是指对应的饿了么商品类别
// WscCategoryID int64 `orm:"column(wsc_category_id)" json:"wscCategoryID"` // 这个是指对应的美团外卖商品类别
JdID int64 `orm:"column(jd_id)" json:"jdID"` // 这个是指商家自己的商品类别在京东平台上的ID
JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`
Status int8 `orm:"default(1)" json:"status"` //分类状态0表示禁用1表示启用
Img string `orm:"size(512)" json:"img"` //分类图片
JdID int64 `orm:"column(jd_id)" json:"jdID"` // 这个是指商家自己的商品类别在京东平台上的ID
JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`
}
func (*SkuCategory) TableUnique() [][]string {

View File

@@ -499,10 +499,10 @@ func (c *StoreSkuController) RefershStoreSkusMidPrice() {
// @Title 根据Excel刷新京西门店商品价
// @Description 根据Excel刷新京西门店商品价
// @Param token header string true "认证token"
// @Param storeIDs query string true "门店列表"
// @Param isAsync query bool true "是否异步,缺省是同步"
// @Param isContinueWhenError query bool true "单个同步失败是否继续缺省false"
// @Param token header string true "认证token"
// @Param storeIDs formData string true "门店列表"
// @Param isAsync formData bool true "是否异步,缺省是同步"
// @Param isContinueWhenError formData bool true "单个同步失败是否继续缺省false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RefreshJxPriceByExcel [post]
@@ -510,9 +510,9 @@ func (c *StoreSkuController) RefreshJxPriceByExcel() {
var storeIDList []int
c.callRefreshJxPriceByExcel(func(params *tStoreSkuRefreshJxPriceByExcelParams) (retVal interface{}, errCode string, err error) {
if jxutils.Strings2Objs(params.StoreIDs, &storeIDList); err == nil {
// r := c.Ctx.Request
// files := r.MultipartForm.File["userfiles"]
retVal, err = cms.RefreshJxPriceByExcel(params.Ctx, storeIDList, "files", params.IsAsync, params.IsContinueWhenError)
r := c.Ctx.Request
files := r.MultipartForm.File["userfiles"]
retVal, err = cms.RefreshJxPriceByExcel(params.Ctx, storeIDList, files, params.IsAsync, params.IsContinueWhenError)
}
return retVal, "", err
})