Commit 3834dae0 by 朱继来

调整同步CRM,添加邀请码

parent 6608bf38
...@@ -149,3 +149,18 @@ func IsOrder(user_id int) bool { ...@@ -149,3 +149,18 @@ func IsOrder(user_id int) bool {
return false return false
} }
// 获取指定部门ID (线上销售部-33 线下销售部-40 大客户部-39 苏州部-59(外网为69))
func GetSaleDepartmentIds(department_id int) []int {
var sales_department_ids []int
sales_department_ids = append(sales_department_ids, department_id)
var user_department []*UserDepartment
dao.GetCmsDb().Select(&user_department, "select department_id,department_name,parent_id from user_department where parent_id = ?", department_id)
for _, v := range user_department {
sales_department_ids = append(sales_department_ids, v.DepartmentId)
}
return sales_department_ids
}
package logic package logic
import ( import (
"crm-server/cmd/follow/handle"
"crm-server/configs"
"crm-server/internal/common" "crm-server/internal/common"
"crm-server/internal/dao" "crm-server/internal/dao"
"crm-server/internal/model" "crm-server/internal/model"
...@@ -26,7 +28,7 @@ const( ...@@ -26,7 +28,7 @@ const(
//获取会员系统的用户数据sql //获取会员系统的用户数据sql
const GETMEMBERUSER = "select `lie_u`.`user_id`, `lie_u`.`mobile`, `lie_u`.`user_name`, `lie_u`.`email`," + 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_u`.`channel_type`, `lie_c`.`com_id`, `lie_c`.`type_id`," + " `lie_u`.`reg_remark`, `lie_u`.`create_device`, `lie_u`.`create_time`, `lie_u`.`channel_type`, `lie_u`.`invite_code`, `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_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_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`.`user_type`, `lie_i`.`sale_id` as `userinfo_sale_id` from `lie_user_main` as `lie_u` left join `lie_user_info` as " +
...@@ -60,6 +62,50 @@ func SetTagSale(tag string,memberInfo *model.MemberAddUserData){ ...@@ -60,6 +62,50 @@ func SetTagSale(tag string,memberInfo *model.MemberAddUserData){
} }
} }
// 通过用户邀请码获取sale_id
func GetCodeSaleId(code string) int {
returnString := ""
for i:=4;i<len(code) ;i++ {
returnString += string(code[i]-49)
}
returnInt,_ := strconv.Atoi(returnString)
return returnInt
}
//根据sale_id获取用户渠道
func GetChannelType(sale_id int) int {
var department_id int
var ok bool
dao.GetCmsDb().Get(&department_id, "select department_id from user_info where userId = ?", sale_id)
online_department_ids := handle.GetSaleDepartmentIds(configs.Online_sales_department_id) // 线上销售部门
_, ok = handle.SliceFind(online_department_ids, department_id)
if ok {
return 1
}
offline_department_ids := handle.GetSaleDepartmentIds(configs.Offline_sales_department_id) // 线下销售部门
_, ok = handle.SliceFind(offline_department_ids, department_id)
if ok {
return 2
}
key_department_ids := handle.GetSaleDepartmentIds(configs.Key_sales_department_id) // 大客户销售部门
_, ok = handle.SliceFind(key_department_ids, department_id)
if ok {
return 3
}
suzhou_department_ids := handle.GetSaleDepartmentIds(configs.Suzhou_sales_department_id) // 苏州销售部门
_, ok = handle.SliceFind(suzhou_department_ids, department_id)
if ok {
return 4
}
return 1
}
//处理基本的原始数据 //处理基本的原始数据
/* /*
sale_id 获取方式: sale_id 获取方式:
...@@ -71,8 +117,26 @@ func SetTagSale(tag string,memberInfo *model.MemberAddUserData){ ...@@ -71,8 +117,26 @@ func SetTagSale(tag string,memberInfo *model.MemberAddUserData){
func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
var saleId = 0 var saleId = 0
// 用户邀请码是否存在
if MemberUserInfo.Invite_Code != "" {
saleId = GetCodeSaleId(MemberUserInfo.Invite_Code)
MemberUserInfo.Sale_Id = saleId
// 根据sale_id获取用户渠道
var channel_type = GetChannelType(saleId)
MemberUserInfo.Channel_type = channel_type
}
if MemberUserInfo.Sale_Id == 0 && MemberUserInfo.Userinfo_Sale_Id != 0{
MemberUserInfo.Sale_Id = MemberUserInfo.Userinfo_Sale_Id
}
//查找交易员 //查找交易员
err := dao.GetLiexinDb().QueryRowx("select sale_id from lie_order where user_id = ? and is_type = 0 order by create_time desc",MemberUserInfo.User_Id).Scan(&saleId) if MemberUserInfo.Sale_Id == 0 {
err := dao.GetLiexinOrderDb().QueryRowx("select sale_id from lie_order where user_id = ? and is_type = 0 order by create_time desc",MemberUserInfo.User_Id).Scan(&saleId)
if err != nil { if err != nil {
service.WriteErr(err) service.WriteErr(err)
} }
...@@ -80,12 +144,8 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{ ...@@ -80,12 +144,8 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
if saleId != 0 { if saleId != 0 {
MemberUserInfo.Sale_Id = saleId MemberUserInfo.Sale_Id = saleId
} }
if MemberUserInfo.Userinfo_Sale_Id != 0{
MemberUserInfo.Sale_Id = MemberUserInfo.Userinfo_Sale_Id
} }
// 个人转化为贸易商 // 个人转化为贸易商
if MemberUserInfo.Type_Id == 0 { if MemberUserInfo.Type_Id == 0 {
MemberUserInfo.Type_Id = 5 MemberUserInfo.Type_Id = 5
...@@ -143,9 +203,12 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{ ...@@ -143,9 +203,12 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
break break
} }
if MemberUserInfo.Sale_Id == 0 {
SetTagSale(ptag,&MemberUserInfo) SetTagSale(ptag,&MemberUserInfo)
} }
}
if adtag != "" { if adtag != "" {
adtag = strings.Split(adtag,",")[0] adtag = strings.Split(adtag,",")[0]
MemberUserInfo.Adtag = adtag MemberUserInfo.Adtag = adtag
...@@ -167,9 +230,12 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{ ...@@ -167,9 +230,12 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
MemberUserInfo.Channel_source = 9//如果是以上adtag展会用户 MemberUserInfo.Channel_source = 9//如果是以上adtag展会用户
} }
if MemberUserInfo.Sale_Id == 0 {
SetTagSale(adtag,&MemberUserInfo) SetTagSale(adtag,&MemberUserInfo)
} }
}
if MemberUserInfo.User_Type != 0 { if MemberUserInfo.User_Type != 0 {
switch (MemberUserInfo.User_Type) { switch (MemberUserInfo.User_Type) {
case 1: case 1:
...@@ -227,7 +293,7 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{ ...@@ -227,7 +293,7 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
//判断是否下单 //判断是否下单
var orderId int var orderId int
err = dao.GetLiexinDb().QueryRowx("select order_id from lie_order where user_id = ?",MemberUserInfo.User_Id).Scan(orderId); dao.GetLiexinOrderDb().QueryRowx("select order_id from lie_order where user_id = ?",MemberUserInfo.User_Id).Scan(orderId)
if orderId != 0 { if orderId != 0 {
MemberUserInfo.No_Create_Order = 2 MemberUserInfo.No_Create_Order = 2
}else{ }else{
......
...@@ -10,4 +10,5 @@ type InvoiceComUser struct { ...@@ -10,4 +10,5 @@ type InvoiceComUser struct {
Sale_Type int `json:"sale_type" db:"sale_type"` Sale_Type int `json:"sale_type" db:"sale_type"`
Create_Time int `json:"create_time" db:"create_time"` Create_Time int `json:"create_time" db:"create_time"`
Update_Time int `json:"update_time" db:"update_time"` Update_Time int `json:"update_time" db:"update_time"`
Invite_Code string `json:"invite_code" db:"invite_code"`
} }
...@@ -10,6 +10,7 @@ type MemberAddUserData struct { ...@@ -10,6 +10,7 @@ type MemberAddUserData struct {
Create_Device int `json:"create_device"` Create_Device int `json:"create_device"`
Create_Time int `json:"create_time"` Create_Time int `json:"create_time"`
Channel_type int `json:"channel_type"` Channel_type int `json:"channel_type"`
Invite_Code string `json:"invite_code"`
Com_Id int `json:"com_id"` Com_Id int `json:"com_id"`
Type_Id int `json:"type_id"` Type_Id int `json:"type_id"`
Com_Name string `json:"ComName"` Com_Name string `json:"ComName"`
......
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