company_operate.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/models/company_report_permission_log"
  8. "hongze/hz_crm_api/services"
  9. "hongze/hz_crm_api/services/alarm_msg"
  10. "hongze/hz_crm_api/utils"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // Tips: company控制器近万行代码了, GoLand打开都卡...分点函数到这个控制器来=_=!
  16. // Close
  17. // @Title 关闭客户
  18. // @Description 关闭客户
  19. // @Param request body company.CloseCompanyReq true "type json string"
  20. // @Success Ret=200 操作成功
  21. // @router /close [post]
  22. func (this *CompanyController) Close() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. if br.ErrMsg == "" {
  26. br.IsSendEmail = false
  27. }
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. sysUser := this.SysUser
  32. if sysUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. br.Ret = 408
  36. return
  37. }
  38. var req company.CloseCompanyReq
  39. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  40. br.Msg = "参数解析异常!"
  41. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  42. return
  43. }
  44. if req.CompanyId <= 0 {
  45. br.Msg = "参数异常!"
  46. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  47. return
  48. }
  49. req.Remark = strings.TrimSpace(req.Remark)
  50. if req.Remark == "" {
  51. br.Msg = "请填写关闭理由"
  52. return
  53. }
  54. // 权限暂时只给FICC管理员和超管
  55. authArr := []string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN}
  56. if !utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
  57. br.Msg = "无权操作"
  58. br.ErrMsg = "无权操作, RoleTypeCode: " + sysUser.RoleTypeCode
  59. return
  60. }
  61. productId := utils.COMPANY_PRODUCT_FICC_ID
  62. productName := utils.COMPANY_PRODUCT_FICC_NAME
  63. product, e := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  64. if e != nil {
  65. br.Msg = "客户信息异常"
  66. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  67. return
  68. }
  69. if product.Status != utils.COMPANY_STATUS_TRY_OUT {
  70. br.Msg = fmt.Sprintf("客户状态为: %s, 不可关闭", product.Status)
  71. br.ErrMsg = fmt.Sprintf("客户%s状态为: %s, 不可关闭", product.CompanyName, product.Status)
  72. return
  73. }
  74. // 客户权限
  75. permissions, e := company.GetCompanyReportPermission(req.CompanyId, productId)
  76. if e != nil {
  77. br.Msg = "客户权限异常"
  78. br.ErrMsg = "获取客户权限失败, Err: " + e.Error()
  79. return
  80. }
  81. // 关闭客户
  82. if e = company.CloseCompany(req.CompanyId, productId, req.Remark); e != nil {
  83. br.Msg = "关闭失败"
  84. br.ErrMsg = "关闭客户失败, Err: " + e.Error()
  85. return
  86. }
  87. // 操作记录
  88. go func() {
  89. var err error
  90. defer func() {
  91. if err != nil {
  92. alarm_msg.SendAlarmMsg("关闭客户-新增操作记录失败, Err: "+err.Error(), 3)
  93. }
  94. }()
  95. remark := "关闭客户"
  96. operation := utils.COMPANY_STATUS_CLOSE_FLAG
  97. e = services.AddCompanyOperationRecord(req.CompanyId, product.SellerId, sysUser.AdminId, productId, sysUser.AdminId, product.CompanyName,
  98. productName, sysUser.RealName, remark, operation, req.Remark, sysUser.RealName, "", utils.COMPANY_STATUS_CLOSE)
  99. if e != nil {
  100. err = fmt.Errorf("AddCompanyOperationRecord %s", e.Error())
  101. return
  102. }
  103. // 权限关闭日志
  104. logs := make([]*company_report_permission_log.CompanyReportPermissionLog, 0)
  105. for _, p := range permissions {
  106. l := &company_report_permission_log.CompanyReportPermissionLog{
  107. CompanyReportPermissionId: p.CompanyReportPermissionId,
  108. CompanyId: p.CompanyId,
  109. ProductId: productId,
  110. ProductName: p.ProductName,
  111. SysUserId: sysUser.AdminId,
  112. SysUserName: sysUser.RealName,
  113. Remark: remark,
  114. Operation: operation,
  115. Status: p.Status,
  116. CreateTime: time.Now(),
  117. }
  118. logs = append(logs, l)
  119. }
  120. e = company_report_permission_log.MultiCreateCompanyReportPermissionLog(logs)
  121. if e != nil {
  122. err = fmt.Errorf("MultiCreateCompanyReportPermissionLog %s", e.Error())
  123. return
  124. }
  125. }()
  126. br.Ret = 200
  127. br.Success = true
  128. br.Msg = "操作成功"
  129. }
  130. // Close2Loss
  131. // @Title 关闭转流失
  132. // @Description 关闭转流失
  133. // @Param request body company.Close2LossReq true "type json string"
  134. // @Success Ret=200 操作成功
  135. // @router /close2loss [post]
  136. func (this *CompanyController) Close2Loss() {
  137. br := new(models.BaseResponse).Init()
  138. defer func() {
  139. if br.ErrMsg == "" {
  140. br.IsSendEmail = false
  141. }
  142. this.Data["json"] = br
  143. this.ServeJSON()
  144. }()
  145. sysUser := this.SysUser
  146. if sysUser == nil {
  147. br.Msg = "请登录"
  148. br.ErrMsg = "请登录,SysUser Is Empty"
  149. br.Ret = 408
  150. return
  151. }
  152. var req company.Close2LossReq
  153. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  154. br.Msg = "参数解析异常!"
  155. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  156. return
  157. }
  158. if req.CompanyId <= 0 {
  159. br.Msg = "参数异常!"
  160. br.ErrMsg = "CompanyId:" + strconv.Itoa(req.CompanyId)
  161. return
  162. }
  163. // 权限暂时只给FICC管理员和超管
  164. authArr := []string{utils.ROLE_TYPE_CODE_ADMIN, utils.ROLE_TYPE_CODE_FICC_ADMIN}
  165. if !utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
  166. br.Msg = "无权操作"
  167. br.ErrMsg = "无权操作, RoleTypeCode: " + sysUser.RoleTypeCode
  168. return
  169. }
  170. productId := utils.COMPANY_PRODUCT_FICC_ID
  171. productName := utils.COMPANY_PRODUCT_FICC_NAME
  172. product, e := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
  173. if e != nil {
  174. br.Msg = "客户信息异常"
  175. br.ErrMsg = "获取客户信息失败, Err: " + e.Error()
  176. return
  177. }
  178. if product.Status != utils.COMPANY_STATUS_CLOSE {
  179. br.Msg = fmt.Sprintf("客户状态为: %s, 不可转流失", product.Status)
  180. br.ErrMsg = fmt.Sprintf("客户%s状态为: %s, 不可转流失", product.CompanyName, product.Status)
  181. return
  182. }
  183. // 转流失
  184. if e = company.Close2Loss(req.CompanyId, productId); e != nil {
  185. br.Msg = "操作失败"
  186. br.ErrMsg = "关闭转流失失败, Err: " + e.Error()
  187. return
  188. }
  189. // 操作记录
  190. go func() {
  191. remark := "关闭转流失"
  192. operation := utils.COMPANY_STATUS_LOSE_FLAG
  193. _ = services.AddCompanyOperationRecord(req.CompanyId, product.SellerId, sysUser.AdminId, productId, sysUser.AdminId, product.CompanyName,
  194. productName, sysUser.RealName, remark, operation, remark, sysUser.RealName, "", utils.COMPANY_STATUS_LOSE)
  195. }()
  196. br.Ret = 200
  197. br.Success = true
  198. br.Msg = "操作成功"
  199. }