company_approval_message.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/utils"
  7. "strings"
  8. "time"
  9. )
  10. // 客户审批消息管理
  11. type CompanyApprovalMessageController struct {
  12. BaseAuthController
  13. }
  14. // @Title 待办消息列表
  15. // @Description 待办消息列表接口
  16. // @Success 200 {object} company.CompanyApprovalMessageListResp
  17. // @router /message/list [get]
  18. func (this *CompanyApprovalMessageController) SearchList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. sysUser := this.SysUser
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. sysUserId := sysUser.AdminId
  32. var startTime string
  33. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  34. startTime = time.Now().AddDate(0, -1, 0).Format(utils.FormatDateTime)
  35. }
  36. list, err := company.GetCompanyApprovalMessageList(sysUserId, startTime)
  37. if err != nil {
  38. br.Msg = "获取失败"
  39. br.ErrMsg = "获取失败,Err:" + err.Error()
  40. return
  41. }
  42. total, err := company.GetCompanyApprovalMessageCount(sysUserId, startTime)
  43. if err != nil {
  44. br.Msg = "获取失败"
  45. br.ErrMsg = "获取失败,Err:" + err.Error()
  46. return
  47. }
  48. resp := new(company.CompanyApprovalMessageListResp)
  49. resp.List = list
  50. resp.Total = total
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = resp
  55. }
  56. // @Title 待办消息列表(V2版本)
  57. // @Description 待办消息列表接口(V2版本)
  58. // @Success 200 {object} company.CompanyApprovalMessageListResp
  59. // @router /message/listV2 [get]
  60. func (this *CompanyApprovalMessageController) MessageList() {
  61. br := new(models.BaseResponse).Init()
  62. defer func() {
  63. this.Data["json"] = br
  64. this.ServeJSON()
  65. }()
  66. sysUser := this.SysUser
  67. if sysUser == nil {
  68. br.Msg = "请登录"
  69. br.ErrMsg = "请登录,SysUser Is Empty"
  70. br.Ret = 408
  71. return
  72. }
  73. sysUserId := sysUser.AdminId
  74. var startTime string
  75. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER {
  76. startTime = time.Now().AddDate(0, -1, 0).Format(utils.FormatDateTime)
  77. }
  78. list, err := company.GetCompanyApprovalMessageList(sysUserId, startTime)
  79. if err != nil {
  80. br.Msg = "获取失败"
  81. br.ErrMsg = "获取失败,Err:" + err.Error()
  82. return
  83. }
  84. //超管,管理员消息
  85. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  86. startTime = time.Now().AddDate(0, -1, 0).Format(utils.FormatDateTime)
  87. adminList, err := company.GetAdminCompanyApprovalMessageList(startTime)
  88. if err != nil {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "获取失败,Err:" + err.Error()
  91. return
  92. }
  93. list = append(list, adminList...)
  94. }
  95. companyMessageList := make([]*company.CompanyApprovalMessageList, 0)
  96. contractMessageList := make([]*company.CompanyApprovalMessageList, 0)
  97. sealMessageList := make([]*company.CompanyApprovalMessageList, 0)
  98. edbReplaceMessageList := make([]*company.CompanyApprovalMessageList, 0)
  99. etaTrialMessageList := make([]*company.ETATrialApprovalMessageList, 0)
  100. businessTripList := make([]*company.CompanyApprovalMessageList, 0)
  101. for i := 0; i < len(list); i++ {
  102. //if list[i].SourceType == 1
  103. switch list[i].SourceType {
  104. case 1:
  105. companyMessageList = append(companyMessageList, list[i])
  106. case 2:
  107. contractMessageList = append(contractMessageList, list[i])
  108. case 3:
  109. sealMessageList = append(sealMessageList, list[i])
  110. //case 4:
  111. // edbReplaceMessageList = append(edbReplaceMessageList, list[i])
  112. case 9:
  113. item := company.ETATrialApprovalMessageList{
  114. Id: list[i].Id,
  115. MessageStatus: list[i].MessageStatus,
  116. SourceType: list[i].SourceType,
  117. Remark: list[i].Remark,
  118. Content: list[i].Content,
  119. CompanyName: list[i].CompanyName,
  120. CreateTime: list[i].CreateTime,
  121. RealName: list[i].RealName,
  122. }
  123. if strings.Contains(item.Remark, "通过") {
  124. item.Redirect = 1
  125. } else {
  126. item.Redirect = 2
  127. }
  128. etaTrialMessageList = append(etaTrialMessageList, &item)
  129. case 10:
  130. businessTripList = append(businessTripList, list[i])
  131. }
  132. }
  133. companyMessageResp := company.CompanyApprovalMessageListResp{
  134. List: companyMessageList,
  135. Total: len(companyMessageList),
  136. }
  137. contractMessageResp := company.CompanyApprovalMessageListResp{
  138. List: contractMessageList,
  139. Total: len(contractMessageList),
  140. }
  141. sealMessageResp := company.CompanyApprovalMessageListResp{
  142. List: sealMessageList,
  143. Total: len(sealMessageList),
  144. }
  145. edbReplaceMessageResp := company.CompanyApprovalMessageListResp{
  146. List: edbReplaceMessageList,
  147. Total: len(edbReplaceMessageList),
  148. }
  149. etaTrialMessageResp := company.ETATrialApprovalMessageListResp{
  150. List: etaTrialMessageList,
  151. Total: len(etaTrialMessageList),
  152. }
  153. businessTripResp := company.CompanyApprovalMessageListResp{
  154. List: businessTripList,
  155. Total: len(businessTripList),
  156. }
  157. resp := company.CompanyApprovalMessageListV2Resp{
  158. Company: companyMessageResp,
  159. Contract: contractMessageResp,
  160. Seal: sealMessageResp,
  161. EdbReplace: edbReplaceMessageResp,
  162. ETATrial: etaTrialMessageResp,
  163. BusinessTrip: businessTripResp,
  164. }
  165. br.Ret = 200
  166. br.Success = true
  167. br.Msg = "获取成功"
  168. br.Data = resp
  169. }
  170. // @Title 消息已读
  171. // @Description 消息已读接口
  172. // @Param request body company.CompanyApprovalMessageReadReq true "type json string"
  173. // @Success Ret=200 申请成功
  174. // @router /message/read [post]
  175. func (this *CompanyApprovalMessageController) MessageRead() {
  176. br := new(models.BaseResponse).Init()
  177. defer func() {
  178. this.Data["json"] = br
  179. this.ServeJSON()
  180. }()
  181. sysUser := this.SysUser
  182. if sysUser == nil {
  183. br.Msg = "请登录"
  184. br.ErrMsg = "请登录,SysUser Is Empty"
  185. br.Ret = 408
  186. return
  187. }
  188. var req company.CompanyApprovalMessageReadReq
  189. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  190. if err != nil {
  191. br.Msg = "参数解析异常!"
  192. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  193. return
  194. }
  195. if req.Id <= 0 {
  196. br.Msg = "参数错误"
  197. br.ErrMsg = "参数错误,客户id小于等于0"
  198. return
  199. }
  200. item, e := company.GetCompanyApprovalMessageById(req.Id)
  201. if e != nil {
  202. if e.Error() != utils.ErrNoRow() {
  203. br.Msg = "消息已被删除, 请刷新页面"
  204. return
  205. }
  206. br.Msg = "操作失败"
  207. br.ErrMsg = "获取消息失败, Err: " + e.Error()
  208. return
  209. }
  210. // 如果是ETA试用消息且为普通销售, 已读其中一条那么所有该接收者的ETA试用消息均变为已读
  211. if item.SourceType == 9 && (sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER) {
  212. cond := ` AND receive_user_id = ? AND source_type = ? AND message_status = ?`
  213. pars := make([]interface{}, 0)
  214. pars = append(pars, sysUser.AdminId, 9, 0)
  215. if e := company.ModifyCompanyApprovalMessageStatusByCond(cond, pars); e != nil {
  216. br.Msg = "操作失败"
  217. br.ErrMsg = "更新销售ETA试用消息已读状态失败, Err: " + e.Error()
  218. return
  219. }
  220. } else {
  221. err = company.ModifyCompanyApprovalMessageStatus(req.Id)
  222. if err != nil {
  223. br.Msg = "修改失败!"
  224. br.ErrMsg = "修改已读失败,Err:" + err.Error()
  225. return
  226. }
  227. }
  228. br.Ret = 200
  229. br.Success = true
  230. br.Msg = "已读成功"
  231. }