user.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package services
  2. import (
  3. "hongze/hz_eta_api/models"
  4. "hongze/hz_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 mobile == "" {
  39. return
  40. }
  41. companyId := 16
  42. userInfo, err := models.GetWxUserByCompanyIdAndMobile(companyId, mobile)
  43. if err != nil && err.Error() != utils.ErrNoRow() {
  44. return
  45. }
  46. if userInfo != nil {
  47. userId := int(userInfo.UserId)
  48. if err = models.DeleteWxUserAndRecordByUserId(userId); err != nil {
  49. return
  50. }
  51. // 删除所有的标识,并真正删除数据
  52. _ = models.DeleteUserSellerRelationByProductId(userId, 1)
  53. _ = models.DeleteUserSellerRelationByProductId(userId, 2)
  54. }
  55. return nil
  56. }