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
- }
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param _page_size query int true "每页数据条数"
- // @Param _page query int true "当前页页码,从1开始"
- // @Param report_type query string true "类型 day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评 (默认为day:晨报) "
- // @Param keyword query string true "搜索关键词"
- // @Param mobile query string true "用户手机号(加密后的)"
- // @Success 200 {object} report.ReportListResp
- // @router /list [get]
- 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 + `%'`
- }
- //day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评
- 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 init() {
- // var pwd = []byte("15557270714,13253777798")
- // //services.Dojiami()
- // result := utils.DesBase64Encrypt(pwd)
- // fmt.Println(string(result))
- // var dateTxt = []byte("Tl8zwzgQNbEYPUvXleA/XQ==")
- // resultDe := utils.DesBase64Decrypt(dateTxt)
- // fmt.Println(string(resultDe))
- // //fmt.Println(resultStr)
- // //map[appid:XVuGlcyEEVNYVWx6 nonce_str:PsI0pAxDS4 research_report_id:1550 timestamp:1642522516]
- // //map[appid:XVuGlcyEEVNYVWx6 mobile:Tl8zwzgQNbEYPUvXleA/XQ== nonce_str:PsI0pAxDS4 research_report_id:1550 sign:0FFE4F38D4394EA72A947A8ADDAD4996 timestamp:1642522516]
- //
- // fmt.Println("加密解密")
- //}
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param research_report_id query int true "报告ID"
- // @Param mobile query string true "用户手机号(加密后的)"
- // @Success 200 {object} report.ResearchReportInfo
- // @router /getReportInfo [get]
- 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, "获取成功")
- }
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param ResearchReportTypeId query int true "章节ID"
- // @Param mobile query string false "用户手机号(加密后的)"
- // @Success 200 {object} report.ResearchReportTypeContentInfo
- // @router /getReportChapterInfo [get]
- 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, "获取成功")
- }
|