|
@@ -50,13 +50,6 @@ type WxUser struct {
|
|
|
OutboundCountryCode string `description:"外呼手机号区号"`
|
|
|
}
|
|
|
|
|
|
-//添加用户信息
|
|
|
-func AddWxUser(item *WxUser) (lastId int64, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- lastId, err = o.Insert(item)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
type WxUserItem struct {
|
|
|
UserId int `description:"用户id"`
|
|
|
OpenId string `description:"open_id"`
|
|
@@ -85,12 +78,6 @@ type WxUserItem struct {
|
|
|
Source int
|
|
|
}
|
|
|
|
|
|
-func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
|
|
|
- sql := `SELECT * FROM wx_user WHERE union_id=? `
|
|
|
- err = orm.NewOrm().Raw(sql, unionid).QueryRow(&item)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
|
|
|
sql := `SELECT a.*,b.company_name FROM wx_user AS a
|
|
|
LEFT JOIN company AS b on a.company_id=b.company_id
|
|
@@ -99,12 +86,6 @@ func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
|
|
|
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
|
|
|
-}
|
|
|
-
|
|
|
type WxLoginResp struct {
|
|
|
Authorization string
|
|
|
UserId int
|
|
@@ -125,133 +106,6 @@ type WxGetUserInfoReq struct {
|
|
|
Iv string `description:"iv"`
|
|
|
}
|
|
|
|
|
|
-//修改用户会话key
|
|
|
-func ModifyWxUserSessionKey(sessionKey string, userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := `UPDATE wx_user SET session_key=? WHERE user_id=? `
|
|
|
- _, err = o.Raw(sql, sessionKey, userId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-//添加用户信息
|
|
|
-func ModifyWxUserInfo(unionId, nickName, province, city, country, avatar string, gender, userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := `UPDATE wx_user SET union_id=?,unionid=?,nick_name=?,sex=?,province=?,city=?,country=?,headimgurl=? WHERE user_id=? `
|
|
|
- _, err = o.Raw(sql, unionId, unionId, nickName, gender, province, city, country, avatar, userId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-//修改用户会话key
|
|
|
-func DeleteWxUserByUserId(userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := `DELETE FROM wx_user WHERE user_id=? `
|
|
|
- _, err = o.Raw(sql, userId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-type WxGetUserInfoResp struct {
|
|
|
- //UsersId int `orm:"column(id);pk"`
|
|
|
- //Mobile string `description:"手机号"`
|
|
|
- //NickName string `description:"昵称"`
|
|
|
- //Gender int `description:"用户性别 1:男性,2:女性,0:未知(默认)"`
|
|
|
- //CreateTime time.Time `description:"注册时间"`
|
|
|
- //ModifyTime time.Time `description:"修改时间"`
|
|
|
- //AvatarUrl string `description:"头像地址"`
|
|
|
- //City string `description:"城市"`
|
|
|
- //Province string `description:"省"`
|
|
|
- //Country string `description:"国家"`
|
|
|
- //Language string `description:"语言"`
|
|
|
- //Appid string `description:"Appid"`
|
|
|
- //Timestamp int64 `description:"时间戳"`
|
|
|
- Authorization string `description:"登陆凭证,后续接口调用时,带在请求头里面Key:Authorization"`
|
|
|
-}
|
|
|
-
|
|
|
-type WxGetPhoneNumberReq struct {
|
|
|
- EncryptedData string `description:"encryptedData"`
|
|
|
- Iv string `description:"iv"`
|
|
|
-}
|
|
|
-
|
|
|
-func ModifyUsersMobile(usersId int, phoneNumber string) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := `UPDATE wx_user SET mobile=? WHERE user_id=? `
|
|
|
- _, err = o.Raw(sql, phoneNumber, usersId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-type WxGetPhoneNumberResp struct {
|
|
|
- PhoneNumber string `description:"用户绑定的手机号(国外手机号会有区号)"`
|
|
|
- PurePhoneNumber string `description:"没有区号的手机号"`
|
|
|
- CountryCode string `description:"区号"`
|
|
|
-}
|
|
|
-
|
|
|
-func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
|
|
|
- sql := `SELECT a.*,b.company_name FROM wx_user AS a
|
|
|
- LEFT JOIN company AS b on a.company_id=b.company_id
|
|
|
- WHERE a.mobile=? `
|
|
|
- err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
|
|
|
- sql := `SELECT * FROM wx_user WHERE email=? `
|
|
|
- err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func ModifyReportLastViewTime(uid int) (err error) {
|
|
|
- sql := ` UPDATE wx_user SET report_last_view_time=NOW()
|
|
|
- WHERE user_id=? `
|
|
|
- _, err = orm.NewOrm().Raw(sql, uid).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-//变更联系人是否已注册状态
|
|
|
-func ModifyWxUserRegisterStatus(userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
|
|
|
- _, err = o.Raw(sql, 1, userId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-//修改用户是否绑定外呼手机号弹窗
|
|
|
-func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
|
|
|
- _, err = o.Raw(sql, userId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-//列表
|
|
|
-func GetUserListAll() (items []*WxUserItem, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := `SELECT * FROM wx_user WHERE mobile <>'' AND outbound_mobile = ''`
|
|
|
- _, err = o.Raw(sql).QueryRows(&items)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-//修改手机号区号 8位号码+852,9位号码+886,10位号码+1,11位及以上号码+86
|
|
|
-func UPdateUserCountryCode(item *WxUserItem) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- if item.CountryCode == "" && len(item.Mobile) >= 11 {
|
|
|
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=86 , country_code=86 WHERE user_id = ?`
|
|
|
- _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
|
|
|
- } else if item.CountryCode == "" && len(item.Mobile) == 8 {
|
|
|
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=852 , country_code=852 WHERE user_id = ?`
|
|
|
- _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
|
|
|
- } else if item.CountryCode == "" && len(item.Mobile) == 9 {
|
|
|
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=886 , country_code=886 WHERE user_id = ?`
|
|
|
- _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
|
|
|
- } else if item.CountryCode == "" && len(item.Mobile) == 10 {
|
|
|
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=1 , country_code=1 WHERE user_id = ?`
|
|
|
- _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
|
|
|
- } else {
|
|
|
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=? WHERE user_id = ?`
|
|
|
- _, err = o.Raw(sql, item.Mobile, item.CountryCode, item.UserId).Exec()
|
|
|
- }
|
|
|
-
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
func GetWxUserItemByUserUnionId(unionId string) (item *WxUserItem, err error) {
|
|
|
sql := `SELECT a.*,r.headimgurl as headimgurl_record, b.company_name FROM wx_user AS a
|
|
|
INNER JOIN company AS b on a.company_id=b.company_id
|
|
@@ -261,3 +115,23 @@ func GetWxUserItemByUserUnionId(unionId string) (item *WxUserItem, err error) {
|
|
|
err = orm.NewOrm().Raw(sql, unionId).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+//根据用户UnionId取相关信息
|
|
|
+func GetWxUserAouthByUnionId(UnionId string) (item *WxUserItem, err error) {
|
|
|
+ sql := `SELECT
|
|
|
+ a.*,
|
|
|
+ s.union_id,
|
|
|
+ b.company_name
|
|
|
+ FROM
|
|
|
+ cygx_xzs_session AS s
|
|
|
+ INNER JOIN user_record as r ON r.union_id = s.union_id
|
|
|
+ LEFT JOIN wx_user AS a ON a.mobile = r.bind_account
|
|
|
+ LEFT JOIN company AS b ON a.company_id = b.company_id
|
|
|
+ WHERE
|
|
|
+ s.union_id = ?
|
|
|
+ ORDER BY
|
|
|
+ a.company_id DESC
|
|
|
+ LIMIT 1`
|
|
|
+ err = orm.NewOrm().Raw(sql, UnionId).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|