Commit 0bccaa26 by 朱继来

查询用户重复账号

parent 212b747b
package Order
import (
_ "database/sql"
"database/sql"
_ "encoding/json"
"fmt"
_ "fmt"
"github.com/ichunt2019/logger"
......@@ -11,7 +12,17 @@ import (
_ "time"
)
// 查询用户订单数
func QueryUserOrder(user_id int) int {
var count int
err := db.DB.QueryRow("select count(*) from lie_order where user_id = ?", user_id).Scan(&count)
if err == sql.ErrNoRows {
logger.Info("没有获取到用户订单,user_id:%d", user_id)
}
return count
}
func UpdateStatus(order_id int, status_extend int) (err error) {
......
package UserCoupon
import (
"database/sql"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
)
// 查询用户优惠券
func QueryUserCoupon(user_id int) int {
var count int
err := db.DB.QueryRow("select count(*) from lie_user_coupon where user_id = ?", user_id).Scan(&count)
if err == sql.ErrNoRows {
logger.Info("没有获取到用户优惠券,user_id:%d", user_id)
}
return count
}
\ No newline at end of file
package UserInfo
import (
"database/sql"
"encoding/json"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
)
type UserInfo struct {
UiId int `db:"ui_id"`
UserId int `db:"user_id"`
CurUserPoint int `db:"cur_user_point"`
WalletBalance float64 `db:"wallet_balance"`
}
// 查询用户钱包余额
func QueryUserWallet(user_id int) []byte {
var balance UserInfo
err := db.DB.Get(&balance,"select ui_id, user_id, cur_user_point, wallet_balance from lie_user_info where user_id = ?", user_id)
if err == sql.ErrNoRows {
logger.Info("没有获取到用户信息,user_id:%d", user_id)
}
res, _ := json.Marshal(balance)
return res
}
\ No newline at end of file
package UserLoginLog
import (
"database/sql"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
)
// 查询用户登录记录
func QueryUserLoginLog(user_id int) int {
var count int
err := db.DB.QueryRow("select count(*) from lie_user_login_log where user_id = ?", user_id).Scan(&count)
if err == sql.ErrNoRows {
logger.Info("没有获取到用户登录记录,user_id:%d", user_id)
}
return count
}
\ No newline at end of file
......@@ -3,10 +3,8 @@ package UserMain
import (
"database/sql"
_ "encoding/json"
"fmt"
_ "github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/util"
"log"
)
......@@ -18,21 +16,51 @@ type UserMain struct {
Count int `db:"count"`
}
func initDb(dns string) (err error) {
err = db.Init(dns)
// 查询重复账号
func QueryRepeatAccount(field string) []string {
var user_main []*UserMain
err := db.DB.Select(&user_main, "select "+field+", count(*) as count from lie_user_main where "+field+" != '' group by "+field+" having count > 1")
if err == sql.ErrNoRows {
log.Printf("not found data of the id:%d", 1)
}
if err != nil {
return
panic(err)
}
return
if user_main == nil {
return nil
}
var data []string
for _, v := range user_main {
if field == "mobile" {
data = append(data, v.Mobile)
} else if field == "email" {
data = append(data, v.Email)
}
}
return data
}
// 多行查询
func QueryRepeatAccount(field string) {
initDb(util.Configs.Liexin_databases.Dns) //初始化db
/**
根据指定账号查询user_id
account 账号
types 账号类型,1-手机,2-邮箱
*/
func QueryUserId(account string, account_type int) []int {
var field string
if account_type == 1 {
field = "mobile"
} else {
field = "email"
}
var user_main []*UserMain
err := db.DB.Select(&user_main, "select "+ field +", count(*) as count from lie_user_main where ? != '' group by ? having count > 1", field, field)
err := db.DB.Select(&user_main, "select user_id from lie_user_main where "+field+" = ?", account)
if err == sql.ErrNoRows {
log.Printf("not found data of the id:%d", 1)
......@@ -43,10 +71,13 @@ func QueryRepeatAccount(field string) {
}
if user_main == nil {
return
return nil
}
var data []int
for _, v := range user_main {
fmt.Println(v)
data = append(data, v.UserId)
}
return data
}
\ No newline at end of file
package main
import (
"encoding/json"
"flag"
_ "fmt"
"fmt"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/dal/user/UserCoupon"
"go-queue-server/dal/user/UserInfo"
"go-queue-server/dal/user/UserLoginLog"
"go-queue-server/dal/user/UserMain"
"go-queue-server/dal/order/Order"
"go-queue-server/util"
"strconv"
)
func initDb(dns string) (err error) {
err = db.Init(dns)
if err != nil {
return
}
return
}
var ConfigDir string
var LogDir string
......@@ -32,5 +48,84 @@ func main() {
logger.InitLogger("file",logConfig)
logger.Init()
UserMain.QueryRepeatAccount("mobile")
//初始化db
initDb(util.Configs.Liexin_databases.Dns)
mobiles := UserMain.QueryRepeatAccount("mobile") // 查询重复手机号码
emails := UserMain.QueryRepeatAccount("email") // 查询重复邮箱
checkUser(mobiles, 1)
checkUser(emails, 2)
}
// 检查用户
func checkUser(data []string, account_type int) {
for _, v := range data {
user_ids := UserMain.QueryUserId(v, account_type)
fmt.Println(v)
//fmt.Println(user_ids)
logger.Info("重复账号:%s,对应的ID:%d" , v, user_ids)
for _, uid := range user_ids {
res := checkUserInfo(uid, v)
fmt.Println(uid)
if !res {
logger.Info("用户:"+v+", ID:"+strconv.Itoa(uid)+",不存在平台数据")
}
}
}
}
// 检查用户是否存在订单、登录、钱包余额、积分、优惠券
func checkUserInfo(user_id int, account string) bool {
var order_count int
var login_count int
var user_info *UserInfo.UserInfo
var balance float64
var point int
var coupon_count int
order_count = Order.QueryUserOrder(user_id)
login_count = UserLoginLog.QueryUserLoginLog(user_id)
user_info_res := UserInfo.QueryUserWallet(user_id)
json.Unmarshal([]byte(user_info_res), &user_info)
balance = user_info.WalletBalance // 钱包余额
point = user_info.CurUserPoint // 当前积分
coupon_count = UserCoupon.QueryUserCoupon(user_id)
//fmt.Println(order_count)
//fmt.Println(login_count)
//fmt.Println(balance)
//fmt.Println(point)
//fmt.Println(coupon_count)
if order_count == 0 && login_count == 0 && balance == 0 && point == 0 && coupon_count == 0 {
return false
}
var msg_text string
if order_count != 0 {
msg_text += ",存在订单数据"
}
if login_count != 0 {
msg_text += ",存在登录数据"
}
if balance != 0 {
msg_text += ",存在余额"
}
if point != 0 {
msg_text += ",存在积分"
}
if coupon_count != 0 {
msg_text += ",存在优惠券"
}
logger.Info("用户:"+ account +",ID:" + strconv.Itoa(user_id) + msg_text)
return true
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment