report.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. mobile, err = url.QueryUnescape(mobile)
  66. if err != nil {
  67. c.FailWithMessage("mobile 必传")
  68. return
  69. }
  70. var dateTxt = []byte(mobile)
  71. resultDe := utils.DesBase64Decrypt(dateTxt)
  72. deMobile := string(resultDe)
  73. if deMobile == "" {
  74. c.FailWithMessage("手机号加密格式错误")
  75. return
  76. }
  77. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  78. if err != nil {
  79. c.FailWithMessage("获取失败")
  80. return
  81. }
  82. if totalFicc < 1 {
  83. c.FailWithMessage("用户不存在")
  84. return
  85. }
  86. var condition string
  87. var pars []interface{}
  88. condition = ` AND enabled = 1 `
  89. if keyWord != "" {
  90. condition += ` AND research_report_name LIKE '%` + keyWord + `%'`
  91. }
  92. //day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评
  93. if reportType != "week" && reportType != "two_week" && reportType != "month" && reportType != "other" {
  94. reportType = "day"
  95. }
  96. if reportType != "" {
  97. condition += ` AND type = ? AND status = 'report' `
  98. pars = append(pars, reportType)
  99. }
  100. total, err := tables.GetReportListCount(condition, pars)
  101. if err != nil {
  102. c.FailWithMessage("获取失败")
  103. return
  104. }
  105. list, err := tables.GetReportList(condition, pars, startSize, pageSize)
  106. if err != nil {
  107. c.FailWithMessage("获取失败")
  108. return
  109. }
  110. mobile = url.QueryEscape(mobile) //转义 +
  111. nonceStr := common.GetRandString(10)
  112. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  113. if len(list) > 0 {
  114. for k, v := range list {
  115. postData := make(map[string]string)
  116. reportId := strconv.Itoa(v.ResearchReportId)
  117. parameter := "mobile=" + mobile + "&research_report_id=" + reportId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  118. postData["mobile"] = mobile
  119. postData["research_report_id"] = reportId
  120. postData["appid"] = utils.ReportAppid
  121. postData["nonce_str"] = nonceStr
  122. postData["timestamp"] = timeUnix
  123. sign := utils.GetSign(postData)
  124. list[k].HttpUrl = utils.ResearchReportUrl + "hzsl/report/detail?" + parameter + "&sign=" + sign
  125. }
  126. }
  127. page := utils.GetPaging(currentIndex, pageSize, total)
  128. resp := tables.ReportListResp{
  129. List: list,
  130. Paging: page,
  131. }
  132. c.OkDetailed(resp, "获取成功")
  133. }
  134. // @Title 获取报告详情
  135. // @Description 获取报告详情
  136. // @Param research_report_id query int true "报告ID"
  137. // @Param mobile query string true "用户手机号(加密后的)"
  138. // @Success 200 {object} report.ResearchReportInfo
  139. // @router /getReportInfo [get]
  140. func (c *ReportControllerCommon) GetReportInfo() {
  141. researchReportId, _ := c.GetInt("research_report_id")
  142. //mobile := c.GetString("mobile")
  143. if researchReportId < 1 {
  144. c.FailWithMessage("请传入报告id")
  145. return
  146. }
  147. mobile := c.GetString("mobile")
  148. if mobile == "" {
  149. c.FailWithMessage("mobile 必传")
  150. return
  151. }
  152. var dateTxt = []byte(mobile)
  153. resultDe := utils.DesBase64Decrypt(dateTxt)
  154. deMobile := string(resultDe)
  155. if deMobile == "" {
  156. c.FailWithMessage("手机号加密格式错误")
  157. return
  158. }
  159. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  160. if err != nil {
  161. c.FailWithMessage("获取失败")
  162. return
  163. }
  164. if totalFicc < 1 {
  165. c.FailWithMessage("用户不存在")
  166. return
  167. }
  168. userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
  169. if err != nil {
  170. c.FailWithMessage("找不到该用户")
  171. return
  172. }
  173. reportInfo, hasPermission, err := tables.GetResearchReportInfo(researchReportId, userInfo.UserId)
  174. if err != nil {
  175. fmt.Println(err)
  176. c.FailWithMessage("获取报告失败")
  177. return
  178. }
  179. if !hasPermission {
  180. c.FailWithMessage("无权限")
  181. return
  182. }
  183. mobile = url.QueryEscape(mobile) //转义 +
  184. nonceStr := common.GetRandString(10)
  185. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  186. if len(reportInfo.ResearchReportTypeList) > 1 {
  187. for k, v := range reportInfo.ResearchReportTypeList {
  188. postData := make(map[string]string)
  189. reportId := strconv.Itoa(int(v.ResearchReportTypeId))
  190. parameter := "mobile=" + mobile + "&ResearchReportTypeId=" + reportId + "&appid=" + utils.ReportAppid + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  191. postData["mobile"] = mobile
  192. postData["ResearchReportTypeId"] = reportId
  193. postData["appid"] = utils.ReportAppid
  194. postData["nonce_str"] = nonceStr
  195. postData["timestamp"] = timeUnix
  196. sign := utils.GetSign(postData)
  197. reportInfo.ResearchReportTypeList[k].HttpUrl = utils.ResearchReportUrl + "report/?" + parameter + "&sign=" + sign
  198. }
  199. }
  200. c.OkDetailed(reportInfo, "获取成功")
  201. }
  202. // @Title 获取章节详情接口
  203. // @Description 获取章节详情
  204. // @Param ResearchReportTypeId query int true "章节ID"
  205. // @Param mobile query string false "用户手机号(加密后的)"
  206. // @Success 200 {object} report.ResearchReportTypeContentInfo
  207. // @router /getReportChapterInfo [get]
  208. func (c *ReportControllerCommon) GetResearchReportChapter() {
  209. researchReportTypeId, _ := c.GetInt("ResearchReportTypeId")
  210. //mobile := c.GetString("mobile")
  211. if researchReportTypeId < 1 {
  212. c.FailWithMessage("请传入章节id")
  213. return
  214. }
  215. mobile := c.GetString("mobile")
  216. if mobile == "" {
  217. c.FailWithMessage("mobile 必传")
  218. return
  219. }
  220. var dateTxt = []byte(mobile)
  221. resultDe := utils.DesBase64Decrypt(dateTxt)
  222. deMobile := string(resultDe)
  223. if deMobile == "" {
  224. c.FailWithMessage("手机号加密格式错误")
  225. return
  226. }
  227. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  228. if err != nil {
  229. c.FailWithMessage("获取失败")
  230. return
  231. }
  232. if totalFicc < 1 {
  233. c.FailWithMessage("用户不存在")
  234. return
  235. }
  236. userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
  237. if err != nil {
  238. c.FailWithMessage("找不到该用户")
  239. return
  240. }
  241. reportInfo, hasPermission, err := tables.GetResearchReportTypeContentInfo(uint64(researchReportTypeId), uint64(userInfo.UserId))
  242. if err != nil {
  243. fmt.Println(err)
  244. c.FailWithMessage("获取报告失败")
  245. return
  246. }
  247. if !hasPermission {
  248. c.FailWithMessage("无权限")
  249. return
  250. }
  251. c.OkDetailed(reportInfo, "获取成功")
  252. }