cygx_user_record.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. CygxBindAccount string `descritpion:"绑定时的账号,最大长度:128"`
  18. CygxUserId int `description:"用户id"`
  19. }
  20. // 添加
  21. func AddCygxUserRecord(item *CygxUserRecord) (lastId int64, err error) {
  22. o := orm.NewOrmUsingDB("hz_cygx")
  23. lastId, err = o.Insert(item)
  24. return
  25. }
  26. // 获取数量
  27. func GetCygxUserRecordCount(openId string) (count int, err error) {
  28. o := orm.NewOrmUsingDB("hz_cygx")
  29. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_record WHERE open_id=? `
  30. err = o.Raw(sqlCount, openId).QueryRow(&count)
  31. return
  32. }
  33. // 根据Openid获取用户详情
  34. func GetCygxUserRecordByOpenid(opendId string) (item *CygxUserRecord, err error) {
  35. o := orm.NewOrmUsingDB("hz_cygx")
  36. sql := `SELECT
  37. *
  38. FROM
  39. cygx_user_record
  40. WHERE open_id = ?
  41. LIMIT 1 `
  42. err = o.Raw(sql, opendId).QueryRow(&item)
  43. return
  44. }
  45. // 获取列表
  46. func GetCygxUserRecordyList() (items []*CygxUserRecord, err error) {
  47. o := orm.NewOrmUsingDB("hz_cygx")
  48. sql := `SELECT * FROM cygx_user_record `
  49. _, err = o.Raw(sql).QueryRows(&items)
  50. return
  51. }
  52. // 更新关注信息
  53. func SetUserSubscribeByOpenid(openId string) (err error) {
  54. o := orm.NewOrmUsingDB("hz_cygx")
  55. sql := ` UPDATE cygx_user_record SET subscribe=1,subscribe_time=NOW() WHERE open_id=? `
  56. _, err = o.Raw(sql, openId).Exec()
  57. return
  58. }
  59. // 根据openid解除绑定用户关系
  60. func UpdateCygxUserRecordMobile(userId int, mobile, openId string) (err error) {
  61. o := orm.NewOrmUsingDB("hz_cygx")
  62. msql := ` UPDATE cygx_user_record SET cygx_user_id = ?,cygx_bind_account= ? WHERE union_id = ? `
  63. _, err = o.Raw(msql, userId, mobile, openId).Exec()
  64. return
  65. }
  66. // 根据openid更新用户绑定的手机号
  67. func UpdateCygxUserRecordMobileByOpenId(userId int, mobile, openId string) (err error) {
  68. o := orm.NewOrmUsingDB("hz_cygx")
  69. msql := ` UPDATE cygx_user_record SET cygx_user_id = ?,cygx_bind_account= ? WHERE open_id = ? `
  70. _, err = o.Raw(msql, userId, mobile, openId).Exec()
  71. return
  72. }