js代码大全网站源码(用120行JS代码,实现多条件数据去重合并(附源码))

上周接到一个CRM的项目,要求做客户去重

具体是一个客户包含男方联系信息和女方联系信息,联系信息字段为:姓名、性别、年龄、电话1、电话2、微信1、微信2。要求录入客户时,如果电话或者微信已存在于系统,则将录入的数据合并到现有的客户当中,合并规则:现有客户已存在数据的字段不变,仅合并新录入的字段数据

老规矩我们还是在白码低代码开发平台上做。

实现过程如下:

1、数据表设计




2、功能实现

2.1 填写-基础资料




2.2 填写-男方女方联系资料

此处先使用“交互-输入”步骤记录填写的数据,待去重判断完毕后再做处理。




3、去重处理

1)获取填写的电话和微信,据此在数据库中查询“客户联系资料”表,得到linkList。

代码:

   let man = await $model.getValue("5fae403073276c5e9b02ec3c");//交互输入的男方     let woman = await $model.getValue("5fae403073276c5e9b02ec3d");//交互输入的女方     let customer = await $params.customer;//填写客户基础资料     let phoneList = [];//填写的电话     let phone1 = man["field_1605181125961"];//男电话1     if (phone1) phoneList.push(phone1);     let phone2 = man["field_1605181149276"];//男电话2     if (phone2) phoneList.push(phone2);     let phone3 = woman["field_1605181195092"];//女电话1     if (phone3) phoneList.push(phone3);     let phone4 = woman["field_1605181195341"];//女电话2 if (phone4) phoneList.push(phone4);     let wxList = [];//填写的微信     let wx1 = man["field_1605181124563"];//男微信1     if (wx1) phoneList.push(wx1);     let wx2 = man["field_1605181125184"];//男微信2     if (wx2) phoneList.push(wx2);     let wx3 = woman["field_1605181194364"];//女微信1     if (wx3) phoneList.push(wx3);     let wx4 = woman["field_1605181194697"];//女微信2 if (wx4) phoneList.push(wx4);     //根据填写的电话微信查询联系人资料     let linkList = await $plugin.data.queryData("5fae403073276c5e9b02eba7", {         $or: [             { "5fae403073276c5e9b02ebe6": phoneList },//电话1             { "5fae403073276c5e9b02ebe7": phoneList },//电话2             { "5fae403073276c5e9b02ebe4": wxList },//微信1             { "5fae403073276c5e9b02ebe5": wxList }//微信2         ]     });

2)若linkList长度大于0,表示已存在客户,进行客户基础资料、男方、女方联系数据合并,并弹出合并提示。

代码:

 if (linkList.length > 0) {         //合并客户基本资料         let repeatCustDetail = await $plugin.data.getData("5fae403073276c5e9b02eba6", linkList[0]["5fae403073276c5e9b02ebe9"]);//根据查到的重复联系资料,获取客户基本资料         await $plugin.data.updateData("5fae403073276c5e9b02eba6", repeatCustDetail._id, {             //原字段存在值则保持不变             "5fae403073276c5e9b02ebd6": repeatCustDetail["5fae403073276c5e9b02ebd6"] || customer["5fae403073276c5e9b02ebd6"], //咨询内容             "5fae403073276c5e9b02ebd7": repeatCustDetail["5fae403073276c5e9b02ebd7"] || customer["5fae403073276c5e9b02ebd7"],//客户类型             "5fae403073276c5e9b02ebd8": repeatCustDetail["5fae403073276c5e9b02ebd8"] || customer["5fae403073276c5e9b02ebd8"],//客户需求             "5fae403073276c5e9b02ebd9": repeatCustDetail["5fae403073276c5e9b02ebd9"] || customer["5fae403073276c5e9b02ebd9"],//所属项目             "5fae403073276c5e9b02ebde": repeatCustDetail["5fae403073276c5e9b02ebde"] || customer["5fae403073276c5e9b02ebde"],//备注         });         //合并男方资料         let repeatMan = await $plugin.data.getData("5fae403073276c5e9b02eba7", repeatCustDetail["5fae403073276c5e9b02ebd4"]);         let manName = repeatMan["5fae403073276c5e9b02ebe1"] || man["field_1605181119810"];         let manAge = repeatMan["5fae403073276c5e9b02ebe3"] != 0 ? repeatMan["5fae403073276c5e9b02ebe3"] : man["field_1605181120513"];         await $plugin.data.updateData("5fae403073276c5e9b02eba7", repeatMan._id, {             //原字段存在值则保持不变             "5fae403073276c5e9b02ebe1": manName,//姓名             "5fae403073276c5e9b02ebe3": manAge || 0,//年龄             "5fae403073276c5e9b02ebe4": repeatMan["5fae403073276c5e9b02ebe4"] || wx1,//w1             "5fae403073276c5e9b02ebe5": repeatMan["5fae403073276c5e9b02ebe5"] || wx2,//w2             "5fae403073276c5e9b02ebe6": repeatMan["5fae403073276c5e9b02ebe6"] || phone1,//p1             "5fae403073276c5e9b02ebe7": repeatMan["5fae403073276c5e9b02ebe7"] || phone2,//p2         });         //合并女方资料         let repeatWoman = await $plugin.data.getData("5fae403073276c5e9b02eba7", repeatCustDetail["5fae403073276c5e9b02ebd5"]);         let womanName = repeatWoman["5fae403073276c5e9b02ebe1"] || woman["field_1605181191670"];         let womanAge = repeatWoman["5fae403073276c5e9b02ebe3"] != 0 ? repeatWoman["5fae403073276c5e9b02ebe3"] : woman["field_1605181192156"];         await $plugin.data.updateData("5fae403073276c5e9b02eba7", repeatWoman._id, {             //原字段存在值则保持不变             "5fae403073276c5e9b02ebe1": womanName,//姓名             "5fae403073276c5e9b02ebe3": womanAge || 0,//年龄             "5fae403073276c5e9b02ebe4": repeatWoman["5fae403073276c5e9b02ebe4"] || wx3,//w1             "5fae403073276c5e9b02ebe5": repeatWoman["5fae403073276c5e9b02ebe5"] || wx4,//w2             "5fae403073276c5e9b02ebe6": repeatWoman["5fae403073276c5e9b02ebe6"] || phone3,//p1             "5fae403073276c5e9b02ebe7": repeatWoman["5fae403073276c5e9b02ebe7"] || phone4,//p2         });         //删除新建的客户基础资料         await $plugin.data.removeData("5fae403073276c5e9b02eba6", customer._id);         //调用功能:提示         await $model.command("program", {             flow: "5fae403073276c5e9b02ec2f",             data: {                 "5fae403073276c5e9b02ec3f": {                     "field_1605239257122": "去重提示",                     "field_1605241201785": "所填号码或微信已存在,填写数据已合并到序号为【" + repeatCustDetail["5fae403073276c5e9b02ebcf"] + "】的客户中。"                 }             }         });     }

3)若linkList长度为0,表示可以创建新客户,将“交互输入”的联系资料保存。

代码:

js代码大全

        //新客户------------------------------------------------------------------         //创建男方         await $plugin.data.saveData("5fae403073276c5e9b02eba7", {             "5fae403073276c5e9b02ebe1": man["field_1605181119810"],//姓名             "5fae403073276c5e9b02ebe2": "男",//性别             "5fae403073276c5e9b02ebe3": man["field_1605181120513"] || 0,//年龄             "5fae403073276c5e9b02ebe4": wx1,//w1             "5fae403073276c5e9b02ebe5": wx2,//w2             "5fae403073276c5e9b02ebe6": phone1,//p1             "5fae403073276c5e9b02ebe7": phone2,//p2             "5fae403073276c5e9b02ebe9": customer._id//客戶基本信息         });         //创建女方         await $plugin.data.saveData("5fae403073276c5e9b02eba7", {             "5fae403073276c5e9b02ebe1": woman["field_1605181191670"],//姓名             "5fae403073276c5e9b02ebe2": "女",//性别             "5fae403073276c5e9b02ebe3": woman["field_1605181192156"] || 0,//年龄             "5fae403073276c5e9b02ebe4": wx3,//w1             "5fae403073276c5e9b02ebe5": wx4,//w2             "5fae403073276c5e9b02ebe6": phone3,//p1             "5fae403073276c5e9b02ebe7": phone4,//p2             "5fae403073276c5e9b02ebe9": customer._id//客戶基本信息         });4、运行效果

4.1录入新客户



4.2客户去重


您可以还会对下面的文章感兴趣

使用微信扫描二维码后

点击右上角发送给好友