package controllers import ( //"bufio" //"io" //"path" //"rdluck_tools/http" "bufio" "io" //"bufio" "encoding/json" "fmt" "github.com/medivhzhan/weapp/v2" "hongze/hongze_cygx/models" "hongze/hongze_cygx/services" "hongze/hongze_cygx/utils" "html" "rdluck_tools/http" //"rdluck_tools/http" //"io" nhttp "net/http" "os" //"rdluck_tools/http" //"path" //"rdluck_tools/http" "regexp" "strconv" "strings" "time" ) type ArticleController struct { BaseAuthController } type ArticleCommonController struct { BaseCommonController } // @Title 获取报告详情 // @Description 获取报告详情接口 // @Param ArticleId query int true "报告ID" // @Success 200 {object} models.ArticleDetailResp // @router /detail [get] func (this *ArticleController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } uid := user.UserId articleId, err := this.GetInt("ArticleId") if articleId <= 0 { br.Msg = "文章不存在" br.ErrMsg = "文章不存在,文章ID错误" return } detail := new(models.ArticleDetail) hasPermission := 0 hasFree := 0 var haveResearch bool //判断是否已经申请过 applyCount, err := models.GetApplyRecordCount(uid) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error() return } //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"` if user.CompanyId > 1 { companyPermission, err := models.GetCompanyPermission(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } detail, err = models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } detail.Body = html.UnescapeString(detail.Body) //detail.Abstract = html.UnescapeString(detail.Abstract) detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract) if companyPermission == "" { if applyCount > 0 { hasPermission = 5 } else { hasPermission = 2 } hasFree = 2 goto Loop } else { hasFree = 1 var articlePermissionPermissionName string if detail.CategoryId > 0 { articlePermission, err := models.GetArticlePermission(detail.CategoryId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if articlePermission == nil { br.Msg = "获取信息失败" br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } articlePermissionPermissionName = articlePermission.PermissionName } else { articlePermissionPermissionName = detail.CategoryName } var hasPersion bool slice := strings.Split(articlePermissionPermissionName, ",") for _, v := range slice { if strings.Contains(companyPermission, v) { hasPersion = true } } if strings.Contains(detail.CategoryName, "研选") { detail.IsResearch = true } userType, _, err := services.GetUserType(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取用户信息失败,Err:" + err.Error() return } if userType == 1 && strings.Contains(detail.CategoryName, "研选") { hasPersion = false } if hasPersion { hasPermission = 1 historyRecord := new(models.CygxArticleHistoryRecord) historyRecord.UserId = uid historyRecord.ArticleId = articleId historyRecord.CreateTime = time.Now() historyRecord.Mobile = user.Mobile historyRecord.Email = user.Email historyRecord.CompanyId = user.CompanyId historyRecord.CompanyName = user.CompanyName recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId) if recordCount == 0 { go models.AddCygxArticleHistoryRecord(historyRecord) } else { detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } if detailNew.StopTime > 0 { go models.AddCygxArticleHistoryRecord(historyRecord) } } } else { //无该行业权限 hasPermission = 3 } if hasPermission == 1 { key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) if !utils.Rc.IsExist(key) { //新增浏览记录 record := new(models.CygxArticleViewRecord) record.UserId = uid record.ArticleId = articleId record.CreateTime = time.Now() record.Mobile = user.Mobile record.Email = user.Email record.CompanyId = user.CompanyId record.CompanyName = user.CompanyName go models.AddCygxArticleViewRecord(record) utils.Rc.Put(key, 1, 5*time.Second) models.ModifyReportLastViewTime(uid) } } } collectCount, err := models.GetArticleCollectCount(uid, articleId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if collectCount > 0 { detail.IsCollect = true } interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 { detail.IsInterviewApply = true detail.InterviewApplyStatus = interviewApplyItem.Status } //获取销售手机号 sellerItem, err := models.GetSellerByCompanyId(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if sellerItem != nil { detail.SellerMobile = sellerItem.Mobile detail.SellerName = sellerItem.RealName } sellerList, err := models.GetSellerList(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } fmt.Println(detail.SellerAndMobile) if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") { strnum := strings.Index(detail.SellerAndMobile, "-") detail.SellerAndMobile = detail.SellerAndMobile[0:strnum] fmt.Println(detail.SellerAndMobile) if strnum > 0 { nickName := detail.SellerAndMobile[0:strnum] sellerAndMobile := &models.SellerRep{ SellerMobile: "", SellerName: nickName, } sellerList = append(sellerList, sellerAndMobile) } } detail.SellerList = sellerList } else { //潜在客户 if applyCount > 0 { hasPermission = 5 } else { hasPermission = 4 } } Loop: if hasPermission != 1 { detail.Body = "" detail.BodyText = "" } else { articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取关注信息失败,Err:" + err.Error() return } detail.FollowNum = articleFollowdetail.DNum detail.CollectionNum = articleFollowdetail.AcNum if articleFollowdetail.MdNum > 0 { detail.IsFollow = true } if detail.IsSummary == 1 { detail.IsBelongSummary = true } if detail.IsReport == 1 { detail.IsBelongReport = true } haveResearch = true } resp := new(models.ArticleDetailResp) resp.HasPermission = hasPermission resp.HaveResearch = haveResearch resp.HasFree = hasFree resp.Detail = detail br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 收藏 // @Description 收藏 // @Param request body models.ArticleCollectReq true "type json string" // @Success 200 {object} models.FontsCollectResp // @router /collect [post] func (this *ArticleController) ArticleCollect() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请重新登录" br.Ret = 408 return } uid := user.UserId var req models.ArticleCollectReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } count, err := models.GetArticleCollectCount(uid, req.ArticleId) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(models.ArticleCollectResp) if count <= 0 { item := new(models.CygxArticleCollect) item.ArticleId = req.ArticleId item.UserId = uid item.CreateTime = time.Now() _, err = models.AddCygxArticleCollect(item) if err != nil { br.Msg = "收藏失败" br.ErrMsg = "收藏失败,Err:" + err.Error() return } br.Msg = "收藏成功" resp.Status = 1 } else { err = models.RemoveArticleCollect(uid, req.ArticleId) if err != nil { br.Msg = "取消收藏失败" br.ErrMsg = "取消收藏失败,Err:" + err.Error() return } br.Msg = "已取消收藏" resp.Status = 2 } collectTotal, err := models.GetArticleCollectUsersCount(req.ArticleId) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp.CollectCount = collectTotal br.Ret = 200 br.Success = true br.Data = resp } // @Title 访谈申请 // @Description 访谈申请 // @Param request body models.ArticleInterviewApplyReq true "type json string" // @Success 200 {object} models.FontsCollectResp // @router /interview/apply [post] func (this *ArticleController) InterviewApply() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请重新登录" br.Ret = 408 return } uid := user.UserId var req models.ArticleInterviewApplyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } article, err := models.GetArticleDetailById(req.ArticleId) if err != nil { br.Msg = "获取纪要失败!" br.ErrMsg = "获取纪要失败,Err:" + err.Error() return } count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(models.ArticleInterviewApplyResp) if count <= 0 { item := new(models.CygxInterviewApply) item.ArticleId = req.ArticleId item.UserId = uid item.CompanyId = user.CompanyId item.Status = "待邀请" item.Sort = 1 item.ArticleTitle = article.Title item.CreateTime = time.Now() item.ModifyTime = time.Now() item.ArticleIdMd5 = article.ArticleIdMd5 _, err = models.AddCygxInterviewApply(item) if err != nil { br.Msg = "申请失败" br.ErrMsg = "申请失败,Err:" + err.Error() return } br.Msg = "申请成功" resp.Status = 1 //发送模板消息 if user.CompanyId > 1 { mobile := user.Mobile if mobile == "" { mobile = user.Email } sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId) if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" { openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1) if openIpItem != nil && openIpItem.OpenId != "" { go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId) } } } } else { err = models.RemoveArticleInterviewApply(uid, req.ArticleId) if err != nil { br.Msg = "取消申请失败" br.ErrMsg = "取消申请失败,Err:" + err.Error() return } br.Msg = "已取消申请" resp.Status = 2 if user.CompanyId > 1 { mobile := user.Mobile if mobile == "" { mobile = user.Email } sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId) if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" { openIpItem, _ := models.GetUserRecordByUserId(sellerItem.UserId, 1) if openIpItem != nil && openIpItem.OpenId != "" { go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem.OpenId) } } } } br.Ret = 200 br.Success = true br.Data = resp } // @Title 获取报告详情 // @Description 获取报告详情接口 // @Param ArticleIdMd5 query int true "报告ID" // @Success 200 {object} models.ArticleDetailResp // @router /look/detail [get] func (this *ArticleCommonController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() articleIdMd5 := this.GetString("ArticleIdMd5") if articleIdMd5 == "" { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } resp := new(models.ArticleDetailResp) detail, err := models.GetArticleDetailByIdMd5(articleIdMd5) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } if detail == nil { resp.HasPermission = 2 } else { resp.HasPermission = 1 } if detail != nil { detail.Body = html.UnescapeString(detail.Body) detail.Abstract = html.UnescapeString(detail.Abstract) } sellerList, err := models.GetSellerList(detail.ArticleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(detail.ArticleId) return } if detail.ArticleId > 1000000 { var hrefRegexp = regexp.MustCompile("[0-9]\\d*") match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1) if match != nil { for _, v := range match { sellerAndMobile := &models.SellerRep{ SellerMobile: v, SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1), } sellerList = append(sellerList, sellerAndMobile) } } } detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract) detail.SellerList = sellerList resp.Detail = detail br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 上传文章阅读时间 // @Description 上传文章阅读时间接口 // @Param request body models.AddStopTimeRep true "type json string" // @Success 200 {object} models.ArticleDetailResp // @router /addStopTime [post] func (this *ArticleController) AddStopTime() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var req models.AddStopTimeRep err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } uid := user.UserId articleId := req.ArticleId stopTime := req.StopTime if articleId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } if stopTime == 0 { stopTime = 1 //br.Msg = "时间格式错误" //br.ErrMsg = "时间错误" //return } detail := new(models.ArticleDetail) hasPermission := 0 hasFree := 0 //判断是否已经申请过 applyCount, err := models.GetApplyRecordCount(uid) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error() return } //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"` if user.CompanyId > 1 { companyPermission, err := models.GetCompanyPermission(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } detail, err = models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if companyPermission == "" { if applyCount > 0 { hasPermission = 5 } else { hasPermission = 2 } hasFree = 2 goto Loop } else { hasFree = 1 var articlePermissionPermissionName string if detail.CategoryId > 0 { articlePermission, err := models.GetArticlePermission(detail.CategoryId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if articlePermission == nil { br.Msg = "获取信息失败" br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } articlePermissionPermissionName = articlePermission.PermissionName } else { articlePermissionPermissionName = detail.CategoryName } var hasPersion bool slice := strings.Split(articlePermissionPermissionName, ",") for _, v := range slice { if strings.Contains(companyPermission, v) { hasPersion = true } } if hasPersion { detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId) if err == nil { //br.Msg = "获取信息失败" //br.ErrMsg = "获取最新阅读信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) //return hasPermission = 1 historyRecord := new(models.AddStopTimeNewRep) historyRecord.StopTime = detailNew.StopTime + stopTime historyRecord.Id = detailNew.Id go models.AddArticleStopTime(historyRecord) } } else { //无该行业权限 hasPermission = 3 } } } else { //潜在客户 if applyCount > 0 { hasPermission = 5 } else { hasPermission = 4 } } Loop: resp := new(models.ArticleDetailAddStopTimeRep) resp.HasPermission = hasPermission resp.HasFree = hasFree br.Ret = 200 br.Success = true br.Msg = "操作成功" br.Data = resp } // @Title 文章带问 // @Description 新增文章带问接口 // @Param request body models.AddArticleAskRep true "type json string" // @Success Ret=200 新增成功 // @router /askAdd [post] func (this *ArticleController) AskAdd() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.AddArticleAskRep err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.Content == "" { br.Msg = "建议内容不可为空" return } content := req.Content itemToken, err := services.WxGetToken() if err != nil { br.Msg = "GetWxAccessToken Err:" + err.Error() return } if itemToken.AccessToken == "" { br.Msg = "accessToken is empty" return } commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content) if err != nil { br.Msg = "内容校验失败!" br.ErrMsg = "内容校验失败,Err:" + err.Error() return } if commerr.ErrCode != 0 { br.Msg = "内容违规,请重新提交!" br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG return } articleId := req.ArticleId count, _ := models.GetArticleCountById(articleId) if count == 0 { br.Msg = "操作失败" br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId) return } companyDetail, err := models.GetCompanyDetailById(user.CompanyId) if err != nil { br.Msg = "提交失败!" br.ErrMsg = "获取客户详情失败,Err:" + err.Error() return } if companyDetail == nil { br.Msg = "提交失败!" br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) return } item := new(models.CygxArticleAsk) item.UserId = user.UserId item.ArticleId = req.ArticleId item.CompanyId = user.CompanyId item.CompanyName = companyDetail.CompanyName item.CreateTime = time.Now() item.Mobile = user.Mobile item.Email = user.Email item.Content = content _, err = models.AddArticleAsk(item) if err != nil { br.Msg = "提交失败" br.ErrMsg = "提交失败,Err:" + err.Error() return } companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error() return } var mobile string if utils.WxMsgTemplateIdAskMsgMobile == "" { mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile } else { mobile = utils.WxMsgTemplateIdAskMsgMobile } openIdList, err := models.GetWxOpenIdByMobileList(mobile) if err != nil { br.Msg = "提交失败" br.ErrMsg = "提交失败,Err:" + err.Error() return } detail, err := models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")" go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId) br.Ret = 200 br.Success = true br.Msg = "提交成功" } // @Title 下载PDF打水印 // @Description 下载PDF打水印接口 // @Param ArticleId query int true "报告ID" // @Success 200 {object} models.ArticleDetailFileLink // @router /pdfwatermark [get] func (this *ArticleController) Pdfwatermark() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } articleId, err := this.GetInt("ArticleId") if articleId <= 0 { br.Msg = "文章不存在" br.ErrMsg = "文章不存在,文章ID错误" return } detail := new(models.ArticleDetail) detail, err = models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } fileLink := detail.FileLink if fileLink == "" { br.Msg = "下载失败" br.ErrMsg = "下载失败,报告链接不存在" return } mobile := user.Mobile if mobile == "" { mobile = user.Email } dataMap := make(map[string]interface{}) dataMap["Mobile"] = mobile //dataMap["Name"] = user.RealName dataMap["Name"] = "" pdfPath := "static/" pdfUrl := fileLink fileName := utils.GetRandStringNoSpecialChar(28) + ".pdf" res, err := nhttp.Get(pdfUrl) if err != nil { fmt.Println("A error occurred!") return } defer res.Body.Close() // 获得get请求响应的reader对象 reader := bufio.NewReaderSize(res.Body, 32*1024) file, err := os.Create(pdfPath + fileName) if err != nil { panic(err) } //获得文件的writer对象 writer := bufio.NewWriter(file) written, _ := io.Copy(writer, reader) fmt.Printf("Total length: %d", written) str, _ := os.Getwd() fileLink = str + "/" + pdfPath + fileName dataMap["FileLink"] = fileLink postUrl := "http://127.0.0.1:5007/pdfwatermark/" // fmt.Println("postUrl:", postUrl) postData, err := json.Marshal(dataMap) if err != nil { br.Msg = "下载失败" br.ErrMsg = "解析,Marshal,Err:" + err.Error() return } fmt.Println("publish ppt param:", string(postData)) result, err := http.Post(postUrl, string(postData)) if err != nil { br.Msg = "下载失败" br.ErrMsg = "Marshal,Err:" + err.Error() return } fmt.Println("publish pdf result:", string(result)) var pdfResult PublishPdfResult err = json.Unmarshal(result, &pdfResult) if err != nil { br.Msg = "下载失败" br.ErrMsg = "Unmarshal,Err:" + err.Error() return } //fmt.Println(pdfResult) resp := new(models.ArticleDetailFileLink) filePathName := strings.TrimLeft(pdfResult.FilePath, ".") //filePathOldName := strings.TrimLeft(pdfResult.FileOldPath, ".") filePath := pdfResult.Pdfpath + filePathName //filePathOld := pdfResult.Pdfpath + filePathOldName randStr := utils.GetRandStringNoSpecialChar(28) fileName = randStr + ".pdf" hzUploadDir := "static/pdf/" savePath := hzUploadDir + time.Now().Format("200601/20060102/") savePath += fileName //上传到阿里云 err = services.UploadFileToAliyun(fileName, filePath, savePath) if err != nil { br.Msg = "下载失败" br.ErrMsg = "文件上传失败,Err:" + err.Error() return } utils.FileLog.Info("%s:", time.Now().Format(utils.FormatDateTime)) utils.FileLog.Info("end update oss ") fileHost := "https://hzstatic.hzinsights.com/" resourceUrl := fileHost + savePath defer func() { os.Remove(filePath) os.Remove(fileLink) }() resp.FileLink = resourceUrl br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } type PublishPdfResult struct { Result string `json:"result"` FilePath string `json:"file_path"` FileOldPath string `json:"file_old_path"` Pdfpath string `json:"pdfpath"` }