report.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. package controllers
  2. import (
  3. "fmt"
  4. "github.com/rdlucklib/rdluck_tools/common"
  5. tables "hongze/hongze_open_api/models/tables/report"
  6. "hongze/hongze_open_api/models/tables/wx_user"
  7. "hongze/hongze_open_api/utils"
  8. "net/url"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // 报告模块
  14. type ReportController struct {
  15. BaseAuth
  16. }
  17. // 报告模块
  18. type ReportControllerCommon struct {
  19. BaseCommon
  20. }
  21. // @Title 获取报告列表接口
  22. // @Description 获取报告列表
  23. // @Param _page_size query int true "每页数据条数"
  24. // @Param _page query int true "当前页页码,从1开始"
  25. // @Param report_type query string true "类型 day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评 (默认为day:晨报) "
  26. // @Param keyword query string true "搜索关键词"
  27. // @Param mobile query string true "用户手机号(加密后的)"
  28. // @Success 200 {object} report.ReportListResp
  29. // @router /list [get]
  30. func (c *ReportController) ListReport() {
  31. pageSize, _ := c.GetInt("_page_size")
  32. currentIndex, _ := c.GetInt("_page")
  33. keyWord := c.GetString("keyword")
  34. reportType := c.GetString("report_type")
  35. //mobile := c.GetString("mobile")
  36. var startSize int
  37. if pageSize <= 0 {
  38. pageSize = utils.PageSize20
  39. }
  40. if currentIndex <= 0 {
  41. currentIndex = 1
  42. }
  43. startSize = utils.StartIndex(currentIndex, pageSize)
  44. //通过url获取mobile中的参数
  45. var mobile string
  46. URL, err := url.Parse(c.Ctx.Input.URI())
  47. if err != nil {
  48. fmt.Println(err)
  49. c.FailWithMessage("获取报告失败")
  50. return
  51. }
  52. urlParameter := URL.RawQuery
  53. sliceUrl := strings.Split(urlParameter, "&")
  54. if len(sliceUrl) > 0 {
  55. for _, v := range sliceUrl {
  56. if strings.Contains(v, "mobile=") {
  57. mobile = strings.Replace(v, "mobile=", "", -1)
  58. }
  59. }
  60. }
  61. if mobile == "" {
  62. c.FailWithMessage("mobile 必传")
  63. return
  64. }
  65. var dateTxt = []byte(mobile)
  66. resultDe := utils.DesBase64Decrypt(dateTxt)
  67. deMobile := string(resultDe)
  68. if deMobile == "" {
  69. c.FailWithMessage("手机号加密格式错误")
  70. return
  71. }
  72. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  73. if err != nil {
  74. c.FailWithMessage("获取失败")
  75. return
  76. }
  77. if totalFicc < 1 {
  78. c.FailWithMessage("用户不存在")
  79. return
  80. }
  81. var condition string
  82. var pars []interface{}
  83. condition = ` AND enabled = 1 `
  84. if keyWord != "" {
  85. condition += ` AND research_report_name LIKE '%` + keyWord + `%'`
  86. }
  87. //day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评
  88. if reportType != "week" && reportType != "two_week" && reportType != "month" && reportType != "other" {
  89. reportType = "day"
  90. }
  91. if reportType != "" {
  92. condition += ` AND type = ? AND status = 'report' `
  93. pars = append(pars, reportType)
  94. }
  95. total, err := tables.GetReportListCount(condition, pars)
  96. if err != nil {
  97. c.FailWithMessage("获取失败")
  98. return
  99. }
  100. list, err := tables.GetReportList(condition, pars, startSize, pageSize)
  101. if err != nil {
  102. c.FailWithMessage("获取失败")
  103. return
  104. }
  105. mobile = url.QueryEscape(mobile) //转义 +
  106. nonceStr := common.GetRandString(10)
  107. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  108. if len(list) > 0 {
  109. for k, v := range list {
  110. postData := make(map[string]string)
  111. reportId := strconv.Itoa(v.ResearchReportId)
  112. parameter := "mobile=" + mobile + "&research_report_id=" + reportId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  113. postData["mobile"] = mobile
  114. postData["research_report_id"] = reportId
  115. postData["appid"] = utils.ReportAppid
  116. postData["nonce_str"] = nonceStr
  117. postData["timestamp"] = timeUnix
  118. sign := utils.GetSign(postData)
  119. list[k].HttpUrl = utils.ResearchReportUrl + "hzsl/report/detail?" + parameter + "&sign=" + sign
  120. }
  121. }
  122. page := utils.GetPaging(currentIndex, pageSize, total)
  123. resp := tables.ReportListResp{
  124. List: list,
  125. Paging: page,
  126. }
  127. c.OkDetailed(resp, "获取成功")
  128. }
  129. // @Title 获取报告详情
  130. // @Description 获取报告详情
  131. // @Param research_report_id query int true "报告ID"
  132. // @Param mobile query string true "用户手机号(加密后的)"
  133. // @Success 200 {object} report.ResearchReportInfo
  134. // @router /getReportInfo [get]
  135. func (c *ReportControllerCommon) GetReportInfo() {
  136. researchReportId, _ := c.GetInt("research_report_id")
  137. //mobile := c.GetString("mobile")
  138. if researchReportId < 1 {
  139. c.FailWithMessage("请传入报告id")
  140. return
  141. }
  142. mobile := c.GetString("mobile")
  143. if mobile == "" {
  144. c.FailWithMessage("mobile 必传")
  145. return
  146. }
  147. var dateTxt = []byte(mobile)
  148. resultDe := utils.DesBase64Decrypt(dateTxt)
  149. deMobile := string(resultDe)
  150. if deMobile == "" {
  151. c.FailWithMessage("手机号加密格式错误")
  152. return
  153. }
  154. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  155. if err != nil {
  156. c.FailWithMessage("获取失败")
  157. return
  158. }
  159. if totalFicc < 1 {
  160. c.FailWithMessage("用户不存在")
  161. return
  162. }
  163. userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
  164. if err != nil {
  165. c.FailWithMessage("找不到该用户")
  166. return
  167. }
  168. reportInfo, hasPermission, err := tables.GetResearchReportInfo(researchReportId, userInfo.UserId)
  169. if err != nil {
  170. fmt.Println(err)
  171. c.FailWithMessage("获取报告失败")
  172. return
  173. }
  174. if !hasPermission {
  175. c.FailWithMessage("无权限")
  176. return
  177. }
  178. mobile = url.QueryEscape(mobile) //转义 +
  179. nonceStr := common.GetRandString(10)
  180. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  181. if len(reportInfo.ResearchReportTypeList) > 1 {
  182. for k, v := range reportInfo.ResearchReportTypeList {
  183. postData := make(map[string]string)
  184. reportId := strconv.Itoa(int(v.ResearchReportTypeId))
  185. parameter := "mobile=" + mobile + "&ResearchReportTypeId=" + reportId + "&appid=" + utils.ReportAppid + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  186. postData["mobile"] = mobile
  187. postData["ResearchReportTypeId"] = reportId
  188. postData["appid"] = utils.ReportAppid
  189. postData["nonce_str"] = nonceStr
  190. postData["timestamp"] = timeUnix
  191. sign := utils.GetSign(postData)
  192. reportInfo.ResearchReportTypeList[k].HttpUrl = utils.ResearchReportUrl + "report/?" + parameter + "&sign=" + sign
  193. }
  194. }
  195. c.OkDetailed(reportInfo, "获取成功")
  196. }
  197. // @Title 获取章节详情接口
  198. // @Description 获取章节详情
  199. // @Param ResearchReportTypeId query int true "章节ID"
  200. // @Param mobile query string false "用户手机号(加密后的)"
  201. // @Success 200 {object} report.ResearchReportTypeContentInfo
  202. // @router /getReportChapterInfo [get]
  203. func (c *ReportControllerCommon) GetResearchReportChapter() {
  204. researchReportTypeId, _ := c.GetInt("ResearchReportTypeId")
  205. //mobile := c.GetString("mobile")
  206. if researchReportTypeId < 1 {
  207. c.FailWithMessage("请传入章节id")
  208. return
  209. }
  210. mobile := c.GetString("mobile")
  211. if mobile == "" {
  212. c.FailWithMessage("mobile 必传")
  213. return
  214. }
  215. var dateTxt = []byte(mobile)
  216. resultDe := utils.DesBase64Decrypt(dateTxt)
  217. deMobile := string(resultDe)
  218. if deMobile == "" {
  219. c.FailWithMessage("手机号加密格式错误")
  220. return
  221. }
  222. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  223. if err != nil {
  224. c.FailWithMessage("获取失败")
  225. return
  226. }
  227. if totalFicc < 1 {
  228. c.FailWithMessage("用户不存在")
  229. return
  230. }
  231. userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
  232. if err != nil {
  233. c.FailWithMessage("找不到该用户")
  234. return
  235. }
  236. reportInfo, hasPermission, err := tables.GetResearchReportTypeContentInfo(uint64(researchReportTypeId), uint64(userInfo.UserId))
  237. if err != nil {
  238. fmt.Println(err)
  239. c.FailWithMessage("获取报告失败")
  240. return
  241. }
  242. if !hasPermission {
  243. c.FailWithMessage("无权限")
  244. return
  245. }
  246. c.OkDetailed(reportInfo, "获取成功")
  247. }