Commit e66d70cf by 任晓松

update

parent 2ef8835a
...@@ -5,140 +5,17 @@ class TaskAction extends APIBase { ...@@ -5,140 +5,17 @@ class TaskAction extends APIBase {
constructor() { constructor() {
super(); super();
this.orderinfoSve = system.getObject("service.dbcorder.orderinfoSve"); this.orderinfoSve = system.getObject("service.dbcorder.orderinfoSve");
this.opneedinfoSve = system.getObject("service.dbneed.opneedinfoSve");
} }
/** /**
* 同步蜂擎需求商机 * 接口跳转-POST请求
* @returns {Promise<void>} * action_process 执行的流程
*/ * action_type 执行的类型
async taskNeed() { * action_body 执行的参数
//获取 need_info_fq 未处理的需求 */
let fqNeeds = await this.needinfofqDao.getAllNeeds() async taskNeed(pobj, qobj, req) {
let ids = []; var result = await this.opneedinfoSve.syncNeedBusiness();
let needDict = {}; return result;
for (let i = 0; i < fqNeeds.length; i++) {
ids.push(fqNeeds[i].channelNeedNo);
needDict[fqNeeds[i].channelNeedNo] = fqNeeds[i].status;
}
//根据ids 获取企服通需求
let needs = await this.needinfoDao.getNeedsByIds(ids);
let setObj = [];
let existIds = [];
let ids1 = [];
let ids2 = [];
let ids3 = [];
//已经存在的需求,更改状态
for(let i = 0;i < needs.length; i++){
let need = needs[i];
let obj = {
id:need.id,
}
if(needDict[need.channelNeedNo] == 1){
obj.status = 'ygj';
obj.statusName = '已跟进';
ids1.push(need.channelNeedNo);
}
if(needDict[need.channelNeedNo] == 2){
obj.status = 'ygb';
obj.statusName = '已关闭';
ids2.push(need.channelNeedNo);
}
if(needDict[need.channelNeedNo] == 3){
obj.status = 'ycd';
obj.statusName = '已成单';
ids3.push(need.channelNeedNo);
}
setObj.push(obj);
existIds.push(need.channelNeedNo);
}
// 不存在的订单 添加到企服通
let createObj = [];
let setFqObj1 = [];
let setFqObj2 = [];
for(let i =0;i<fqNeeds.length;i++){
let fqNeed = fqNeeds[i];
if(!existIds.includes(fqNeed.channelNeedNo)){
let obj = {
channelNeedNo:fqNeed.channelNeedNo,
city:fqNeed.city,
province:fqNeed.province,
publishContent: fqNeed.publishContent,
publishMobile:fqNeed.publishMobile,
notes:fqNeed.notes,
followContent:fqNeed.followContent,
disposeNotes:fqNeed.disposeNotes,
typeCode:fqNeed.typeCode,
created_at:fqNeed.created_at
}
if(fqNeed.status == 1){
obj.status = 'ygj';
obj.statusName = '已跟进';
}
if(fqNeed.status == 2){
obj.status = 'ygb';
obj.statusName = '已关闭';
}
if(fqNeed.status == 3){
obj.status = 'ycd';
obj.statusName = '已成单';
}
if(fqNeed.status == 4 || fqNeed.status == 0){
obj.status = 'yts';
obj.statusName = '已推送';
}
if(['360_icp ','360_edi','360_sbzc'].includes(fqNeed.sourceCode)){
obj.uapp_id = 50;
}
if(['baidu_edi','baidu_gsreg','baidu_icp','baidu_radiotv','baidu_wangwen'].includes(fqNeed.sourceCode)){
obj.uapp_id = 44;
}
if(['edi_ali','ic_ali','icp_ali','tm_ali','tmd_ali'].includes(fqNeed.sourceCode)){
obj.uapp_id = 18;
}
if(['youke'].includes(fqNeed.sourceCode)){
obj.uapp_id = 40;
}
if(['tm_jdyun'].includes(fqNeed.sourceCode)){
obj.uapp_id = 31;
}
if(['tm_bw'].includes(fqNeed.sourceCode)){
obj.uapp_id = 35;
}
if(['tm_1688'].includes(fqNeed.sourceCode)){
obj.uapp_id = 0;
}
createObj.push(obj);
setFqObj2.push(fqNeed.channelNeedNo);
}else {
setFqObj1.push(fqNeed.channelNeedNo);
}
}
//企服通 批量更新状态
let updateRet =null;
if(setObj.length>0){
// updateRet = await this.needinfoDao.bulkUpdate(setObj);
if(ids1.length>0){
updateRet = await this.needinfoDao.bulkUpdateStatus('ygj','已跟进',ids1);
}
if(ids2.length>0){
updateRet = await this.needinfoDao.bulkUpdateStatus('ygb','已关闭',ids2);
}
if(ids3.length>0){
updateRet = await this.needinfoDao.bulkUpdateStatus('ycd','已成单',ids3);
}
if(updateRet.length > 0){
updateRet = await this.needinfofqDao.bulkUpdate(setFqObj1);
}
}
//企服通 批量添加
if(createObj.length>0){
updateRet = await this.needinfoDao.bulkCreate(createObj);
if(updateRet.length >0 ){
updateRet = await this.needinfofqDao.bulkUpdate(setFqObj2);
}
}
return system.getResult(updateRet)
} }
} }
......
...@@ -11,6 +11,7 @@ class NeedinfofqDao extends Dao { ...@@ -11,6 +11,7 @@ class NeedinfofqDao extends Dao {
where: { where: {
handleStatus: 0 handleStatus: 0
}, },
order: [["id","desc"]],
limit: 300 limit: 300
}) })
return fqNeeds; return fqNeeds;
......
...@@ -23,7 +23,7 @@ class OrderInfoService extends ServiceBase { ...@@ -23,7 +23,7 @@ class OrderInfoService extends ServiceBase {
async taskSyncOrderStatus(){ async taskSyncOrderStatus(){
let sql="SELECT * FROM `c_order_info_fq` LIMIT 300"; let sql="SELECT * FROM `c_order_info_fq` LIMIT 300";
var this.dao.customQuery(sql); var result =await this.customQuery(sql);
} }
//--------------------task--------------ednd--------------------- //--------------------task--------------ednd---------------------
......
...@@ -10,6 +10,7 @@ class NeedinfoService extends ServiceBase { ...@@ -10,6 +10,7 @@ class NeedinfoService extends ServiceBase {
this.needsolutionSve = system.getObject("service.dbneed.needsolutionSve"); this.needsolutionSve = system.getObject("service.dbneed.needsolutionSve");
this.needsolutionDao = system.getObject("db.dbneed.needsolutionDao"); this.needsolutionDao = system.getObject("db.dbneed.needsolutionDao");
this.needinfoDao = system.getObject("db.dbneed.needinfoDao"); this.needinfoDao = system.getObject("db.dbneed.needinfoDao");
this.needinfofqDao = system.getObject("db.dbneed.needinfofqDao");
} }
async getItemByNeedNo (pobj) { async getItemByNeedNo (pobj) {
var item = await this.dao.getItemByNeedNo(pobj.actionBody.needNo); var item = await this.dao.getItemByNeedNo(pobj.actionBody.needNo);
...@@ -394,6 +395,142 @@ class NeedinfoService extends ServiceBase { ...@@ -394,6 +395,142 @@ class NeedinfoService extends ServiceBase {
} }
return system.getResultSuccess(); return system.getResultSuccess();
} }
/**
* 同步蜂擎需求商机
* @returns {Promise<void>}
*/
async syncNeedBusiness() {
//获取 need_info_fq 未处理的需求
let fqNeeds = await this.needinfofqDao.getAllNeeds()
let ids = [];
let needDict = {};
for (let i = 0; i < fqNeeds.length; i++) {
ids.push(fqNeeds[i].channelNeedNo);
needDict[fqNeeds[i].channelNeedNo] = fqNeeds[i].status;
}
//根据ids 获取企服通需求
let needs = await this.needinfoDao.getNeedsByIds(ids);
let setObj = [];
let existIds = [];
let ids1 = [];
let ids2 = [];
let ids3 = [];
//已经存在的需求,更改状态
for(let i = 0;i < needs.length; i++){
let need = needs[i];
let obj = {
id:need.id,
}
if(needDict[need.channelNeedNo] == 1){
obj.status = 'ygj';
obj.statusName = '已跟进';
ids1.push(need.channelNeedNo);
}
if(needDict[need.channelNeedNo] == 2){
obj.status = 'ygb';
obj.statusName = '已关闭';
ids2.push(need.channelNeedNo);
}
if(needDict[need.channelNeedNo] == 3){
obj.status = 'ycd';
obj.statusName = '已成单';
ids3.push(need.channelNeedNo);
}
setObj.push(obj);
existIds.push(need.channelNeedNo);
}
// 不存在的订单 添加到企服通
let createObj = [];
let setFqObj1 = [];
let setFqObj2 = [];
for(let i =0;i<fqNeeds.length;i++){
let fqNeed = fqNeeds[i];
if(!existIds.includes(fqNeed.channelNeedNo)){
let obj = {
channelNeedNo:fqNeed.channelNeedNo,
city:fqNeed.city,
province:fqNeed.province,
publishContent: fqNeed.publishContent,
publishMobile:fqNeed.publishMobile,
notes:fqNeed.notes,
followContent:fqNeed.followContent,
disposeNotes:fqNeed.disposeNotes,
typeCode:fqNeed.typeCode,
created_at:fqNeed.created_at
}
if(fqNeed.status == 1){
obj.status = 'ygj';
obj.statusName = '已跟进';
}
if(fqNeed.status == 2){
obj.status = 'ygb';
obj.statusName = '已关闭';
}
if(fqNeed.status == 3){
obj.status = 'ycd';
obj.statusName = '已成单';
}
if(fqNeed.status == 4 || fqNeed.status == 0){
obj.status = 'yts';
obj.statusName = '已推送';
}
if(['360_icp ','360_edi','360_sbzc'].includes(fqNeed.sourceCode)){
obj.uapp_id = 50;
}
if(['baidu_edi','baidu_gsreg','baidu_icp','baidu_radiotv','baidu_wangwen'].includes(fqNeed.sourceCode)){
obj.uapp_id = 44;
}
if(['edi_ali','ic_ali','icp_ali','tm_ali','tmd_ali'].includes(fqNeed.sourceCode)){
obj.uapp_id = 18;
}
if(['youke'].includes(fqNeed.sourceCode)){
obj.uapp_id = 40;
}
if(['tm_jdyun'].includes(fqNeed.sourceCode)){
obj.uapp_id = 31;
}
if(['tm_bw'].includes(fqNeed.sourceCode)){
obj.uapp_id = 35;
}
if(['tm_1688'].includes(fqNeed.sourceCode)){
obj.uapp_id = 0;
}
if(!setFqObj2.includes(fqNeed.channelNeedNo)){
createObj.push(obj);
setFqObj2.push(fqNeed.channelNeedNo);
}
}else {
setFqObj1.push(fqNeed.channelNeedNo);
}
}
//企服通 批量更新状态
let updateRet =null;
if(setObj.length>0){
// updateRet = await this.needinfoDao.bulkUpdate(setObj);
if(ids1.length>0){
updateRet = await this.needinfoDao.bulkUpdateStatus('ygj','已跟进',ids1);
}
if(ids2.length>0){
updateRet = await this.needinfoDao.bulkUpdateStatus('ygb','已关闭',ids2);
}
if(ids3.length>0){
updateRet = await this.needinfoDao.bulkUpdateStatus('ycd','已成单',ids3);
}
if(updateRet.length > 0){
updateRet = await this.needinfofqDao.bulkUpdate(setFqObj1);
}
}
//企服通 批量添加
if(createObj.length>0){
updateRet = await this.needinfoDao.bulkCreate(createObj);
if(updateRet.length >0 ){
updateRet = await this.needinfofqDao.bulkUpdate(setFqObj2);
}
}
return system.getResult(updateRet)
}
} }
module.exports = NeedinfoService; module.exports = NeedinfoService;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment