|
@@ -90,23 +90,19 @@ type WxUserItem struct {
|
|
|
}
|
|
|
|
|
|
func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT * FROM wx_user WHERE union_id=? `
|
|
|
- err = orm.NewOrm().Raw(sql, unionid).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, unionid).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 根据用户ID获取相关信息
|
|
|
func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
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.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)
|
|
|
+ err = o.Raw(sql, userId).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -132,7 +128,7 @@ type WxGetUserInfoReq struct {
|
|
|
|
|
|
// 修改用户会话key
|
|
|
func ModifyWxUserSessionKey(sessionKey string, userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `UPDATE wx_user SET session_key=? WHERE user_id=? `
|
|
|
_, err = o.Raw(sql, sessionKey, userId).Exec()
|
|
|
return
|
|
@@ -140,7 +136,7 @@ func ModifyWxUserSessionKey(sessionKey string, userId int) (err error) {
|
|
|
|
|
|
// 添加用户信息
|
|
|
func ModifyWxUserInfo(unionId, nickName, province, city, country, avatar string, gender, userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
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
|
|
@@ -148,7 +144,7 @@ func ModifyWxUserInfo(unionId, nickName, province, city, country, avatar string,
|
|
|
|
|
|
// 修改用户会话key
|
|
|
func DeleteWxUserByUserId(userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `DELETE FROM wx_user WHERE user_id=? `
|
|
|
_, err = o.Raw(sql, userId).Exec()
|
|
|
return
|
|
@@ -177,7 +173,7 @@ type WxGetPhoneNumberReq struct {
|
|
|
}
|
|
|
|
|
|
func ModifyUsersMobile(usersId int, phoneNumber string) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `UPDATE wx_user SET mobile=? WHERE user_id=? `
|
|
|
_, err = o.Raw(sql, phoneNumber, usersId).Exec()
|
|
|
return
|
|
@@ -191,48 +187,50 @@ type WxGetPhoneNumberResp struct {
|
|
|
|
|
|
// 根据用户手机号获取相关信息
|
|
|
func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
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= '` + mobile + `' ORDER BY a.company_id DESC LIMIT 1 `
|
|
|
- err = orm.NewOrm().Raw(sql).QueryRow(&item)
|
|
|
+ err = o.Raw(sql).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 根据用户手机号获取相关信息
|
|
|
func GetWxUserAouthByMobile(mobile string) (item *WxUserItem, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT
|
|
|
a.*,
|
|
|
- s.mobile,
|
|
|
b.company_name
|
|
|
FROM
|
|
|
- cygx_session_mobile AS s
|
|
|
- LEFT JOIN wx_user AS a ON a.mobile = s.mobile
|
|
|
+ wx_user AS a
|
|
|
LEFT JOIN company AS b ON a.company_id = b.company_id
|
|
|
WHERE
|
|
|
- s.mobile = ?
|
|
|
+ a.mobile = ?
|
|
|
ORDER BY
|
|
|
a.company_id DESC
|
|
|
LIMIT 1`
|
|
|
- err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, mobile).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT * FROM wx_user WHERE email=? `
|
|
|
- err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
|
|
|
+ err = o.Raw(sql, email).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ModifyReportLastViewTime(uid int) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := ` UPDATE wx_user SET report_last_view_time=NOW()
|
|
|
WHERE user_id=? `
|
|
|
- _, err = orm.NewOrm().Raw(sql, uid).Exec()
|
|
|
+ _, err = o.Raw(sql, uid).Exec()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 变更联系人是否已注册状态
|
|
|
func ModifyWxUserRegisterStatus(userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
|
|
|
_, err = o.Raw(sql, 1, userId).Exec()
|
|
|
return
|
|
@@ -240,7 +238,7 @@ func ModifyWxUserRegisterStatus(userId int) (err error) {
|
|
|
|
|
|
// 修改用户是否绑定外呼手机号弹窗
|
|
|
func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
|
|
|
_, err = o.Raw(sql, userId).Exec()
|
|
|
return
|
|
@@ -248,7 +246,7 @@ func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
|
|
|
|
|
|
// 列表
|
|
|
func GetUserListAll() (items []*WxUserItem, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT * FROM wx_user WHERE mobile <>'' AND outbound_mobile = ''`
|
|
|
_, err = o.Raw(sql).QueryRows(&items)
|
|
|
return
|
|
@@ -256,7 +254,7 @@ func GetUserListAll() (items []*WxUserItem, err error) {
|
|
|
|
|
|
// 修改手机号区号 8位号码+852,9位号码+886,10位号码+1,11位及以上号码+86
|
|
|
func UPdateUserCountryCode(item *WxUserItem) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
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()
|
|
@@ -279,42 +277,47 @@ func UPdateUserCountryCode(item *WxUserItem) (err error) {
|
|
|
|
|
|
// 判断公司下用户名称是否存在
|
|
|
func GetUserCountByName(companyId int, name string) (count int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? AND real_name = ?`
|
|
|
- err = orm.NewOrm().Raw(sql, companyId, name).QueryRow(&count)
|
|
|
+ err = o.Raw(sql, companyId, name).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 判断这个用户是否被设置消息提醒
|
|
|
func GetUserRemind(uid int) (count int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT COUNT(1) AS count FROM cygx_user_remind WHERE user_id = ? `
|
|
|
- err = orm.NewOrm().Raw(sql, uid).QueryRow(&count)
|
|
|
+ err = o.Raw(sql, uid).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 判断公司下用户名称是否存在
|
|
|
func GetUserCountByThirdName(companyId int, name string) (count int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? AND tripartite_code = ?`
|
|
|
- err = orm.NewOrm().Raw(sql, companyId, name).QueryRow(&count)
|
|
|
+ err = o.Raw(sql, companyId, name).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 获取公司下一共有多少用户
|
|
|
func GetUserCountByCompanyId(companyId int) (count int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? `
|
|
|
- err = orm.NewOrm().Raw(sql, companyId).QueryRow(&count)
|
|
|
+ err = o.Raw(sql, companyId).QueryRow(&count)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func UpdateUserMobile(uid int, mobile string) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := ` UPDATE wx_user SET mobile=?
|
|
|
WHERE user_id=? `
|
|
|
- _, err = orm.NewOrm().Raw(sql, mobile, uid).Exec()
|
|
|
+ _, err = o.Raw(sql, mobile, uid).Exec()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 获取公司下用户详情详情详情
|
|
|
func GetUserByName(companyId int, name string) (item *WxUser, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT * FROM wx_user WHERE company_id = ? AND real_name = ? `
|
|
|
err = o.Raw(sql, companyId, name).QueryRow(&item)
|
|
|
return
|
|
@@ -322,45 +325,61 @@ func GetUserByName(companyId int, name string) (item *WxUser, err error) {
|
|
|
|
|
|
// 获取公司下用户详情详情详情
|
|
|
func GetUserByThirdName(companyId int, name string) (item *WxUser, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT * FROM wx_user WHERE company_id = ? AND tripartite_code = ? `
|
|
|
err = o.Raw(sql, companyId, name).QueryRow(&item)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// 获取所有注册的权益用户
|
|
|
+//func GetUserRegisterList() (items []*WxUser, err error) {
|
|
|
+// o := orm.NewOrmUsingDB("weekly_report")
|
|
|
+// sql := `SELECT
|
|
|
+// u.user_id,
|
|
|
+// u.company_id,
|
|
|
+// u.mobile,
|
|
|
+// u.email,
|
|
|
+// u.real_name,
|
|
|
+// u.is_register,
|
|
|
+// u.is_maker,
|
|
|
+// u.register_time
|
|
|
+// FROM
|
|
|
+// wx_user AS u
|
|
|
+// INNER JOIN company AS c ON c.company_id = u.company_id
|
|
|
+// INNER JOIN company_product AS cp ON cp.company_id = c.company_id
|
|
|
+// WHERE
|
|
|
+// u.company_id IN (
|
|
|
+// SELECT
|
|
|
+// a.company_id
|
|
|
+// FROM
|
|
|
+// company AS a
|
|
|
+// INNER JOIN company_product AS b ON a.company_id = b.company_id
|
|
|
+// WHERE
|
|
|
+// a.enabled = 1
|
|
|
+// AND b.STATUS IN ( '正式', '试用', '冻结' )
|
|
|
+// AND cp.product_id = 2
|
|
|
+// )
|
|
|
+// AND cp.product_id = 2
|
|
|
+// GROUP BY
|
|
|
+// u.user_id `
|
|
|
+// _, err = o.Raw(sql).QueryRows(&items)
|
|
|
+// //AND u.register_time IS NOT NULL OR u.report_last_view_time <>'' 统计阅读时间与注册时间不为空的用户
|
|
|
+// return
|
|
|
+//}
|
|
|
+
|
|
|
// 获取所有注册的权益用户
|
|
|
func GetUserRegisterList() (items []*WxUser, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
sql := `SELECT
|
|
|
- u.user_id,
|
|
|
- u.company_id,
|
|
|
- u.mobile,
|
|
|
- u.email,
|
|
|
- u.real_name,
|
|
|
- u.is_register,
|
|
|
- u.is_maker,
|
|
|
- u.register_time
|
|
|
- FROM
|
|
|
- wx_user AS u
|
|
|
- INNER JOIN company AS c ON c.company_id = u.company_id
|
|
|
- INNER JOIN company_product AS cp ON cp.company_id = c.company_id
|
|
|
- WHERE
|
|
|
- u.company_id IN (
|
|
|
- SELECT
|
|
|
- a.company_id
|
|
|
+ *
|
|
|
FROM
|
|
|
- company AS a
|
|
|
- INNER JOIN company_product AS b ON a.company_id = b.company_id
|
|
|
+ cygx_page_history_record
|
|
|
WHERE
|
|
|
- a.enabled = 1
|
|
|
- AND b.STATUS IN ( '正式', '试用', '冻结' )
|
|
|
- AND cp.product_id = 2
|
|
|
- )
|
|
|
- AND cp.product_id = 2
|
|
|
- GROUP BY
|
|
|
- u.user_id `
|
|
|
+ user_id > 0
|
|
|
+ AND company_id > 0
|
|
|
+ AND create_time > DATE_SUB( DATE( NOW()), INTERVAL 1 DAY )
|
|
|
+ GROUP BY user_id `
|
|
|
_, err = o.Raw(sql).QueryRows(&items)
|
|
|
- //AND u.register_time IS NOT NULL OR u.report_last_view_time <>'' 统计阅读时间与注册时间不为空的用户
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -560,14 +579,14 @@ func GetCygxCompanyUserUserInteraction(userIds string) (items []*CygxUserInterac
|
|
|
man.activity_id IN ( SELECT activity_id FROM cygx_activity_signup AS f WHERE f.user_id = u.user_id AND label != '')
|
|
|
) AS activity_label
|
|
|
FROM
|
|
|
- wx_user AS u WHERE u.user_id IN( ` + userIds + `) `
|
|
|
+ cygx_page_history_record AS u WHERE u.user_id IN( ` + userIds + `) GROUP BY u.user_id `
|
|
|
_, err = o.Raw(sql).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// GetWxUserListByUserIds 根据用户ID集合获取用户
|
|
|
func GetWxUserListByUserIds(userIds string) (list []*WxUserItem, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := ` SELECT u.*, c.company_name FROM wx_user AS u
|
|
|
INNER JOIN company AS c ON c.company_id = u.company_id
|
|
|
WHERE user_id IN (` + userIds + `) `
|
|
@@ -582,7 +601,7 @@ func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) {
|
|
|
return
|
|
|
}
|
|
|
sql := `SELECT* FROM wx_user WHERE mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
_, err = o.Raw(sql, mobiles).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
@@ -594,13 +613,13 @@ func GetWxUserByOutboundMobiles(mobiles []string) (items []*WxUser, err error) {
|
|
|
return
|
|
|
}
|
|
|
sql := `SELECT* FROM wx_user WHERE outbound_mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
_, err = o.Raw(sql, mobiles).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func UserSubscribe(subscribeTime string, userId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `UPDATE wx_user SET cygx_subscribe=1,cygx_subscribe_time=? WHERE user_id = ? `
|
|
|
_, err = o.Raw(sql, subscribeTime, userId).Exec()
|
|
|
return
|
|
@@ -611,7 +630,7 @@ func GetWxUserOutboundMobiles(mobiles []string) (item []*WxUserOutboundMobile, e
|
|
|
if lenmobiles == 0 {
|
|
|
return
|
|
|
}
|
|
|
- o := orm.NewOrm()
|
|
|
+ o := orm.NewOrmUsingDB("weekly_report")
|
|
|
sql := `SELECT u.real_name,u.mobile,u.outbound_mobile,u.company_id,p.company_name ,GROUP_CONCAT( DISTINCT p.seller_name SEPARATOR '/' ) AS seller_name
|
|
|
FROM wx_user as u
|
|
|
INNER JOIN company_product AS p ON p.company_id = u.company_id
|