wx_user.go 2.9 KB

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