Commit 170d329a by Joneq

增加拉取用户脚本

parent 4dea815d
package main
import (
"crm-server/internal/common"
"crm-server/internal/logic"
"crm-server/internal/model"
"crm-server/internal/service"
"strconv"
)
var(
MemberId int
InsertData model.MemberAddUserData
)
//监听用户添加队列
func main(){
//定义错误类型
service.ProGramErrType = "member_user_add:"
//设置所有城市
common.SetCityName()
MemberId = 1
//获取当前会员的基本数据
InsertData = logic.GetMemberUserInfo(MemberId)
//检测用户是否存在
if InsertData.User_Id == 0{
service.WriteErrDetail(strconv.Itoa(MemberId)+"会员系统中用户信息不存在")
}
if logic.CheckMemberIdIsHave(InsertData.User_Id) != 0 {
service.WriteErrDetail(strconv.Itoa(MemberId)+"crm系统中用户已经存在")
}
//处理得到的用户数据
InsertData = logic.HandleData(InsertData)
}
\ No newline at end of file
package logic package common
import ( import (
"crypto/md5" "crypto/md5"
...@@ -10,4 +10,9 @@ func Md5(str string) string { ...@@ -10,4 +10,9 @@ func Md5(str string) string {
hash := md5.New() hash := md5.New()
hash.Write([]byte(str)) hash.Write([]byte(str))
return hex.EncodeToString(hash.Sum(nil)) return hex.EncodeToString(hash.Sum(nil))
} }
\ No newline at end of file
...@@ -10,8 +10,8 @@ import ( ...@@ -10,8 +10,8 @@ import (
func GetDb()(*sqlx.DB) { func GetDb()(*sqlx.DB) {
db1 := configs.GetDBOne() dbConfig := configs.GetDBOne()
db, err := sqlx.Open(db1.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", db1.User, db1.Pass, db1.Ip, db1.Port, db1.Table)) db, err := sqlx.Open(dbConfig.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbConfig.User, dbConfig.Pass, dbConfig.Ip, dbConfig.Port, dbConfig.Table))
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
...@@ -19,8 +19,17 @@ func GetDb()(*sqlx.DB) { ...@@ -19,8 +19,17 @@ func GetDb()(*sqlx.DB) {
} }
func GetCmsDb()(*sqlx.DB) { func GetCmsDb()(*sqlx.DB) {
db1 := configs.GetDBCms() dbConfig := configs.GetDBCms()
db, err := sqlx.Open(db1.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", db1.User, db1.Pass, db1.Ip, db1.Port, db1.Table)) db, err := sqlx.Open(dbConfig.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbConfig.User, dbConfig.Pass, dbConfig.Ip, dbConfig.Port, dbConfig.Table))
if err != nil {
log.Fatalln(err)
}
return db
}
func GetLiexinDb()(*sqlx.DB) {
dbConfig := configs.GetDBLiexin()
db, err := sqlx.Open(dbConfig.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbConfig.User, dbConfig.Pass, dbConfig.Ip, dbConfig.Port, dbConfig.Table))
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
......
package logic
import (
"crm-server/internal/dao"
"crm-server/internal/model"
"crm-server/internal/service"
)
const INSERTCRMUSER = "INSERT INTO `lie_user` (" +
"`outter_id`, `source`,`adtag`, `mobile`,`email`, `create_time`,`copy_time`, `customer_identity`,`name`, `channel_source`,`remark`, " +
"`adtag`,`ptag`,`customer_identity`,`adtag`,`adtag`,`adtag`," +
")VALUES()"
//检测会员用户是否存在
func CheckMemberIdIsHave(memberId int)(returnUserId int){
var userId int = 0
err := dao.GetDb().QueryRowx("select user_id from lie_user where outter_uid = ?",memberId).Scan(&userId)
if err != nil {
service.WriteErr(err)
}
return userId
}
//增加从会员系统来的用户
func InsertMemberUser(memberInfo model.MemberAddUserData) {
//开启事务
//dbTran,_ := dao.GetDb().Begin()
}
\ No newline at end of file
package logic
import (
"crm-server/internal/common"
"crm-server/internal/dao"
"crm-server/internal/model"
"crm-server/internal/service"
"regexp"
"strconv"
"strings"
)
//会员系统的用户逻辑
var(
adtag = ""
ptag = ""
refer = ""
)
const(
AdtagRex = "adtag=.*"
PtagRex = "ptag=.*"
ReferRex = "refer=.*"
)
//获取会员系统的用户数据sql
const GETMEMBERUSER = "select `lie_u`.`user_id`, `lie_u`.`mobile`, `lie_u`.`user_name`, `lie_u`.`email`," +
" `lie_u`.`reg_remark`, `lie_u`.`create_device`, `lie_u`.`create_time`, `lie_c`.`com_id`, `lie_c`.`type_id`," +
" `lie_c`.`com_name`, `lie_c`.`com_desc`, `lie_c`.`com_province_id`, `lie_c`.`com_city_id`, `lie_c`.`com_area_id`," +
" `lie_c`.`com_address`, `lie_c`.`com_telphone`, `lie_c`.`com_fax`, `lie_c`.`brand_list`, `lie_i`.`work_function`," +
" `lie_i`.`user_type`, `lie_i`.`sale_id` as `userinfo_sale_id` from `lie_user_main` as `lie_u` left join `lie_user_info` as " +
"`lie_i` on `lie_u`.`user_id` = `lie_i`.`user_id` left join `lie_user_company` as `lie_c` on `lie_u`.`user_id` = `lie_c`.`user_id`" +
" where `lie_u`.`is_test` = 0 and `lie_u`.`is_type` = 0 and `lie_u`.`user_id` = ? and `lie_u`.`create_device` not in (3, 20)"
//获取会员系统的用户数据sql
func GetMemberUserInfo(memberId int) model.MemberAddUserData {
var MemberUserInfo model.MemberAddUserData
err := dao.GetLiexinDb().QueryRowx(GETMEMBERUSER,memberId).StructScan(&MemberUserInfo)
if err != nil {
service.WriteErr(err)
}
return MemberUserInfo
}
//处理基本的原始数据
func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
var saleId = 0
//查找交易员
err := dao.GetLiexinDb().QueryRowx("select sale_id from lie_order where user_id = ? order by create_time desc",MemberUserInfo.User_Id).Scan(&saleId)
if err != nil {
service.WriteErr(err)
}
if saleId != 0 {
MemberUserInfo.Sale_Id = saleId
}
// 个人转化为贸易商
if MemberUserInfo.Type_Id == 0 {
MemberUserInfo.Type_Id = 5
}
//来源
if MemberUserInfo.Create_Device != 2 {
MemberUserInfo.Source = 1
}else{
MemberUserInfo.Source = 2
}
// 客户身份
if MemberUserInfo.Work_Function != 0 {
MemberUserInfo.Customer_identity = MemberUserInfo.Work_Function
}
//获取oems数据
//抓取adtag和ptag,refer
adtag = regexp.MustCompile(AdtagRex).FindString(MemberUserInfo.Reg_Remark)
ptag = regexp.MustCompile(PtagRex).FindString(MemberUserInfo.Reg_Remark)
refer = regexp.MustCompile(ReferRex).FindString(MemberUserInfo.Reg_Remark)
if refer != ""{
refer = strings.Split(adtag,",")[0]
//如果是以上refer则为自营样片
if strings.Contains(refer,"sample") {
MemberUserInfo.Channel_source = 10
}
}
if ptag != "" {
ptag = strings.Split(adtag,",")[0]
MemberUserInfo.Ptag = strings.Split(ptag,",")[0]
switch ptag {
case "ptag=activity-140":
case "ptag=activity-141":
case "ptag=activity-143":
case "ptag=activity-144":
MemberUserInfo.Customer_identity = 2//如果是以上ptag则为采购用户
MemberUserInfo.Channel_source = 9//如果是以上ptag则为展会用户
break
case "ptag=activity-142":
case "ptag=activity-145":
MemberUserInfo.Customer_identity = 1//如果是以上ptag则为工程师
MemberUserInfo.Channel_source = 9//如果是以上ptag则为展会用户
break
case "ptag=sample":
case "ptag=sample-pop":
case "ptag=samplereg":
case "ptag=sample-stopnav":
MemberUserInfo.Channel_source = 10//如果是以上ptag则为自营样片
break
case "ptag=jr":
MemberUserInfo.Channel_source = 11//如果是以上ptag则为信用金融
break
case "ptag=edcp":
MemberUserInfo.Channel_source = 12//如果是以上ptag则为信用贷测评
break
}
}
if adtag != "" {
adtag = strings.Split(adtag,",")[0]
MemberUserInfo.Adtag = adtag
if adtag == "adtag=bps" {
MemberUserInfo.Channel_source = 13//如果是以上adtag则为白皮书下载用户
}
if adtag == "adtag=findchips" {
MemberUserInfo.Channel_source = 14//如果是以上adtagfindchips广告
}
}
//地址
if MemberUserInfo.Com_Province_Id != 0 && MemberUserInfo.Com_City_Id != 0 && MemberUserInfo.Com_Area_Id != 0 {
MemberUserInfo.Com_Full_addr = common.AllCity[strconv.Itoa(MemberUserInfo.Com_Province_Id)] + common.AllCity[strconv.Itoa(MemberUserInfo.Com_City_Id)] + common.AllCity[strconv.Itoa(MemberUserInfo.Com_Area_Id)] + MemberUserInfo.Com_Address
}
return MemberUserInfo
}
\ No newline at end of file
package model
type MemberAddUserData struct {
User_Id int `json:"user_id"`
Mobile string `json:"mobile"`
User_Name string `json:"user_name"`
Email string `json:"email"`
Reg_Remark string `json:"reg_remark"`
Create_Device int `json:"create_device"`
Create_Time int `json:"create_time"`
Com_Id int `json:"com_id"`
Type_Id int `json:"type_id"`
Com_Name string `json:"ComName"`
Com_Desc string `json:"com_desc"`
Com_Province_Id int `json:"com_provicne_id"`
Com_City_Id int `json:"com_city_id"`
Com_Area_Id int `json:"com_area_id"`
Com_Address string `json:"com_address"`
Com_Telphone string `json:"com_telphone"`
Com_Fax string `json:"com_fax"`
Brand_List string `json:"brand_list"`
Work_Function int `json:"work_function"`
User_Type int `json:"user_type"`
Userinfo_Sale_Id int `json:"userinfo_sale_id"`
Sale_Id int `json:"sale_id"`
Adtag string `json:"adtag"`
Ptag string `json:"ptag"`
Com_Full_addr string `json:"com_full_addr"`
Channel_source int `json:"channel_source"`
Source int `json:"source"`
Customer_identity int `json:"customer_identity"`
}
\ No newline at end of file
package model
type OemsUserinfo struct {
Outter_Uid string `json:"outter_uid"`
Contact string `json:"contact"`
Contact_Name string `json:"contact_name"`
Note string `json:"note"`
}
\ No newline at end of file
package service package service
import ( import (
"crm-server/internal/logic" "crm-server/internal/common"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"time" "time"
) )
...@@ -35,7 +35,7 @@ func SendMessage(mobile int64 , content string){ ...@@ -35,7 +35,7 @@ func SendMessage(mobile int64 , content string){
"touser" : {string(requestTel)}, "touser" : {string(requestTel)},
"keyword" : {"register_nopay_notify"}, "keyword" : {"register_nopay_notify"},
"k1" : {strconv.FormatInt(int64(timeNow),10)}, "k1" : {strconv.FormatInt(int64(timeNow),10)},
"k2" : {logic.Md5(logic.Md5(strconv.FormatInt(int64(timeNow),10))+APIMD5STR)}, "k2" : {common.Md5(common.Md5(strconv.FormatInt(int64(timeNow),10))+APIMD5STR)},
"is_ignore" : {}, "is_ignore" : {},
}) })
......
package service
import "fmt"
//错误日志
//错误类型
var ProGramErrType string = "default:"
//返回原声错误
func WriteErr(err error) {
if err != nil {
switch ProGramErrType {
default:
}
//屏幕打印,加上发送钉钉消息
fmt.Println(ProGramErrType+err.Error())
}
}
//返回详细错误
func WriteErrDetail(errString string) {
switch ProGramErrType {
default:
}
//屏幕打印,加上发送钉钉消息
fmt.Println(errString)
//SendMessage(ADMINTEL,ProGramErrType+errString)
}
\ 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