autoTask.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jybase/mongodb"
  4. "database/sql"
  5. "fmt"
  6. "github.com/gogf/gf/v2/util/gconv"
  7. "log"
  8. "time"
  9. "app.yhyue.com/moapp/jybase/common"
  10. "app.yhyue.com/moapp/jybase/date"
  11. )
  12. func autoTask() {
  13. log.Println("超时未跟进定时任务开始")
  14. t := time.Now()
  15. nowTime := time.Now().Format(date.Date_Full_Layout)
  16. statusMap := map[string]int{
  17. "07": 2, //待签署客户
  18. "06": 2, //高意向客户
  19. "05": 3, //意向客户
  20. "04": 7, //潜在客户
  21. }
  22. //判断节假日
  23. for status, statusInt := range statusMap {
  24. count, counts := 0, 0
  25. for {
  26. count++
  27. currentTime := t.AddDate(0, 0, -count)
  28. if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
  29. isok := false
  30. for k, v := range DateMap {
  31. if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
  32. isok = true
  33. }
  34. }
  35. if isok {
  36. counts++
  37. }
  38. } else {
  39. isok := true
  40. for k, v := range DateMap {
  41. if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
  42. isok = false
  43. }
  44. }
  45. if isok {
  46. counts++
  47. }
  48. }
  49. if counts >= statusInt {
  50. break
  51. }
  52. }
  53. statusMap[status] = count
  54. }
  55. log.Println(statusMap)
  56. for trailstatus := range map[string]string{
  57. "07": "", //待签署客户
  58. "06": "", //高意向客户
  59. "05": "", //意向客户
  60. "04": "", //潜在客户
  61. } {
  62. sql := `SELECT id,position_id,seatNumber,out_task_status FROM dwd_f_crm_clue_info
  63. WHERE trailstatus = ?`
  64. argsSelect := []interface{}{trailstatus}
  65. intime := ""
  66. sql += " AND comeintime <?"
  67. // nt := nexttime.(time.Time)
  68. nt := t.AddDate(0, 0, -statusMap[trailstatus])
  69. intime = nt.Format(date.Date_Full_Layout)
  70. argsSelect = append(argsSelect, intime)
  71. //
  72. TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
  73. for _, v := range *l {
  74. clueId := common.Int64All(v["id"])
  75. position_id := common.Int64All(v["position_id"])
  76. out_task_status := common.IntAll(v["out_task_status"])
  77. args2 := []interface{}{clueId}
  78. //获取跟进内容
  79. // sql1 := `select COUNT(1) FROM dwd_f_crm_trail_content WHERE clue_id =?;`
  80. sql2 := `SELECT COUNT(1) FROM dwd_f_crm_trail_content WHERE clue_id = ? and position_id = ?`
  81. if intime != "" {
  82. sql2 += ` and createtime > ?`
  83. args2 = append(args2, position_id)
  84. args2 = append(args2, intime)
  85. }
  86. //保留未跟进线索
  87. // if c1, c2 := TiDb.CountBySql(sql1, clueId), TiDb.CountBySql(sql2, args2...); (c1 != 0 && c2 > 0) || out_task_status == 1 {
  88. // log.Println("不满足线索过滤", clueId)
  89. // continue
  90. // }
  91. log.Println("intime ", clueId, intime, sql2)
  92. if c2 := TiDb.CountBySql(sql2, args2...); c2 > 0 || out_task_status == 1 {
  93. log.Println("不满足线索过滤", clueId)
  94. continue
  95. }
  96. if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
  97. "is_task": 1,
  98. "task_time": nowTime,
  99. "tasktime": time.Now().Format(date.Date_Short_Layout) + " 10:00:00",
  100. "taskstatus": 0,
  101. "tasksource": "超时未跟进自动加车",
  102. }) {
  103. AddChangeRecord(nil, clueId, position_id, "", "加入任务车", "超时未跟进自动加车", "", nowTime, "", -1)
  104. }
  105. }
  106. return true
  107. }, sql, argsSelect...)
  108. }
  109. log.Println("超时未跟进定时任务结束")
  110. }
  111. func autoTasks() {
  112. log.Println("按照跟进时间提前一天进入任务车定时任务开始")
  113. nowTime2 := time.Now().Format(date.Date_Full_Layout)
  114. nextTime := time.Now().AddDate(0, 0, 1).Format(date.Date_Full_Layout)
  115. TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
  116. for _, v := range *l {
  117. clueId := common.Int64All(v["id"])
  118. position_id := common.Int64All(v["position_id"])
  119. out_task_status := common.IntAll(v["out_task_status"])
  120. if position_id > 0 {
  121. if out_task_status != 1 && position_id > 0 {
  122. if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
  123. "is_task": 1,
  124. "task_time": nowTime2,
  125. "tasktime": nowTime2,
  126. "taskstatus": 0,
  127. "tasksource": "即将到达下次跟进时间",
  128. }) {
  129. AddChangeRecord(nil, clueId, position_id, "", "加入任务车", "即将到达下次跟进时间", "", nowTime2, "", -1)
  130. }
  131. }
  132. }
  133. }
  134. return true
  135. }, `SELECT a.id,a.position_id,a.seatNumber,a.out_task_status FROM dwd_f_crm_clue_info a
  136. LEFT JOIN dwd_f_crm_trail_content c ON c.clue_id=a.id
  137. WHERE c.next_time >= "`+nowTime2+`" and c.next_time <= "`+nextTime+`"`)
  138. log.Println("按照跟进时间提前一天进入任务车定时任务结束")
  139. }
  140. // 所有人达上限退公海处理
  141. func UpperLimitAutoExitSea(upperLimit int64) {
  142. countData := TiDb.SelectBySql(`SELECT
  143. COUNT(b.ID) AS count ,a.position_id
  144. FROM
  145. dwd_f_crm_clue_info b
  146. right JOIN
  147. ( select position_id from dwd_f_crm_personnel_management where assign_type = 1
  148. AND resign = 0 ) a on a.position_id=b.position_id and b.is_transfer != 1
  149. GROUP BY
  150. a.position_id HAVING count<?`, upperLimit)
  151. if countData == nil || len(*countData) > 0 {
  152. return
  153. }
  154. log.Println("所有人达上限退公海处理任务开始")
  155. data := TiDb.SelectBySql(`select * from dwd_f_crm_clue_info where (trailstatus = "04" or trailstatus = "03" or trailstatus = "01" ) and (is_assign = 1)`)
  156. if data != nil && len(*data) > 0 {
  157. fool := false
  158. for _, v := range *data {
  159. trailstatus := gconv.String(v["trailstatus"])
  160. //坐席信息查询
  161. clueId := common.Int64All(v["id"])
  162. createtime := gconv.String(v["comeintime"])
  163. positionId := common.Int64All(v["position_id"])
  164. seatNumber := common.ObjToString(v["seatNumber"])
  165. if trailstatus == "01" {
  166. //该线索最近一次分配给该电销人员后存在通话记录
  167. uid := gconv.String(v["uid"])
  168. if createtime == "" {
  169. continue
  170. }
  171. if !PhoneState(uid, seatNumber, createtime) {
  172. continue
  173. }
  174. }
  175. //退私海处理
  176. nowTime := time.Now().Format(date.Date_Full_Layout)
  177. positionMap := map[int64]interface{}{}
  178. if TiDb.ExecTx("退出线索", func(tx *sql.Tx) bool {
  179. positionMap[positionId] = true
  180. recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign=0,position_id=null,seatNumber=null,updatetime = ?,comeinsource_open=null,level_open=null,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null WHERE id = ?`, nowTime, clueId) //,start_trail_time=null,content=null
  181. recordId2 := AddChangeRecord(tx, clueId, positionId, "", "退回公海", "所有人员私海已达上限", "", nowTime, "", -1)
  182. recordId1 := AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", "/", GetPositionName(seatNumber), nowTime, "", -1)
  183. return recordId > -1 && recordId1 > -1 && recordId2 > -1
  184. }) {
  185. //发送消息,找wjh
  186. fool = true
  187. log.Println("达上限自动退出线索成功")
  188. } else {
  189. log.Println("达上限自动退出线索失败")
  190. }
  191. }
  192. //释放邮件
  193. //发送信息
  194. if fool {
  195. AutoReleaseNots()
  196. } else {
  197. CantBeAssignedNots()
  198. }
  199. }
  200. }
  201. func autoExitSea() {
  202. log.Println("自动退海任务开始")
  203. data := TiDb.SelectBySql(`select * from dwd_f_crm_clue_info where trailstatus = "02" and (is_assign = 1 or is_assign = 0)`)
  204. if data != nil && len(*data) > 0 {
  205. for _, v := range *data {
  206. clueId := common.Int64All(v["id"])
  207. positionId := common.Int64All(v["position_id"])
  208. seatNumber := common.ObjToString(v["seatNumber"])
  209. nowTime := time.Now().Format(date.Date_Full_Layout)
  210. // is_assign := common.IntAll(v["is_assign"])
  211. if TiDb.ExecTx("退出线索", func(tx *sql.Tx) bool {
  212. recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign=-1,position_id=null,seatNumber=null,updatetime = ?,comeinsource_open=null,level_open=null,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null WHERE id = ?`, nowTime, clueId) //,start_trail_time=null,content=null
  213. // ok1 := true
  214. // if is_assign == 1 {
  215. // ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{"clue_id": clueId})
  216. // } else if is_assign == 0 {
  217. // ok1 = TiDb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
  218. // }
  219. recordId1 := AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", GetPositionName(seatNumber), "/", nowTime, "", -1)
  220. recordId2 := AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "流失", "空号停机", nowTime, "", -1)
  221. recordId3 := AddChangeRecord(tx, clueId, positionId, "", "退出任务车", "空号停机自动从线索池删除", "", nowTime, "", -1)
  222. recordId4 := AddChangeRecord(tx, clueId, positionId, "trailstatus", "退出公海", "空号停机自动从线索池删除", "", nowTime, "", -1)
  223. return recordId > -1 && recordId1 > -1 && recordId2 > -1 && recordId3 > -1 && recordId4 > -1
  224. }) {
  225. log.Println("自动退出线索成功")
  226. } else {
  227. log.Println("自动退出线索失败")
  228. }
  229. }
  230. }
  231. datas := TiDb.SelectBySql("select * from dwd_f_crm_clue_info where (trailstatus='09' or trailstatus='00') and is_assign=1")
  232. if datas != nil && len(*datas) > 0 {
  233. for _, v := range *datas {
  234. trailstatus := gconv.String(v["trailstatus"])
  235. clueId := common.Int64All(v["id"])
  236. positionId := common.Int64All(v["position_id"])
  237. seatNumber := common.ObjToString(v["seatNumber"])
  238. nowTime := time.Now().Format(date.Date_Full_Layout)
  239. // is_assign := common.IntAll(v["is_assign"])
  240. if TiDb.ExecTx("自动退海", func(tx *sql.Tx) bool {
  241. recordId := TiDb.UpdateOrDeleteBySqlByTx(tx, `UPDATE dwd_f_crm_clue_info SET is_assign=0,position_id=null,seatNumber=null,updatetime = ?,comeintime_open = ?,comeinsource_open=?,level_open=4,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null WHERE id = ?`, nowTime, nowTime, common.If(trailstatus == "00", 8, 11), clueId) //,content=null,start_trail_time=null
  242. recordId1 := AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", "/", GetPositionName(seatNumber), nowTime, "", -1)
  243. recordId2 := AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "流失", gconv.String(common.If(trailstatus == "00", "无意向客户", "拒绝客户")), nowTime, "", -1)
  244. recordId3 := AddChangeRecord(tx, clueId, positionId, "", "退出任务车", gconv.String(common.If(trailstatus == "00", "无意向客户自动退回公海", "拒绝客户自动退回公海")), "", nowTime, "", -1)
  245. recordId4 := AddChangeRecord(tx, clueId, positionId, "", "退回公海", gconv.String(common.If(trailstatus == "00", "无意向客户自动退回公海", "拒绝客户自动退回公海")), "", nowTime, "", -1)
  246. return recordId > -1 && recordId1 > -1 && recordId2 > -1 && recordId3 > -1 && recordId4 > -1
  247. }) {
  248. log.Println("自动退出私海成功")
  249. } else {
  250. log.Println("自动退出私海失败")
  251. }
  252. }
  253. }
  254. log.Println("自动退海任务结束")
  255. }
  256. func GetPositionName(seatNumber string) string {
  257. data := TiDb.SelectBySql(`select name from dwd_f_crm_personnel_management where resign = 0 and seat_number = ? limit 1`, seatNumber)
  258. if data != nil && len(*data) > 0 {
  259. return common.ObjToString((*data)[0]["name"])
  260. }
  261. return ""
  262. }
  263. func Thaw() {
  264. //3个工作日查询
  265. k := db.ThawDay
  266. nowTime := time.Now()
  267. for {
  268. if k == 0 {
  269. break
  270. }
  271. nowTime = nowTime.AddDate(0, 0, -1)
  272. if !IsBreak(nowTime) {
  273. continue
  274. }
  275. k--
  276. }
  277. nameMap := map[int64]string{}
  278. nameList := TiDb.SelectBySql("select name,position_id from dwd_f_crm_personnel_management")
  279. if nameList != nil && len(*nameList) > 0 {
  280. for _, v := range *nameList {
  281. nameMap[gconv.Int64(v["position_id"])] = gconv.String(v["name"])
  282. }
  283. }
  284. //查询
  285. layout := "2006-01-02 15:04:05"
  286. //三天以后退公海处理
  287. TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
  288. for _, v := range *l {
  289. clueId := gconv.Int64(v["id"])
  290. positionId := gconv.Int64(v["position_id"])
  291. freezeInt64 := int64(0)
  292. freezeStr := gconv.String(v["FREEZE_TIME"])
  293. if freezeStr != "" {
  294. t, _ := time.ParseInLocation(layout, freezeStr, time.Local)
  295. freezeInt64 = t.Unix()
  296. }
  297. if freezeInt64 < nowTime.Unix() {
  298. nowTime := time.Now().Format(date.Date_Full_Layout)
  299. //超三天处理
  300. //分配状态改改
  301. if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
  302. "is_assign": 0,
  303. "position_id": 0,
  304. "seatNumber": nil,
  305. }) {
  306. AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", "/", nameMap[positionId], nowTime, "", -1)
  307. }
  308. AddChangeRecord(nil, clueId, positionId, "position_id", "线索解冻", "自动退回公海", "", nowTime, "", -1)
  309. } else {
  310. if !FindUpperLimit(gconv.String(positionId), "", false) {
  311. nowTime := time.Now().Format(date.Date_Full_Layout)
  312. if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
  313. "is_assign": 1,
  314. }) {
  315. AddChangeRecord(nil, clueId, positionId, "position_id", "所属人变更", nameMap[positionId], "/", nowTime, "", -1)
  316. }
  317. AddChangeRecord(nil, clueId, positionId, "position_id", "线索解冻", "销售人员私海线索已释放", "", nowTime, "", -1)
  318. }
  319. }
  320. }
  321. return true
  322. }, `select id,position_id,FREEZE_TIME from dwd_f_crm_clue_info where is_assign = -3 `)
  323. }
  324. func IsBreak(currentTime time.Time) bool {
  325. if currentTime.Weekday() == time.Sunday {
  326. isok := false
  327. for k, v := range DateMap {
  328. if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
  329. isok = true
  330. }
  331. }
  332. return isok
  333. } else {
  334. isok := true
  335. for k, v := range DateMap {
  336. if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
  337. isok = false
  338. }
  339. }
  340. return isok
  341. }
  342. }
  343. func PhoneState(uid, seatNumber, createtime string) bool {
  344. phoneData := TiDb.SelectBySql("select DISTINCT phone from dwd_f_userbase_contacts where baseinfo_id= ?", uid)
  345. if phoneData == nil || len(*phoneData) == 0 {
  346. //数据不对跳过去
  347. return false
  348. }
  349. for _, v1 := range *phoneData {
  350. phone := gconv.String(v1["phone"])
  351. callData := TiDb.SelectBySql("select DISTINCT Exten from Call_Accounting.voice_record where CalledNo=? and createtime>=? ORDER BY createTime", phone, createtime)
  352. if callData == nil || len(*callData) == 0 {
  353. //手机号没有通话记录
  354. continue
  355. }
  356. for _, v2 := range *callData {
  357. exten := gconv.String(v2["Exten"])
  358. if seatNumber == exten {
  359. return true
  360. }
  361. }
  362. }
  363. return false
  364. }
  365. func LockHandle() {
  366. time.Now()
  367. log.Println("线索锁定定时任务开始")
  368. timeData := -1 * (db.CornExp8 + 5)
  369. timeDate := time.Now().Add(time.Duration(timeData) * time.Second)
  370. timeStr := timeDate.Format("2006-01-02 15:04:05")
  371. a := 1
  372. fool := false
  373. page := 1
  374. pageSize := 1000
  375. for !fool {
  376. sqlStr := fmt.Sprintf(`select id,cluename,position_id,updatetime,company_nature,company_verification,lock_status from dwd_f_crm_clue_info where updatetime>="%s" order by updatetime limit %d OFFSET %d`, timeStr, pageSize, (page-1)*pageSize)
  377. data := TiDb.SelectBySql(sqlStr)
  378. if len(*data) == 0 {
  379. fool = true
  380. break
  381. }
  382. for _, v := range *data {
  383. log.Println(a, gconv.String(v["updatetime"]))
  384. a++
  385. clue_id := gconv.Int64(v["id"])
  386. cluename := gconv.String(v["cluename"])
  387. position_id := gconv.String(v["position_id"])
  388. company_nature := gconv.Int64(v["company_nature"])
  389. company_verification := gconv.Int64(v["company_verification"])
  390. lock_status := gconv.Int64(v["lock_status"])
  391. //非集团在工商需要查询其他数据是否分配的有人
  392. if company_nature == 0 && company_verification == 1 {
  393. status4Data := TiDb.SelectBySql(fmt.Sprintf(`select GROUP_CONCAT(DISTINCT position_id) as position_id from dwd_f_crm_clue_info where cluename="%s" and position_id>0 `, cluename))
  394. if len(*status4Data) > 0 || status4Data != nil {
  395. position_id = gconv.String((*status4Data)[0]["position_id"])
  396. }
  397. }
  398. if company_nature == 1 && lock_status != 3 {
  399. //无需锁定处理
  400. if lock_status != 3 {
  401. go UpdateData(3, map[string]interface{}{
  402. "id": clue_id,
  403. }, 3, "")
  404. }
  405. } else if company_nature == 0 && company_verification == 1 {
  406. //已锁定处理
  407. if position_id != "" {
  408. go UpdateData(1, map[string]interface{}{
  409. "cluename": cluename,
  410. "company_verification": 1,
  411. "company_nature": 0,
  412. }, 1, position_id)
  413. } else {
  414. go UpdateData(2, map[string]interface{}{
  415. "cluename": cluename,
  416. "company_verification": 1,
  417. "company_nature": 0,
  418. }, 2, "")
  419. }
  420. } else {
  421. //未锁定处理
  422. if lock_status != 2 {
  423. go UpdateData(2, map[string]interface{}{
  424. "id": clue_id,
  425. }, 2, "")
  426. }
  427. }
  428. }
  429. page++
  430. }
  431. log.Println("线索锁定定时任务结束")
  432. }
  433. func UpdateData(lockStatus int64, query map[string]interface{}, status int, positionId string) {
  434. TiDb.Update("dwd_f_crm_clue_info", query, map[string]interface{}{
  435. "lock_status": lockStatus,
  436. "lock_position_id": positionId,
  437. })
  438. }
  439. // 大会员子账号不作为电销线索
  440. func ClueToDxTask() {
  441. //把所-5有的用户刷至公海
  442. ok := TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"is_assign": -5}, map[string]interface{}{"is_assign": 0, "seatNumber": nil, "position_id": 0})
  443. if !ok {
  444. log.Println("更新dwd_f_crm_clue_info处理子账号出错")
  445. return
  446. }
  447. //查询在客成的用户
  448. res := TiDb.Query("SELECT clue_id,ent_id FROM `dwd_f_csm_customer_info` WHERE is_transfer = 0")
  449. if res == nil || len(*res) <= 0 {
  450. log.Println("查dwd_f_csm_customer_info 客成用户异常")
  451. return
  452. }
  453. log.Println("客成用户量:", len(*res))
  454. for _, val := range *res {
  455. //log.Println("ent_id", val["ent_id"])
  456. clue_id := gconv.Int(val["clue_id"])
  457. childIds := []string{}
  458. if gconv.String(val["ent_id"]) == "" || gconv.String(val["ent_id"]) == "0" {
  459. continue
  460. }
  461. if mongodb.IsObjectIdHex(gconv.String(val["ent_id"])) { //mongodb 个人身份大会员
  462. //查询个人大会员下的子账号
  463. query := map[string]interface{}{"s_member_mainid": gconv.String(val["ent_id"])}
  464. childAccount, _ := Mgo.Find("user", query, "", `"_id":1`, false, -1, -1)
  465. if childAccount != nil && len(*childAccount) > 0 {
  466. log.Println("个人大会员子账号数量:", gconv.String(val["ent_id"]), len(*childAccount))
  467. for _, v := range *childAccount {
  468. childIds = append(childIds, mongodb.BsonIdToSId(v["_id"]))
  469. }
  470. }
  471. } else { //企业大会员
  472. //根据企业id查询企业下的员工
  473. if gconv.Int(val["ent_id"]) == 0 {
  474. continue
  475. }
  476. data := TiDb.Query("SELECT userid,uid FROM dwd_f_userbase_id_mapping WHERE ent_id = ?", gconv.Int(val["ent_id"]))
  477. if data != nil && len(*data) > 0 {
  478. log.Println("企业下员工数:", gconv.Int(val["ent_id"]), len(*data))
  479. for _, vv := range *data {
  480. childIds = append(childIds, gconv.String(vv["userid"]))
  481. }
  482. }
  483. }
  484. //更新线索信息
  485. if len(childIds) > 0 {
  486. ids := ""
  487. for k, vv := range childIds {
  488. if k == 0 {
  489. ids += fmt.Sprintf("'%s'", vv)
  490. } else {
  491. ids += fmt.Sprintf(",'%s'", vv)
  492. }
  493. }
  494. //log.Println("线索ids:", ids)
  495. sql := fmt.Sprintf("UPDATE dwd_f_crm_clue_info SET is_assign = -5 WHERE id != %d and userid IN (%s)", clue_id, ids)
  496. log.Println("sql:", sql)
  497. up := TiDb.UpdateOrDeleteBySql(sql)
  498. if up < 0 {
  499. log.Println("更新线索为-5出错", childIds)
  500. return
  501. }
  502. }
  503. }
  504. log.Println("定时任务完成")
  505. }