report.go 7.5 KB

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