浏览代码

海通国际接口文档整理

xingzai 2 年之前
父节点
当前提交
97f4f058c3
共有 2 个文件被更改,包括 245 次插入2 次删除
  1. 244 1
      controllers/htgj.go
  2. 1 1
      services/task.go

+ 244 - 1
controllers/htgj.go

@@ -595,7 +595,7 @@ func (this *BaseHtgjController) AskAdd() {
 // @Description 获取所有品种(无需token)
 // @Success 200 {object} models.ChartPermissionResp
 // @router /permission/allPublic [get]
-func (this *BaseHtgjController) DetailPublic() {
+func (this *BaseHtgjController) PermissionPublic() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
@@ -810,3 +810,246 @@ Loop:
 	br.Msg = "操作成功"
 	br.Data = resp
 }
+
+// @Title 获取报告详情(无需token)
+// @Description 获取报告详情接口
+// @Param   ArticleId   query   int  true       "报告ID"
+// @Param   CompanyCode     query string  false       "机构编号"
+// @Param   CompanyName     query string  false       "机构名称"
+// @Param   Email     query string  false       "邮箱"
+// @Param   Sign   query   string  false       "加密签名"
+// @Success 200 {object} models.ArticleDetailHtgjResp
+// @router /detailPublic [get]
+func (this *BaseHtgjController) DetailPublic() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	articleId, _ := this.GetInt("ArticleId")
+	companyCode := this.GetString("CompanyCode")
+	companyNameHt := this.GetString("CompanyName")
+	email := this.GetString("Email")
+	sign := this.GetString("Sign")
+	resp := new(models.ArticleDetailHtgjResp)
+	if companyCode == "" || email == "" {
+		resp.HasPermission = 2
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+	if articleId <= 0 {
+		br.Msg = "文章不存在"
+		br.ErrMsg = "文章不存在,文章ID错误"
+		return
+	}
+
+	errMsg, err, wxUser, companyName := services.CheckHtgj(companyCode, companyNameHt, email, sign)
+
+	if errMsg != "" {
+		br.Msg = errMsg
+		return
+	}
+	companyPermission, err := models.GetCompanyPermission(wxUser.CompanyId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户权限失败,Err:" + err.Error() + ";articleId" + strconv.Itoa(articleId)
+		return
+	}
+	hasPermission := 0
+
+	detail, err := models.GetArticleDetailById(articleId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	detail.Body = html.UnescapeString(detail.Body)
+	detail.Body = strings.Replace(detail.Body, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
+	detail.Body = strings.Replace(detail.Body, "pre", "div", -1)
+	detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
+
+	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(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if articlePermission == nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(wxUser.UserId) + ";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 {
+		hasPermission = 1
+	}
+	if strings.Contains(detail.CategoryName, "研选") {
+		detail.IsResearch = true
+	}
+
+	resp.HasPermission = hasPermission
+	if hasPermission == 1 {
+		//获取销售手机号
+		sellerItem, err := models.GetSellerByCompanyId(wxUser.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取销售数据失败2,Err:" + strconv.Itoa(wxUser.UserId) + ";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(wxUser.UserId) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if detail.ArticleId >= utils.SummaryArticleId && strings.Contains(detail.SellerAndMobile, "-") {
+			strnum := strings.Index(detail.SellerAndMobile, "-")
+			detail.SellerAndMobile = detail.SellerAndMobile[0:strnum]
+			if strnum > 0 {
+				nickName := detail.SellerAndMobile[0:strnum]
+				sellerAndMobile := &models.SellerRep{
+					SellerMobile: "",
+					SellerName:   nickName,
+				}
+				sellerList = append(sellerList, sellerAndMobile)
+			}
+		}
+		detail.SellerList = sellerList
+		resp.Detail = detail
+		historyRecord := new(models.CygxArticleHistoryRecord)
+		historyRecord.UserId = wxUser.UserId
+		historyRecord.ArticleId = articleId
+		historyRecord.CreateTime = time.Now()
+		historyRecord.Mobile = wxUser.Mobile
+		historyRecord.Email = wxUser.Email
+		historyRecord.CompanyId = wxUser.CompanyId
+		historyRecord.CompanyName = companyName
+		recordCount, _ := models.GetNoAddStoptimeArticleCount(wxUser.UserId, articleId)
+		if recordCount == 0 {
+			go models.AddCygxArticleHistoryRecord(historyRecord)
+		} else {
+			detailNew, err := models.GetNewArticleHistoryRecord(wxUser.UserId, articleId)
+			if err != nil {
+				br.Msg = "获取信息失败"
+				br.ErrMsg = "获取信息失败,Err:" + err.Error()
+				return
+			}
+			if detailNew.StopTime > 0 {
+				go models.AddCygxArticleHistoryRecord(historyRecord)
+			}
+		}
+		key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(wxUser.UserId)
+		if !utils.Rc.IsExist(key) {
+			//新增浏览记录
+			record := new(models.CygxArticleViewRecord)
+			record.UserId = wxUser.UserId
+			record.ArticleId = articleId
+			record.CreateTime = time.Now()
+			record.Mobile = wxUser.Mobile
+			record.Email = wxUser.Email
+			record.CompanyId = wxUser.CompanyId
+			record.CompanyName = companyName
+			go models.AddCygxArticleViewRecord(record)
+			utils.Rc.Put(key, 1, 5*time.Second)
+			models.ModifyReportLastViewTime(wxUser.UserId)
+		}
+		if detail.ArticleId < utils.SummaryArticleId {
+			chartUserTokenByMobile, _ := services.GetUserTokenByMobile(utils.HtgjPublicMobile)
+			detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
+			detail.IsNeedJump = true
+		}
+	}
+	resp.CompanyName = companyName
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 页面访问统计(无需token)
+// @Description 上传页面访问统计(无需token)
+// @Param	request	body models.CygxPageHistoryRecordHtgjRep true "type json string"
+// @Success Ret=200 新增成功
+// @router /pageHistoryPublic [post]
+func (this *BaseHtgjController) PageHistoryPublic() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	var req models.CygxPageHistoryRecordHtgjRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	companyCode := req.CompanyCode
+	companyName := req.CompanyName
+	wxuUserName := req.Email
+	sign := req.Sign
+	if companyCode == "" || companyName == "" || wxuUserName == "" || sign == "" {
+		br.Msg = "上传失败"
+		br.ErrMsg = "必填参数不能为空"
+		return
+	}
+	companyNameHt := companyCode + "_" + companyName
+	errMsg := services.CheckSign(companyCode+companyName+wxuUserName, sign)
+	if errMsg != "" {
+		br.Msg = errMsg
+		return
+	}
+	companyInfo, err := models.GetCompanyByThirdName(companyNameHt)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+		return
+	}
+	user, err := models.GetUserByThirdName(companyInfo.CompanyId, wxuUserName)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
+		return
+	}
+	item := new(models.CygxPageHistoryRecord)
+	item.UserId = user.UserId
+	item.CreateTime = time.Now()
+	item.Mobile = user.Mobile
+	item.Email = user.Email
+	item.CompanyId = user.CompanyId
+	item.CompanyName = companyName
+	item.DetailId = req.DetailId
+	item.ChartPermissionId = req.ChartPermissionId
+	item.IndustrialManagementId = req.IndustrialManagementId
+	item.PageType = "ArticleCopy"
+	_, err = models.AddCygxPageHistoryRecord(item)
+	if err != nil {
+		br.Msg = "记录信息失败"
+		br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "新增成功"
+}

+ 1 - 1
services/task.go

@@ -97,7 +97,7 @@ func Task() {
 	//GetAddpArticle() //同步日度点评数据
 	//SendEmailAllUserWithRAI()     //发送当前所有权益用户到沈大爷的邮箱
 	//SendEmailAllUserWithCompany() //发送这些公司下的用户到沈大爷的邮箱
-	//task.StartTask()
+	task.StartTask()
 	//StatisticalReport()//导出报表
 	fmt.Println("end")
 }