update.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. }
  51. // ModifyUserIdByUnionId 根据unionId更改user_id
  52. func ModifyUserIdByUnionId(unionId string, userId int) (err error) {
  53. err = global.DEFAULT_MYSQL.Model(UserRecord{}).Select("UserID", "BindAccount").Where("union_id = ? AND user_id = 0", unionId).Updates(UserRecord{
  54. UserID: userId,
  55. }).Error
  56. return
  57. }