wx_user.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package models
  2. import (
  3. "eta/eta_api/global"
  4. "eta/eta_api/utils"
  5. "time"
  6. )
  7. type WxUser struct {
  8. UserId int64 `gorm:"column:user_id;primaryKey;autoIncrement"`
  9. Mobile string
  10. Email string
  11. CompanyId int
  12. RealName string `description:"姓名"`
  13. NickName string `description:"昵称"`
  14. CreatedTime time.Time
  15. MobileTwo string `description:"备用手机号"`
  16. BusinessCardUrl string `description:"名片"`
  17. IsMaker int `description:"是否决策人,1:是,0:否"`
  18. Position string `description:"职位"`
  19. Sex int `description:"普通用户性别,1为男性,2为女性"`
  20. DepartmentName string `description:"联系人部门"`
  21. RegisterTime time.Time
  22. RegisterPlatform int
  23. Remark string `description:"备注"`
  24. CountryCode string `description:"区号,86、852、886等"`
  25. OutboundMobile string `description:"外呼手机号"`
  26. OutboundCountryCode string `description:"外呼手机号区号,86、852、886等"`
  27. LastUpdatedTime time.Time `description:"最近一次更新时间"`
  28. IsDeal int `description:"是否标记处理 0-未处理 1-已处理"`
  29. OpenId string `gorm:"column:open_id" description:"微信openid"`
  30. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  31. UserLabel string `description:"查研观向用户标签"`
  32. }
  33. func GetWxUserByMobile(mobile string) (item *WxUser, err error) {
  34. o := global.DbMap[utils.DbNameWeekly]
  35. sql := `SELECT * FROM wx_user WHERE mobile = ? LIMIT 1`
  36. err = o.Raw(sql, mobile).First(&item).Error
  37. return
  38. }
  39. // Update 更新wxUser信息
  40. func (WxUser *WxUser) Update(cols []string) (err error) {
  41. o := global.DbMap[utils.DbNameWeekly]
  42. err = o.Select(cols).Updates(WxUser).Error
  43. return
  44. }
  45. // GetWxUserByCompanyIdAndMobile 根据客户ID及手机号获取用户
  46. func GetWxUserByCompanyIdAndMobile(companyId int, mobile string) (item *WxUser, err error) {
  47. o := global.DbMap[utils.DbNameWeekly]
  48. sql := ` SELECT * FROM wx_user WHERE company_id = ? AND mobile = ? LIMIT 1 `
  49. err = o.Raw(sql, companyId, mobile).First(&item).Error
  50. return
  51. }
  52. // DeleteWxUserAndRecordByUserId 删除用户及第三方信息
  53. func DeleteWxUserAndRecordByUserId(userId int) (err error) {
  54. to := global.DbMap[utils.DbNameWeekly].Begin()
  55. defer func() {
  56. if err != nil {
  57. _ = to.Rollback()
  58. } else {
  59. _ = to.Commit()
  60. }
  61. }()
  62. // 删除wx_user
  63. userSql := ` DELETE FROM wx_user WHERE user_id = ? LIMIT 1 `
  64. err = to.Exec(userSql, userId).Error
  65. // 删除user_record
  66. if err == nil {
  67. recordSql := ` DELETE FROM user_record WHERE user_id = ? `
  68. err = to.Exec(recordSql, userId).Error
  69. }
  70. return
  71. }