user.go 1.8 KB

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