jobutil.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/gogf/gf/v2/util/gconv"
  5. "log"
  6. "strings"
  7. "time"
  8. "app.yhyue.com/moapp/jybase/common"
  9. "app.yhyue.com/moapp/jybase/date"
  10. "app.yhyue.com/moapp/jybase/mongodb"
  11. )
  12. // 未支付订单 30分钟一次
  13. func orders() {
  14. //一个小时未支付进入线索 A
  15. log.Println("未支付订单定时任务开始")
  16. lastOrderId := cfg.LastOrderId
  17. selectTimeStart := time.Unix(time.Now().Unix()-7200, 0).Format(date.Date_Full_Layout)
  18. selectTimeEnd := time.Unix(time.Now().Unix()-3600, 0).Format(date.Date_Full_Layout)
  19. sql := fmt.Sprintf(`select * from dataexport_order where create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
  20. data := Mysql.SelectBySql(sql)
  21. if data != nil && *data != nil && len(*data) > 0 {
  22. for _, v := range *data {
  23. order_status := common.IntAll(v["order_status"])
  24. is_backstage_order := common.IntAll(v["is_backstage_order"])
  25. product_type_str1 := `"大会员","VIP订阅","数据流量包","历史数据"`
  26. product_type := common.ObjToString(v["product_type"])
  27. if order_status == 0 && is_backstage_order == 0 && strings.Contains(product_type_str1, product_type) {
  28. ok1, ok2 := FormatData(v, "orders")
  29. if !ok1 {
  30. common.WriteSysConfig(&cfg)
  31. log.Println("线索卡点", "orders", v, selectTimeEnd, selectTimeStart)
  32. break
  33. } else {
  34. if !ok2 {
  35. log.Println("用户分配已达上限", "orders", v, selectTimeEnd, selectTimeStart)
  36. common.WriteSysConfig(&cfg)
  37. break
  38. }
  39. }
  40. }
  41. cfg.LastOrderId = common.IntAll(v["id"])
  42. }
  43. }
  44. common.WriteSysConfig(&cfg)
  45. log.Println("未支付订单定时任务结束")
  46. }
  47. func readClue() {
  48. log.Println("读表进线索定时任务开始")
  49. lastReadClueTime := cfg.LastReadClueTime
  50. sql := fmt.Sprintf(`select * from clue_info where updatetime > "%s" order by updatetime asc`, fmt.Sprint(lastReadClueTime))
  51. data := TiDb.SelectBySql(sql)
  52. if data != nil && *data != nil && len(*data) > 0 {
  53. for _, v := range *data {
  54. ok1, ok2 := FormatData(v, "readClue")
  55. if !ok1 {
  56. common.WriteSysConfig(&cfg)
  57. log.Println("用户分配已达上限", "readClue", v, lastReadClueTime)
  58. break
  59. } else {
  60. if !ok2 {
  61. log.Println("用户分配已达上限", "readClue", v, lastReadClueTime)
  62. common.WriteSysConfig(&cfg)
  63. break
  64. }
  65. }
  66. cfg.LastReadClueTime = common.ObjToString(v["updatetime"])
  67. }
  68. }
  69. common.WriteSysConfig(&cfg)
  70. log.Println("读表进线索定时任务结束")
  71. }
  72. // 新注册用户 5分钟一次
  73. func users() {
  74. //判断节假日
  75. runOk := getRunOk()
  76. if !runOk {
  77. log.Println("不是工作日,任务暂停")
  78. return
  79. }
  80. //新用户注册后5分钟内进入线索 C
  81. log.Println("新注册用户定时任务开始")
  82. selectTimeEnd := cfg.LastUserId
  83. sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where createtime > "%s" and source = "0101" and status != 2`, selectTimeEnd)
  84. data := TiDb.SelectBySql(sql)
  85. if data != nil && *data != nil && len(*data) > 0 {
  86. for k, v := range *data {
  87. createtime := common.ObjToString(v["createtime"])
  88. ok1, ok2 := FormatData(v, "users")
  89. if !ok1 {
  90. common.WriteSysConfig(&cfg)
  91. log.Println("线索卡点", "users", v, selectTimeEnd)
  92. break
  93. } else {
  94. if !ok2 {
  95. log.Println("用户分配已达上限", "users", v, selectTimeEnd)
  96. common.WriteSysConfig(&cfg)
  97. break
  98. }
  99. }
  100. if k == len(*data)-1 {
  101. cfg.LastUserId = createtime
  102. }
  103. }
  104. }
  105. common.WriteSysConfig(&cfg)
  106. log.Println("新注册用户定时任务结束")
  107. }
  108. // 留资 5分钟一次
  109. func saleLeads() {
  110. //判断节假日
  111. runOk := getRunOk()
  112. if !runOk {
  113. log.Println("不是工作日,任务暂停")
  114. return
  115. }
  116. //留资后5分钟内进入线索
  117. //分为免费留资和付费留资 付费B 免费C
  118. log.Println("用户留资定时任务开始")
  119. session := Mgo.GetMgoConn()
  120. lastId := cfg.LastId
  121. defer func() {
  122. Mgo.DestoryMongoConn(session)
  123. }()
  124. query := map[string]interface{}{}
  125. if lastId != "" {
  126. query["_id"] = map[string]interface{}{"$gt": mongodb.StringTOBsonId(lastId)}
  127. }
  128. log.Println("query :", query)
  129. iter := session.DB(cfg.Mgo.DbName).C("saleLeads").Find(&query).Sort("_id").Iter()
  130. thisData := map[string]interface{}{}
  131. for {
  132. if !iter.Next(&thisData) {
  133. break
  134. }
  135. ok1, ok2 := FormatData(thisData, "saleLeads")
  136. if !ok1 {
  137. common.WriteSysConfig(&cfg)
  138. log.Println("线索卡点", "saleLeads", thisData, lastId)
  139. break
  140. } else {
  141. if !ok2 {
  142. log.Println("用户分配已达上限", "saleLeads", thisData, lastId)
  143. common.WriteSysConfig(&cfg)
  144. break
  145. }
  146. }
  147. cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
  148. }
  149. common.WriteSysConfig(&cfg)
  150. log.Println("用户留资定时任务结束")
  151. }
  152. func userbase() {
  153. log.Println("userbase定时任务开始")
  154. selectTimeEnd := time.Unix(time.Now().Unix()-1800, 0).Format("2006-01-02 15:04:05")
  155. sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where updatetime > "%s" and source != "0105" and source != "0104" and source != "0103" and source != "0102"`, selectTimeEnd)
  156. //sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where id='11927183'`)
  157. data := TiDb.SelectBySql(sql)
  158. if data != nil && *data != nil && len(*data) > 0 {
  159. for _, v := range *data {
  160. phone := common.ObjToString(v["phone"])
  161. uId := common.ObjToString(v["uid"])
  162. userId := common.ObjToString(v["userid"])
  163. registedate := common.ObjToString(v["l_registedate"])
  164. name := common.ObjToString(v["name"])
  165. nowTime := time.Now().Format(date.Date_Full_Layout)
  166. source := common.ObjToString(v["source"])
  167. if phone != "" {
  168. contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
  169. if contactsData == nil || len(*contactsData) == 0 {
  170. contactsData2 := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where baseinfo_id = ? and is_delete = 1", uId)
  171. if contactsData2 != nil && len(*contactsData2) > 0 {
  172. log.Println("userbase uid不为空 新增通讯录", uId)
  173. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  174. "status": 1,
  175. "is_delete": 1,
  176. "createtime": nowTime,
  177. "updatetime": nowTime,
  178. "phone": phone,
  179. "baseinfo_id": uId,
  180. "SOURCE": source,
  181. })
  182. } else {
  183. registedates, _ := time.Parse(date.Date_Full_Layout, registedate)
  184. count := TiDb.CountBySql("select count(1) as count from dwd_f_crm_clue_info where uid = ?", uId)
  185. log.Println("userbase uid 线索数量 ", count)
  186. log.Println("userbase uid 注册时间 ", registedates)
  187. if time.Now().Unix()-registedates.Unix() > int64(cfg.RegTimes)*86400 {
  188. if count == 0 {
  189. // TiDb.Insert("dwd_f_crm_open_sea", map[string]interface{}{
  190. // "clue_id": clueId,
  191. // "comeintime": nowTime,
  192. // "comeinsource": 2,
  193. // })
  194. clueId := TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
  195. "userid": userId,
  196. "uid": uId,
  197. "is_assign": 0,
  198. "comeintime": nowTime,
  199. "createtime": nowTime,
  200. "updatetime": nowTime,
  201. "cluename": phone,
  202. "top_cluetype": "532",
  203. "sub_cluetype": "475",
  204. "trailstatus": "01",
  205. "name": name,
  206. "phone": phone,
  207. "comeintime_open": nowTime,
  208. "comeinsource_open": 1,
  209. "FREEZE_TIME": nowTime,
  210. })
  211. if clueId > 0 {
  212. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  213. "status": 1,
  214. "is_delete": 1,
  215. "createtime": nowTime,
  216. "updatetime": nowTime,
  217. "phone": phone,
  218. "baseinfo_id": uId,
  219. "SOURCE": source,
  220. })
  221. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  222. "clue_id": clueId,
  223. "position_id": -1,
  224. "change_type": "创建线索",
  225. "new_value": "系统自动创建",
  226. "createtime": nowTime,
  227. "BCPCID": common.GetRandom(32),
  228. "operator_id": -1,
  229. })
  230. }
  231. } else {
  232. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  233. "status": 1,
  234. "is_delete": 1,
  235. "createtime": nowTime,
  236. "updatetime": nowTime,
  237. "phone": phone,
  238. "baseinfo_id": uId,
  239. "SOURCE": source,
  240. })
  241. }
  242. } else {
  243. if count == 0 {
  244. ok1, ok2 := FormatData(v, "users")
  245. if !ok1 {
  246. common.WriteSysConfig(&cfg)
  247. log.Println("线索卡点", "userbase uid", v, uId)
  248. break
  249. } else {
  250. if !ok2 {
  251. log.Println("用户分配已达上限", "userbase uid", v, uId)
  252. common.WriteSysConfig(&cfg)
  253. break
  254. }
  255. }
  256. } else {
  257. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  258. "status": 1,
  259. "is_delete": 1,
  260. "createtime": nowTime,
  261. "updatetime": nowTime,
  262. "phone": phone,
  263. "baseinfo_id": uId,
  264. "SOURCE": source,
  265. })
  266. }
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. log.Println("userbase定时任务结束")
  274. }
  275. func getRunOk() bool {
  276. currentTime, runOk := time.Now(), false
  277. if currentTime.Weekday() == time.Sunday {
  278. isok := false
  279. for k, v := range DateMap {
  280. if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
  281. isok = true
  282. }
  283. }
  284. if isok {
  285. runOk = true
  286. }
  287. } else {
  288. isok := true
  289. for k, v := range DateMap {
  290. if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
  291. isok = false
  292. }
  293. }
  294. if isok {
  295. runOk = true
  296. }
  297. }
  298. return runOk
  299. }
  300. func getAreaCode(userId string) (code string) {
  301. followData := Base.Find("follow_project_monitor", map[string]interface{}{"s_userid": userId}, "", "", -1, -1)
  302. sidArr := []string{}
  303. if followData != nil && len(*followData) > 0 {
  304. for _, v := range *followData {
  305. infoId := common.ObjToString(v["s_id"])
  306. sidArr = append(sidArr, infoId)
  307. }
  308. }
  309. if len(sidArr) > 0 {
  310. query := `{"query": {"bool": {"must": [{"terms": {"_id": ["%s"]}}],"must_not": [],"should": []}}}`
  311. query = fmt.Sprintf(query, strings.Join(sidArr, `","`))
  312. biddingData := Es.Get("bidding", "bidding", query)
  313. if biddingData != nil && len(*biddingData) > 0 {
  314. codeMap := map[string]string{}
  315. codeArr := []string{}
  316. for _, v := range *biddingData {
  317. area := common.ObjToString(v["area"])
  318. address := common.ObjToString(v["city"])
  319. if address == "" {
  320. address = area
  321. }
  322. codeMap[address] = AreaCode[address]
  323. }
  324. if len(codeMap) > 0 {
  325. for _, v := range codeMap {
  326. codeArr = append(codeArr, v)
  327. }
  328. }
  329. if len(codeArr) > 0 {
  330. code = strings.Join(codeArr, ",")
  331. }
  332. }
  333. }
  334. log.Println("code ", code)
  335. return
  336. }
  337. func getClueType(item string, data map[string]interface{}, sourceCode string, sourceId int64) (pcode, code, level, topname, subname string) {
  338. if item == "orders" {
  339. productType := common.ObjToString(data["product_type"])
  340. pcode = "1"
  341. level = "A"
  342. topname = "提交订单未支付"
  343. if productType == "VIP订阅" {
  344. code = "6"
  345. subname = "超级订阅"
  346. } else if productType == "大会员" {
  347. code = "7"
  348. subname = "大会员"
  349. } else if productType == "数据流量包" {
  350. code = "8"
  351. subname = "数据流量包"
  352. } else if productType == "历史数据" {
  353. code = "9"
  354. subname = "数据自助导出"
  355. }
  356. } else if item == "users" {
  357. pcode = "4"
  358. code = "154"
  359. level = "C"
  360. topname = "新增注册"
  361. subname = "新增注册用户"
  362. } else if item == "message" {
  363. pcode = "532"
  364. code = "477"
  365. level = "B"
  366. topname = "其他"
  367. subname = "机器人客服主动咨询"
  368. } else if item == "readClue" {
  369. level = "A"
  370. topname = "超级订阅临期用户"
  371. pcode = "614"
  372. if sourceId == 1 {
  373. code = "615"
  374. subname = "60天后到期"
  375. } else if sourceId == 2 {
  376. code = "616"
  377. subname = "45天后到期"
  378. } else if sourceId == 3 {
  379. code = "617"
  380. subname = "15天后到期"
  381. } else {
  382. code = "618"
  383. subname = "7天后到期"
  384. }
  385. } else {
  386. if sourceCode != "" {
  387. codeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"source": sourceCode}, "", "")
  388. if codeData != nil && len(*codeData) > 0 {
  389. pcode = common.ObjToString((*codeData)["pcode"])
  390. code = common.ObjToString((*codeData)["code"])
  391. level = common.ObjToString((*codeData)["clue_level"])
  392. subname = common.ObjToString((*codeData)["name"])
  393. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": pcode}, "", "")
  394. if pcodeData != nil && len(*pcodeData) > 0 {
  395. topname = common.ObjToString((*pcodeData)["name"])
  396. }
  397. }
  398. }
  399. }
  400. return
  401. }
  402. // 获取自动分配的人
  403. func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId int64, seatNumber, saleName string, saleData []map[string]interface{}, isOk, isFreeze bool, noticePositionId int64) {
  404. isOk = false
  405. isFreeze = false
  406. if TiDb.Count("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone, "is_assign": 1}) == 0 { //线索没销售进入,有销售走分配次数最少的逻辑
  407. if isGroup == 0 && isCommerce == 1 && cluename != "" { //非集团在工商库线索名不为空
  408. cdata := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "", "")
  409. if cdata != nil && len(*cdata) > 0 { //找到了公司有人在跟进
  410. isOk = true
  411. positionId = common.Int64All((*cdata)["position_id"])
  412. noticePositionId = positionId
  413. seatNumber = common.ObjToString((*cdata)["seatNumber"])
  414. log.Println("positionId seatNumber ", positionId, seatNumber)
  415. if positionId > 0 {
  416. pdata := TiDb.SelectBySql(`select * from dwd_f_crm_personnel_management where seat_number is not null and seat_number != ""`)
  417. if pdata != nil {
  418. saleData = *pdata
  419. for _, v := range *pdata {
  420. resign := common.IntAll(v["resign"])
  421. if positionId == common.Int64All(v["position_id"]) {
  422. if resign == 1 { //离职分配,找到的销售离职了,分给组员,没离职就给他
  423. sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, positionId)
  424. if sdata != nil && len(*sdata) > 0 {
  425. for _, m := range *sdata {
  426. if !FindUpperLimit(gconv.String(positionId), mode, true) {
  427. positionId = common.Int64All(m["position_id"])
  428. noticePositionId = positionId
  429. seatNumber = common.ObjToString(m["seat_number"])
  430. saleName = common.ObjToString(m["name"])
  431. return
  432. }
  433. }
  434. isFreeze = true
  435. positionId = 0
  436. seatNumber = ""
  437. saleName = ""
  438. return
  439. }
  440. } else {
  441. if FindUpperLimit(gconv.String(positionId), mode, true) {
  442. isFreeze = true
  443. }
  444. saleName = common.ObjToString(v["name"])
  445. }
  446. }
  447. }
  448. }
  449. if isFreeze {
  450. positionId = 0
  451. seatNumber = ""
  452. saleName = ""
  453. }
  454. return
  455. }
  456. }
  457. }
  458. }
  459. query := `select * from dwd_f_crm_personnel_management where assign_type = 1 and`
  460. if mode == "A" {
  461. query += ` assign_level like "%A%"`
  462. } else if mode == "B" {
  463. query += ` assign_level like "%B%"`
  464. } else {
  465. query += ` assign_level like "%C%"`
  466. }
  467. data := TiDb.SelectBySql(query)
  468. if data != nil && len(*data) > 0 {
  469. saleData = *data
  470. sql := "select * from dwd_f_crm_clue_autodraw_record where clue_level = ?"
  471. countData := TiDb.SelectBySql(sql, mode)
  472. if countData != nil && len(*countData) > 0 {
  473. for _, v := range *data {
  474. isOk := false //判断是否有新员工
  475. for _, vv := range *countData {
  476. if common.Int64All(v["position_id"]) == common.Int64All(vv["position_id"]) {
  477. if common.IntAll(v["resign"]) == 0 {
  478. vv["status"] = 1
  479. } else {
  480. vv["status"] = 2
  481. }
  482. isOk = true
  483. }
  484. }
  485. if !isOk { //有新员工直接分给新员工
  486. positionId = common.Int64All(v["position_id"])
  487. saleName = common.ObjToString(v["name"])
  488. log.Println("新员工, ", positionId, saleName)
  489. rData := TiDb.FindOne("dwd_f_crm_clue_autodraw_record", map[string]interface{}{"clue_level": mode}, "", "count desc")
  490. TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
  491. "position_id": positionId,
  492. "clue_level": mode,
  493. "count": common.Int64All((*rData)["count"]),
  494. })
  495. break
  496. }
  497. }
  498. if positionId == 0 {
  499. res := int64(0)
  500. countres := 0
  501. for _, v := range *countData {
  502. if common.IntAll(v["status"]) == 1 {
  503. if FindUpperLimit(gconv.String(v["position_id"]), mode, true) {
  504. continue
  505. }
  506. if countres == 0 {
  507. res = common.Int64All(v["count"])
  508. positionId = common.Int64All(v["position_id"])
  509. } else {
  510. if common.Int64All(v["count"]) <= res {
  511. res = common.Int64All(v["count"])
  512. positionId = common.Int64All(v["position_id"])
  513. }
  514. }
  515. countres++
  516. }
  517. }
  518. log.Println(444, res)
  519. }
  520. } else {
  521. for _, kv := range *data {
  522. positionId1 := gconv.String(kv["position_id"])
  523. if !FindUpperLimit(positionId1, "", false) {
  524. positionId = common.Int64All(kv["position_id"])
  525. saleName = common.ObjToString(kv["name"])
  526. rData := TiDb.FindOne("dwd_f_crm_clue_autodraw_record", map[string]interface{}{"clue_level": mode}, "", "count desc")
  527. if rData != nil && len(*rData) > 0 {
  528. TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
  529. "position_id": positionId,
  530. "clue_level": mode,
  531. "count": common.Int64All((*rData)["count"]),
  532. })
  533. } else {
  534. TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
  535. "position_id": positionId,
  536. "clue_level": mode,
  537. "count": 0,
  538. })
  539. }
  540. break
  541. }
  542. }
  543. }
  544. for _, v := range *data {
  545. if positionId == common.Int64All(v["position_id"]) {
  546. seatNumber = common.ObjToString(v["seat_number"])
  547. saleName = common.ObjToString(v["name"])
  548. }
  549. }
  550. }
  551. return
  552. }
  553. func getPositionId(phone string) (positionId int64) {
  554. userData, ok := Mgo.FindOne("user", map[string]interface{}{"s_phone": phone})
  555. if ok && userData != nil && len(*userData) > 0 {
  556. userId := common.Int64All((*userData)["base_user_id"])
  557. positionData := Base.FindOne("base_position", map[string]interface{}{"type": 1, "ent_id": 25917, "user_id": userId}, "", "") //TODO ent_id
  558. if positionData != nil && len(*positionData) > 0 {
  559. positionId = common.Int64All((*positionData)["id"])
  560. }
  561. }
  562. return
  563. }
  564. func GetCompanyType(companyName string) (int, int) {
  565. //是否是集团
  566. isGroup, isCommerce := 0, 0
  567. if c := TiDb.CountBySql(`select count(1) from group_company_name where company_name=?`, companyName); c > 0 {
  568. isGroup = 1
  569. }
  570. //是否在工商库
  571. if c := MgoQyxy.Count("qyxy_std", map[string]interface{}{"company_name": companyName, "company_type": map[string]interface{}{"$ne": "个体工商户"}}); c > 0 {
  572. isCommerce = 1
  573. }
  574. return isGroup, isCommerce
  575. }
  576. // 查询是否达上限
  577. func FindUpperLimit(positionId string, level string, isAdd bool) bool {
  578. if positionId == "" {
  579. return false
  580. }
  581. isFull := false
  582. isFull = TiDb.CountBySql(`select count(1) from dwd_f_crm_clue_info where position_id=? and is_assign=1 and trailstatus != '08' `, positionId) >= cfg.AllocationCap
  583. if isFull && isAdd && level != "" {
  584. TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, positionId, level)
  585. }
  586. return isFull
  587. }
  588. func getSeatNumberPositionId(seatNumber string) (positionId int64) {
  589. saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"seat_number": seatNumber}, "", "")
  590. if saleData != nil && len(*saleData) > 0 {
  591. positionId = common.Int64All((*saleData)["position_id"])
  592. }
  593. return
  594. }