update.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package user_record
  2. import "hongze/hongze_yb/global"
  3. // Update 更新对应字段数据
  4. func (userRecord *UserRecord) Update(updateCols []string) (err error) {
  5. err = global.DEFAULT_MYSQL.Model(userRecord).Select(updateCols).Updates(*userRecord).Error
  6. return
  7. }
  8. // ModifyUserRecordInfo 修改用户微信信息
  9. func (userRecord *UserRecord) ModifyUserRecordInfo(nickName, headimgUrl, city, province, country string, sex int64) (err error) {
  10. userRecord.NickName = nickName
  11. userRecord.Headimgurl = headimgUrl
  12. userRecord.City = city
  13. userRecord.Province = province
  14. userRecord.Country = country
  15. userRecord.Sex = sex
  16. var updateCols = []string{"NickName", "Headimgurl", "City", "Province", "Country", "Sex"}
  17. err = userRecord.Update(updateCols)
  18. return
  19. }
  20. // UnBindUserRecordByOpenid 解除绑定用户关系
  21. func (userRecord *UserRecord) UnBindUserRecordByOpenid() (err error) {
  22. userRecord.UserID = 0
  23. userRecord.BindAccount = ""
  24. var updateCols = []string{"UserID", "BindAccount"}
  25. err = userRecord.Update(updateCols)
  26. return
  27. }
  28. // UnBindUserRecordByOpenid 根据openid解除绑定用户关系
  29. func UnBindUserRecordByOpenid(openId string) (err error) {
  30. err = global.DEFAULT_MYSQL.Model(UserRecord{}).Select("UserID", "BindAccount").Where("open_id = ? ", openId).Updates(UserRecord{
  31. UserID: 0,
  32. BindAccount: "",
  33. }).Error
  34. return
  35. }
  36. // ModifySessionKeyByOpenid 根据openid更新sessionKey
  37. func ModifySessionKeyByOpenid(openId, sessionKey string) (err error) {
  38. err = global.DEFAULT_MYSQL.Model(UserRecord{}).Select("SessionKey").Where("open_id = ? ", openId).Updates(UserRecord{
  39. SessionKey: sessionKey,
  40. }).Error
  41. return
  42. }
  43. // UnBindUserRecordByUnionId 根据unionId和平台信息解除绑定用户关系
  44. func UnBindUserRecordByUnionId(unionId string, platform int) (err error) {
  45. err = global.DEFAULT_MYSQL.Model(UserRecord{}).Select("UserID", "BindAccount").Where("union_id = ? AND create_platform = ?", unionId, platform).Updates(UserRecord{
  46. UserID: 0,
  47. BindAccount: "",
  48. }).Error
  49. return
  50. }