wx_user.go 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "time"
  5. )
  6. type WxUser struct {
  7. UserId int64 `gorm:"column:user_id;primaryKey;type:bigint" orm:"column(user_id);pk" gorm:"primaryKey" description:"用户ID"`
  8. Mobile string `gorm:"column:mobile;type:varchar(255)" orm:"column(mobile)" description:"手机号"`
  9. Email string `gorm:"column:email;type:varchar(255)" orm:"column(email)" description:"邮箱"`
  10. CompanyId int `gorm:"column:company_id;type:int" orm:"column(company_id)" description:"公司ID"`
  11. RealName string `gorm:"column:real_name;type:varchar(255)" orm:"column(real_name)" description:"姓名"`
  12. NickName string `gorm:"column:nick_name;type:varchar(255)" orm:"column(nick_name)" description:"昵称"`
  13. CreatedTime time.Time `gorm:"column:created_time;type:datetime" orm:"column(created_time)" description:"创建时间"`
  14. MobileTwo string `gorm:"column:mobile_two;type:varchar(255)" orm:"column(mobile_two)" description:"备用手机号"`
  15. BusinessCardUrl string `gorm:"column:business_card_url;type:varchar(255)" orm:"column(business_card_url)" description:"名片"`
  16. IsMaker int `gorm:"column:is_maker;type:int" orm:"column(is_maker)" description:"是否决策人,1:是,0:否"`
  17. Position string `gorm:"column:position;type:varchar(255)" orm:"column(position)" description:"职位"`
  18. Sex int `gorm:"column:sex;type:int" orm:"column(sex)" description:"普通用户性别,1为男性,2为女性"`
  19. DepartmentName string `gorm:"column:department_name;type:varchar(255)" orm:"column(department_name)" description:"联系人部门"`
  20. RegisterTime time.Time `gorm:"column:register_time;type:datetime" orm:"column(register_time)" description:"注册时间"`
  21. RegisterPlatform int `gorm:"column:register_platform;type:int" orm:"column(register_platform)" description:"注册平台"`
  22. Remark string `gorm:"column:remark;type:varchar(255)" orm:"column(remark)" description:"备注"`
  23. CountryCode string `gorm:"column:country_code;type:varchar(255)" orm:"column(country_code)" description:"区号,86、852、886等"`
  24. OutboundMobile string `gorm:"column:outbound_mobile;type:varchar(255)" orm:"column(outbound_mobile)" description:"外呼手机号"`
  25. OutboundCountryCode string `gorm:"column:outbound_country_code;type:varchar(255)" orm:"column(outbound_country_code)" description:"外呼手机号区号,86、852、886等"`
  26. LastUpdatedTime time.Time `gorm:"column:last_updated_time;type:datetime" orm:"column(last_updated_time)" description:"最近一次更新时间"`
  27. IsDeal int `gorm:"column:is_deal;type:int" orm:"column(is_deal)" description:"是否标记处理 0-未处理 1-已处理"`
  28. OpenId string `gorm:"column:open_id;type:varchar(255)" orm:"column(open_id)" description:"微信openid"`
  29. Headimgurl string `gorm:"column:headimgurl;type:varchar(255)" orm:"column(headimgurl)" description:"用户头像"`
  30. UserLabel string `gorm:"column:user_label;type:varchar(255)" orm:"column(user_label)" 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. err = global.DmSQL["weekly"].Raw(sql, mobile).First(&item).Error
  37. return
  38. }
  39. // Update 更新wxUser信息
  40. func (wxUser *WxUser) Update(cols []string) (err error) {
  41. //o := orm.NewOrmUsingDB("weekly")
  42. //_, err = o.Update(wxUser, cols...)
  43. err = global.DmSQL["weekly"].Select(cols).Updates(wxUser).Error
  44. return
  45. }
  46. // GetWxUserByCompanyIdAndMobile 根据客户ID及手机号获取用户
  47. func GetWxUserByCompanyIdAndMobile(companyId int, mobile string) (item *WxUser, err error) {
  48. //o := orm.NewOrmUsingDB("weekly")
  49. sql := ` SELECT * FROM wx_user WHERE company_id = ? AND mobile = ? LIMIT 1 `
  50. //err = o.Raw(sql, companyId, mobile).QueryRow(&item)
  51. err = global.DmSQL["weekly"].Raw(sql, companyId, mobile).First(&item).Error
  52. return
  53. }
  54. // DeleteWxUserAndRecordByUserId 删除用户及第三方信息
  55. func DeleteWxUserAndRecordByUserId(userId int) (err error) {
  56. //o := orm.NewOrmUsingDB("weekly")
  57. //to, err := o.Begin()
  58. to := global.DmSQL["weekly"].Begin()
  59. defer func() {
  60. if err != nil {
  61. _ = to.Rollback()
  62. } else {
  63. _ = to.Commit()
  64. }
  65. }()
  66. // 删除wx_user
  67. userSql := ` DELETE FROM wx_user WHERE user_id = ? LIMIT 1 `
  68. //_, err = to.Raw(userSql, userId).Exec()
  69. err = to.Exec(userSql, userId).Error
  70. // 删除user_record
  71. if err == nil {
  72. recordSql := ` DELETE FROM user_record WHERE user_id = ? `
  73. //_, err = to.Raw(recordSql, userId).Exec()
  74. err = to.Exec(recordSql, userId).Error
  75. }
  76. return
  77. }