company_user.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. package controllers
  2. import (
  3. "hongze/hongze_open_api/logic"
  4. "hongze/hongze_open_api/models/response/company_user"
  5. "hongze/hongze_open_api/models/tables"
  6. "hongze/hongze_open_api/models/tables/wx_user"
  7. "hongze/hongze_open_api/utils"
  8. "strconv"
  9. "time"
  10. )
  11. // CompanyUser
  12. // 客户联系人模块
  13. type CompanyUser struct {
  14. BaseAuth
  15. }
  16. // GetUserReportList
  17. // @Title 获取用户阅读数据报表
  18. // @Description 获取用户阅读数据报表
  19. // @Param start_date query string false "开始日期,格式:2021-11-03"
  20. // @Param end_date query string false "结束日期,格式:2021-11-04"
  21. // @Param mobile query string false "用户手机号"
  22. // @Param email query string false "用户邮箱"
  23. // @Success 200 {object} company_user.UserReportListResp
  24. // @router /user_report_list [get]
  25. func (c *CompanyUser) GetUserReportList() {
  26. //appid权限校验
  27. appid := c.GetString("appid", "")
  28. if utils.RunMode == "release" && appid != "CQWx3EqDLNk7bVHo" {
  29. c.FailWithMessage("无权限")
  30. return
  31. }
  32. mobile := c.GetString("mobile", "")
  33. email := c.GetString("email", "")
  34. startDate := c.GetString("start_date", "")
  35. endDate := c.GetString("end_date", "")
  36. //}
  37. // return
  38. // c.FailWithMessage("end_date必传")
  39. //if endDate == ""{
  40. //}
  41. // return
  42. // c.FailWithMessage("start_date必传")
  43. //if startDate == ""{
  44. startTime := ``
  45. endTime := ``
  46. if startDate != "" && endDate != "" {
  47. startDateTime, err := time.Parse(utils.FormatDate, startDate)
  48. if err != nil {
  49. c.FailWithMessage("start_date格式异常")
  50. return
  51. }
  52. endDateTime, err := time.Parse(utils.FormatDate, endDate)
  53. if err != nil {
  54. c.FailWithMessage("end_date格式异常")
  55. return
  56. }
  57. startTime = startDateTime.Format(utils.FormatDate) + " 00:00:00"
  58. endTime = endDateTime.Format(utils.FormatDate) + " 23:59:59"
  59. }
  60. pageSize := c.PageSize
  61. startSize := c.StartSize
  62. currentIndex := c.StartPage
  63. total, list, err := tables.GetViewReportList(mobile, email, startTime, endTime, startSize, pageSize)
  64. if err != nil {
  65. c.FailWithMessage("获取失败")
  66. return
  67. }
  68. for k, v := range list {
  69. if v.ReportType == "day" {
  70. list[k].MatchTypeName = "晨报"
  71. } else if v.ReportType == "week" {
  72. list[k].MatchTypeName = "周报"
  73. } else if v.ReportType == "two_week" {
  74. list[k].MatchTypeName = "双周报"
  75. } else if v.ReportType == "month" {
  76. list[k].MatchTypeName = "月报"
  77. } else if v.ReportType == "rddp" {
  78. //list[k].MatchTypeName = "日评"
  79. createdTime := utils.StrTimeToTime(v.CreatedTime)
  80. monthStr := createdTime.Format("01")
  81. dayStr := strconv.Itoa(createdTime.Day())
  82. if len(dayStr) == 1 {
  83. dayStr = "0" + dayStr
  84. }
  85. list[k].ResearchReportName += "(" + monthStr + dayStr + ")"
  86. }
  87. if v.StopTime != "--" {
  88. list[k].StopTime += "s"
  89. }
  90. //v.CompanyName = wxUserInfo.CompanyName
  91. //v.UserName = wxUserInfo.RealName
  92. //v.Mobile = wxUserInfo.Mobile
  93. }
  94. page := utils.GetPaging(currentIndex, pageSize, total)
  95. resp := company_user.UserReportListResp{
  96. List: list,
  97. Paging: page,
  98. }
  99. c.OkDetailed(resp, "获取成功")
  100. }
  101. // GetUserReportListV2
  102. // @Title 获取用户阅读数据报表
  103. // @Description 合同详情接口
  104. // @Param mobile query string false "用户手机号"
  105. // @Param email query string false "用户邮箱"
  106. // @Success 200 {object} company_user.UserReportListResp
  107. func (c *CompanyUser) GetUserReportListV2() {
  108. mobile := c.GetString("mobile", "")
  109. startDate := c.GetString("start_date", "")
  110. endDate := c.GetString("end_date", "")
  111. if startDate == "" {
  112. c.FailWithMessage("start_date必传")
  113. return
  114. }
  115. if endDate == "" {
  116. c.FailWithMessage("end_date必传")
  117. return
  118. }
  119. startDateTime, err := time.Parse(utils.FormatDate, startDate)
  120. if err != nil {
  121. c.FailWithMessage("start_date格式异常")
  122. return
  123. }
  124. endDateTime, err := time.Parse(utils.FormatDate, endDate)
  125. if err != nil {
  126. c.FailWithMessage("end_date格式异常")
  127. return
  128. }
  129. var wxUserInfo *wx_user.WxUserItem
  130. if mobile != "" {
  131. item, err := wx_user.GetWxUserByMobile(mobile)
  132. if err != nil {
  133. c.FailWithMessage("找不到该用户")
  134. return
  135. }
  136. wxUserInfo = item
  137. }
  138. email := c.GetString("email", "")
  139. if wxUserInfo == nil && email != "" {
  140. item, err := wx_user.GetWxUserByEmail(email)
  141. if err != nil {
  142. c.FailWithMessage("找不到该用户")
  143. return
  144. }
  145. wxUserInfo = item
  146. }
  147. if wxUserInfo == nil {
  148. c.FailWithMessage("找不该用户")
  149. }
  150. pageSize := c.PageSize
  151. startSize := c.StartSize
  152. currentIndex := c.StartPage
  153. total, list, err := tables.GetViewReportList(wxUserInfo.Mobile, wxUserInfo.Email, startDateTime.Format(utils.FormatDate)+" 00:00:00", endDateTime.Format(utils.FormatDate)+" 23:59:59", startSize, pageSize)
  154. if err != nil {
  155. c.FailWithMessage("获取失败")
  156. return
  157. }
  158. for k, v := range list {
  159. if v.ReportType == "day" {
  160. list[k].MatchTypeName = "晨报"
  161. } else if v.ReportType == "week" {
  162. list[k].MatchTypeName = "周报"
  163. } else if v.ReportType == "two_week" {
  164. list[k].MatchTypeName = "双周报"
  165. } else if v.ReportType == "month" {
  166. list[k].MatchTypeName = "月报"
  167. } else if v.ReportType == "rddp" {
  168. //list[k].MatchTypeName = "日评"
  169. createdTime := utils.StrTimeToTime(v.CreatedTime)
  170. monthStr := createdTime.Format("01")
  171. dayStr := strconv.Itoa(createdTime.Day())
  172. if len(dayStr) == 1 {
  173. dayStr = "0" + dayStr
  174. }
  175. list[k].ResearchReportName += "(" + monthStr + dayStr + ")"
  176. }
  177. if v.StopTime != "--" {
  178. list[k].StopTime += "s"
  179. }
  180. v.CompanyName = wxUserInfo.CompanyName
  181. v.Mobile = wxUserInfo.Mobile
  182. }
  183. page := utils.GetPaging(currentIndex, pageSize, total)
  184. resp := company_user.UserReportListResp{
  185. List: list,
  186. Paging: page,
  187. }
  188. c.OkDetailed(resp, "获取成功")
  189. }
  190. // GetUserReportViewTotalList
  191. // @Title 获取用户阅读数据报表
  192. // @Description 获取用户阅读数据报表
  193. // @Success 200 {object} []logic.UserView
  194. // @router /view_total_list [get]
  195. func (c *CompanyUser) GetUserReportViewTotalList() {
  196. //appid权限校验
  197. appid := c.GetString("appid", "")
  198. if utils.RunMode == "release" && appid != "CQWx3EqDLNk7bVHo" {
  199. c.FailWithMessage("无权限")
  200. return
  201. }
  202. list, err := logic.GetUserViewTotal()
  203. if err != nil {
  204. c.FailWithMessage("获取失败")
  205. return
  206. }
  207. resp := list
  208. c.OkDetailed(resp, "获取成功")
  209. }