report.go 7.4 KB

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