clue.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package service
  2. import (
  3. "math"
  4. "time"
  5. common "app.yhyue.com/moapp/jybase/common"
  6. . "bp.jydev.jianyu360.cn/BaseService/biService/entity"
  7. "bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
  8. )
  9. func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
  10. count1 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 1})
  11. count2 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 2})
  12. count3 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 3})
  13. counts1 := int64(math.Floor(float64(this.Count) / float64(10) * 2))
  14. counts2 := int64(math.Floor(float64(this.Count) / float64(10) * 4))
  15. counts3 := this.Count - counts1 - counts2
  16. if counts1 > count1 {
  17. counts2 += counts1 - count1
  18. }
  19. if counts2 > count2 {
  20. counts3 += counts2 - count2
  21. }
  22. DrawClues(this.PositionId, counts1, counts2, counts3)
  23. return &biservice.AddProjectResp{
  24. ErrorCode: 0,
  25. Data: &biservice.AddProject{
  26. Status: 1,
  27. },
  28. }
  29. }
  30. func DrawClues(positionId, count1, count2, count3 int64) {
  31. data1 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 1}, "", "", 0, count1)
  32. data2 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 2}, "", "", 0, count2)
  33. data3 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 3}, "", "", 0, count3)
  34. if data1 != nil && len(*data1) > 0 {
  35. for _, v := range *data1 {
  36. //update postionid and update record
  37. clueId := common.Int64All(v["clue_id"])
  38. nowTime := time.Now().Format("2006-01-02 15:04:05")
  39. seatNumber, name := getSeatNumber(positionId)
  40. JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
  41. JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
  42. JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clue_id})
  43. JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
  44. "clue_id": clueId,
  45. "seatNumber": seatNumber,
  46. "position_id": positionId,
  47. "comeintime": nowTime,
  48. "comeinsource": 3,
  49. "is_task": 0,
  50. })
  51. JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  52. "clue_id": clueId,
  53. "position_id": positionId,
  54. "change_field": "position_id",
  55. "change_type": "所属人变更",
  56. "old_value": "/",
  57. "new_value": name,
  58. "createtime": nowTime,
  59. "BCPCID": common.GetRandom(32),
  60. "operator_id": positionId,
  61. })
  62. })
  63. }
  64. }
  65. if data2 != nil && len(*data2) > 0 {
  66. for _, v := range *data2 {
  67. JyBiTidb.ExecTx("领取线索等", func(tx *sql.Tx) bool {
  68. clueId := common.Int64All(v["clue_id"])
  69. nowTime := time.Now().Format("2006-01-02 15:04:05")
  70. seatNumber, name := getSeatNumber(positionId)
  71. JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
  72. JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
  73. JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clue_id})
  74. JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
  75. "clue_id": clueId,
  76. "seatNumber": seatNumber,
  77. "position_id": positionId,
  78. "comeintime": nowTime,
  79. "comeinsource": 3,
  80. "is_task": 0,
  81. })
  82. JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  83. "clue_id": clueId,
  84. "position_id": positionId,
  85. "change_field": "position_id",
  86. "change_type": "所属人变更",
  87. "old_value": "/",
  88. "new_value": name,
  89. "createtime": nowTime,
  90. "BCPCID": common.GetRandom(32),
  91. "operator_id": positionId,
  92. })
  93. })
  94. })
  95. }
  96. }
  97. if data3 != nil && len(*data3) > 0 {
  98. for _, v := range *data3 {
  99. JyBiTidb.ExecTx("领取线索等", func(tx *sql.Tx) bool {
  100. clueId := common.Int64All(v["clue_id"])
  101. nowTime := time.Now().Format("2006-01-02 15:04:05")
  102. seatNumber, name := getSeatNumber(positionId)
  103. JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
  104. JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
  105. JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clue_id})
  106. JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
  107. "clue_id": clueId,
  108. "seatNumber": seatNumber,
  109. "position_id": positionId,
  110. "comeintime": nowTime,
  111. "comeinsource": 3,
  112. "is_task": 0,
  113. })
  114. JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  115. "clue_id": clueId,
  116. "position_id": positionId,
  117. "change_field": "position_id",
  118. "change_type": "所属人变更",
  119. "old_value": "/",
  120. "new_value": name,
  121. "createtime": nowTime,
  122. "BCPCID": common.GetRandom(32),
  123. "operator_id": positionId,
  124. })
  125. })
  126. })
  127. }
  128. }
  129. }
  130. func getSeatNumber(positionId int64) (seatNumber, name string) {
  131. positionData := JyTidb.FindOne("base_position", map[string]interface{}{"id": positionId}, "", "")
  132. if positionData != nil && len(*positionData) > 0 {
  133. userId := common.Int64All((*positionData)["user_id"])
  134. if userId > 0 {
  135. userData := Mgo.FindOne("user", map[string]interface{}{"base_user_id": userId})
  136. if userData != nil && len(*userData) > 0 {
  137. s_phone := common.ObjToString((*userData)["s_phone"])
  138. if s_phone == "" {
  139. s_phone = common.ObjToString((*userData)["s_m_phone"])
  140. }
  141. saleData := JyBiTidb.FindOne("jy_salesperson_info", map[string]interface{}{"phone": s_phone}, "", "")
  142. if saleData != nil && len(*saleData) > 0 {
  143. seatNumber = common.ObjToString((*saleData)["seatNumber"])
  144. name = common.ObjToString((*saleData)["name"])
  145. }
  146. }
  147. }
  148. }
  149. return
  150. }