|
@@ -43,10 +43,6 @@ func (this *AnalystController) UploadImage() {
|
|
|
}
|
|
|
defer f.Close()
|
|
|
ext := path.Ext(h.Filename)
|
|
|
- //if ext != ".pdf" {
|
|
|
- // br.Msg = "文件格式不正确"
|
|
|
- // return
|
|
|
- //}
|
|
|
size, err := strconv.Atoi(utils.UPLOAD_IMG_SIZE)
|
|
|
if err != nil {
|
|
|
size = 15
|
|
@@ -55,8 +51,8 @@ func (this *AnalystController) UploadImage() {
|
|
|
br.Msg = fmt.Sprintf("头像文件大小不能超过%dK", size)
|
|
|
return
|
|
|
}
|
|
|
- dateDir := time.Now().Format("20060102")
|
|
|
- uploadDir := utils.STATIC_DIR + "ht/" + dateDir
|
|
|
+ dateDir := time.Now().Format(time.DateOnly)
|
|
|
+ uploadDir := utils.STATIC_DIR + "ht/analyst/" + dateDir
|
|
|
err = os.MkdirAll(uploadDir, utils.DIR_MOD)
|
|
|
if err != nil {
|
|
|
br.Msg = "存储目录创建失败"
|
|
@@ -72,33 +68,47 @@ func (this *AnalystController) UploadImage() {
|
|
|
br.ErrMsg = "头像上传失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- pdfUploadDir := utils.RESOURCE_DIR + "analyst/"
|
|
|
- savePdfToOssPath := pdfUploadDir + time.Now().Format("200601/20060102/")
|
|
|
+ thumbnailPath, err := utils.ImageResize(fpath, 1200)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "头像上传失败"
|
|
|
+ br.ErrMsg = "头像上传失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ossUploadDir := utils.RESOURCE_DIR + "analyst/"
|
|
|
+ saveOssPath := ossUploadDir + time.Now().Format("200601/20060102/")
|
|
|
imgName := utils.GetRandStringNoSpecialChar(28)
|
|
|
- savePdfToOssPath += imgName
|
|
|
-
|
|
|
+ saveOssPath += imgName
|
|
|
defer func() {
|
|
|
_ = os.Remove(fpath)
|
|
|
+ _ = os.Remove(thumbnailPath)
|
|
|
}()
|
|
|
-
|
|
|
ossClient := services.NewOssClient()
|
|
|
if ossClient == nil {
|
|
|
br.Msg = "头像上传失败"
|
|
|
br.ErrMsg = "初始化OSS服务失败"
|
|
|
return
|
|
|
}
|
|
|
- imgUrl, err := ossClient.UploadFile("", fpath, savePdfToOssPath)
|
|
|
+ //新增上传缩略图
|
|
|
+
|
|
|
+ thumbnailUrl, err := ossClient.UploadFile("", thumbnailPath, saveOssPath+"_thumbnail")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "头像上传失败"
|
|
|
+ br.ErrMsg = "头像上传失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ imgUrl, err := ossClient.UploadFile("", fpath, saveOssPath)
|
|
|
if err != nil {
|
|
|
br.Msg = "头像上传失败"
|
|
|
br.ErrMsg = "头像上传失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
base := path.Base(h.Filename)
|
|
|
- resp := new(response.ReportPdfUploadResp)
|
|
|
- resp.Url = imgUrl
|
|
|
- resp.FileName = base
|
|
|
-
|
|
|
+ thumbnailBase := path.Base(h.Filename + "_thumbnail")
|
|
|
+ resp := new(response.HeadImageUploadResp)
|
|
|
+ resp.Url = thumbnailUrl
|
|
|
+ resp.OriginUrl = imgUrl
|
|
|
+ resp.FileName = thumbnailBase
|
|
|
+ resp.OriginFileName = base
|
|
|
br.Data = resp
|
|
|
br.Msg = "上传成功"
|
|
|
br.Ret = 200
|
|
@@ -118,7 +128,6 @@ func (this *AnalystController) GetAnalystByName(AnalystName string) {
|
|
|
this.ServeJSON()
|
|
|
}()
|
|
|
analyst, err := models.GetAnalystByName(AnalystName)
|
|
|
-
|
|
|
if err != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
@@ -241,6 +250,7 @@ func (this *AnalystController) Edit() {
|
|
|
}
|
|
|
analyst.Introduction = req.Introduction
|
|
|
analyst.Position = req.Position
|
|
|
+ analyst.HeadOriginImgUrl = req.HeadOriginImgUrl
|
|
|
analyst.ProfessionalCertificate = req.ProfessionalCertificate
|
|
|
analyst.InvestmentCertificate = req.InvestmentCertificate
|
|
|
analyst.UpdatedTime = time.Now()
|