interview_apply.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/controllers"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/cygx"
  8. cygxService "hongze/hz_crm_api/services/cygx"
  9. "hongze/hz_crm_api/utils"
  10. "strings"
  11. )
  12. // 访谈申请
  13. type InterviewApplyController struct {
  14. controllers.BaseAuthController
  15. }
  16. // @Title 访谈申请列表
  17. // @Description 访谈申请列表接口
  18. // @Param PageSize query int true "每页数据条数"
  19. // @Param CurrentIndex query int true "当前页页码,从1开始"
  20. // @Param KeyWord query string true "搜索关键词"
  21. // @Success 200 {object} cygx.InterviewApplyListResp
  22. // @router /interview/list [get]
  23. func (this *InterviewApplyController) List() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. sysUser := this.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. br.Ret = 408
  34. return
  35. }
  36. pageSize, _ := this.GetInt("PageSize")
  37. currentIndex, _ := this.GetInt("CurrentIndex")
  38. keyWord := this.GetString("KeyWord")
  39. keyWord = strings.Trim(keyWord, " ")
  40. keyWord = strings.Replace(keyWord, "'", "", -1)
  41. roleTypeCode := sysUser.RoleTypeCode
  42. var condition string
  43. var pars []interface{}
  44. //{
  45. // if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  46. // if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  47. // condition += ` AND c.product_id=? `
  48. // pars = append(pars, 1)
  49. // } else if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  50. // condition += ` AND c.product_id=? `
  51. // pars = append(pars, 2)
  52. // } else {
  53. // if sysUser.Authority <= 0 {
  54. // condition += ` AND c.seller_id=? `
  55. // pars = append(pars, sysUser.AdminId)
  56. // } else {
  57. // if sysUser.Authority == 1 {
  58. // condition += ` AND c.department_id=? `
  59. // pars = append(pars, sysUser.DepartmentId)
  60. // }
  61. // if sysUser.Authority == 2 {
  62. // condition += ` AND c.group_id=? `
  63. // pars = append(pars, sysUser.GroupId)
  64. // }
  65. // }
  66. // }
  67. // }
  68. //}
  69. {
  70. if roleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  71. //权益申请销售只能看到自己名下的客户的申请
  72. companyIds, err := cygxService.GetAdminLookUserCompanyIds(sysUser)
  73. if err != nil {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
  76. return
  77. }
  78. lencompanyIds := len(companyIds)
  79. if lencompanyIds > 0 {
  80. condition += ` AND a.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
  81. pars = append(pars, companyIds)
  82. }
  83. }
  84. }
  85. var startSize int
  86. if pageSize <= 0 {
  87. pageSize = utils.PageSize20
  88. }
  89. if currentIndex <= 0 {
  90. currentIndex = 1
  91. }
  92. startSize = paging.StartIndex(currentIndex, pageSize)
  93. if keyWord != "" {
  94. var conditionuiUser string
  95. var parsUser []interface{}
  96. conditionuiUser += ` AND (mobile LIKE '%` + keyWord + `%' OR email LIKE '%` + keyWord + `%' OR real_name LIKE '%` + keyWord + `%') `
  97. listUser, err := models.GetWxUserList(conditionuiUser, parsUser)
  98. if err != nil {
  99. br.Msg = "获取失败"
  100. br.ErrMsg = ",GetWxUserListErr:" + err.Error()
  101. return
  102. }
  103. var userIds []int
  104. for _, v := range listUser {
  105. userIds = append(userIds, int(v.UserId))
  106. }
  107. lenuserIds := len(userIds)
  108. if lenuserIds > 0 {
  109. condition += ` AND a.user_id IN (` + utils.GetOrmInReplace(lenuserIds) + `)`
  110. pars = append(pars, userIds)
  111. }
  112. }
  113. total, err := cygx.GetInterviewApplyListCount(condition, pars)
  114. if err != nil {
  115. br.Msg = "获取失败"
  116. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  117. return
  118. }
  119. list, err := cygx.GetInterviewApplyList(condition, pars, startSize, pageSize)
  120. if err != nil {
  121. br.Msg = "获取失败"
  122. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  123. return
  124. }
  125. var userIds []int
  126. for _, v := range list {
  127. userIds = append(userIds, v.UserId)
  128. }
  129. listUser, err := models.GetWxUserRaiSllerListByUserIds(userIds)
  130. if err != nil {
  131. br.Msg = "获取失败"
  132. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  133. return
  134. }
  135. //拼接用户相关信息
  136. mapUser := make(map[int]*models.WxUserSller)
  137. for _, v := range listUser {
  138. mapUser[v.UserId] = v
  139. }
  140. for _, v := range list {
  141. if mapUser[v.UserId] != nil {
  142. v.UserRealName = mapUser[v.UserId].RealName
  143. v.Mobile = mapUser[v.UserId].Mobile
  144. v.CompanyName = mapUser[v.UserId].CompanyName
  145. v.SalesRealName = mapUser[v.UserId].SellerName
  146. }
  147. }
  148. if list == nil {
  149. list = make([]*cygx.CygxInterviewApply, 0)
  150. }
  151. resp := new(cygx.InterviewApplyListResp)
  152. page := paging.GetPaging(currentIndex, pageSize, total)
  153. resp.List = list
  154. resp.Paging = page
  155. br.Ret = 200
  156. br.Success = true
  157. br.Msg = "获取成功"
  158. br.Data = resp
  159. }
  160. // @Title 访谈申请状态变更接口
  161. // @Description 访谈申请状态变更接口(包含取消和状态更新)
  162. // @Param request body cygx.InterviewApplyStatusReq true "type json string"
  163. // @Success Ret=200 访谈申请取消成功
  164. // @router /interview/status/modify [post]
  165. func (this *InterviewApplyController) InterviewApplyCancel() {
  166. br := new(models.BaseResponse).Init()
  167. defer func() {
  168. this.Data["json"] = br
  169. this.ServeJSON()
  170. }()
  171. sysUser := this.SysUser
  172. if sysUser == nil {
  173. br.Msg = "请登录"
  174. br.ErrMsg = "请登录,SysUser Is Empty"
  175. br.Ret = 408
  176. return
  177. }
  178. var req cygx.InterviewApplyStatusReq
  179. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  180. if err != nil {
  181. br.Msg = "参数解析异常!"
  182. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  183. return
  184. }
  185. if req.InterviewApplyId <= 0 {
  186. br.Msg = "参数错误"
  187. br.ErrMsg = "参数错误,访谈申请id小于等于0"
  188. return
  189. }
  190. item, err := cygx.GetCygxInterviewApplyDetail(req.InterviewApplyId)
  191. if err != nil {
  192. br.Msg = "获取数据失败"
  193. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  194. return
  195. }
  196. var status string
  197. if req.HandleType == 2 {
  198. if item.Status == "已取消" || item.Status == "已完成" {
  199. br.Msg = "当前状态为:" + item.Status + ",不可进行取消操作"
  200. br.ErrMsg = "当前状态为:" + item.Status + ",不可进行取消操作"
  201. return
  202. }
  203. status = "已取消"
  204. } else {
  205. if req.InterviewTime != "" {
  206. status = "待访谈"
  207. } else {
  208. status = "已完成"
  209. }
  210. }
  211. err = cygx.InterviewApplyStatusModify(req.InterviewApplyId, status, req.InterviewTime)
  212. if err != nil {
  213. br.Msg = "状态更新失败"
  214. br.ErrMsg = "状态更新失败,Err:" + err.Error()
  215. return
  216. }
  217. br.Ret = 200
  218. br.Success = true
  219. br.Msg = "状态更新成功"
  220. }