activity_loss.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package cygx
  2. import (
  3. "hongze/hz_crm_api/controllers"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/models/company"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/utils"
  8. "strings"
  9. )
  10. // 到会管理
  11. type ActivityLossCoAntroller struct {
  12. controllers.BaseAuthController
  13. }
  14. // @Title 获取流失且参加过会议的客户
  15. // @Description 获取流失且参加过会议的客户接口
  16. // @Param KeyWord query string true "搜索关键词"
  17. // @Success 200 {object} cygx.CompanyNameAndIdListResp
  18. // @router /activityLoss/company/list [get]
  19. func (this *ActivityLossCoAntroller) CompanyList() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. sysUser := this.SysUser
  26. if sysUser == nil {
  27. br.Msg = "请登录"
  28. br.ErrMsg = "请登录,SysUser Is Empty"
  29. br.Ret = 408
  30. return
  31. }
  32. keyWord := this.GetString("KeyWord")
  33. keyWord = strings.Trim(keyWord, " ")
  34. keyWord = strings.Replace(keyWord, "'", "", -1)
  35. if keyWord == "" {
  36. br.Msg = "请输入关键词"
  37. br.IsSendEmail = false
  38. return
  39. }
  40. resp := new(company.CompanyNameAndIdListResp)
  41. var companyCondition string
  42. var companypars []interface{}
  43. var listResp []*company.CompanyNameAndId
  44. companyCondition += ` AND b.product_name = ? `
  45. companypars = append(companypars, "权益")
  46. companyCondition += ` AND b.status = ? `
  47. companypars = append(companypars, "流失")
  48. companyCondition += ` AND a.company_name LIKE '%` + keyWord + `%' `
  49. companyList, err := company.GetCompanyIdListByproductName(companyCondition, companypars)
  50. if err != nil {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "获取失败,Err:" + err.Error()
  53. return
  54. }
  55. companyArr := make([]int, 0)
  56. for _, v := range companyList {
  57. companyArr = append(companyArr, v.CompanyId)
  58. }
  59. companyLen := len(companyArr)
  60. if companyLen == 0 {
  61. goto Loop
  62. } else {
  63. var condition string
  64. var pars []interface{}
  65. condition += ` AND s.company_id IN (` + utils.GetOrmInReplace(companyLen) + `)`
  66. pars = append(pars, companyArr)
  67. companyUserSignUpList, err := cygx.GetCompanyByUserSignUp(condition, pars)
  68. if err != nil {
  69. br.Msg = "获取失败"
  70. br.ErrMsg = "获取失败,Err:" + err.Error()
  71. return
  72. }
  73. mapcompanyUserSignUp := make(map[int]int)
  74. for _, v := range companyUserSignUpList {
  75. mapcompanyUserSignUp[v.CompanyId] = v.CompanyId
  76. }
  77. for _, v := range companyList {
  78. if _, ok := mapcompanyUserSignUp[v.CompanyId]; ok {
  79. listResp = append(listResp, v)
  80. }
  81. }
  82. }
  83. Loop:
  84. if len(listResp) == 0 {
  85. listResp = make([]*company.CompanyNameAndId, 0)
  86. }
  87. resp.List = listResp
  88. br.Ret = 200
  89. br.Success = true
  90. br.Msg = "获取成功"
  91. br.Data = resp
  92. }
  93. // @Title 获取流失且参加过会议的客户
  94. // @Description 获取流失且参加过会议的客户接口
  95. // @Param CompanyName query string true "搜索关键词"
  96. // @Success 200 {object} cygx.UserSignUpLossListResp
  97. // @router /activityLoss/user/list [get]
  98. func (this *ActivityLossCoAntroller) UserList() {
  99. br := new(models.BaseResponse).Init()
  100. defer func() {
  101. this.Data["json"] = br
  102. this.ServeJSON()
  103. }()
  104. sysUser := this.SysUser
  105. if sysUser == nil {
  106. br.Msg = "请登录"
  107. br.ErrMsg = "请登录,SysUser Is Empty"
  108. br.Ret = 408
  109. return
  110. }
  111. companyName := this.GetString("CompanyName")
  112. companyName = strings.Trim(companyName, " ")
  113. companyName = strings.Replace(companyName, "'", "", -1)
  114. resp := new(cygx.UserSignUpLossListResp)
  115. nameItem, err := company.CheckCompanyProductByName(companyName, 2)
  116. if err != nil && err.Error() != utils.ErrNoRow() {
  117. br.Msg = "校验客户名称是否存在失败"
  118. br.ErrMsg = "校验客户名称是否存在失败,Err:" + err.Error()
  119. return
  120. }
  121. var listResp []*cygx.UserSignUpLossResp
  122. if nameItem == nil {
  123. goto Loop
  124. } else {
  125. companyId := nameItem.CompanyId
  126. var condition string
  127. var pars []interface{}
  128. condition += ` AND s.company_id = ? `
  129. pars = append(pars, companyId)
  130. companyUserSignUpList, err := cygx.GetUserSignUpList(condition, pars)
  131. if err != nil {
  132. br.Msg = "获取失败"
  133. br.ErrMsg = "获取失败,Err:" + err.Error()
  134. return
  135. }
  136. mapUserSignUp := make(map[string]string)
  137. mapTotalMeeting := make(map[string]int)
  138. for _, v := range companyUserSignUpList {
  139. mapTotalMeeting[v.Mobile]++
  140. }
  141. for _, v := range companyUserSignUpList {
  142. if _, ok := mapUserSignUp[v.Mobile]; !ok {
  143. item := new(cygx.UserSignUpLossResp)
  144. item.RealName = v.RealName
  145. item.Mobile = v.Mobile
  146. item.TotalMeeting = mapTotalMeeting[v.Mobile]
  147. listResp = append(listResp, item)
  148. }
  149. mapUserSignUp[v.Mobile] = v.Mobile
  150. }
  151. resp.CompanyId = nameItem.CompanyId
  152. resp.CompanyName = nameItem.CompanyName
  153. resp.SellerName = nameItem.SellerName
  154. }
  155. Loop:
  156. if len(listResp) == 0 {
  157. listResp = make([]*cygx.UserSignUpLossResp, 0)
  158. }
  159. resp.List = listResp
  160. br.Ret = 200
  161. br.Success = true
  162. br.Msg = "获取成功"
  163. br.Data = resp
  164. }
  165. // @Title 参会明细
  166. // @Description 获取流失且参加过会议的参会明细接口
  167. // @Param Mobile query int true "手机号"
  168. // @Success 200 {object} cygx.UserSignUpMeetLossListResp
  169. // @router /activityLoss/meet/list [get]
  170. func (this *ActivityLossCoAntroller) MeetList() {
  171. br := new(models.BaseResponse).Init()
  172. defer func() {
  173. this.Data["json"] = br
  174. this.ServeJSON()
  175. }()
  176. sysUser := this.SysUser
  177. if sysUser == nil {
  178. br.Msg = "请登录"
  179. br.ErrMsg = "请登录,SysUser Is Empty"
  180. br.Ret = 408
  181. return
  182. }
  183. mobile := this.GetString("Mobile")
  184. if mobile == "" {
  185. br.Msg = "手机号不能为空"
  186. br.IsSendEmail = false
  187. return
  188. }
  189. resp := new(cygx.UserSignUpMeetLossListResp)
  190. userInfo, err := models.GetWxUserByMobile(mobile)
  191. if err != nil && err.Error() != utils.ErrNoRow() {
  192. br.Msg = "获取失败"
  193. br.ErrMsg = "获取失败,Err:" + err.Error()
  194. return
  195. }
  196. var list []*cygx.AttendanceDetail
  197. if userInfo == nil {
  198. goto Loop
  199. } else {
  200. var condition string
  201. condition = ` AND s.is_meeting = 1 GROUP BY s.activity_id `
  202. list, err = cygx.GetAttendanceDetailListGroupByUser(mobile, condition)
  203. if err != nil && err.Error() != utils.ErrNoRow() {
  204. br.Msg = "获取失败"
  205. br.ErrMsg = "获取失败,Err:" + err.Error()
  206. return
  207. }
  208. resp.RealName = userInfo.RealName
  209. resp.Mobile = userInfo.Mobile
  210. }
  211. Loop:
  212. if len(list) == 0 {
  213. list = make([]*cygx.AttendanceDetail, 0)
  214. }
  215. resp.List = list
  216. br.Ret = 200
  217. br.Success = true
  218. br.Msg = "获取成功"
  219. br.Data = resp
  220. }