user.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package services
  2. import (
  3. "eta/eta_api/models"
  4. "eta/eta_api/utils"
  5. "time"
  6. )
  7. // SwitchHzUserEnabledByMobile 根据手机号启用/禁用弘则研究下的联系人
  8. func SwitchHzUserEnabledByMobile(opEnabled int, mobile string) (err error) {
  9. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  10. return
  11. }
  12. if mobile == "" {
  13. return
  14. }
  15. userInfo, err := models.GetWxUserByMobile(mobile)
  16. if err != nil && err.Error() != utils.ErrNoRow() {
  17. return
  18. }
  19. // 存在相应联系人
  20. if userInfo != nil {
  21. // 禁用-联系人为弘则研究下的则设置为潜在用户
  22. updateCols := make([]string, 0)
  23. if opEnabled == 0 && userInfo.CompanyId == 16 {
  24. userInfo.CompanyId = 1
  25. userInfo.LastUpdatedTime = time.Now()
  26. updateCols = append(updateCols, "CompanyId", "LastUpdatedTime")
  27. _ = userInfo.Update(updateCols)
  28. }
  29. // 启用-联系人为潜在用户则设置为弘则研究下
  30. if opEnabled == 1 && userInfo.CompanyId == 1 {
  31. userInfo.CompanyId = 16
  32. userInfo.LastUpdatedTime = time.Now()
  33. updateCols = append(updateCols, "CompanyId", "LastUpdatedTime")
  34. _ = userInfo.Update(updateCols)
  35. }
  36. }
  37. return nil
  38. }
  39. // DeleteHzUserByMobile 根据手机号删除弘则研究下的联系人
  40. func DeleteHzUserByMobile(mobile string) (err error) {
  41. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  42. return
  43. }
  44. if mobile == "" {
  45. return
  46. }
  47. companyId := 16
  48. userInfo, err := models.GetWxUserByCompanyIdAndMobile(companyId, mobile)
  49. if err != nil && err.Error() != utils.ErrNoRow() {
  50. return
  51. }
  52. if userInfo != nil {
  53. userId := int(userInfo.UserId)
  54. if err = models.DeleteWxUserAndRecordByUserId(userId); err != nil {
  55. return
  56. }
  57. // 删除所有的标识,并真正删除数据
  58. _ = models.DeleteUserSellerRelationByProductId(userId, 1)
  59. _ = models.DeleteUserSellerRelationByProductId(userId, 2)
  60. }
  61. return nil
  62. }