package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type CygxUserRecord struct { UserRecordId int `orm:"column(user_record_id);pk"` OpenId string `description:"用户openid,最大长度:32"` UnionId string `description:"用户unionid,最大长度:64"` NickName string `descritpion:"用户昵称,最大长度:32"` Sex int `descritpion:"普通用户性别,1为男性,2为女性"` Province string `description:"普通用户个人资料填写的省份,最大长度:30"` City string `description:"普通用户个人资料填写的城市,最大长度:30"` Country string `description:"国家,如中国为CN,最大长度:30"` Headimgurl string `description:"用户第三方(微信)头像,最大长度:512"` CreateTime time.Time `description:"创建时间,关系添加时间、用户授权时间"` CygxBindAccount string `descritpion:"绑定时的账号,最大长度:128"` CygxUserId int `description:"用户id"` } // 添加 func AddCygxUserRecord(item *CygxUserRecord) (lastId int64, err error) { o := orm.NewOrmUsingDB("hz_cygx") lastId, err = o.Insert(item) return } // 获取数量 func GetCygxUserRecordCount(openId string) (count int, err error) { o := orm.NewOrmUsingDB("hz_cygx") sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_record WHERE open_id=? ` err = o.Raw(sqlCount, openId).QueryRow(&count) return } // 根据Openid获取用户详情 func GetCygxUserRecordByOpenid(opendId string) (item *CygxUserRecord, err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := `SELECT * FROM cygx_user_record WHERE open_id = ? LIMIT 1 ` err = o.Raw(sql, opendId).QueryRow(&item) return } // 获取列表 func GetCygxUserRecordyList() (items []*CygxUserRecord, err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := `SELECT * FROM cygx_user_record ` _, err = o.Raw(sql).QueryRows(&items) return } // 更新关注信息 func SetUserSubscribeByOpenid(openId string) (err error) { o := orm.NewOrmUsingDB("hz_cygx") sql := ` UPDATE cygx_user_record SET subscribe=1,subscribe_time=NOW() WHERE open_id=? ` _, err = o.Raw(sql, openId).Exec() return } // 根据openid解除绑定用户关系 func UpdateCygxUserRecordMobile(userId int, mobile, openId string) (err error) { o := orm.NewOrmUsingDB("hz_cygx") msql := ` UPDATE cygx_user_record SET cygx_user_id = ?,cygx_bind_account= ? WHERE union_id = ? ` _, err = o.Raw(msql, userId, mobile, openId).Exec() return } // 根据openid更新用户绑定的手机号 func UpdateCygxUserRecordMobileByOpenId(userId int, mobile, openId string) (err error) { o := orm.NewOrmUsingDB("hz_cygx") msql := ` UPDATE cygx_user_record SET cygx_user_id = ?,cygx_bind_account= ? WHERE open_id = ? ` _, err = o.Raw(msql, userId, mobile, openId).Exec() return }