calendar.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. package roadshow
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_mobile_admin/controllers"
  6. "hongze/hongze_mobile_admin/models"
  7. "hongze/hongze_mobile_admin/models/roadshow"
  8. "hongze/hongze_mobile_admin/models/tables/admin"
  9. "hongze/hongze_mobile_admin/services"
  10. "hongze/hongze_mobile_admin/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. //日历
  16. type CalendarController struct {
  17. controllers.BaseAuth
  18. }
  19. // CalendarList
  20. // @Title 我的日历列表
  21. // @Description 我的日历列表接口
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码,从1开始"
  24. // @Param Status query int true "1:待接受,2:包含,已接受,已拒绝,已删除"
  25. // @Success 200 {object} roadshow.CalendarListResp
  26. // @router /calendar/list [get]
  27. func (this *CalendarController) CalendarList() {
  28. adminItem := this.AdminWx
  29. status, _ := this.GetInt("Status")
  30. pageSize, _ := this.GetInt("PageSize")
  31. currentIndex, _ := this.GetInt("CurrentIndex")
  32. var total int
  33. page := paging.GetPaging(currentIndex, pageSize, total)
  34. var startSize int
  35. if pageSize <= 0 {
  36. pageSize = utils.PageSize10
  37. }
  38. if currentIndex <= 0 {
  39. currentIndex = 1
  40. }
  41. startSize = paging.StartIndex(currentIndex, pageSize)
  42. var condition string
  43. var pars []interface{}
  44. condition += ` AND b.researcher_id=?`
  45. pars = append(pars, adminItem.AdminId)
  46. condition += ` AND a.activity_type IN('路演','公开会议') `
  47. if status == 1 {
  48. condition += ` AND b.status=?`
  49. pars = append(pars, 1)
  50. } else {
  51. condition += ` AND b.status IN(2,3,4)`
  52. }
  53. resp := new(roadshow.CalendarListResp)
  54. total, err := roadshow.GetCalendarListCount(condition, pars)
  55. if err != nil && err.Error() != utils.ErrNoRow() {
  56. this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarListCount,Err:"+err.Error())
  57. return
  58. }
  59. page = paging.GetPaging(currentIndex, pageSize, total)
  60. dataList, err := roadshow.GetCalendarList(condition, pars, status, startSize, pageSize)
  61. if err != nil {
  62. this.FailWithMessage("获取信息失败!", "获取数据失败,GetCalendarList,Err:"+err.Error())
  63. return
  64. }
  65. resp.Paging = page
  66. resp.List = dataList
  67. this.OkDetailed(resp, "获取成功")
  68. }
  69. // Accept
  70. // @Description 接受路演活动接口
  71. // @Param request body roadshow.AcceptReq true "type json string"
  72. // @Success Ret=200 保存成功
  73. // @router /accept [post]
  74. func (this *CalendarController) Accept() {
  75. //adminItem:=this.AdminWx
  76. var req roadshow.AcceptReq
  77. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  78. if err != nil {
  79. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  80. return
  81. }
  82. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  83. this.FailWithMessage("参数错误!", "RsCalendarId 或 RsCalendarResearcherId 小于等于0:")
  84. return
  85. }
  86. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  87. if err != nil {
  88. this.FailWithMessage("获取数据失败!", "GetRsCalendarById Err:"+err.Error())
  89. return
  90. }
  91. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  92. if err != nil {
  93. this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById Err:"+err.Error())
  94. return
  95. }
  96. if rsCalendarResearcher.Status == 2 {
  97. this.FailWithMessage("已接受,不可重复操作!", "")
  98. return
  99. } else if rsCalendarResearcher.Status == 3 {
  100. this.FailWithMessage("已拒绝,不可进行接受操作!", "")
  101. return
  102. } else if rsCalendarResearcher.Status == 4 {
  103. this.FailWithMessage("已删除,不可进行接受操作!", "")
  104. return
  105. } else if rsCalendarResearcher.Status == 5 {
  106. this.FailWithMessage("已撤回,不可进行接受操作!", "")
  107. return
  108. }
  109. whereParams := make(map[string]interface{})
  110. updateParams := make(map[string]interface{})
  111. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  112. whereParams["rs_calendar_id"] = req.RsCalendarId
  113. updateParams["status"] = 2
  114. updateParams["modify_time"] = time.Now()
  115. updateParams["approve_time"] = time.Now()
  116. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  117. if err != nil {
  118. this.FailWithMessage("获取数据失败!", "UpdateCalendarResearcher Err:"+err.Error())
  119. return
  120. }
  121. //模板消息通知
  122. {
  123. if rsCalendar != nil {
  124. sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
  125. first := "【" + this.AdminWx.RealName + "】接受了你的【" + rsCalendar.ActivityType + "】申请"
  126. var keyword1 string
  127. if rsCalendar.ActivityType == "路演" {
  128. keyword1 = rsCalendar.CompanyName + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  129. } else {
  130. keyword1 = rsCalendar.Theme + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  131. }
  132. keyword2 := "已接受"
  133. remark := ""
  134. if sysAdmin.Mobile != "" {
  135. go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, sysAdmin.Mobile, "", "")
  136. }
  137. }
  138. }
  139. this.OkDetailed(nil, "保存成功")
  140. }
  141. // @Title 拒绝路演活动接口
  142. // @Description 拒绝路演活动接口
  143. // @Param request body roadshow.RefuseReq true "type json string"
  144. // @Success Ret=200 保存成功
  145. // @router /refuse [post]
  146. func (this *CalendarController) Refuse() {
  147. //adminItem:=this.AdminWx
  148. var req roadshow.RefuseReq
  149. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  150. if err != nil {
  151. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  152. return
  153. }
  154. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  155. this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  156. return
  157. }
  158. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  159. if err != nil {
  160. this.FailWithMessage("获取数据失败!", "GetRsCalendarById,Err:"+err.Error())
  161. return
  162. }
  163. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  164. if err != nil {
  165. this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById,Err:"+err.Error())
  166. return
  167. }
  168. if rsCalendarResearcher.Status == 2 {
  169. this.FailWithMessage("已接受,不可进行拒绝操作!", "")
  170. return
  171. } else if rsCalendarResearcher.Status == 3 {
  172. this.FailWithMessage("已拒绝,不可进行重复操作!", "")
  173. return
  174. } else if rsCalendarResearcher.Status == 4 {
  175. this.FailWithMessage("已删除,不可进行拒绝操作!", "")
  176. return
  177. } else if rsCalendarResearcher.Status == 5 {
  178. this.FailWithMessage("已撤回,不可进行拒绝操作!", "")
  179. return
  180. }
  181. whereParams := make(map[string]interface{})
  182. updateParams := make(map[string]interface{})
  183. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  184. whereParams["rs_calendar_id"] = req.RsCalendarId
  185. updateParams["status"] = 3
  186. updateParams["refuse_reason"] = req.RefuseReason
  187. updateParams["refuse_time"] = time.Now()
  188. updateParams["modify_time"] = time.Now()
  189. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  190. if err != nil {
  191. this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
  192. return
  193. }
  194. //模板消息通知
  195. {
  196. if rsCalendar != nil {
  197. sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
  198. first := "【" + this.AdminWx.RealName + "】拒绝了你的【" + rsCalendar.ActivityType + "】申请"
  199. var keyword1 string
  200. if rsCalendar.ActivityType == "路演" {
  201. keyword1 = rsCalendar.CompanyName + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  202. } else {
  203. keyword1 = rsCalendar.Theme + "," + rsCalendar.RoadshowType + rsCalendar.ActivityType
  204. }
  205. keyword2 := "已拒绝"
  206. remark := req.RefuseReason
  207. if sysAdmin.Mobile != "" {
  208. go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, sysAdmin.Mobile, "", "")
  209. }
  210. }
  211. }
  212. this.OkDetailed(nil, "保存成功")
  213. }
  214. // @Title 日历详情
  215. // @Description 日历详情接口
  216. // @Param RsCalendarId query int true "路演活动id"
  217. // @Param RsCalendarResearcherId query int true "活动研究员id"
  218. // @Success 200 {object} roadshow.CalendarDetailResp
  219. // @router /calendar/detail [get]
  220. func (this *CalendarController) CalendarDetail() {
  221. //adminItem:=this.AdminWx
  222. //roleTypeCode := adminItem.RoleTypeCode
  223. rsCalendarId, _ := this.GetInt("RsCalendarId")
  224. rsCalendarResearcherId, _ := this.GetInt("RsCalendarResearcherId")
  225. if rsCalendarId <= 0 || rsCalendarResearcherId <= 0 {
  226. this.FailWithMessage("参数错误", "rsCalendarId 或 rsCalendarResearcherId")
  227. return
  228. }
  229. calendarItem, err := roadshow.GetRsCalendarById(rsCalendarId)
  230. if err != nil {
  231. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
  232. return
  233. }
  234. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(rsCalendarResearcherId)
  235. if err != nil {
  236. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  237. return
  238. }
  239. companyDetailView := new(roadshow.CompanyDetailView)
  240. if calendarItem != nil && calendarItem.CompanyId > 0 {
  241. companyId := calendarItem.CompanyId
  242. companyProductItem, err := models.GetCompanyProductByCompanyIdAndProductId(companyId, 1)
  243. if err != nil {
  244. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  245. return
  246. }
  247. permissionList, err := models.GetCompanyProductReportPermissionList(companyId, 1)
  248. if err != nil {
  249. this.FailWithMessage("搜索客户权限失败", "搜索客户权限失败!GetRsCalendarResearcherById:"+err.Error())
  250. return
  251. }
  252. var permissionArr []string
  253. for _, v := range permissionList {
  254. permissionArr = append(permissionArr, v.PermissionName)
  255. }
  256. readNum := companyProductItem.ViewTotal
  257. companyDetailView.CompanyId = companyProductItem.CompanyId
  258. companyDetailView.CompanyName = companyProductItem.CompanyName
  259. companyDetailView.Status = companyProductItem.Status
  260. companyDetailView.IndustryId = companyProductItem.IndustryId
  261. companyDetailView.IndustryName = companyProductItem.IndustryName
  262. companyDetailView.PermissionName = strings.Join(permissionArr, "/")
  263. companyDetailView.ReportReadTotal = readNum //ficc报告-累计阅读次数
  264. }
  265. resp := new(roadshow.CalendarDetailResp)
  266. resp.RsCalendarItem = calendarItem
  267. resp.RsCalendarResearcherItem = rsCalendarResearcherItem
  268. resp.CompanyDetail = companyDetailView
  269. this.OkDetailed(resp, "获取成功")
  270. }