修改商品库增加操作日志
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/refutil"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
@@ -876,7 +877,7 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf
|
||||
if err = dao.GetEntity(db, skuName); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var beforSkuName = *skuName
|
||||
if payload["name"] != nil {
|
||||
newSkuName := utils.TrimBlankChar(utils.Interface2String(payload["name"]))
|
||||
if hasSensitiveWord, err := CheckHasSensitiveWord(newSkuName); hasSensitiveWord {
|
||||
@@ -999,6 +1000,10 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf
|
||||
_, err = CurVendorSync.SyncSku(ctx, db, nameID, -1, false, false, userName)
|
||||
errList.AddErr(err)
|
||||
err = errList.GetErrListAsOne()
|
||||
if globals.IsAddEvent {
|
||||
mapBefore := refutil.FindMapAndStructMixed(valid, beforSkuName)
|
||||
err = AddEventDetail(db, ctx, model.OperateUpdate, nameID, model.ThingTypeSkuName, 0, BuildDiffData(mapBefore), BuildDiffData(valid))
|
||||
}
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
@@ -1126,6 +1131,7 @@ func UpdateSku(ctx *jxcontext.Context, skuID int, payload map[string]interface{}
|
||||
if err = dao.GetEntity(db, sku); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var beforSku = *sku
|
||||
valid := dao.StrictMakeMapByStructObject(payload, sku, userName)
|
||||
if len(valid) > 0 {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
||||
@@ -1179,6 +1185,10 @@ func UpdateSku(ctx *jxcontext.Context, skuID int, payload map[string]interface{}
|
||||
_, err = CurVendorSync.SyncSku(ctx, db, -1, sku.ID, false, false, userName)
|
||||
errList.AddErr(err)
|
||||
err = errList.GetErrListAsOne()
|
||||
if globals.IsAddEvent {
|
||||
mapBefore := refutil.FindMapAndStructMixed(valid, beforSku)
|
||||
err = AddEventDetail(db, ctx, model.OperateUpdate, skuID, model.ThingTypeSku, 0, BuildDiffData(mapBefore), BuildDiffData(valid))
|
||||
}
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
@@ -1906,24 +1916,30 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
return retVal, err
|
||||
}
|
||||
if result.Img != "" {
|
||||
if resBinary, _, err := jxutils.DownloadFileByURL(result.Img); err == nil {
|
||||
if downloadURL, err := jxutils.UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+"origin"+result.Img[strings.LastIndex(result.Img, "/")+1:len(result.Img)]); err == nil {
|
||||
resBinary2, _, err := jxutils.DownloadFileByURL(downloadURL + model.SkuNameImgStandard)
|
||||
downloadURL2, err := jxutils.UploadExportContent(resBinary2, utils.Int64ToStr(time.Now().Unix())+downloadURL[strings.LastIndex(downloadURL, "/")+1:len(downloadURL)])
|
||||
if err == nil {
|
||||
skuName.Img = downloadURL2
|
||||
} else {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
} else {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
} else {
|
||||
downloadURL, err := uploadImgStandard(skuName.Img)
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
skuName.Img = downloadURL
|
||||
// if resBinary, _, err := jxutils.DownloadFileByURL(result.Img); err == nil {
|
||||
// if downloadURL, err := jxutils.UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+"origin"+result.Img[strings.LastIndex(result.Img, "/")+1:len(result.Img)]); err == nil {
|
||||
// resBinary2, _, err := jxutils.DownloadFileByURL(downloadURL + model.SkuNameImgStandard)
|
||||
// downloadURL2, err := jxutils.UploadExportContent(resBinary2, utils.Int64ToStr(time.Now().Unix())+downloadURL[strings.LastIndex(downloadURL, "/")+1:len(downloadURL)])
|
||||
// if err == nil {
|
||||
// skuName.Img = downloadURL2
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
} else {
|
||||
skuName.Img = model.NOSkuNameImg
|
||||
}
|
||||
@@ -2106,36 +2122,42 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
}
|
||||
//需要把图片传到七牛云上
|
||||
if !strings.Contains(skuName.Img, "image.jxc4.com") {
|
||||
if resBinary, _, err := jxutils.DownloadFileByURL(skuName.Img); err == nil {
|
||||
if downloadURL, err := jxutils.UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+"origin"+skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil {
|
||||
if img, _, err := datares.Binary2Image(resBinary, http.DetectContentType(resBinary)); err == nil {
|
||||
if img.Bounds().Dx() != datares.MainImgWidth || img.Bounds().Dy() != datares.MainImgHeight {
|
||||
if resBinary2, _, err := jxutils.DownloadFileByURL(downloadURL + model.SkuNameImgStandard); err == nil {
|
||||
if downloadURL2, err := jxutils.UploadExportContent(resBinary2, utils.Int64ToStr(time.Now().Unix())+skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil {
|
||||
skuName.Img = downloadURL2
|
||||
} else {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
} else {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
} else {
|
||||
skuName.Img = downloadURL
|
||||
}
|
||||
} else {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
} else {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
} else {
|
||||
downloadURL, err := uploadImgStandard(skuName.Img)
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
skuName.Img = downloadURL
|
||||
// if resBinary, _, err := jxutils.DownloadFileByURL(skuName.Img); err == nil {
|
||||
// if downloadURL, err := jxutils.UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+"origin"+skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil {
|
||||
// if img, _, err := datares.Binary2Image(resBinary, http.DetectContentType(resBinary)); err == nil {
|
||||
// if img.Bounds().Dx() != datares.MainImgWidth || img.Bounds().Dy() != datares.MainImgHeight {
|
||||
// if resBinary2, _, err := jxutils.DownloadFileByURL(downloadURL + model.SkuNameImgStandard); err == nil {
|
||||
// if downloadURL2, err := jxutils.UploadExportContent(resBinary2, utils.Int64ToStr(time.Now().Unix())+skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil {
|
||||
// skuName.Img = downloadURL2
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// skuName.Img = downloadURL
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
}
|
||||
skuName.Status = model.SkuStatusNormal
|
||||
skuName.IsGlobal = model.YES
|
||||
@@ -2242,3 +2264,34 @@ func RefreshJdDepot(ctx *jxcontext.Context) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
//标准化上传图片。
|
||||
//图片是非京西图片上传到七牛云转换为京西图片
|
||||
func uploadImgStandard(imgUrl string) (downloadResult string, err error) {
|
||||
if resBinary, _, err := jxutils.DownloadFileByURL(imgUrl); err == nil {
|
||||
if downloadURL, err := jxutils.UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+"origin"+imgUrl[strings.LastIndex(imgUrl, "/")+1:len(imgUrl)]); err == nil {
|
||||
if img, _, err := datares.Binary2Image(resBinary, http.DetectContentType(resBinary)); err == nil {
|
||||
if img.Bounds().Dx() != datares.MainImgWidth || img.Bounds().Dy() != datares.MainImgHeight { //如果不是标准的800x800就再把图片格式化上传
|
||||
if resBinary2, _, err := jxutils.DownloadFileByURL(downloadURL + model.SkuNameImgStandard); err == nil {
|
||||
if downloadURL2, err := jxutils.UploadExportContent(resBinary2, utils.Int64ToStr(time.Now().Unix())+imgUrl[strings.LastIndex(imgUrl, "/")+1:len(imgUrl)]); err == nil {
|
||||
downloadResult = downloadURL2
|
||||
} else {
|
||||
return downloadResult, err
|
||||
}
|
||||
} else {
|
||||
return downloadResult, err
|
||||
}
|
||||
} else {
|
||||
downloadResult = downloadURL
|
||||
}
|
||||
} else {
|
||||
return downloadResult, err
|
||||
}
|
||||
} else {
|
||||
return downloadResult, err
|
||||
}
|
||||
} else {
|
||||
return downloadResult, err
|
||||
}
|
||||
return downloadResult, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user