cygx_user_record.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxUserRecord struct {
  7. UserRecordId int `orm:"column(user_record_id);pk"`
  8. OpenId string `description:"用户openid,最大长度:32"`
  9. UnionId string `description:"用户unionid,最大长度:64"`
  10. NickName string `descritpion:"用户昵称,最大长度:32"`
  11. Sex int `descritpion:"普通用户性别,1为男性,2为女性"`
  12. Province string `description:"普通用户个人资料填写的省份,最大长度:30"`
  13. City string `description:"普通用户个人资料填写的城市,最大长度:30"`
  14. Country string `description:"国家,如中国为CN,最大长度:30"`
  15. Headimgurl string `description:"用户第三方(微信)头像,最大长度:512"`
  16. CreateTime time.Time `description:"创建时间,关系添加时间、用户授权时间"`
  17. }
  18. // 添加
  19. func AddCygxUserRecord(item *CygxUserRecord) (lastId int64, err error) {
  20. o := orm.NewOrm()
  21. lastId, err = o.Insert(item)
  22. return
  23. }
  24. // 获取数量
  25. func GetCygxUserRecordCount(openId string) (count int, err error) {
  26. o := orm.NewOrmUsingDB("weekly_report")
  27. sqlCount := ` SELECT COUNT(1) AS count FROM user_record WHERE open_id=? `
  28. err = o.Raw(sqlCount, openId).QueryRow(&count)
  29. return
  30. }
  31. // 修改
  32. func UpdateCygxUserRecord(item *CygxUserRecord) (err error) {
  33. o := orm.NewOrm()
  34. msql := ` UPDATE cygx_user_record SET nick_name = ?,sex=?,province=?,city=? ,country=? ,headimgurl=? WHERE open_id = ? `
  35. _, err = o.Raw(msql, item.NickName, item.Sex, item.Province, item.City, item.Country, item.Headimgurl, item.OpenId).Exec()
  36. return
  37. }
  38. // 修改
  39. func UpdateUserRecord(item *CygxUserRecord) (err error) {
  40. o := orm.NewOrmUsingDB("weekly_report")
  41. msql := ` UPDATE user_record SET nick_name = ?,sex=?,province=?,city=? ,country=? ,headimgurl=? WHERE union_id = ? AND create_platform = 4 `
  42. _, err = o.Raw(msql, item.NickName, item.Sex, item.Province, item.City, item.Country, item.Headimgurl, item.UnionId).Exec()
  43. return
  44. }