jobutil.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jybase/redis"
  4. "fmt"
  5. "log"
  6. "math"
  7. "strings"
  8. "time"
  9. "github.com/gogf/gf/v2/util/gconv"
  10. "app.yhyue.com/moapp/jybase/common"
  11. "app.yhyue.com/moapp/jybase/date"
  12. "app.yhyue.com/moapp/jybase/mongodb"
  13. )
  14. // 电销工单生成
  15. func rderAcceptance() {
  16. sql := fmt.Sprintf(`select * from order_acceptance where is_clue=2 and is_delete=1 order by propose_time `)
  17. //sql := fmt.Sprintf(`select * from order_acceptance where is_clue=2 and is_delete=1 and id = 333 order by propose_time `)
  18. data := WorkOrder.SelectBySql(sql)
  19. if data != nil && len(*data) > 0 {
  20. for _, v := range *data {
  21. acceptance_no := gconv.String(v["acceptance_no"])
  22. childrenArr := WorkOrder.Find("order_acceptance_children", map[string]interface{}{
  23. "acceptance_no": acceptance_no,
  24. }, "", "", -1, -1)
  25. if childrenArr != nil && len(*childrenArr) > 0 {
  26. company := ""
  27. phone := ""
  28. demand := ""
  29. name := ""
  30. product := ""
  31. for _, v1 := range *childrenArr {
  32. if gconv.String(v1["field_name"]) == "公司名称" {
  33. company = gconv.String(v1["field_value"])
  34. }
  35. if gconv.String(v1["field_name"]) == "联系方式num" {
  36. phone = gconv.String(v1["field_value"])
  37. }
  38. if gconv.String(v1["field_name"]) == "客户姓名" {
  39. name = gconv.String(v1["field_value"])
  40. }
  41. if gconv.String(v1["field_name"]) == "客户需求" {
  42. demand = gconv.String(v1["field_value"])
  43. }
  44. if gconv.String(v1["field_name"]) == "咨询产品" {
  45. product = gconv.String(v1["field_value"])
  46. }
  47. }
  48. if !WorkDataHandle(company, phone, demand, name, product, v) {
  49. log.Println("工单创建失败")
  50. }
  51. }
  52. }
  53. }
  54. }
  55. func WorkDataHandle(company, phone, demand, name, product string, acceptanceData map[string]interface{}) bool {
  56. uId := ""
  57. query := map[string]interface{}{}
  58. contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
  59. if contactsData != nil && len(*contactsData) > 0 {
  60. if common.ObjToString((*contactsData)[0]["baseinfo_id"]) != "" {
  61. uId = common.ObjToString((*contactsData)[0]["baseinfo_id"])
  62. query["uid"] = uId
  63. }
  64. }
  65. if uId == "" {
  66. log.Println("用户信息不存在")
  67. return false
  68. }
  69. cluename := company
  70. if cluename == "" {
  71. cluename = phone //没有线索名,手机号代替
  72. }
  73. ok, data, saleData := false, map[string]interface{}{}, []map[string]interface{}{}
  74. isGroup, isCommerce := GetCompanyType(cluename)
  75. uCount, _ := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
  76. if uCount != nil && len(*uCount) > 0 {
  77. clueId := gconv.Int64((*uCount)["id"])
  78. positionId := gconv.Int64((*uCount)["position_id"])
  79. trailstatus := gconv.String((*uCount)["trailstatus"])
  80. IS_TRANSFER := gconv.Int64((*uCount)["IS_TRANSFER"])
  81. if IS_TRANSFER == 1 {
  82. //客成处理
  83. //客成
  84. //生成客成数据
  85. customerMap := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{
  86. "clue_id": clueId,
  87. }, "position_id,name", "")
  88. if customerMap != nil && len(*customerMap) > 0 {
  89. UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String((*uCount)["name"]), phone, "", "", "", "", "", "", gconv.String((*uCount)["seat_number"]), "", gconv.Int64((*uCount)["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false, demand)
  90. data = map[string]interface{}{
  91. "type": "kc",
  92. "position_id": (*customerMap)["position_id"],
  93. "name": (*customerMap)["name"],
  94. }
  95. } else {
  96. log.Println("查询不到客成数据", clueId, uId)
  97. return false
  98. }
  99. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  100. "clue_id": clueId,
  101. "position_id": (*customerMap)["position_id"],
  102. "change_type": "加入任务车",
  103. "new_value": "咨询客服转客成",
  104. "createtime": time.Now().Format(date.Date_Full_Layout),
  105. "BCPCID": common.GetRandom(32),
  106. "operator_id": -1,
  107. })
  108. } else {
  109. if positionId == 0 {
  110. //线索变更
  111. ok, data, saleData = FindPosition(0, "", gconv.String(acceptanceData["creator_time"]))
  112. if !ok {
  113. log.Println(positionId, "用户查询失败")
  114. return false
  115. }
  116. UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
  117. } else {
  118. ok, data, saleData = FindPosition(positionId, trailstatus, gconv.String(acceptanceData["creator_time"]))
  119. if !ok {
  120. log.Println(positionId, "用户查询失败")
  121. return false
  122. }
  123. if gconv.Int64(data["position_id"]) == positionId {
  124. UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false, demand)
  125. } else {
  126. UpdateClue(*uCount, saleData, "", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", company, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), "", gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, true, demand)
  127. }
  128. }
  129. }
  130. } else {
  131. //新增线索
  132. ok, data, _ = FindPosition(0, "", gconv.String(acceptanceData["creator_time"]))
  133. if !ok {
  134. return false
  135. }
  136. SaveClue("", "", uId, "5", "169", "新增线索", "主动咨询客服留资客户", cluename, name, gconv.String(data["name"]), phone, "", "", "", "", "", "", gconv.String(data["seat_number"]), gconv.Int64(data["position_id"]), "", "", "", []string{}, "", isGroup, isCommerce, false, demand)
  137. }
  138. //工单生成
  139. ok1 := AddOrderWork(acceptanceData, data, product, phone, company)
  140. log.Println("工单创建", ok1, gconv.String(acceptanceData["acceptance_no"]))
  141. return true
  142. }
  143. func AddOrderWork(acceptanceData map[string]interface{}, userData map[string]interface{}, product, phone, company string) bool {
  144. nowTime := time.Now().Format(date.Date_Full_Layout)
  145. work_order_no := fmt.Sprintf("GD%s%s", time.Now().Format(date.Date_yyyyMMdd), FindNumber("gd"))
  146. productArr := []string{}
  147. for _, v := range strings.Split(product, ",") {
  148. switch ProductMap[v] {
  149. case "dk":
  150. continue
  151. default:
  152. productArr = append(productArr, v)
  153. }
  154. }
  155. two_type := "dx"
  156. if gconv.String(userData["type"]) == "kc" {
  157. two_type = "kc"
  158. }
  159. personMap := GetPerson(gconv.String(userData["position_id"]))
  160. if personMap == nil || len(personMap) == 0 {
  161. return false
  162. }
  163. orderWorkMap := map[string]interface{}{
  164. "work_order_no": work_order_no,
  165. "acceptance_no": gconv.String(acceptanceData["acceptance_no"]),
  166. "type": strings.Join(productArr, ","),
  167. "status": common.If(gconv.Int64(userData["orderStatus"]) == 0, 2, 1),
  168. "initiator_name": gconv.String(acceptanceData["creator_name"]),
  169. "initiator_position_id": gconv.String(acceptanceData["initiator_position_id"]),
  170. "current_name": userData["name"],
  171. "current_position_id": userData["position_id"],
  172. "is_delete": 1,
  173. "creator_name": gconv.String(acceptanceData["creator_name"]),
  174. "creator_position_id": gconv.String(acceptanceData["creator_position_id"]),
  175. "creator_time": nowTime,
  176. "two_type": two_type,
  177. "department_no": gconv.String(personMap["deptId"]),
  178. "department_name": gconv.String(personMap["deptName"]),
  179. "update_time": common.If(gconv.Int64(userData["orderStatus"]) == 0, nowTime, nil),
  180. }
  181. ok3 := WorkOrder.Insert("order_work", orderWorkMap)
  182. if ok3 > 0 {
  183. status := 2
  184. if WorkOrder.Count("order_work", map[string]interface{}{
  185. "status": 1,
  186. "acceptance_no": gconv.String(acceptanceData["acceptance_no"]),
  187. }) > 0 {
  188. status = 1
  189. }
  190. WorkOrder.Update("order_acceptance", map[string]interface{}{
  191. "id": acceptanceData["id"],
  192. }, map[string]interface{}{
  193. "is_clue": 3,
  194. "status": status,
  195. "over_time": common.If(status == 1, nil, nowTime),
  196. })
  197. //日志添加
  198. approvalRecordMap := map[string]interface{}{
  199. "work_order_no": work_order_no,
  200. "status": common.If(gconv.Int64(userData["orderStatus"]) == 0, 3, 1),
  201. "new_status": common.If(gconv.Int64(userData["orderStatus"]) == 0, 2, nil),
  202. "handle_name": userData["name"],
  203. "handle_position_id": userData["position_id"],
  204. "handle_dept_id": gconv.String(personMap["deptId"]),
  205. "handle_dept_name": gconv.String(personMap["deptName"]),
  206. "creator_name": gconv.String(acceptanceData["creator_name"]),
  207. "creator_position_id": gconv.String(acceptanceData["initiator_position_id"]),
  208. "is_delete": 1,
  209. "creator_time": nowTime,
  210. "handle_time": common.If(gconv.Int64(userData["orderStatus"]) == 0, nowTime, nil),
  211. "update_name": common.If(gconv.Int64(userData["orderStatus"]) == 0, userData["name"], nil),
  212. "update_position_id": common.If(gconv.Int64(userData["orderStatus"]) == 0, userData["position_id"], nil),
  213. "update_time": common.If(gconv.Int64(userData["orderStatus"]) == 0, nowTime, nil),
  214. }
  215. WorkOrder.Insert("approval_record", approvalRecordMap)
  216. WorkMail(personMap,
  217. strings.Join(productArr, ","),
  218. gconv.Int64(common.If(gconv.Int64(userData["orderStatus"]) == 0, 2, 1)),
  219. gconv.String(personMap["name"]),
  220. gconv.String(acceptanceData["creator_name"]),
  221. nowTime,
  222. work_order_no,
  223. phone,
  224. company)
  225. return true
  226. }
  227. return false
  228. }
  229. // 本级以及上级管理员查询
  230. func GetPerson(positionId string) map[string]interface{} {
  231. person := map[string]interface{}{}
  232. positionArrMap := Base.SelectBySql(fmt.Sprintf(`select a.phone,b.id,b.ent_id from
  233. base_user a
  234. INNER JOIN base_position b
  235. on b.id=%s and b.user_id=a.id and b.type=1`,
  236. positionId))
  237. if positionArrMap == nil || len(*positionArrMap) == 0 {
  238. return map[string]interface{}{}
  239. }
  240. phone := gconv.String((*positionArrMap)[0]["phone"])
  241. entId := gconv.String((*positionArrMap)[0]["ent_id"])
  242. entUserArrMap := Mysql.SelectBySql(fmt.Sprintf(`SELECT
  243. a.name as name,a.mail as mail,b.dept_id as deptId,a.phone ,c.name as deptName
  244. FROM
  245. entniche_user a
  246. INNER JOIN entniche_department_user b ON a.ent_id =%s
  247. AND a.phone IN %s
  248. and a.id=b.user_id
  249. inner join entniche_department c on b.dept_id=c.id
  250. `, entId, fmt.Sprintf("(%s)", phone)))
  251. //商机管理员
  252. if entUserArrMap == nil || len(*entUserArrMap) == 0 {
  253. return map[string]interface{}{}
  254. }
  255. deptId := gconv.Int64((*entUserArrMap)[0]["deptId"])
  256. person = map[string]interface{}{
  257. "name": gconv.String((*entUserArrMap)[0]["name"]),
  258. "mail": gconv.String((*entUserArrMap)[0]["mail"]),
  259. "phone": gconv.String((*entUserArrMap)[0]["phone"]),
  260. "deptId": gconv.String((*entUserArrMap)[0]["deptId"]),
  261. "deptName": gconv.String((*entUserArrMap)[0]["deptName"]),
  262. }
  263. //本部门管理员查询
  264. depthMap := Mysql.SelectBySql(`SELECT
  265. c.name as name,c.mail as mail
  266. FROM
  267. entniche_department_user a
  268. INNER JOIN entniche_user_role b ON a.dept_id = ?
  269. AND a.user_id = b.user_id
  270. AND b.role_id !=""
  271. INNER JOIN entniche_user c ON a.user_id = c.id`, deptId)
  272. if depthMap != nil && len(*depthMap) > 0 {
  273. person["deptPersonName"] = gconv.String((*depthMap)[0]["name"])
  274. person["deptPersonMail"] = gconv.String((*depthMap)[0]["mail"])
  275. }
  276. //商机管理员查询
  277. superiorDepthMap := Mysql.SelectBySql(`SELECT
  278. c.*
  279. FROM
  280. entniche_department d
  281. INNER JOIN entniche_department_user a ON d.id = ?
  282. AND d.pid = a.dept_id
  283. INNER JOIN entniche_user_role b ON a.user_id = b.user_id
  284. AND b.role_id !=""
  285. INNER JOIN entniche_user c ON a.user_id = c.id`, deptId)
  286. if superiorDepthMap != nil && len(*superiorDepthMap) > 0 {
  287. person["superiorDepthPersonName"] = gconv.String((*superiorDepthMap)[0]["name"])
  288. person["superiorDepthPersonMail"] = gconv.String((*superiorDepthMap)[0]["mail"])
  289. }
  290. return person
  291. }
  292. // 编号查询
  293. func FindNumber(moudle string) string {
  294. today := time.Now().Format("2006-01-02")
  295. yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
  296. key := fmt.Sprintf("%s_%s", today, moudle)
  297. yesterdayKey := fmt.Sprintf("%s_%s", yesterday, moudle)
  298. if ok, _ := redis.Exists("newother", yesterdayKey); ok {
  299. //删除之前数据
  300. redis.Del("newother", yesterdayKey)
  301. }
  302. count := redis.Incr("newother", key)
  303. log.Println("编号获取", moudle, fmt.Sprintf("%04d", count))
  304. return fmt.Sprintf("%04d", count)
  305. }
  306. // 人员查询
  307. func GetAllocation(proportion1, proportion3 float64, deptCount1, deptCount3 int64, administrators1, administrators3 map[string]interface{}, creatorTime string) map[string]interface{} {
  308. log.Println("分配比例查询", proportion1, proportion3, deptCount1, deptCount3)
  309. if deptCount1 == 0 {
  310. return administrators1
  311. }
  312. if deptCount3 == 0 {
  313. return administrators3
  314. }
  315. nowAllocationRatio := math.Round(gconv.Float64(deptCount1 / deptCount3))
  316. if cfg.AllocationRatio == 0 {
  317. //重新计算
  318. cfg.AllocationRatio = math.Round(proportion1 / proportion3)
  319. cfg.AllocationTime = creatorTime
  320. common.WriteSysConfig(&cfg)
  321. log.Println("新增计算比例", cfg.AllocationRatio)
  322. } else {
  323. if nowAllocationRatio == cfg.AllocationRatio {
  324. //重新计算
  325. cfg.AllocationRatio = math.Round(proportion1 / proportion3)
  326. cfg.AllocationTime = creatorTime
  327. common.WriteSysConfig(&cfg)
  328. }
  329. }
  330. if nowAllocationRatio > cfg.AllocationRatio {
  331. return administrators3
  332. } else {
  333. return administrators1
  334. }
  335. //达到比例也重新计算
  336. }
  337. func FindPosition(positionId int64, trailstatus, creatorTime string) (bool, map[string]interface{}, []map[string]interface{}) {
  338. allData := []map[string]interface{}{}
  339. //查询两个部门高级管理员
  340. //查询两个部门所有人员标识
  341. //电销三部
  342. userData1 := TiDb.SelectBySql(`SELECT
  343. a.position_id,
  344. a.name,
  345. b.seat_number,
  346. b.role_id,
  347. a.bi_pcode,
  348. a.dept_name
  349. FROM
  350. dwd_d_crm_department_level_succbi a
  351. INNER JOIN dwd_f_crm_personnel_management b ON a.resign = 0 and b.resign = 0
  352. AND a.dept_name LIKE "%电销部%"
  353. AND a.position_id = b.position_id`)
  354. userData3 := TiDb.SelectBySql(`SELECT
  355. a.position_id,
  356. a.name,
  357. b.seat_number,
  358. b.role_id,
  359. a.bi_pcode,
  360. a.dept_name
  361. FROM
  362. dwd_d_crm_department_level_succbi a
  363. INNER JOIN dwd_f_crm_personnel_management b ON a.resign = 0 and b.resign = 0
  364. AND a.resign = 0
  365. AND a.dept_name LIKE "%销售三部"
  366. AND a.position_id = b.position_id`)
  367. if userData3 == nil || len(*userData3) == 0 || userData1 == nil || len(*userData1) == 0 {
  368. return false, map[string]interface{}{}, allData
  369. }
  370. //一部管理员信息
  371. administrators1 := map[string]interface{}{}
  372. //三部管理员信息
  373. administrators3 := map[string]interface{}{}
  374. //返回当前人信息
  375. administrators := map[string]interface{}{}
  376. //电销一部
  377. deptNameMap1 := map[string]interface{}{}
  378. deptNameMap3 := map[string]interface{}{}
  379. proportion1 := float64(0)
  380. proportion3 := float64(0)
  381. for _, v := range *userData3 {
  382. v["type"] = 3
  383. id := gconv.Int64(v["position_id"])
  384. roleId := gconv.Int64(v["role_id"])
  385. if id == positionId {
  386. administrators = v
  387. }
  388. if roleId == 8 {
  389. v["orderStatus"] = 2
  390. administrators3 = v
  391. } else if roleId == 3 {
  392. proportion3 += 0.5
  393. } else {
  394. proportion3 += 1
  395. }
  396. deptNameMap3[gconv.String(v["bi_pcode"])] = true
  397. allData = append(allData, v)
  398. }
  399. for _, v := range *userData1 {
  400. v["type"] = 1
  401. id := gconv.Int64(v["position_id"])
  402. roleId := gconv.Int64(v["role_id"])
  403. if id == positionId {
  404. administrators = v
  405. }
  406. if roleId == 8 {
  407. v["orderStatus"] = 2
  408. administrators1 = v
  409. } else if roleId == 3 {
  410. proportion1 += 0.5
  411. } else {
  412. proportion1 += 1
  413. }
  414. deptNameMap1[gconv.String(v["bi_pcode"])] = true
  415. allData = append(allData, v)
  416. }
  417. if positionId != 0 {
  418. if administrators == nil || len(administrators) == 0 {
  419. return false, map[string]interface{}{}, allData
  420. }
  421. positiontype := gconv.Int64(administrators["type"])
  422. if trailstatus == "01" || trailstatus == "03" || trailstatus == "04" {
  423. switch positiontype {
  424. case 1:
  425. //找他上级
  426. administrators = administrators1
  427. case 3:
  428. //找他上级
  429. administrators = administrators3
  430. }
  431. return true, administrators, allData
  432. } else {
  433. return true, administrators, allData
  434. }
  435. }
  436. //按照比例分配选择一部还是三部
  437. //一部查询
  438. deptCount1 := CalculateProportion(deptNameMap1)
  439. //三部查询
  440. deptCount3 := CalculateProportion(deptNameMap3)
  441. return true, GetAllocation(proportion1, proportion3, deptCount1, deptCount3, administrators1, administrators3, creatorTime), allData
  442. log.Println("电销信息获取失败", positionId)
  443. return false, map[string]interface{}{}, allData
  444. }
  445. func CalculateProportion(deptNameMap map[string]interface{}) int64 {
  446. deptNameStr := ""
  447. for k := range deptNameMap {
  448. if deptNameStr == "" {
  449. deptNameStr = k
  450. } else {
  451. deptNameStr = fmt.Sprintf("%s,%s", deptNameStr, k)
  452. }
  453. }
  454. if deptNameStr == "" {
  455. return int64(0)
  456. }
  457. count := int64(0)
  458. sql := fmt.Sprintf(`SELECT
  459. sum(1) as count
  460. FROM
  461. order_work a
  462. INNER JOIN approval_record b ON a.creator_time > "%s"
  463. AND FIND_IN_SET( a.department_no , "%s")
  464. AND a.work_order_no = b.work_order_no
  465. and (b.new_status!= 1 or b.new_status is null )
  466. `, cfg.AllocationTime, deptNameStr)
  467. data := WorkOrder.SelectBySql(sql)
  468. if data != nil && len(*data) > 0 {
  469. count = gconv.Int64((*data)[0]["count"])
  470. }
  471. return count
  472. }
  473. // 未支付订单 30分钟一次
  474. func orders() {
  475. //一个小时未支付进入线索 A
  476. log.Println("未支付订单定时任务开始")
  477. lastOrderId := cfg.LastOrderId
  478. selectTimeStart := time.Unix(time.Now().Unix()-7200, 0).Format(date.Date_Full_Layout)
  479. selectTimeEnd := time.Unix(time.Now().Unix()-3600, 0).Format(date.Date_Full_Layout)
  480. sql := fmt.Sprintf(`select * from dataexport_order where create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
  481. data := Mysql.SelectBySql(sql)
  482. if data != nil && *data != nil && len(*data) > 0 {
  483. for _, v := range *data {
  484. order_status := common.IntAll(v["order_status"])
  485. is_backstage_order := common.IntAll(v["is_backstage_order"])
  486. product_type_str1 := `"大会员","VIP订阅","数据流量包","历史数据"`
  487. product_type := common.ObjToString(v["product_type"])
  488. if order_status == 0 && is_backstage_order == 0 && strings.Contains(product_type_str1, product_type) {
  489. ok1, ok2 := FormatData(v, "orders")
  490. if !ok1 {
  491. common.WriteSysConfig(&cfg)
  492. log.Println("线索卡点", "orders", v, selectTimeEnd, selectTimeStart)
  493. break
  494. } else {
  495. if !ok2 {
  496. log.Println("用户分配已达上限", "orders", v, selectTimeEnd, selectTimeStart)
  497. common.WriteSysConfig(&cfg)
  498. break
  499. }
  500. }
  501. }
  502. cfg.LastOrderId = common.IntAll(v["id"])
  503. }
  504. }
  505. common.WriteSysConfig(&cfg)
  506. log.Println("未支付订单定时任务结束")
  507. }
  508. func readClue() {
  509. log.Println("读表进线索定时任务开始")
  510. lastReadClueTime := cfg.LastReadClueTime
  511. sql := fmt.Sprintf(`select * from clue_info where updatetime > "%s" order by updatetime asc`, fmt.Sprint(lastReadClueTime))
  512. data := TiDb.SelectBySql(sql)
  513. if data != nil && *data != nil && len(*data) > 0 {
  514. for _, v := range *data {
  515. ok1, ok2 := FormatData(v, "readClue")
  516. if !ok1 {
  517. common.WriteSysConfig(&cfg)
  518. log.Println("线索卡点", "readClue", v, lastReadClueTime)
  519. break
  520. } else {
  521. if !ok2 {
  522. log.Println("用户分配已达上限", "readClue", v, lastReadClueTime)
  523. common.WriteSysConfig(&cfg)
  524. break
  525. }
  526. }
  527. cfg.LastReadClueTime = common.ObjToString(v["updatetime"])
  528. }
  529. }
  530. common.WriteSysConfig(&cfg)
  531. log.Println("读表进线索定时任务结束")
  532. }
  533. // 新注册用户 5分钟一次
  534. func users() {
  535. //判断节假日
  536. runOk := getRunOk()
  537. if !runOk {
  538. log.Println("不是工作日,任务暂停")
  539. return
  540. }
  541. //新用户注册后5分钟内进入线索 C
  542. log.Println("新注册用户定时任务开始")
  543. selectTimeEnd := cfg.LastUserId
  544. sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where createtime > "%s" and source = "0101" and status != 2`, selectTimeEnd)
  545. data := TiDb.SelectBySql(sql)
  546. if data != nil && *data != nil && len(*data) > 0 {
  547. for k, v := range *data {
  548. createtime := common.ObjToString(v["createtime"])
  549. ok1, ok2 := FormatData(v, "users")
  550. if !ok1 {
  551. common.WriteSysConfig(&cfg)
  552. log.Println("线索卡点", "users", v, selectTimeEnd)
  553. break
  554. } else {
  555. if !ok2 {
  556. log.Println("用户分配已达上限", "users", v, selectTimeEnd)
  557. common.WriteSysConfig(&cfg)
  558. break
  559. }
  560. }
  561. if k == len(*data)-1 {
  562. cfg.LastUserId = createtime
  563. }
  564. }
  565. }
  566. common.WriteSysConfig(&cfg)
  567. log.Println("新注册用户定时任务结束")
  568. }
  569. // 留资 5分钟一次
  570. func saleLeads() {
  571. //判断节假日
  572. runOk := getRunOk()
  573. if !runOk {
  574. log.Println("不是工作日,任务暂停")
  575. return
  576. }
  577. //留资后5分钟内进入线索
  578. //分为免费留资和付费留资 付费B 免费C
  579. log.Println("用户留资定时任务开始")
  580. session := Mgo.GetMgoConn()
  581. lastId := cfg.LastId
  582. defer func() {
  583. Mgo.DestoryMongoConn(session)
  584. }()
  585. query := map[string]interface{}{}
  586. if lastId != "" {
  587. query["_id"] = map[string]interface{}{"$gt": mongodb.StringTOBsonId(lastId)}
  588. }
  589. log.Println("query :", query)
  590. iter := session.DB(cfg.Mgo.DbName).C("saleLeads").Find(&query).Sort("_id").Iter()
  591. thisData := map[string]interface{}{}
  592. for {
  593. if !iter.Next(&thisData) {
  594. break
  595. }
  596. sourceCode := common.ObjToString(thisData["source"])
  597. if sourceCode == "" {
  598. log.Println("留资没有source", thisData)
  599. continue
  600. }
  601. //
  602. filterArr := []string{"-pc", "-app", "-wx", "-h5"}
  603. sourceMap := map[string]string{}
  604. saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE (department LIKE '%大客户%' or department LIKE '%市场组%') AND is_delete = 1`)
  605. if saleSource != nil && len(*saleSource) > 0 {
  606. for _, v := range *saleSource {
  607. source := common.ObjToString(v["source"])
  608. name := common.ObjToString(v["name"])
  609. for _, s := range filterArr {
  610. name = strings.ReplaceAll(name, s, "")
  611. }
  612. sourceMap[source] = name
  613. }
  614. }
  615. if sourceMap[sourceCode] != "" {
  616. continue
  617. }
  618. ok1, ok2 := FormatData(thisData, "saleLeads")
  619. if !ok1 {
  620. common.WriteSysConfig(&cfg)
  621. log.Println("线索卡点", "saleLeads", thisData, lastId)
  622. break
  623. } else {
  624. if !ok2 {
  625. log.Println("用户分配已达上限", "saleLeads", thisData, lastId)
  626. common.WriteSysConfig(&cfg)
  627. break
  628. }
  629. }
  630. cfg.LastId = mongodb.BsonIdToSId(thisData["_id"])
  631. }
  632. common.WriteSysConfig(&cfg)
  633. log.Println("用户留资定时任务结束")
  634. }
  635. func userbase() {
  636. log.Println("userbase定时任务开始")
  637. selectTimeEnd := time.Unix(time.Now().Unix()-1800, 0).Format("2006-01-02 15:04:05")
  638. 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)
  639. //sql := fmt.Sprintf(`select * from dwd_f_userbase_baseinfo where id='11927183'`)
  640. data := TiDb.SelectBySql(sql)
  641. if data != nil && *data != nil && len(*data) > 0 {
  642. for _, v := range *data {
  643. phone := common.ObjToString(v["phone"])
  644. uId := common.ObjToString(v["uid"])
  645. userId := common.ObjToString(v["userid"])
  646. registedate := common.ObjToString(v["l_registedate"])
  647. name := common.ObjToString(v["name"])
  648. nowTime := time.Now().Format(date.Date_Full_Layout)
  649. source := common.ObjToString(v["source"])
  650. if phone != "" {
  651. contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
  652. if contactsData == nil || len(*contactsData) == 0 {
  653. contactsData2 := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where baseinfo_id = ? and is_delete = 1", uId)
  654. if contactsData2 != nil && len(*contactsData2) > 0 {
  655. log.Println("userbase uid不为空 新增通讯录", uId)
  656. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  657. "status": 1,
  658. "is_delete": 1,
  659. "createtime": nowTime,
  660. "updatetime": nowTime,
  661. "phone": phone,
  662. "baseinfo_id": uId,
  663. "SOURCE": source,
  664. })
  665. } else {
  666. registedates, _ := time.Parse(date.Date_Full_Layout, registedate)
  667. count := TiDb.CountBySql("select count(1) as count from dwd_f_crm_clue_info where uid = ?", uId)
  668. log.Println("userbase uid 线索数量 ", count)
  669. log.Println("userbase uid 注册时间 ", registedates)
  670. if time.Now().Unix()-registedates.Unix() > int64(cfg.RegTimes)*86400 {
  671. if count == 0 {
  672. // TiDb.Insert("dwd_f_crm_open_sea", map[string]interface{}{
  673. // "clue_id": clueId,
  674. // "comeintime": nowTime,
  675. // "comeinsource": 2,
  676. // })
  677. clueId := TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
  678. "userid": userId,
  679. "uid": uId,
  680. "is_assign": 0,
  681. "comeintime": nowTime,
  682. "createtime": nowTime,
  683. "updatetime": nowTime,
  684. "cluename": phone,
  685. "top_cluetype": "532",
  686. "sub_cluetype": "475",
  687. "trailstatus": "01",
  688. "name": name,
  689. "phone": phone,
  690. "comeintime_open": nowTime,
  691. "comeinsource_open": 1,
  692. "FREEZE_TIME": nowTime,
  693. })
  694. if clueId > 0 {
  695. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  696. "status": 1,
  697. "is_delete": 1,
  698. "createtime": nowTime,
  699. "updatetime": nowTime,
  700. "phone": phone,
  701. "baseinfo_id": uId,
  702. "SOURCE": source,
  703. })
  704. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  705. "clue_id": clueId,
  706. "position_id": -1,
  707. "change_type": "创建线索",
  708. "new_value": "系统自动创建",
  709. "createtime": nowTime,
  710. "BCPCID": common.GetRandom(32),
  711. "operator_id": -1,
  712. })
  713. }
  714. } else {
  715. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  716. "status": 1,
  717. "is_delete": 1,
  718. "createtime": nowTime,
  719. "updatetime": nowTime,
  720. "phone": phone,
  721. "baseinfo_id": uId,
  722. "SOURCE": source,
  723. })
  724. }
  725. } else {
  726. if count == 0 {
  727. ok1, ok2 := FormatData(v, "users")
  728. if !ok1 {
  729. common.WriteSysConfig(&cfg)
  730. log.Println("线索卡点", "userbase uid", v, uId)
  731. break
  732. } else {
  733. if !ok2 {
  734. log.Println("用户分配已达上限", "userbase uid", v, uId)
  735. common.WriteSysConfig(&cfg)
  736. break
  737. }
  738. }
  739. } else {
  740. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  741. "status": 1,
  742. "is_delete": 1,
  743. "createtime": nowTime,
  744. "updatetime": nowTime,
  745. "phone": phone,
  746. "baseinfo_id": uId,
  747. "SOURCE": source,
  748. })
  749. }
  750. }
  751. }
  752. }
  753. }
  754. }
  755. }
  756. log.Println("userbase定时任务结束")
  757. }
  758. func getRunOk() bool {
  759. currentTime, runOk := time.Now(), false
  760. if currentTime.Weekday() == time.Sunday {
  761. isok := false
  762. for k, v := range DateMap {
  763. if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
  764. isok = true
  765. }
  766. }
  767. if isok {
  768. runOk = true
  769. }
  770. } else {
  771. isok := true
  772. for k, v := range DateMap {
  773. if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
  774. isok = false
  775. }
  776. }
  777. if isok {
  778. runOk = true
  779. }
  780. }
  781. return runOk
  782. }
  783. func getAreaCode(userId string) (code string) {
  784. followData := Base.Find("follow_project_monitor", map[string]interface{}{"s_userid": userId}, "", "", -1, -1)
  785. sidArr := []string{}
  786. if followData != nil && len(*followData) > 0 {
  787. for _, v := range *followData {
  788. infoId := common.ObjToString(v["s_id"])
  789. sidArr = append(sidArr, infoId)
  790. }
  791. }
  792. if len(sidArr) > 0 {
  793. query := `{"query": {"bool": {"must": [{"terms": {"_id": ["%s"]}}],"must_not": [],"should": []}}}`
  794. query = fmt.Sprintf(query, strings.Join(sidArr, `","`))
  795. biddingData := Es.Get("bidding", "bidding", query)
  796. if biddingData != nil && len(*biddingData) > 0 {
  797. codeMap := map[string]string{}
  798. codeArr := []string{}
  799. for _, v := range *biddingData {
  800. area := common.ObjToString(v["area"])
  801. address := common.ObjToString(v["city"])
  802. if address == "" {
  803. address = area
  804. }
  805. codeMap[address] = AreaCode[address]
  806. }
  807. if len(codeMap) > 0 {
  808. for _, v := range codeMap {
  809. codeArr = append(codeArr, v)
  810. }
  811. }
  812. if len(codeArr) > 0 {
  813. code = strings.Join(codeArr, ",")
  814. }
  815. }
  816. }
  817. log.Println("code ", code)
  818. return
  819. }
  820. func getClueType(item string, data map[string]interface{}, sourceCode string, sourceId int64) (pcode, code, level, topname, subname string) {
  821. if item == "orders" {
  822. productType := common.ObjToString(data["product_type"])
  823. pcode = "1"
  824. level = "A"
  825. topname = "提交订单未支付"
  826. if productType == "VIP订阅" {
  827. code = "6"
  828. subname = "超级订阅"
  829. } else if productType == "大会员" {
  830. code = "7"
  831. subname = "大会员"
  832. } else if productType == "数据流量包" {
  833. code = "8"
  834. subname = "数据流量包"
  835. } else if productType == "历史数据" {
  836. code = "9"
  837. subname = "数据自助导出"
  838. }
  839. } else if item == "users" {
  840. pcode = "4"
  841. code = "154"
  842. level = "C"
  843. topname = "新增注册"
  844. subname = "新增注册用户"
  845. } else if item == "message" {
  846. pcode = "532"
  847. code = "477"
  848. level = "B"
  849. topname = "其他"
  850. subname = "机器人客服主动咨询"
  851. } else if item == "readClue" {
  852. level = "A"
  853. topname = "超级订阅临期用户"
  854. pcode = "614"
  855. if sourceId == 1 {
  856. code = "615"
  857. subname = "60天后到期"
  858. } else if sourceId == 2 {
  859. code = "616"
  860. subname = "45天后到期"
  861. } else if sourceId == 3 {
  862. code = "617"
  863. subname = "15天后到期"
  864. } else {
  865. code = "618"
  866. subname = "7天后到期"
  867. }
  868. } else {
  869. if sourceCode != "" {
  870. codeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"source": sourceCode}, "", "")
  871. if codeData != nil && len(*codeData) > 0 {
  872. pcode = common.ObjToString((*codeData)["pcode"])
  873. code = common.ObjToString((*codeData)["code"])
  874. level = common.ObjToString((*codeData)["clue_level"])
  875. subname = common.ObjToString((*codeData)["name"])
  876. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": pcode}, "", "")
  877. if pcodeData != nil && len(*pcodeData) > 0 {
  878. topname = common.ObjToString((*pcodeData)["name"])
  879. }
  880. }
  881. }
  882. }
  883. return
  884. }
  885. // 获取自动分配的人
  886. func autoDraw(mode, cluename, phone string, isGroup, isCommerce int) (positionId int64, seatNumber, saleName string, saleData []map[string]interface{}, isOk, isFreeze bool, noticePositionId int64) {
  887. isOk = false
  888. isFreeze = false
  889. if TiDb.Count("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone, "is_assign": 1}) == 0 { //线索没销售进入,有销售走分配次数最少的逻辑
  890. if isGroup == 0 && isCommerce == 1 && cluename != "" { //非集团在工商库线索名不为空
  891. cdata := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "", "")
  892. if cdata != nil && len(*cdata) > 0 { //找到了公司有人在跟进
  893. isOk = true
  894. positionId = common.Int64All((*cdata)["position_id"])
  895. noticePositionId = positionId
  896. seatNumber = common.ObjToString((*cdata)["seatNumber"])
  897. log.Println("positionId seatNumber ", positionId, seatNumber)
  898. if positionId > 0 {
  899. pdata := TiDb.SelectBySql(`select * from dwd_f_crm_personnel_management where seat_number is not null and seat_number != ""`)
  900. if pdata != nil {
  901. saleData = *pdata
  902. for _, v := range *pdata {
  903. resign := common.IntAll(v["resign"])
  904. if positionId == common.Int64All(v["position_id"]) {
  905. if resign == 1 { //离职分配,找到的销售离职了,分给组员,没离职就给他
  906. 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)
  907. if sdata != nil && len(*sdata) > 0 {
  908. for _, m := range *sdata {
  909. if !FindUpperLimit(gconv.String(positionId), mode, true) {
  910. positionId = common.Int64All(m["position_id"])
  911. noticePositionId = positionId
  912. seatNumber = common.ObjToString(m["seat_number"])
  913. saleName = common.ObjToString(m["name"])
  914. return
  915. }
  916. }
  917. isFreeze = true
  918. positionId = 0
  919. seatNumber = ""
  920. saleName = ""
  921. return
  922. }
  923. } else {
  924. if FindUpperLimit(gconv.String(positionId), mode, true) {
  925. isFreeze = true
  926. }
  927. saleName = common.ObjToString(v["name"])
  928. }
  929. }
  930. }
  931. }
  932. if isFreeze {
  933. positionId = 0
  934. seatNumber = ""
  935. saleName = ""
  936. }
  937. return
  938. }
  939. }
  940. }
  941. }
  942. query := `select * from dwd_f_crm_personnel_management where assign_type = 1 and`
  943. if mode == "A" {
  944. query += ` assign_level like "%A%"`
  945. } else if mode == "B" {
  946. query += ` assign_level like "%B%"`
  947. } else {
  948. query += ` assign_level like "%C%"`
  949. }
  950. data := TiDb.SelectBySql(query)
  951. if data != nil && len(*data) > 0 {
  952. saleData = *data
  953. sql := "select * from dwd_f_crm_clue_autodraw_record where clue_level = ?"
  954. countData := TiDb.SelectBySql(sql, mode)
  955. if countData != nil && len(*countData) > 0 {
  956. for _, v := range *data {
  957. isOk := false //判断是否有新员工
  958. for _, vv := range *countData {
  959. if common.Int64All(v["position_id"]) == common.Int64All(vv["position_id"]) {
  960. if common.IntAll(v["resign"]) == 0 {
  961. vv["status"] = 1
  962. } else {
  963. vv["status"] = 2
  964. }
  965. isOk = true
  966. }
  967. }
  968. if !isOk { //有新员工直接分给新员工
  969. positionId = common.Int64All(v["position_id"])
  970. saleName = common.ObjToString(v["name"])
  971. log.Println("新员工, ", positionId, saleName)
  972. rData := TiDb.FindOne("dwd_f_crm_clue_autodraw_record", map[string]interface{}{"clue_level": mode}, "", "count desc")
  973. TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
  974. "position_id": positionId,
  975. "clue_level": mode,
  976. "count": common.Int64All((*rData)["count"]),
  977. })
  978. break
  979. }
  980. }
  981. if positionId == 0 {
  982. res := int64(0)
  983. countres := 0
  984. for _, v := range *countData {
  985. if common.IntAll(v["status"]) == 1 {
  986. if FindUpperLimit(gconv.String(v["position_id"]), mode, false) {
  987. continue
  988. }
  989. if countres == 0 {
  990. res = common.Int64All(v["count"])
  991. positionId = common.Int64All(v["position_id"])
  992. } else {
  993. if common.Int64All(v["count"]) <= res {
  994. res = common.Int64All(v["count"])
  995. positionId = common.Int64All(v["position_id"])
  996. }
  997. }
  998. countres++
  999. }
  1000. }
  1001. log.Println(444, res)
  1002. }
  1003. } else {
  1004. for _, kv := range *data {
  1005. positionId1 := gconv.String(kv["position_id"])
  1006. if !FindUpperLimit(positionId1, "", false) {
  1007. positionId = common.Int64All(kv["position_id"])
  1008. saleName = common.ObjToString(kv["name"])
  1009. rData := TiDb.FindOne("dwd_f_crm_clue_autodraw_record", map[string]interface{}{"clue_level": mode}, "", "count desc")
  1010. if rData != nil && len(*rData) > 0 {
  1011. TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
  1012. "position_id": positionId,
  1013. "clue_level": mode,
  1014. "count": common.Int64All((*rData)["count"]),
  1015. })
  1016. } else {
  1017. TiDb.Insert("dwd_f_crm_clue_autodraw_record", map[string]interface{}{
  1018. "position_id": positionId,
  1019. "clue_level": mode,
  1020. "count": 0,
  1021. })
  1022. }
  1023. break
  1024. }
  1025. }
  1026. }
  1027. for _, v := range *data {
  1028. if positionId == common.Int64All(v["position_id"]) {
  1029. seatNumber = common.ObjToString(v["seat_number"])
  1030. saleName = common.ObjToString(v["name"])
  1031. }
  1032. }
  1033. }
  1034. return
  1035. }
  1036. func getPositionId(phone string) (positionId int64) {
  1037. userData, ok := Mgo.FindOne("user", map[string]interface{}{"s_phone": phone})
  1038. if ok && userData != nil && len(*userData) > 0 {
  1039. userId := common.Int64All((*userData)["base_user_id"])
  1040. positionData := Base.FindOne("base_position", map[string]interface{}{"type": 1, "ent_id": 25917, "user_id": userId}, "", "") //TODO ent_id
  1041. if positionData != nil && len(*positionData) > 0 {
  1042. positionId = common.Int64All((*positionData)["id"])
  1043. }
  1044. }
  1045. return
  1046. }
  1047. func GetCompanyType(companyName string) (int, int) {
  1048. //是否是集团
  1049. isGroup, isCommerce := 0, 0
  1050. if c := TiDb.CountBySql(`select count(1) from group_company_name where company_name=?`, companyName); c > 0 {
  1051. isGroup = 1
  1052. }
  1053. //是否在工商库
  1054. if c := MgoQyxy.Count("qyxy_std", map[string]interface{}{"company_name": companyName, "company_type": map[string]interface{}{"$ne": "个体工商户"}}); c > 0 {
  1055. isCommerce = 1
  1056. }
  1057. return isGroup, isCommerce
  1058. }
  1059. // 查询是否达上限
  1060. func FindUpperLimit(positionId string, level string, isAdd bool) bool {
  1061. if positionId == "" {
  1062. return false
  1063. }
  1064. isFull := false
  1065. 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
  1066. if isFull && isAdd && level != "" {
  1067. TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, positionId, level)
  1068. }
  1069. return isFull
  1070. }
  1071. func getSeatNumberPositionId(seatNumber string) (positionId int64) {
  1072. saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"seat_number": seatNumber}, "", "")
  1073. if saleData != nil && len(*saleData) > 0 {
  1074. positionId = common.Int64All((*saleData)["position_id"])
  1075. }
  1076. return
  1077. }