12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325 |
- package service
- import (
- "context"
- "database/sql"
- "encoding/json"
- "fmt"
- "github.com/gogf/gf/v2/util/gconv"
- "io/ioutil"
- "log"
- "math"
- "net/http"
- "net/url"
- "regexp"
- "strings"
- "sync"
- "sync/atomic"
- "time"
- "app.yhyue.com/moapp/jybase/mongodb"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/es"
- . "bp.jydev.jianyu360.cn/BaseService/biService/entity"
- "bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
- "github.com/zeromicro/go-zero/core/logx"
- )
- const (
- competitors = "www.chinabidding.cn,www.yingcaicheng.com,cg.zbj.com,www.chinabidding.cn,bid.cyc-fund.com.cn,www.zbytb.com"
- )
- func ClueImportTt(this *biservice.ClueImportReq) *biservice.ClueImportResp {
- result, status := ClueImportTtSync(this)
- return &biservice.ClueImportResp{
- ErrorCode: 0,
- Data: &biservice.ClueImport{
- Status: int64(status),
- Result: result,
- },
- }
- }
- func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
- if ClueImportTtLock.TryLock() {
- defer ClueImportTtLock.Unlock()
- result, status, counts := "导入成功", 1, int64(0)
- data := BiService.Find("customer_data_temp", map[string]interface{}{"import_pc": this.Pcbh}, "", "", -1, -1)
- if data != nil && len(*data) > 0 {
- wg := new(sync.WaitGroup)
- ch := make(chan bool, 20)
- for _, v := range *data {
- wg.Add(1)
- ch <- true
- go func(v map[string]interface{}) {
- defer func() {
- wg.Done()
- <-ch
- }()
- v["isCompetitors"] = "否"
- id := common.ObjToString(v["id"])
- href := common.ObjToString(v["href"])
- for _, vv := range strings.Split(competitors, ",") {
- if strings.Contains(href, vv) {
- v["isCompetitors"] = "是"
- }
- }
- delete(v, "temp_id")
- delete(v, "import_pc")
- delete(v, "projectId")
- id_new := common.GetMd5String(fmt.Sprintf("%s_%d", common.ObjToString(v["id"]), common.Int64All(v["multipackage_id"])))
- v["id_new"] = id_new
- if BiService.Count("customer_data_ttzl", map[string]interface{}{"id_new": id_new}) > 0 {
- logx.Info("数据重复", id)
- return
- }
- if dataId := BiService.Insert("customer_data_ttzl", v); dataId > 0 {
- if details, ok := CreateEs(v); ok {
- BiService.Insert("customer_data_ttzl_gl", map[string]interface{}{"msg_id": dataId, "info_id": id, "details": details, "isHistory": "否"})
- atomic.AddInt64(&counts, 1)
- logx.Info("es存入成功", id)
- } else {
- logx.Info("es存入失败!!", id)
- }
- } else {
- logx.Info("tidb存入失败!!", id)
- }
- }(v)
- }
- wg.Wait()
- }
- BiService.Update("customer_data_import_record", map[string]interface{}{"import_pc": this.Pcbh}, map[string]interface{}{
- "import_end_time": time.Now().Format(date.Date_Full_Layout),
- "import_count": counts,
- "import_res": result,
- })
- return result, status
- } else {
- BiService.Update("customer_data_import_record", map[string]interface{}{"import_pc": this.Pcbh}, map[string]interface{}{
- "import_end_time": time.Now().Format(date.Date_Full_Layout),
- "import_res": "导入失败,有正在进行的导入任务",
- })
- return "有正在进行的导入任务", 2
- }
- }
- // 根据id重新生成es
- func CreateEsById(newId string) bool {
- data := BiService.FindOne("customer_data_ttzl", map[string]interface{}{"id_new": newId}, "", "")
- if data == nil || len(*data) == 0 {
- logx.Info("没有找到该数据", newId)
- return false
- }
- _, ok := CreateEs(*data)
- return ok
- }
- // 重新生成es
- func CreateEs(v map[string]interface{}) (string, bool) {
- details := ""
- biddingData, ok := Bidding.FindOne("bidding", map[string]interface{}{"_id": mongodb.StringTOBsonId(common.ObjToString(v["id"]))})
- if ok && biddingData != nil && len(*biddingData) > 0 {
- details = common.ObjToString((*biddingData)["detail"])
- }
- delete(v, "isCompetitors")
- delete(v, "msg_id")
- v["details"] = cleanHTML(details)
- if common.ObjToString(v["publishtime"]) != "" {
- v["publishtime2"] = common.ObjToString(v["publishtime"])
- publishtime, _ := time.ParseInLocation(date.Date_Full_Layout, common.ObjToString(v["publishtime"]), time.Local)
- v["publishtime"] = publishtime.UnixMilli()
- } else {
- delete(v, "publishtime")
- }
- for k, vv := range v {
- if vv == nil {
- delete(v, k)
- }
- }
- //
- esV7 := Es.(*es.EsV7)
- client := esV7.GetEsConn()
- defer esV7.DestoryEsConn(client)
- newId := common.ObjToString(v["id_new"])
- client.Delete().Index("ttbid").Id(newId).Refresh("true").Do(context.TODO())
- _, err := client.Index().Index("ttbid").Id(newId).BodyJson(v).Refresh("true").Do(context.TODO())
- if err != nil {
- logx.Info("保存到ES出错", err.Error())
- return details, false
- } else {
- return details, true
- }
- }
- func DelById(index, id string) bool {
- esV7 := Es.(*es.EsV7)
- client := esV7.GetEsConn()
- defer esV7.DestoryEsConn(client)
- _, err := client.Delete().Index(index).Id(id).Refresh("true").Do(context.TODO())
- if err != nil {
- logx.Info("删除es出错:", id, err)
- return false
- }
- return true
- }
- func cleanHTML(htmlString string) string {
- // 清理HTML标签
- htmlRegex := regexp.MustCompile("<[^>]*>")
- cleanedString := htmlRegex.ReplaceAllString(htmlString, "")
- // 清理换行符和制表符
- cleanedString = strings.ReplaceAll(cleanedString, "\n", "")
- cleanedString = strings.ReplaceAll(cleanedString, "\t", "")
- // 清理多余的空格
- cleanedString = strings.TrimSpace(cleanedString)
- return cleanedString
- }
- func ClueAdd(this *biservice.ClueAddReq, col string) *biservice.AddProjectResp {
- status := 1
- nowTime := time.Now().Format(date.Date_Full_Layout)
- if this.Company == "" {
- this.Company = this.Phone
- }
- isGroup, isCommerce := CompanyType(this.Company)
- saveMap := map[string]interface{}{
- "unique_id": this.Phone,
- "phone": this.Phone,
- "username": this.Username,
- "source": this.Source,
- "status999": this.Status999,
- "owner": this.Owner,
- "empNo": this.EmpNo,
- "company": this.Company,
- "isPolicymaker": this.IsPolicymaker,
- "belongToIndustry": this.BelongToIndustry,
- "job": this.Job,
- "customerNeeds": this.CustomerNeeds,
- "belongTo": this.BelongTo,
- "wantGoods": this.WantGoods,
- "customerBudget": this.CustomerBudget,
- "createTime": nowTime,
- "lastUpdateTime": nowTime,
- }
- token := getToken()
- updateData := map[string]interface{}{
- "dbType": "0001",
- "customerList": []map[string]interface{}{saveMap},
- }
- dataByte, _ := json.Marshal(&updateData)
- url := `https://a1.7x24cc.com/commonInte?flag=1007&account=N000000029739&accessToken=` + token + `&json=` + url.QueryEscape(string(dataByte))
- bs, err := doGet(url)
- if err != nil {
- status = -1
- logx.Info("调用接口失败")
- } else {
- resMap := common.StringToMap(string(bs))
- if resMap["success"] != nil && resMap["success"].(bool) {
- saveMap["company_nature"] = isGroup
- saveMap["company_verification"] = isCommerce
- CallTidb.Insert(col, saveMap)
- } else {
- status = -1
- }
- }
- return &biservice.AddProjectResp{
- ErrorCode: 0,
- Data: &biservice.AddProject{
- Status: int64(status),
- },
- }
- }
- func DistributeClue(this *biservice.DistributeClueReq) *biservice.AddProjectResp {
- count, status := DistributeClueSync(this)
- logx.Info("分配数量 ", count)
- return &biservice.AddProjectResp{
- ErrorCode: 0,
- Data: &biservice.AddProject{
- Status: int64(status),
- Count: int64(count),
- },
- }
- }
- func getToken() string {
- url := "https://a1.7x24cc.com/accessToken?account=N000000029739&appid=w4w2ex0bnt1n61or&secret=3c8f7dd04d2c11edb786132b38c4d48a"
- bs, err := doGet(url)
- if err != nil {
- logx.Info("token生成失败", err)
- return ""
- }
- tokenMap := common.StringToMap(string(bs))
- if tokenMap["success"].(bool) {
- return common.ObjToString(tokenMap["accessToken"])
- }
- return ""
- }
- func DistributeClueSync(this *biservice.DistributeClueReq) (int, int) {
- if DistributeLock.TryLock() {
- defer DistributeLock.Unlock()
- saleMap, count := map[string]map[string]interface{}{}, 0
- saleData := JyBiTidb.SelectBySql("select * from dwd_f_crm_personnel_management where resign = 0")
- if saleData != nil && len(*saleData) > 0 {
- for _, v := range *saleData {
- name := common.ObjToString(v["name"])
- saleMap[name] = v
- }
- }
- for _, data := range this.Datas {
- seatNumber := common.ObjToString(saleMap[data.Name]["seat_number"])
- distributedCount := int(data.DistributedCount)
- if distributedCount > 0 {
- distributedArr := this.ClueIdList[count : count+distributedCount]
- count += distributedCount
- DistributeClueMore(saleMap, distributedArr, seatNumber, data.Name, data.PositionId, this.PositionId, this.IsTask)
- }
- }
- return count, 1
- } else {
- return 0, 2
- }
- }
- func DistributeClueMore(saleMap map[string]map[string]interface{}, distributedArr []int64, seatNumber, name string, positionId, thispositionId, isTask int64) {
- wg := new(sync.WaitGroup)
- ch := make(chan bool, 20)
- for _, v := range distributedArr {
- wg.Add(1)
- ch <- true
- go func(v int64) {
- defer func() {
- wg.Done()
- <-ch
- }()
- clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, "", "")
- nowTime := time.Now().Format(date.Date_Full_Layout)
- if clueData != nil && len(*clueData) > 0 {
- isAssign := common.IntAll((*clueData)["is_assign"])
- clueSeatNumber := common.ObjToString((*clueData)["seatNumber"])
- oldName := ""
- trailstatus := common.ObjToString((*clueData)["trailstatus"])
- if clueSeatNumber != "" {
- for _, s := range saleMap {
- if common.ObjToString(s["seat_number"]) == clueSeatNumber {
- oldName = common.ObjToString(s["name"])
- }
- }
- }
- if isAssign == 1 {
- oldpositionId := common.Int64All((*clueData)["position_id"])
- updateClue := map[string]interface{}{
- "position_id": positionId,
- "seatNumber": seatNumber,
- "is_assign": 1,
- "updatetime": nowTime,
- "comeintime": nowTime,
- "comeinsource_private": 4,
- "level_open": nil,
- "clue_level": nil,
- "out_task_time": nil,
- "out_task_status": nil,
- // "comeinsource_open": nil,
- }
- if oldName != name {
- updateClue["start_trail_time"] = nil
- updateClue["next_trail_time"] = nil
- }
- if isTask == int64(1) {
- updateClue["is_task"] = 1
- updateClue["task_time"] = nowTime
- updateClue["tasktime"] = nowTime
- updateClue["taskstatus"] = 0
- updateClue["tasksource"] = "主动分配客户"
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": v,
- "position_id": positionId,
- "change_type": "加入任务车",
- "new_value": "主动分配客户",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": thispositionId,
- })
- }
- ok := JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, updateClue)
- // ok := JyBiTidb.Update("dwd_f_crm_private_sea", map[string]interface{}{"clue_id": v}, map[string]interface{}{
- // "position_id": positionId,
- // "seatNumber": seatNumber,
- // "comeinsource": 4,
- // "comeintime": nowTime,
- // })
- if ok {
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": v,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": oldName,
- "new_value": name,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": thispositionId,
- })
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": v,
- "position_id": oldpositionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "流失",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": thispositionId,
- })
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": v,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": thispositionId,
- })
- } else {
- logx.Info("私海修改失败 ", v, positionId, seatNumber)
- }
- } else {
- updateClue := map[string]interface{}{
- "position_id": positionId,
- "seatNumber": seatNumber,
- "is_assign": 1,
- "updatetime": nowTime,
- "comeintime": nowTime,
- "comeinsource_private": 4,
- "is_task": 0,
- "taskstatus": 0,
- "level_open": nil,
- "clue_level": nil,
- "out_task_time": nil,
- "out_task_status": nil,
- "next_trail_time": nil,
- "start_trail_time": nil,
- // "comeinsource_open": nil,
- }
- updateClue["trailstatus"] = "01"
- if isTask == int64(1) {
- updateClue["is_task"] = 1
- updateClue["task_time"] = nowTime
- updateClue["tasktime"] = nowTime
- updateClue["taskstatus"] = 0
- updateClue["tasksource"] = "主动分配客户"
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": v,
- "position_id": positionId,
- "change_type": "加入任务车",
- "new_value": "主动分配客户",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": thispositionId,
- })
- }
- ok := JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": v}, updateClue)
- // seaId := JyBiTidb.Insert("dwd_f_crm_private_sea", map[string]interface{}{
- // "clue_id": v,
- // "position_id": positionId,
- // "seatNumber": seatNumber,
- // "comeinsource": 4,
- // "comeintime": nowTime,
- // "is_task": 0,
- // // "task_time": nowTime,
- // // "tasktime": nowTime,
- // "taskstatus": 0,
- // // "tasksource": "线索批量分配",
- // })
- if ok {
- // JyBiTidb.Delete("dwd_f_crm_open_sea", map[string]interface{}{"clue_id": v})
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": v,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": "/",
- "new_value": name,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": thispositionId,
- })
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": v,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "商机线索",
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": thispositionId,
- })
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": v,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "商机线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": thispositionId,
- })
- } else {
- logx.Info("私海插入失败 ", v, positionId, seatNumber)
- }
- }
- }
- }(v)
- }
- wg.Wait()
- }
- func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
- count, status := DrawClueSync(this)
- logx.Info("领取数量 ", count)
- return &biservice.AddProjectResp{
- ErrorCode: 0,
- Data: &biservice.AddProject{
- Status: int64(status),
- Count: int64(count),
- },
- }
- }
- func DrawClueSync(this *biservice.DrawClueReq) (int, int) {
- if DataLock.TryLock() {
- defer DataLock.Unlock()
- count1 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=1 and is_assign=0 and is_transfer != 1`)
- count2 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=2 and is_assign=0 and is_transfer != 1`)
- counts1, counts2, counts3 := int64(0), int64(0), int64(0)
- counts1 = int64(math.Ceil(float64(this.Count) / float64(10) * 5))
- if this.Count-counts1 == 0 {
- counts2 = 0
- counts3 = 0
- } else {
- counts2 = int64(math.Ceil(float64(this.Count) / float64(10) * 4))
- if this.Count-counts1-counts2 == 0 {
- counts3 = 0
- } else {
- counts3 = this.Count - counts1 - counts2
- }
- }
- if counts1 > count1 {
- counts2 += counts1 - count1
- counts1 = count1
- }
- if counts2 > count2 {
- counts3 += counts2 - count2
- counts2 = count2
- }
- logx.Info(count1, count2)
- logx.Info(counts1, counts2, counts3)
- return DrawClues(this.PositionId, counts1, counts2, counts3), 1
- } else {
- return 0, 2
- }
- }
- func DrawClues(positionId, count1, count2, count3 int64) int {
- nowTime := time.Now().Format("2006-01-02 15:04:05")
- seatNumber, name := getSeatNumber(positionId)
- drawCount := 0
- //data1, data2, data3, drawCount := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}, 0
- /*if count1 > 0 {
- data1 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 1, positionId)
- if data1 != nil && len(*data1) > 0 {
- if int64(len(*data1)) >= count1 {
- data11 := (*data1)[0:count1]
- data1 = &data11
- count1 = 0
- } else {
- count1 = count1 - int64(len(*data1))
- }
- }
- }
- if count2 > 0 {
- data2 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 2, positionId)
- if data2 != nil && len(*data2) > 0 {
- if int64(len(*data2)) >= count2 {
- data11 := (*data2)[0:count2]
- data2 = &data11
- count2 = 0
- } else {
- count2 = count2 - int64(len(*data2))
- }
- }
- }
- if count3 > 0 {
- data3 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 3, positionId)
- if data3 != nil && len(*data3) > 0 {
- if int64(len(*data3)) >= count3 {
- data11 := (*data3)[0:count3]
- data3 = &data11
- count3 = 0
- } else {
- count3 = count3 - int64(len(*data3))
- }
- }
- }*/
- //
- /*if data1 != nil && len(*data1) > 0 {
- count := batchDraw(*data1, nowTime, seatNumber, name, positionId, "1")
- drawCount += count
- }
- if data2 != nil && len(*data2) > 0 {
- count := batchDraw(*data2, nowTime, seatNumber, name, positionId, "1")
- drawCount += count
- }
- if data3 != nil && len(*data3) > 0 {
- count := batchDraw(*data3, nowTime, seatNumber, name, positionId, "1")
- drawCount += count
- }*/
- //
- logx.Info("count1,count2,count3 ", count1, count2, count3, drawCount)
- if count1 > 0 {
- counts, counts1 := 0, 0
- for {
- logx.Info("等级1线索领取", count1, counts1, counts)
- data := JyBiTidb.SelectBySql(`SELECT a.label,a.labelChangeTime,a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a
- WHERE a.level_open = 1 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
- counts1++
- if data != nil && len(*data) > 0 {
- count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
- if count > 0 {
- counts++
- }
- }
- if counts == int(count1) {
- drawCount += int(count1)
- break
- }
- if counts1 > 5*int(count1) {
- count2 += count1 - int64(counts)
- drawCount += int(counts)
- break
- }
- }
- }
- if count2 > 0 {
- counts, counts1 := 0, 0
- for {
- logx.Info("等级2线索领取", count2, counts1, counts)
- data := JyBiTidb.SelectBySql(`SELECT a.label,a.labelChangeTime,a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a
- WHERE a.level_open = 2 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
- counts1++
- if data != nil && len(*data) > 0 {
- count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
- if count > 0 {
- counts++
- }
- }
- if counts == int(count2) {
- drawCount += int(count2)
- break
- }
- if counts1 > 5*int(count2) {
- count3 += count2 - int64(counts)
- drawCount += int(counts)
- break
- }
- }
- }
- if count3 > 0 {
- counts, counts1 := 0, 0
- for {
- logx.Info("等级3线索领取", count3, counts1, counts)
- data := JyBiTidb.SelectBySql(`SELECT a.label,a.labelChangeTime, a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a
- WHERE a.level_open = 3 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
- counts1++
- if data != nil && len(*data) > 0 {
- count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
- if count > 0 {
- counts++
- }
- }
- if counts == int(count3) {
- drawCount += int(count3)
- break
- }
- if counts1 > 5*int(count3) {
- drawCount += int(counts)
- break
- }
- }
- }
- return drawCount
- }
- func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string, positionId int64, dataType string) int {
- count := 0
- for _, v := range data {
- clueId := common.Int64All(v["id"])
- //cluename := common.ObjToString(v["cluename"])
- /* if dataType == "2" {
- cdata := JyBiMysql.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1, "company_nature": 0, "company_verification": 1}, "", "")
- if cdata != nil && len(*cdata) > 0 {
- salePositionId := common.Int64All((*cdata)["position_id"])
- if pcount := JyBiMysql.Count("dwd_f_crm_personnel_management", map[string]interface{}{"resign": 0, "position_id": salePositionId}); pcount > 0 {
- logx.Info("当前线索有在职销售 ", clueId, cluename)
- return count
- } else {
- saledata := JyBiMysql.SelectBySql(`SELECT position_id from dwd_d_crm_department_level_succbi WHERE bi_pcode in (SELECT bi_pcode from dwd_d_crm_department_level_succbi WHERE position_id = ?) AND resign = 0`, salePositionId)
- if saledata != nil && len(*saledata) > 0 {
- isOk := false
- for _, s := range *saledata {
- sid := common.Int64All(s["position_id"])
- if sid == positionId {
- isOk = true
- }
- }
- if !isOk {
- logx.Info("当前线索销售离职,只能同部门领取 ", clueId, cluename)
- return count
- }
- }
- }
- }
- }*/
- trailstatus := common.ObjToString(v["trailstatus"])
- if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
- updateClue := map[string]interface{}{
- "position_id": positionId,
- "seatNumber": seatNumber,
- "is_assign": 1,
- "updatetime": nowTime,
- "comeintime": nowTime,
- "comeinsource_private": 3,
- "is_task": 1,
- "task_time": nowTime,
- "tasktime": nowTime,
- "taskstatus": 0,
- "tasksource": "领取公海线索",
- "level_open": nil,
- "clue_level": nil,
- }
- updateClue["trailstatus"] = "01"
- ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
- recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": "/",
- "new_value": name,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": positionId,
- })
- recordId1 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_type": "领取公海线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": positionId,
- })
- recordId2 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_type": "加入任务车",
- "new_value": "领取公海线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": positionId,
- })
- recordId3, recordId4 := int64(0), int64(0)
- recordId3 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "商机线索",
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": positionId,
- })
- recordId4 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "商机线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": positionId,
- })
- //标签处理
- label := gconv.Int64(v["label"])
- trailstatusCode := gconv.String(v["trailstatus"])
- LabelHandel(tx, label, 3, clueId, "", "01", trailstatusCode, name, "/", 0)
- return ok1 && recordId > 0 && recordId1 > 0 && recordId2 > 0 && recordId3 > -1 && recordId4 > -1
- }) {
- logx.Info("领取线索成功")
- count++
- } else {
- logx.Info("领取线索失败")
- }
- }
- return count
- }
- func getSeatNumber(positionId int64) (seatNumber, name string) {
- saleData := JyBiTidb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": positionId}, "", "")
- if saleData != nil && len(*saleData) > 0 {
- seatNumber = common.ObjToString((*saleData)["seat_number"])
- name = common.ObjToString((*saleData)["name"])
- }
- return
- }
- func ClueImport(this *biservice.ClueImportReq) *biservice.ClueImportResp {
- result, status := ClueImportSync(this)
- return &biservice.ClueImportResp{
- ErrorCode: 0,
- Data: &biservice.ClueImport{
- Status: int64(status),
- Result: result,
- },
- }
- }
- func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
- if ClueImportLock.TryLock() {
- defer ClueImportLock.Unlock()
- result, status, dataArr, countOpen, countAdd, countPrivate := "", 1, []map[string]interface{}{}, 0, 0, 0
- phoneRegexp := regexp.MustCompile(`^1[0-9]{10}$`)
- nowTime, counts := time.Now().Format(date.Date_Full_Layout), 0
- data := JyBiTidb.Find("dwd_f_crm_bulk_import", map[string]interface{}{"PCBH": this.Pcbh}, "", "", -1, -1)
- if data != nil && len(*data) > 0 {
- for k, v := range *data {
- companyName := common.ObjToString(v["GSMC"])
- name := common.ObjToString(v["XM"])
- position := common.ObjToString(v["ZW"])
- phone := common.ObjToString(v["LXFS"])
- clueSource := common.ObjToString(v["XSXSLY"])
- if companyName == "" {
- companyName = phone
- }
- isOK, isOks, dataMap := false, true, map[string]interface{}{
- "cluename": companyName,
- "companyName": common.ObjToString(v["GSMC"]),
- "name": name,
- "phone": phone,
- "position": position,
- "clueSource": clueSource,
- }
- if phone == "" {
- isOks = false
- counts++
- result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“联系方式为空”"
- } else {
- if !phoneRegexp.MatchString(phone) {
- if !isOks {
- result += ",“联系方式格式有误”"
- } else {
- counts++
- result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“联系方式格式有误”"
- }
- isOks = false
- } else {
- userData := JyBiTidb.FindOne("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}, "", "")
- if userData != nil && len(*userData) > 0 {
- source := common.ObjToString((*userData)["source"])
- userId, belong_to := "", ""
- uId := common.ObjToString((*userData)["baseinfo_id"])
- baseData := JyBiTidb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uId}, "", "")
- if baseData != nil {
- userId = common.ObjToString((*baseData)["userid"])
- belong_to = common.ObjToString((*baseData)["belong_to"])
- }
- if source == "0205" {
- if !isOks {
- result += ",“该线索已归属域外”"
- } else {
- counts++
- result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“该线索已归属域外”"
- }
- isOks = false
- } else if strings.HasPrefix(belong_to, "03") {
- if !isOks {
- result += ",“该线索已归属合作渠道一切都好”"
- } else {
- counts++
- result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“该线索已归属合作渠道一切都好”"
- }
- isOks = false
- } else {
- isOK = true
- dataMap["userId"] = userId
- dataMap["uId"] = uId
- }
- } else {
- dataMap["uId"] = common.GetRandom(32)
- dataMap["isOk"] = "0"
- }
- }
- }
- if clueSource == "" {
- if !isOks {
- result += ",“销售线索来源为空”"
- } else {
- counts++
- result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“销售线索来源为空”"
- }
- isOks = false
- } else {
- sourceData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"name": clueSource}, "", "")
- if sourceData == nil || len(*sourceData) == 0 {
- if !isOks {
- result += ",“销售线索来源不存在”"
- } else {
- counts++
- result += fmt.Sprint(counts) + ".第" + fmt.Sprint(k+2) + "行,“销售线索来源不存在”"
- }
- isOks = false
- } else {
- isOK = true
- code := common.ObjToString((*sourceData)["code"])
- pcode := common.ObjToString((*sourceData)["pcode"])
- dataMap["top_cluetype"] = pcode
- dataMap["sub_cluetype"] = code
- dataMap["clue_level"] = gconv.String((*sourceData)["clue_level"])
- }
- }
- if isOK {
- dataArr = append(dataArr, dataMap)
- }
- if !isOks {
- result += "\n"
- }
- }
- if result != "" {
- status = -1
- JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
- "DRJSSJ": nowTime, //结束时间
- "SBYY": result, //失败原因
- "DRZT": "导入失败",
- })
- } else {
- for _, v := range dataArr {
- phone := common.ObjToString(v["phone"])
- cluename := common.ObjToString(v["cluename"])
- name := common.ObjToString(v["name"])
- level := gconv.String(v["clue_level"])
- position := common.ObjToString(v["position"])
- isGroup, isCommerce := CompanyType(cluename)
- clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
- if clueData == nil || len(*clueData) == 0 {
- countAdd++
- if v["isOk"] != nil {
- JyBiTidb.Insert("dwd_f_userbase_baseinfo", map[string]interface{}{
- "userid": v["userId"],
- "uid": v["uId"],
- "name": name,
- "phone": phone,
- "belong_to": "0100",
- "source": "0203",
- "company_name": cluename,
- "status": 3,
- "createtime": nowTime,
- "updatetime": nowTime,
- })
- }
- clueId := JyBiTidb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
- "userid": v["userId"],
- "uid": v["uId"],
- "is_assign": 0,
- "comeintime": nowTime,
- "createtime": nowTime,
- "updatetime": nowTime,
- "cluename": cluename,
- "top_cluetype": v["top_cluetype"],
- "sub_cluetype": v["sub_cluetype"],
- "trailstatus": "01",
- "name": name,
- "phone": phone,
- "position": position,
- "batch_import": this.Pcbh,
- "comeintime_open": nowTime,
- "comeinsource_open": 1,
- "company_nature": isGroup,
- "company_verification": isCommerce,
- })
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": -1,
- "change_type": "创建线索",
- "new_value": "线索导入创建",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- if JyBiTidb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
- JyBiTidb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
- "status": 1,
- "is_delete": 1,
- "createtime": nowTime,
- "updatetime": nowTime,
- "phone": phone,
- "baseinfo_id": v["uId"],
- "source": "0203",
- })
- }
- } else {
- isUpdate := gconv.Int64((*clueData)["is_artificially_modified"])
- if isUpdate == 1 {
- cluename = ""
- } else {
- if gconv.String(v["companyName"]) != "" {
- cluename = gconv.String(v["companyName"])
- } else {
- cluename = ""
- }
- }
- is_assign := common.IntAll((*clueData)["is_assign"])
- clueId := common.Int64All((*clueData)["id"])
- batch_import := common.ObjToString((*clueData)["batch_import"])
- old_cluename := common.ObjToString((*clueData)["cluename"])
- old_name := common.ObjToString((*clueData)["name"])
- old_position := common.ObjToString((*clueData)["position"])
- old_top_cluetype := common.ObjToString((*clueData)["top_cluetype"])
- old_sub_cluetype := common.ObjToString((*clueData)["sub_cluetype"])
- top_cluetype := common.ObjToString(v["top_cluetype"])
- sub_cluetype := common.ObjToString(v["sub_cluetype"])
- label := gconv.Int64(v["label"])
- trailstatusCode := gconv.String(v["trailstatus"])
- old_topname, old_subname := "", ""
- if old_top_cluetype != "" {
- pcodeData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
- if pcodeData != nil && len(*pcodeData) > 0 {
- old_topname = common.ObjToString((*pcodeData)["name"])
- }
- }
- if old_sub_cluetype != "" {
- pcodeData := JyBiTidb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
- if pcodeData != nil && len(*pcodeData) > 0 {
- old_subname = common.ObjToString((*pcodeData)["name"])
- }
- }
- positionId := common.Int64All((*clueData)["position_id"])
- batch_imports := ""
- if is_assign == 0 {
- countOpen++
- if batch_import != "" {
- batch_imports = batch_import + "," + this.Pcbh
- } else {
- batch_imports = this.Pcbh
- }
- updateData := map[string]interface{}{
- "batch_import": batch_imports,
- "updatetime": nowTime,
- "top_cluetype": top_cluetype,
- "sub_cluetype": sub_cluetype,
- }
- if cluename != "" && cluename != old_cluename {
- updateData["cluename"] = cluename
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": -1,
- "change_field": "cluename",
- "change_type": "基本信息变更",
- "old_value": common.If(old_cluename == "", "/", old_cluename),
- "new_value": cluename,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- }
- if name != "" && name != old_name {
- updateData["name"] = name
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": -1,
- "change_field": "name",
- "change_type": "基本信息变更",
- "old_value": common.If(old_name == "", "/", old_name),
- "new_value": name,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- }
- if position != "" && position != old_position {
- updateData["position"] = position
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": -1,
- "change_field": "position",
- "change_type": "基本信息变更",
- "old_value": common.If(old_position == "", "/", old_position),
- "new_value": position,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- }
- if top_cluetype != "" && top_cluetype != old_top_cluetype {
- updateData["position"] = position
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": -1,
- "change_field": "top_cluetype",
- "change_type": "基本信息变更",
- "old_value": common.If(old_topname == "", "/", old_topname),
- "new_value": "批量导入线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- }
- if sub_cluetype != "" && sub_cluetype != old_sub_cluetype {
- updateData["position"] = position
- taskstatus := gconv.Int64((*clueData)["taskstatus"])
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": -1,
- "change_field": "sub_cluetype", //111
- "change_type": "基本信息变更",
- "old_value": common.If(old_subname == "", "/", old_subname),
- "new_value": v["clueSource"],
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- LabelHandel(nil, label, 2, clueId, level, trailstatusCode, trailstatusCode, "", "", taskstatus)
- }
- JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
- } else if is_assign == 1 {
- countPrivate++
- if batch_import != "" {
- batch_imports = batch_import + "," + this.Pcbh
- } else {
- batch_imports = this.Pcbh
- }
- updateData := map[string]interface{}{
- "batch_import": batch_imports,
- "updatetime": nowTime,
- "top_cluetype": v["top_cluetype"],
- "sub_cluetype": v["sub_cluetype"],
- }
- updateData["is_task"] = 1
- updateData["task_time"] = nowTime
- updateData["tasktime"] = nowTime
- updateData["taskstatus"] = 0
- updateData["tasksource"] = "线索来源更新客户"
- if cluename != "" && cluename != old_cluename {
- updateData["cluename"] = cluename
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "cluename",
- "change_type": "基本信息变更",
- "old_value": common.If(old_cluename == "", "/", old_cluename),
- "new_value": cluename,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- }
- if name != "" && name != old_name {
- updateData["name"] = name
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "name",
- "change_type": "基本信息变更",
- "old_value": common.If(old_name == "", "/", old_name),
- "new_value": name,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- }
- if position != "" && position != old_position {
- updateData["position"] = position
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position",
- "change_type": "基本信息变更",
- "old_value": common.If(old_position == "", "/", old_position),
- "new_value": position,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- }
- if top_cluetype != "" && top_cluetype != old_top_cluetype {
- updateData["position"] = position
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "top_cluetype",
- "change_type": "基本信息变更",
- "old_value": common.If(old_topname == "", "/", old_topname),
- "new_value": "批量导入线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- taskstatus := gconv.Int64((*clueData)["taskstatus"])
- LabelHandel(nil, label, 2, positionId, level, trailstatusCode, trailstatusCode, "", "", taskstatus)
- }
- if sub_cluetype != "" && sub_cluetype != old_sub_cluetype {
- updateData["position"] = position
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "sub_cluetype", //222
- "change_type": "基本信息变更",
- "old_value": common.If(old_subname == "", "/", old_subname),
- "new_value": v["clueSource"],
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- }
- JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateData)
- JyBiTidb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_type": "加入任务车",
- "new_value": "线索来源更新客户",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": this.PositionId,
- })
- }
- }
- }
- JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
- "DRJSSJ": nowTime, //结束时间
- "ZJXST": len(dataArr), //总计线索条数
- "ZFXSSHXST": countPrivate, //私海重复条数
- "ZFXSGHXST": countOpen, //公海重复条数
- "XZXST": countAdd, //新增条数
- "DRZT": "导入成功",
- })
- }
- }
- return result, status
- } else {
- JyBiTidb.Update("dwd_f_crm_bulk_import_record", map[string]interface{}{"PCBH": this.Pcbh}, map[string]interface{}{
- "DRJSSJ": time.Now().Format(date.Date_Full_Layout), //结束时间
- "SBYY": "有正在进行的导入任务", //失败原因
- "DRZT": "导入失败",
- })
- return "有正在进行的导入任务", 2
- }
- }
- func doGet(url string) ([]byte, error) {
- req, err := http.NewRequest("GET", url, nil)
- if err != nil {
- return nil, err
- }
- resp, err := http.DefaultClient.Do(req)
- if err != nil {
- return nil, err
- }
- bs, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return nil, err
- }
- defer func() {
- _ = resp.Body.Close()
- }()
- logx.Info(url, "调用结果 ", string(bs))
- return bs, nil
- }
- func FindClueInfo(in *biservice.FindClueInfoReq) (map[string]interface{}, int64) {
- data := map[string]interface{}{}
- uId := ""
- contactsData := JyBiMysql.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", in.Phone)
- if contactsData != nil && len(*contactsData) > 0 {
- if common.ObjToString((*contactsData)[0]["baseinfo_id"]) != "" {
- uId = common.ObjToString((*contactsData)[0]["baseinfo_id"])
- }
- }
- if uId == "" {
- return data, 1
- }
- //线索查询
- clueData := JyBiMysql.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
- if clueData != nil && len(*clueData) > 0 {
- data["clue_id"] = gconv.Int64((*clueData)["id"])
- data["position_id"] = in.PositionId
- data["uid"] = gconv.String((*clueData)["uid"])
- data["userid"] = gconv.String((*clueData)["userid"])
- data["clue_position_id"] = gconv.Int64((*clueData)["position_id"])
- } else {
- return data, 1
- }
- return data, 0
- }
- // 线索标签修改 label labelChangeTime
- func LabelHandel(tx *sql.Tx, oldlabelType, labelType, clueId int64, level, oldTrailstatusCode, trailstatusCode, name, oldName string, status int64) {
- log.Println("线索标签修改:", "oldlabelType:", oldlabelType, "labelType:", labelType, "clueId:", clueId, "level:", level, "oldTrailstatusCode:", oldTrailstatusCode, "trailstatusCode:", trailstatusCode, "status:", status)
- //先查询以前什么类型
- if trailstatusCode != "01" && oldTrailstatusCode != "01" {
- log.Println("不属于商机类型", clueId)
- return
- }
- if status != 0 {
- log.Println("不属于未完成", clueId)
- return
- }
- updateLabelType := int64(0)
- nowStr := time.Now().Format("2006-01-02")
- if labelType == 2 {
- if level != "A" && level != "B" && level != "C" {
- return
- }
- //查询以前是什么数据
- //人员变更
- if oldlabelType != 1 {
- updateLabelType = labelType
- }
- } else {
- //查询以前是什么数据
- if oldName != name {
- if oldlabelType != 1 && oldlabelType != 2 {
- updateLabelType = 3
- }
- }
- }
- if updateLabelType > 0 {
- ok := false
- if tx == nil {
- ok = JyBiTidb.Update("dwd_f_crm_clue_info", map[string]interface{}{
- "id": clueId,
- }, map[string]interface{}{
- "label": updateLabelType,
- "labelChangeTime": nowStr,
- })
- } else {
- ok = JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
- "id": clueId,
- }, map[string]interface{}{
- "label": updateLabelType,
- "labelChangeTime": nowStr,
- })
- }
- log.Println("线索标签修改:", ok)
- }
- }
|