Commit 3834dae0 by 朱继来

调整同步CRM,添加邀请码

parent 6608bf38
......@@ -149,3 +149,18 @@ func IsOrder(user_id int) bool {
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
import (
"crm-server/cmd/follow/handle"
"crm-server/configs"
"crm-server/internal/common"
"crm-server/internal/dao"
"crm-server/internal/model"
......@@ -26,7 +28,7 @@ const(
//获取会员系统的用户数据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_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_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 " +
......@@ -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 获取方式:
......@@ -71,20 +117,34 @@ func SetTagSale(tag string,memberInfo *model.MemberAddUserData){
func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
var saleId = 0
//查找交易员
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 err != nil {
service.WriteErr(err)
}
if 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.Userinfo_Sale_Id != 0{
if MemberUserInfo.Sale_Id == 0 && MemberUserInfo.Userinfo_Sale_Id != 0{
MemberUserInfo.Sale_Id = MemberUserInfo.Userinfo_Sale_Id
}
//查找交易员
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 {
service.WriteErr(err)
}
if saleId != 0 {
MemberUserInfo.Sale_Id = saleId
}
}
// 个人转化为贸易商
if MemberUserInfo.Type_Id == 0 {
......@@ -143,7 +203,10 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
break
}
SetTagSale(ptag,&MemberUserInfo)
if MemberUserInfo.Sale_Id == 0 {
SetTagSale(ptag,&MemberUserInfo)
}
}
if adtag != "" {
......@@ -167,7 +230,10 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
MemberUserInfo.Channel_source = 9//如果是以上adtag展会用户
}
SetTagSale(adtag,&MemberUserInfo)
if MemberUserInfo.Sale_Id == 0 {
SetTagSale(adtag,&MemberUserInfo)
}
}
if MemberUserInfo.User_Type != 0 {
......@@ -227,7 +293,7 @@ func HandleData(MemberUserInfo model.MemberAddUserData) model.MemberAddUserData{
//判断是否下单
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 {
MemberUserInfo.No_Create_Order = 2
}else{
......
package model
type InvoiceComUser struct {
Id int `json:"id" db:"id"`
Com_Id int `json:"com_id" db:"com_id"`
User_Id int `json:"user_id" db:"user_id"`
Sale_Id int `json:"sale_id" db:"sale_id"`
Status int `json:"status" db:"status"`
Department_Id int `json:"department_id" db:"department_id"`
Sale_Type int `json:"sale_type" db:"sale_type"`
Create_Time int `json:"create_time" db:"create_time"`
Update_Time int `json:"update_time" db:"update_time"`
Id int `json:"id" db:"id"`
Com_Id int `json:"com_id" db:"com_id"`
User_Id int `json:"user_id" db:"user_id"`
Sale_Id int `json:"sale_id" db:"sale_id"`
Status int `json:"status" db:"status"`
Department_Id int `json:"department_id" db:"department_id"`
Sale_Type int `json:"sale_type" db:"sale_type"`
Create_Time int `json:"create_time" db:"create_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 {
Create_Device int `json:"create_device"`
Create_Time int `json:"create_time"`
Channel_type int `json:"channel_type"`
Invite_Code string `json:"invite_code"`
Com_Id int `json:"com_id"`
Type_Id int `json:"type_id"`
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