package models import ( "rdluck_tools/orm" "time" ) type WxUser struct { UserId int `orm:"column(user_id);pk"` OpenId string `description:"open_id"` UnionId string `description:"union_id"` Subscribe string `description:"是否关注"` CompanyId int `description:"客户id"` NickName string `description:"用户昵称"` RealName string `description:"用户实际名称"` UserCode string `description:"用户编码"` Mobile string `description:"手机号码"` BindAccount string `description:"绑定时的账号"` WxCode string `description:"微信号"` Profession string `description:"职业"` Email string `description:"邮箱"` Telephone string `description:"座机"` Sex int `description:"普通用户性别,1为男性,2为女性"` Province string `description:"普通用户个人资料填写的省份"` City string `description:"普通用户个人资料填写的城市"` Country string `description:"国家,如中国为CN"` SubscribeTime int `description:"关注时间"` Remark string `description:"备注"` Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"` Privilege string `description:"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"` Unionid string `description:"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。"` FirstLogin int `description:"是否第一次登陆"` Enabled int `description:"是否可用"` CreatedTime time.Time `description:"创建时间"` LastUpdatedTime time.Time `description:"最新一次修改时间"` Seller string `description:"销售员"` Note string `description:"客户备份信息"` IsNote int `description:"是否备注过信息"` FromType string `description:"report' COMMENT 'report:研报,teleconference:电话会"` ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"` } type WxUserItem struct { UserId int `description:"用户id"` OpenId string `description:"open_id"` UnionId string `description:"union_id"` CompanyId int `description:"客户id"` NickName string `description:"用户昵称"` RealName string `description:"用户实际名称"` Mobile string `description:"手机号码"` BindAccount string `description:"绑定时的账号"` Email string `description:"邮箱"` Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"` ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"` FirstLogin int `description:"是否第一次登陆"` } func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) { sql := `SELECT * FROM wx_user WHERE user_id=? ` err = orm.NewOrm().Raw(sql, userId).QueryRow(&item) return } func GetWxUserItemByOpenId(openId string) (item *WxUserItem, err error) { sql := `SELECT * FROM wx_user WHERE open_id=? ` err = orm.NewOrm().Raw(sql, openId).QueryRow(&item) return } func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) { sql := `SELECT * FROM wx_user WHERE unionid=? ` err = orm.NewOrm().Raw(sql, unionid).QueryRow(&item) return } type PermissionSearchKeyWord struct { KeyWord string } func GetPermissionSearchKeyWord(userId int) (items []*PermissionSearchKeyWord, err error) { sql := "SELECT a.key_word FROM chart_permission_search_key_word_mapping AS a INNER JOIN company_report_permission AS crp ON a.chart_permission_id=crp.chart_permission_id INNER JOIN wx_user AS wu ON wu.company_id=crp.company_id WHERE wu.user_id=? AND `from`='rddp' GROUP BY a.key_word" o := orm.NewOrm() _, err = o.Raw(sql, userId).QueryRows(&items) return } //判断客户权限总数 func GetUserIsMaxPermission(companyId int) (count int, err error) { sql := ` SELECT COUNT(DISTINCT b.chart_permission_id) as count FROM company as a INNER JOIN company_report_permission as b on a.company_id=b.company_id WHERE b.company_id=? ` o := orm.NewOrm() err = o.Raw(sql, companyId).QueryRow(&count) return } //添加用户信息 func AddWxUser(item *WxUser) (err error) { o := orm.NewOrm() _, err = o.Insert(item) return } /* return response()->json(['code'=>'0', 'data'=>array( 'open_id'=>$open_id, 'rddp_access_token'=>$session_data->access_token, 'user_id'=>$userId, 'expires'=>$session_data->expire_time, 'first_login'=>$firstLogin, 'user_permission'=>$userPermission, ) ]); */ type WxLoginResp struct { Code int OpenId string Authorization string UserId int Expires time.Time FirstLogin int UserPermission int }