|
@@ -103,7 +103,7 @@ func (this *CustomerOperation) CList(searchCode string, isCliam int64, entUserId
|
|
"$regex": searchCode,
|
|
"$regex": searchCode,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- customerList := Mysql.SelectBySql("SELECT ec.name,euu.customer_id FROM entniche_user_customer euu LEFT JOIN entniche_customer ec ON ec.id = euu.customer_id WHERE user_id = ? AND (source_type =1 or source_type =4) ", entUserId)
|
|
|
|
|
|
+ customerList := Mysql.SelectBySql("SELECT ec.name,euu.customer_id FROM entniche_user_customer euu LEFT JOIN entniche_customer ec ON ec.id = euu.customer_id WHERE user_id = ? AND ec.state=1 and (source_type =1 or source_type =4) ", entUserId)
|
|
customerMap := map[string]interface{}{}
|
|
customerMap := map[string]interface{}{}
|
|
for _, value := range *customerList {
|
|
for _, value := range *customerList {
|
|
customerMap[qu.ObjToString(value["name"])] = value["customer_id"]
|
|
customerMap[qu.ObjToString(value["name"])] = value["customer_id"]
|
|
@@ -192,12 +192,11 @@ func (this *CustomerOperation) CheckPower(mold int, entUserId int, name string,
|
|
msg = fmt.Sprintf("您的关注客户数量已经超过%d,请取消关注部分后再操作。", config.Config.FollowCustomer.CustomerNumb)
|
|
msg = fmt.Sprintf("您的关注客户数量已经超过%d,请取消关注部分后再操作。", config.Config.FollowCustomer.CustomerNumb)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
//查询
|
|
//查询
|
|
//判断该企业是否存在
|
|
//判断该企业是否存在
|
|
res := Mysql.FindOne(Entniche_customer, M{"dept_id": dept_id, "ent_id": ent_id, "name": name}, "id,dept_id", "")
|
|
res := Mysql.FindOne(Entniche_customer, M{"dept_id": dept_id, "ent_id": ent_id, "name": name}, "id,dept_id", "")
|
|
//查询企业客户数
|
|
//查询企业客户数
|
|
- data := Mysql.SelectBySql("SELECT count( a.count ) as count FROM (SELECT COUNT( id ) as count FROM entniche_customer WHERE ent_id = ? GROUP BY name ) a", ent_id)
|
|
|
|
|
|
+ data := Mysql.SelectBySql("SELECT count( a.count ) as count FROM (SELECT COUNT( id ) as count FROM entniche_customer WHERE b.state=1 and ent_id = ? GROUP BY name ) a", ent_id)
|
|
if len((*data)) > 0 {
|
|
if len((*data)) > 0 {
|
|
enterpriseNumb := qutil.Int64All((*data)[0]["count"])
|
|
enterpriseNumb := qutil.Int64All((*data)[0]["count"])
|
|
//判断企业客户数
|
|
//判断企业客户数
|
|
@@ -210,7 +209,7 @@ func (this *CustomerOperation) CheckPower(mold int, entUserId int, name string,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//判断自己是否有此客户
|
|
//判断自己是否有此客户
|
|
- userData := Mysql.SelectBySql("select count(ec.id) as count from entniche_customer ec INNER join entniche_user_customer euc on ec.id=euc.customer_id where ec.`name`=? and euc.user_id=?", name, entUserId)
|
|
|
|
|
|
+ userData := Mysql.SelectBySql("select count(ec.id) as count from entniche_customer ec INNER join entniche_user_customer euc on ec.id=euc.customer_id where ec.state=1 and ec.`name`=? and euc.user_id=?", name, entUserId)
|
|
if len((*userData)) > 0 {
|
|
if len((*userData)) > 0 {
|
|
prsonalNumb := qutil.Int64All((*userData)[0]["count"])
|
|
prsonalNumb := qutil.Int64All((*userData)[0]["count"])
|
|
//判断企业客户数
|
|
//判断企业客户数
|
|
@@ -292,7 +291,7 @@ func (this *CustomerOperation) Claimoperation(data *CurrentUser, ent_id, entUser
|
|
//认领处理
|
|
//认领处理
|
|
//true 取消认领;默认 false 认领
|
|
//true 取消认领;默认 false 认领
|
|
if this.D {
|
|
if this.D {
|
|
- dataList := Mysql.SelectBySql("select ec.* from entniche_customer ec,entniche_user_customer euc where ec.name =? and ec.ent_id=? and ec.id =euc.customer_id and euc.user_id=?", name, ent_id, entUserId)
|
|
|
|
|
|
+ dataList := Mysql.SelectBySql("select ec.* from entniche_customer ec,entniche_user_customer euc where ec.name =? and ec.ent_id=? and ec.id =euc.customer_id and euc.user_id=? and ec.state=1", name, ent_id, entUserId)
|
|
//true 取消认领
|
|
//true 取消认领
|
|
if len(*dataList) > 0 {
|
|
if len(*dataList) > 0 {
|
|
for _, value := range *dataList {
|
|
for _, value := range *dataList {
|
|
@@ -302,33 +301,18 @@ func (this *CustomerOperation) Claimoperation(data *CurrentUser, ent_id, entUser
|
|
//判断客户和别的数据数据是否还有关系
|
|
//判断客户和别的数据数据是否还有关系
|
|
dataList = Mysql.SelectBySql("select euc.* from entniche_user_customer euc where euc.customer_id=? ", customer_id)
|
|
dataList = Mysql.SelectBySql("select euc.* from entniche_user_customer euc where euc.customer_id=? ", customer_id)
|
|
if len((*dataList)) == 0 {
|
|
if len((*dataList)) == 0 {
|
|
- userCustomerQueryMap := map[string]interface{}{
|
|
|
|
- "id": customer_id,
|
|
|
|
|
|
+ updateOk := Mysql.Update(Entniche_customer, M{"id": customer_id}, map[string]interface{}{
|
|
|
|
+ "state": 0,
|
|
|
|
+ })
|
|
|
|
+ if !updateOk {
|
|
|
|
+ log.Printf("客户%s 更新出错\n", customer_id)
|
|
|
|
+ return false
|
|
}
|
|
}
|
|
- B = Mysql.Delete(Entniche_customer, userCustomerQueryMap)
|
|
|
|
}
|
|
}
|
|
- /* //生命周期添加
|
|
|
|
- cycleMap := map[string]interface{}{
|
|
|
|
- "cancel_claim_time": time_now,
|
|
|
|
- "type": 4,
|
|
|
|
- "cancel_claim_person": name,
|
|
|
|
- "customer_id": customer_id,
|
|
|
|
- "reason": this.Reason,
|
|
|
|
- }
|
|
|
|
- insertOk := entniceLifeCycleAdd(cycleMap, nil)
|
|
|
|
- if !insertOk {
|
|
|
|
- log.Printf("客户%s 更新生命周期出错\n", name)
|
|
|
|
- return false
|
|
|
|
- }*/
|
|
|
|
- /* deleteMap := map[string]interface{}{
|
|
|
|
- "userid": this.UserId,
|
|
|
|
- "customer_id": customer_id,
|
|
|
|
- }*/
|
|
|
|
- //Mysql.Delete(Bdcollection_entniche, deleteMap)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- dataList := Mysql.SelectBySql("select ec.* from entniche_customer ec,entniche_user_customer euc where ec.name =? and ec.ent_id=? and ec.dept_id=? and ec.id =euc.customer_id and euc.user_id=?", name, ent_id, dept_id, entUserId)
|
|
|
|
|
|
+ dataList := Mysql.SelectBySql("select ec.* from entniche_customer ec,entniche_user_customer euc where ec.name =? and ec.ent_id=? and ec.dept_id=? and ec.id =euc.customer_id and euc.user_id=? and ec.state=1", name, ent_id, dept_id, entUserId)
|
|
// 认领
|
|
// 认领
|
|
//查询是否存在用户
|
|
//查询是否存在用户
|
|
//添加完用户之后自动分配
|
|
//添加完用户之后自动分配
|
|
@@ -385,48 +369,40 @@ func (this *CustomerOperation) Claimoperation(data *CurrentUser, ent_id, entUser
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //查看客户是否存在
|
|
ok := Mysql.ExecTx("添加客户", func(tx *sql.Tx) bool {
|
|
ok := Mysql.ExecTx("添加客户", func(tx *sql.Tx) bool {
|
|
time_now := time.Now().Format(qu.Date_Full_Layout)
|
|
time_now := time.Now().Format(qu.Date_Full_Layout)
|
|
- customer_id := Mysql.InsertByTx(tx, Entniche_customer, map[string]interface{}{
|
|
|
|
- "name": name,
|
|
|
|
- "ent_id": ent_id,
|
|
|
|
- "dept_id": data.Dept.Id,
|
|
|
|
- "editperson": data.User_name,
|
|
|
|
- "createtime": time_now,
|
|
|
|
- "timestamp": time_now,
|
|
|
|
- "area": province,
|
|
|
|
- "city": city,
|
|
|
|
- })
|
|
|
|
- if customer_id <= 0 {
|
|
|
|
- return false
|
|
|
|
|
|
+ customer_id := int64(0)
|
|
|
|
+ res := Mysql.FindOne(Entniche_customer, M{"dept_id": dept_id, "ent_id": ent_id, "name": name}, "id,dept_id,state", "")
|
|
|
|
+ if qutil.IntAll((*res)["state"]) == 0 {
|
|
|
|
+ customer_id = qutil.Int64All((*res)["id"])
|
|
|
|
+ updateOk := Mysql.UpdateByTx(tx, Entniche_customer, M{"id": customer_id}, map[string]interface{}{
|
|
|
|
+ "state": 1,
|
|
|
|
+ })
|
|
|
|
+ if !updateOk {
|
|
|
|
+ log.Printf("客户%s 更新出错\n", name)
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ customer_id = Mysql.InsertByTx(tx, Entniche_customer, map[string]interface{}{
|
|
|
|
+ "name": name,
|
|
|
|
+ "ent_id": ent_id,
|
|
|
|
+ "dept_id": data.Dept.Id,
|
|
|
|
+ "editperson": data.User_name,
|
|
|
|
+ "createtime": time_now,
|
|
|
|
+ "timestamp": time_now,
|
|
|
|
+ "area": province,
|
|
|
|
+ "city": city,
|
|
|
|
+ })
|
|
|
|
+ if customer_id <= 0 {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- //生命周期添加
|
|
|
|
- /*cycleMap := map[string]interface{}{
|
|
|
|
- "add_time": time_now,
|
|
|
|
- "type": 0,
|
|
|
|
- "add_person": data.User_name,
|
|
|
|
- "customer_id": customer_id,
|
|
|
|
- }*/
|
|
|
|
- //insertOk := entniceLifeCycleAdd(cycleMap, tx)
|
|
|
|
- /*if !insertOk {
|
|
|
|
- log.Printf("客户%s 更新生命周期出错\n", name)
|
|
|
|
- return false
|
|
|
|
- }*/
|
|
|
|
//添加完成默认分配给自己
|
|
//添加完成默认分配给自己
|
|
if Mysql.InsertByTx(tx, Entniche_user_customer, map[string]interface{}{"customer_id": customer_id, "user_id": entUserId, "type": 1, "source": 1, "source_type": 1, "timestamp": time_now}) < 0 {
|
|
if Mysql.InsertByTx(tx, Entniche_user_customer, map[string]interface{}{"customer_id": customer_id, "user_id": entUserId, "type": 1, "source": 1, "source_type": 1, "timestamp": time_now}) < 0 {
|
|
log.Printf("%s客户关联异常", name)
|
|
log.Printf("%s客户关联异常", name)
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
- /*cycleMap1 := map[string]interface{}{
|
|
|
|
- "claim_time": time_now,
|
|
|
|
- "type": 1,
|
|
|
|
- "claim_person": data.User_name,
|
|
|
|
- "customer_id": customer_id,
|
|
|
|
- }
|
|
|
|
- if !entniceLifeCycleAdd(cycleMap1, tx) {
|
|
|
|
- log.Printf("%s客户关联异常", name)
|
|
|
|
- return false
|
|
|
|
- }*/
|
|
|
|
cycleMap := map[string]interface{}{
|
|
cycleMap := map[string]interface{}{
|
|
"claim_time": time_now,
|
|
"claim_time": time_now,
|
|
"type": 1,
|
|
"type": 1,
|
|
@@ -489,7 +465,7 @@ func (this *CustomerOperation) IsCollclaim() map[string]interface{} {
|
|
res := map[string]interface{}{}
|
|
res := map[string]interface{}{}
|
|
res["iscoll"] = false
|
|
res["iscoll"] = false
|
|
for _, v := range strings.Split(this.Names, ",") {
|
|
for _, v := range strings.Split(this.Names, ",") {
|
|
- bdinfos := Mysql.SelectBySql(fmt.Sprintf("SELECT ecn.id FROM %s ecn,%s euu WHERE ecn.id = euu.customer_id AND euu.user_id =? AND ecn.`name` = ? AND (euu.source_type =1 or euu.source_type=4)", Entniche_customer, Entniche_user_customer), this.EntUserId, v)
|
|
|
|
|
|
+ bdinfos := Mysql.SelectBySql(fmt.Sprintf("SELECT ecn.id FROM %s ecn,%s euu WHERE ecn.id = euu.customer_id AND euu.user_id =? AND ecn.`name` = ? AND ecn.state=1 and (euu.source_type =1 or euu.source_type=4)", Entniche_customer, Entniche_user_customer), this.EntUserId, v)
|
|
if len((*bdinfos)) > 0 {
|
|
if len((*bdinfos)) > 0 {
|
|
nameArr = append(nameArr, v)
|
|
nameArr = append(nameArr, v)
|
|
res["iscoll"] = true
|
|
res["iscoll"] = true
|