123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- package service
- import (
- "math"
- "time"
- common "app.yhyue.com/moapp/jybase/common"
- . "bp.jydev.jianyu360.cn/BaseService/biService/entity"
- "bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
- )
- func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
- count1 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 1})
- count2 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 2})
- count3 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 3})
- counts1 := int64(math.Floor(float64(this.Count) / float64(10) * 2))
- counts2 := int64(math.Floor(float64(this.Count) / float64(10) * 4))
- counts3 := this.Count - counts1 - counts2
- if counts1 > count1 {
- counts2 += counts1 - count1
- }
- if counts2 > count2 {
- counts3 += counts2 - count2
- }
- DrawClues(this.PositionId, counts1, counts2, counts3)
- return &biservice.AddProjectResp{
- ErrorCode: 0,
- Data: &biservice.AddProject{
- Status: 1,
- },
- }
- }
- func DrawClues(positionId, count1, count2, count3 int64) {
- data1 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 1}, "", "", 0, count1)
- data2 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 2}, "", "", 0, count2)
- data3 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 3}, "", "", 0, count3)
- if data1 != nil && len(*data1) > 0 {
- for _, v := range *data1 {
- //update postionid and update record
- clueId := common.Int64All(v["clue_id"])
- nowTime := time.Now().Format("2006-01-02 15:04:05")
- seatNumber, name := getSeatNumber(positionId)
- JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
- JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
- JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clue_id})
- JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
- "clue_id": clueId,
- "seatNumber": seatNumber,
- "position_id": positionId,
- "comeintime": nowTime,
- "comeinsource": 3,
- "is_task": 0,
- })
- JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": "/",
- "new_value": name,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": positionId,
- })
- })
- }
- }
- if data2 != nil && len(*data2) > 0 {
- for _, v := range *data2 {
- JyBiTidb.ExecTx("领取线索等", func(tx *sql.Tx) bool {
- clueId := common.Int64All(v["clue_id"])
- nowTime := time.Now().Format("2006-01-02 15:04:05")
- seatNumber, name := getSeatNumber(positionId)
- JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
- JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
- JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clue_id})
- JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
- "clue_id": clueId,
- "seatNumber": seatNumber,
- "position_id": positionId,
- "comeintime": nowTime,
- "comeinsource": 3,
- "is_task": 0,
- })
- JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": "/",
- "new_value": name,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": positionId,
- })
- })
- })
- }
- }
- if data3 != nil && len(*data3) > 0 {
- for _, v := range *data3 {
- JyBiTidb.ExecTx("领取线索等", func(tx *sql.Tx) bool {
- clueId := common.Int64All(v["clue_id"])
- nowTime := time.Now().Format("2006-01-02 15:04:05")
- seatNumber, name := getSeatNumber(positionId)
- JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
- JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
- JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clue_id})
- JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
- "clue_id": clueId,
- "seatNumber": seatNumber,
- "position_id": positionId,
- "comeintime": nowTime,
- "comeinsource": 3,
- "is_task": 0,
- })
- JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": "/",
- "new_value": name,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": positionId,
- })
- })
- })
- }
- }
- }
- func getSeatNumber(positionId int64) (seatNumber, name string) {
- positionData := JyTidb.FindOne("base_position", map[string]interface{}{"id": positionId}, "", "")
- if positionData != nil && len(*positionData) > 0 {
- userId := common.Int64All((*positionData)["user_id"])
- if userId > 0 {
- userData := Mgo.FindOne("user", map[string]interface{}{"base_user_id": userId})
- if userData != nil && len(*userData) > 0 {
- s_phone := common.ObjToString((*userData)["s_phone"])
- if s_phone == "" {
- s_phone = common.ObjToString((*userData)["s_m_phone"])
- }
- saleData := JyBiTidb.FindOne("jy_salesperson_info", map[string]interface{}{"phone": s_phone}, "", "")
- if saleData != nil && len(*saleData) > 0 {
- seatNumber = common.ObjToString((*saleData)["seatNumber"])
- name = common.ObjToString((*saleData)["name"])
- }
- }
- }
- }
- return
- }
|