123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- package controllers
- import (
- "fmt"
- tables "hongze/hongze_open_api/models/tables/report"
- "hongze/hongze_open_api/models/tables/wx_user"
- "hongze/hongze_open_api/utils"
- "rdluck_tools/common"
- "strconv"
- "time"
- )
- type ReportController struct {
- BaseAuth
- }
- func (c *ReportController) ListReport() {
- pageSize, _ := c.GetInt("_page_size")
- currentIndex, _ := c.GetInt("_page")
- keyWord := c.GetString("keyword")
- reportType := c.GetString("report_type")
- mobile := c.GetString("mobile")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- if mobile == "" {
- c.FailWithMessage("mobile 必传")
- return
- }
- var dateTxt = []byte(mobile)
- resultDe := utils.DesBase64Decrypt(dateTxt)
- deMobile := string(resultDe)
- if deMobile == "" {
- c.FailWithMessage("手机号加密格式错误")
- return
- }
- totalFicc, err := tables.GetUserReportFiccCount(deMobile)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- if totalFicc < 1 {
- c.FailWithMessage("用户不存在")
- return
- }
- var condition string
- var pars []interface{}
- condition = ` AND enabled = 1 `
- if keyWord != "" {
- condition += ` AND research_report_name LIKE '%` + keyWord + `%'`
- }
-
- if reportType != "week" && reportType != "two_week" && reportType != "month" && reportType != "other" {
- reportType = "day"
- }
- if reportType != "" {
- condition += ` AND type = ? `
- pars = append(pars, reportType)
- }
- total, err := tables.GetReportListCount(condition, pars)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- list, err := tables.GetReportList(condition, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- nonceStr := common.GetRandString(10)
- timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
- if len(list) > 0 {
- for k, v := range list {
- postData := make(map[string]string)
- reportId := strconv.Itoa(v.ResearchReportId)
- parameter := "mobile=" + mobile + "&research_report_id=" + reportId + "&nonce_str=" + nonceStr + "×tamp=" + timeUnix
- postData["mobile"] = mobile
- postData["research_report_id"] = reportId
- postData["appid"] = utils.ReportAppid
- postData["nonce_str"] = nonceStr
- postData["timestamp"] = timeUnix
- sign := utils.GetSign(postData)
- list[k].HttpUrl = utils.ResearchReportUrl + "report/getReportInfo?" + parameter + "&sign=" + sign
- }
- }
- page := utils.GetPaging(currentIndex, pageSize, total)
- resp := tables.ReportListResp{
- List: list,
- Paging: page,
- }
- c.OkDetailed(resp, "获取成功")
- }
- func (c *ReportController) GetReportInfo() {
- researchReportId, _ := c.GetInt("research_report_id")
- mobile := c.GetString("mobile")
- if researchReportId < 1 {
- c.FailWithMessage("请传入报告id")
- return
- }
- if mobile == "" {
- c.FailWithMessage("mobile 必传")
- return
- }
- var dateTxt = []byte(mobile)
- resultDe := utils.DesBase64Decrypt(dateTxt)
- deMobile := string(resultDe)
- if deMobile == "" {
- c.FailWithMessage("手机号加密格式错误")
- return
- }
- totalFicc, err := tables.GetUserReportFiccCount(deMobile)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- if totalFicc < 1 {
- c.FailWithMessage("用户不存在")
- return
- }
- userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
- if err != nil {
- c.FailWithMessage("找不到该用户")
- return
- }
- reportInfo, hasPermission, err := tables.GetResearchReportInfo(researchReportId, userInfo.UserId)
- if err != nil {
- fmt.Println(err)
- c.FailWithMessage("获取报告失败")
- return
- }
- if !hasPermission {
- c.FailWithMessage("无权限")
- return
- }
- nonceStr := common.GetRandString(10)
- timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
- if len(reportInfo.ResearchReportTypeList) > 1 {
- for k, v := range reportInfo.ResearchReportTypeList {
- postData := make(map[string]string)
- reportId := strconv.Itoa(int(v.ResearchReportTypeId))
- parameter := "mobile=" + mobile + "&ResearchReportTypeId=" + reportId + "&appid=" + utils.ReportAppid + "&nonce_str=" + nonceStr + "×tamp=" + timeUnix
- postData["mobile"] = mobile
- postData["ResearchReportTypeId"] = reportId
- postData["appid"] = utils.ReportAppid
- postData["nonce_str"] = nonceStr
- postData["timestamp"] = timeUnix
- sign := utils.GetSign(postData)
- reportInfo.ResearchReportTypeList[k].HttpUrl = utils.ResearchReportUrl + "report/getReportChapterInfo?" + parameter + "&sign=" + sign
- }
- }
- c.OkDetailed(reportInfo, "获取成功")
- }
- func (c *ReportController) GetResearchReportChapter() {
- researchReportTypeId, _ := c.GetInt("ResearchReportTypeId")
- mobile := c.GetString("mobile")
- if researchReportTypeId < 1 {
- c.FailWithMessage("请传入章节id")
- return
- }
- if mobile == "" {
- c.FailWithMessage("mobile 必传")
- return
- }
- var dateTxt = []byte(mobile)
- resultDe := utils.DesBase64Decrypt(dateTxt)
- deMobile := string(resultDe)
- if deMobile == "" {
- c.FailWithMessage("手机号加密格式错误")
- return
- }
- totalFicc, err := tables.GetUserReportFiccCount(deMobile)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- if totalFicc < 1 {
- c.FailWithMessage("用户不存在")
- return
- }
- userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
- if err != nil {
- c.FailWithMessage("找不到该用户")
- return
- }
- reportInfo, hasPermission, err := tables.GetResearchReportTypeContentInfo(uint64(researchReportTypeId), uint64(userInfo.UserId))
- if err != nil {
- fmt.Println(err)
- c.FailWithMessage("获取报告失败")
- return
- }
- if !hasPermission {
- c.FailWithMessage("无权限")
- return
- }
- c.OkDetailed(reportInfo, "获取成功")
- }
|