package controllers

import (
	"hongze/hongze_cygx/models"
	"hongze/hongze_cygx/models/ficc_report"
	"hongze/hongze_cygx/services"
	"hongze/hongze_cygx/utils"
	"time"
)

type FiccYbController struct {
	BaseAuthController
}

// @Title 获取报告详情
// @Description 获取报告详情接口
// @Param   ReportId   query   int  true       "报告ID"
// @Success 200 {object} models.ArticleDetailResp
// @router /detail [get]
func (this *FiccYbController) 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
	reportId, err := this.GetInt("ReportId")
	if err != nil {
		br.Msg = "文章不存在"
		br.ErrMsg = "文章不存在，文章ID错误" + err.Error()
		return
	}
	if reportId <= 0 {
		br.Msg = "文章不存在"
		br.ErrMsg = "文章不存在，文章ID错误"
		return
	}
	detail, err := services.GetReportDetail(user, reportId)
	if err != nil {
		br.Msg = "文章不存在"
		br.ErrMsg = "获取研报信息失败" + err.Error()
		return
	}
	br.Ret = 200
	br.Success = true
	br.Msg = "获取成功"
	br.Data = detail
}

// @Title 记录点击信息
// @Description 记录点击信息
// @Param	request	body cygx.CygxBannerIdReq true "type json string"
// @Success 200 Ret=200 发布成功
// @router /add/xcx/history [post]
func (this *FiccYbController) AddXcxHistory() {
	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
	}
	historyRecord := new(ficc_report.FiccYbXcxHistory)
	historyRecord.UserId = user.UserId
	historyRecord.RealName = user.RealName
	historyRecord.CreateTime = time.Now()
	historyRecord.Mobile = user.Mobile
	historyRecord.Email = user.Email
	historyRecord.CompanyId = user.CompanyId
	historyRecord.CompanyName = user.CompanyName
	historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
	historyRecord.SellerName, _, _ = services.GetSellerName(user)
	_, err := ficc_report.AddFiccYbXcxHistory(historyRecord)
	if err != nil {
		br.Msg = "记录访问信息失败"
		br.ErrMsg = "记录访问信息失败" + err.Error()
	}
	br.Ret = 200
	br.Success = true
	br.Msg = "记录成功"
}
