Commit 107a6e24 by 宋毅

Merge branch 'center-order' of gitlab.gongsibao.com:jiangyong/zhichan into center-order

parents 33d48d3b b0a619a6
......@@ -28,7 +28,7 @@ class APIBase {
return system.getResultSuccess();
}
}
if (["updateTmStatus"].indexOf(methodname) >= 0) {
if (["updateTmStatus","bulkCreateNeeds","bulkCreateOrders"].indexOf(methodname) >= 0) {
return system.getResultSuccess();
}
if (!pobj.appInfo) {
......
......@@ -48,6 +48,9 @@ class IcAPI extends APIBase {
case "getStatisticsByProduct":
opResult = await this.opNeedInfoSve.getStatisticsByProduct(pobj);
break;
case "getNeedProductType":
opResult = await this.opNeedInfoSve.getNeedProductType(pobj);
break;
case "getStatisticsByArea":
opResult = await this.opNeedInfoSve.getStatisticsByCity(pobj);
break;
......@@ -60,6 +63,9 @@ class IcAPI extends APIBase {
case "getNeedComparisonList":
opResult = await this.opNeedInfoSve.getNeedComparisonList(pobj,pobj.actionBody);
break;
case "updateNeedPushStatus":
opResult = await this.opNeedInfoSve.updateNeedPushStatus(pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
......@@ -5,18 +5,27 @@ class TaskAction extends APIBase {
constructor() {
super();
this.orderinfoSve = system.getObject("service.dbcorder.orderinfoSve");
this.opneedinfoSve = system.getObject("service.dbneed.opneedinfoSve");
}
/**
* 接口跳转-POST请求
* 需求商机同步
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async taskNeed(pobj, qobj, req) {
if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空");
}
var result = await this.opActionProcess(pobj, pobj.actionType, req);
var result = await this.opneedinfoSve.syncNeedBusiness();
return result;
}
/**
* 订单商机同步
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async taskOrder(pobj, qobj, req) {
var result = await this.orderinfoSve.syncOrderBusiness();
return result;
}
......
......@@ -50,6 +50,11 @@ class Dao {
return this.model.findAll({ attributes: qobj.fields });
}
}
async findAll(qobj, t) {
var apps = await this.model.findAll(qobj);
return apps;
}
async bulkDeleteByWhere(whereParam, t) {
var en = null;
if (t != null && t != 'undefined') {
......
const system = require("../../../system");
const Dao = require("../../dao.base");
const {Op} = require("sequelize");
class OrderInfoDao extends Dao {
constructor() {
super(Dao.getModelName(OrderInfoDao));
......@@ -56,5 +57,50 @@ class OrderInfoDao extends Dao {
await this.customInsert(sql, null, t);
return system.getResultSuccess()
}
/**
* 根据ids 获取需求
* @param ids
* @returns {Promise<void>}
*/
async getOrdersByIds(ids){
let orders = await this.findAll({
where: {
channelOrderNo: {
[Op.in]:ids
}
}
})
return orders;
}
/**
* 批量更新
* @param needs
* @returns {Promise<Array<Model>|*>}
*/
async bulkUpdate(orders){
let result = await this.bulkCreate(orders,{
fields:["id", "status","statusName"] ,
updateOnDuplicate: ["status","statusName"]
});
return result;
}
/**
* 批量更新
* @param needs
* @returns {Promise<Array<Model>|*>}
*/
async bulkUpdateStatus(status,statusName,ids){
let result = await this.updateByWhere({orderStatus:status,orderStatusName:statusName},{
where : {
channelOrderNo:{
[Op.in]:ids
}
}
});
return result;
}
}
module.exports = OrderInfoDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
const {Op} = require("sequelize");
class OrderinfofqDao extends Dao {
constructor() {
super(Dao.getModelName(OrderinfofqDao));
}
/**
* 取300条未处理的数据
* @returns {Promise<Array<Model>>}
*/
async getAllOrders(){
let fqNeeds = await this.findAll({
where: {
handleStatus: 0
},
order: [["id","desc"]],
limit: 300
})
return fqNeeds;
}
/**
* 批量更新
* @param needs
* @returns {Promise<Array<Model>|*>}
*/
async bulkUpdate(ids){
let result = await this.updateByWhere({handleStatus:1},{
where : {
channelOrderNo:{
[Op.in]:ids
}
}
});
return result;
}
}
module.exports = OrderinfofqDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
const {Op} = require("sequelize");
class NeedinfoDao extends Dao {
constructor() {
super(Dao.getModelName(NeedinfoDao));
......@@ -72,5 +73,50 @@ class NeedinfoDao extends Dao {
raw: true
});
}
/**
* 根据ids 获取需求
* @param ids
* @returns {Promise<void>}
*/
async getNeedsByIds(ids){
let needs = await this.findAll({
where: {
channelNeedNo: {
[Op.in]:ids
}
}
})
return needs;
}
/**
* 批量更新
* @param needs
* @returns {Promise<Array<Model>|*>}
*/
async bulkUpdate(needs){
let result = await this.bulkCreate(needs,{
fields:["id", "status","statusName"] ,
updateOnDuplicate: ["status","statusName"]
});
return result;
}
/**
* 批量更新
* @param needs
* @returns {Promise<Array<Model>|*>}
*/
async bulkUpdateStatus(status,statusName,ids){
let result = await this.updateByWhere({status:status,statusName:statusName},{
where : {
channelNeedNo:{
[Op.in]:ids
}
}
});
return result;
}
}
module.exports = NeedinfoDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
const {Op} = require("sequelize");
class NeedinfofqDao extends Dao {
constructor() {
super(Dao.getModelName(NeedinfofqDao));
}
/**
* 取300条未处理的数据
* @returns {Promise<Array<Model>>}
*/
async getAllNeeds(){
let fqNeeds = await this.findAll({
where: {
handleStatus: 0
},
order: [["id","desc"]],
limit: 300
})
return fqNeeds;
}
/**
* 批量更新
* @param needs
* @returns {Promise<Array<Model>|*>}
*/
async bulkUpdate(ids){
let result = await this.updateByWhere({handleStatus:1},{
where : {
channelNeedNo:{
[Op.in]:ids
}
}
});
return result;
}
}
module.exports = NeedinfofqDao;
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("orderinfofq", {
sourceName :DataTypes.STRING(128),// 来源名称(source_name)
serviceOrderNo :DataTypes.STRING(128),// 服务商订单号(页面中列表中显示该单号)-云服(no)
channelServiceNo :DataTypes.STRING(128),// 渠道服务单号
channelOrderNo :DataTypes.STRING(128),// 渠道订单号(页面中列表中显示该单号)(idempotent_no)
channelNeedNo :DataTypes.STRING(128), // 渠道需求号(页面中列表中显示该需求号)
needNo :DataTypes.STRING(128), //需求号(need_no)
payTime :DataTypes.DATE,// 支付时间(first_pay_time)
quantity :DataTypes.INTEGER,// 项目订单数量(即服务项目的倍数,默认值为1)
orderStatusName :DataTypes.STRING(50),//订单状态名称
orderStatus :DataTypes.INTEGER,// 订单状态: 1: 待付款, 2: 已付款, 4: 服务中, 8: 已完成, 16: 已退款, 32: 已作废
totalSum :DataTypes.DECIMAL(12, 2),// 订单总额(产品价格×优惠费率×订单件数)
payTotalSum :DataTypes.DECIMAL(12, 2),// 订单付款总额
refundSum :DataTypes.DECIMAL(12, 2),// 退款金额
refundTime :DataTypes.DATE, //2020/6/17 lin新增 退款时间
notes :DataTypes.STRING,// 备注
isSolution :DataTypes.INTEGER,// 是否有方案,0无,1有
handleStatus :DataTypes.INTEGER, // 处理状态,0否,1是
source_code :DataTypes.STRING
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
timestamps: true,
updated_at: true,// 2020 0618 lin修改
//freezeTableName: true,
// define the table's name
tableName: 'c_order_info_fq',
validate: {
},
indexes: [
]
});
}
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("needinfofq", {
sourceCode: DataTypes.STRING(128), //来源code )idempotent_source
channelNeedNo: DataTypes.STRING(128), //渠道需求号(页面中列表中显示该需求号)
publishContent: DataTypes.TEXT,//发布内容
publishMobile: DataTypes.STRING,//发布者手机号
followContent: DataTypes.TEXT,//跟进内容
notes: DataTypes.TEXT,//备注
disposeNotes: DataTypes.STRING,//处理的备注
statusName: DataTypes.STRING,
status: DataTypes.INTEGER,
city: DataTypes.STRING(50), // 城市
province: DataTypes.STRING(50), // 省份
typeCode: DataTypes.STRING(50), //产品类型编码',
typeName: DataTypes.STRING(50), //类型产品名称',
channelTypeCode: DataTypes.STRING(50), //渠道产品类型编码',
channelTypeName: DataTypes.STRING(255), //渠道产品类型名称',
handleStatus:DataTypes.INTEGER //处理状态,0否,1是
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'n_need_info_fq',
validate: {
},
indexes: [
]
});
}
......@@ -17,13 +17,14 @@ class OrderInfoService extends ServiceBase {
this.needsolutionDao = system.getObject("db.dbneed.needsolutionDao");
this.orderRegionDao = system.getObject("db.dbcorder.orderregionDao");
this.push360Sve = system.getObject('service.common.push360Sve');
this.orderinfoDao = system.getObject('db.dbcorder.orderinfoDao');
this.orderinfofqDao = system.getObject('db.dbcorder.orderinfofqDao');
}
//--------------------task----------------start-------------------
async taskSyncOrderStatus(){
let sql="SELECT * FROM `c_order_info_fq` LIMIT 300";
var this.dao.customQuery(sql);
var result =await this.customQuery(sql);
}
//--------------------task--------------ednd---------------------
......@@ -1205,7 +1206,7 @@ class OrderInfoService extends ServiceBase {
}
/**
* 需求统计(产品维度)
* 订单统计(产品维度)
* @param pobj
* @returns {Promise<void>}
*/
......@@ -1223,7 +1224,7 @@ class OrderInfoService extends ServiceBase {
whereParam.type_code = ac.type_code;
}
if(ac.status){
sql += ` AND status = :status`;
sql += ` AND orderStatus = :status`;
whereParam.status = ac.status;
}
sql += ` GROUP BY uapp_id,DATE_FORMAT(created_at,'%Y-%m-%d') ORDER BY created_at ASC`
......@@ -1232,20 +1233,20 @@ class OrderInfoService extends ServiceBase {
}
/**
* 需求统计(产品维度)
* 订单统计(产品维度)
* @param pobj
* @returns {Promise<void>}
*/
async getOrdersStatisticsByProduct(pobj){
let ac = pobj.actionBody;
let sql = `SELECT b.itemCode typeCode,a.uapp_id,count( * ) count FROM c_order_info a left join c_order_product b on a.orderNo = b.sourceOrderNo WHERE b.itemCode is not null `;
let sql = `SELECT b.channelItemName typeCode,a.uapp_id,count( * ) count FROM c_order_info a left join c_order_product b on a.orderNo = b.sourceOrderNo WHERE b.itemCode is not null `;
let whereParams = {};
if(ac.start&&ac.end){
sql += ` and a.created_at >= :start and a.created_at <= :end `;
whereParams.start = ac.start;
whereParams.end = ac.end;
}
sql += ` GROUP BY b.itemCode,a.uapp_id`;
sql += ` GROUP BY b.channelItemName,a.uapp_id`;
let result = await this.customQuery(sql,whereParams);
return system.getResultSuccess(result);
}
......@@ -1332,6 +1333,11 @@ class OrderInfoService extends ServiceBase {
totalSql += ` and a.uapp_id = :uapp_id`;
whereParams.uapp_id = ab.uapp_id;
}
if(ab.status){
listSql += ` and a.orderStatus = :status`;
totalSql += ` and a.orderStatus = :status`;
whereParams.status = ab.status;
}
if(ab.type_code){
listSql += ` and b.itemCode = :type_code`;
totalSql += ` and b.itemCode = :type_code`;
......@@ -2275,5 +2281,141 @@ class OrderInfoService extends ServiceBase {
}
return system.getResultSuccess(orRet);
}
/**
* 同步蜂擎订单商机
* @returns {Promise<void>}
*/
async syncOrderBusiness() {
//获取 need_info_fq 未处理的需求
let fqOrders = await this.orderinfofqDao.getAllOrders()
let ids = [];
let orderDict = {};
for (let i = 0; i < fqOrders.length; i++) {
ids.push(fqOrders[i].channelOrderNo);
orderDict[fqOrders[i].channelOrderNo] = fqOrders[i].orderStatus;
}
//根据ids 获取企服通需求
let orders = await this.orderinfoDao.getOrdersByIds(ids);
let setObj = [];
let existIds = [];
let ids1 = [];
let ids2 = [];
let ids3 = [];
let ids4 = [];
let ids5 = [];
let ids6 = [];
let ids7 = [];
//已经存在的需求,更改状态
for(let i = 0;i < orders.length; i++){
let order = orders[i];
let obj = {
id:order.id,
}
if(orderDict[order.channelOrderNo] == 1){
ids1.push(order.channelOrderNo);
}
if(orderDict[order.channelOrderNo] == 2){
ids2.push(order.channelOrderNo);
}
if(orderDict[order.channelOrderNo] == 4){
ids3.push(order.channelOrderNo);
}
if(orderDict[order.channelOrderNo] == 8){
ids4.push(order.channelOrderNo);
}
if(orderDict[order.channelOrderNo] == 16){
ids5.push(order.channelOrderNo);
}
if(orderDict[order.channelOrderNo] == 32){
ids6.push(order.channelOrderNo);
}
if(orderDict[order.channelOrderNo] == 64){
ids7.push(order.channelOrderNo);
}
setObj.push(obj);
existIds.push(order.channelOrderNo);
}
// 不存在的订单 添加到企服通
let createObj = [];
let setFqObj1 = [];
let setFqObj2 = [];
for(let i =0;i<fqOrders.length;i++){
let fqOrder = fqOrders[i].dataValues;
if(!existIds.includes(fqOrder.channelOrderNo)){
fqOrder.orderNo = fqOrder.channelOrderNo;
if(['360_icp ','360_edi','360_sbzc'].includes(fqOrder.source_code)){
fqOrder.uapp_id = 50;
}
if(['baidu_edi','baidu_gsreg','baidu_icp','baidu_radiotv','baidu_wangwen'].includes(fqOrder.source_code)){
fqOrder.uapp_id = 44;
}
if(['edi_ali','ic_ali','icp_ali','tm_ali','tmd_ali'].includes(fqOrder.source_code)){
fqOrder.uapp_id = 18;
}
if(['youke'].includes(fqOrder.source_code)){
fqOrder.uapp_id = 40;
}
if(['tm_jdyun'].includes(fqOrder.source_code)){
fqOrder.uapp_id = 31;
}
if(['tm_bw'].includes(fqOrder.source_code)){
fqOrder.uapp_id = 35;
}
if(['tm_1688'].includes(fqOrder.source_code)){
fqOrder.uapp_id = 0;
}
delete fqOrder.sourceName;
delete fqOrder.source_code;
delete fqOrder.handleStatus;
delete fqOrder.id;
if(!setFqObj2.includes(fqOrder.channelOrderNo)){
createObj.push(fqOrder);
setFqObj2.push(fqOrder.channelOrderNo);
}
}else {
setFqObj1.push(fqOrder.channelOrderNo);
}
}
//企服通 批量更新状态
let updateRet =[];
if(setObj.length>0){
// updateRet = await this.needinfoDao.bulkUpdate(setObj);
// 1: 待付款, 2: 已付款, 4: 服务中, 8: 已完成, 16: 已退款, 32: 已作废, 64: 已付部分款
if(ids1.length>0){
updateRet = await this.orderinfoDao.bulkUpdateStatus(1,'待付款',ids1);
}
if(ids2.length>0){
updateRet = await this.orderinfoDao.bulkUpdateStatus(2,'已付款',ids2);
}
if(ids3.length>0){
updateRet = await this.orderinfoDao.bulkUpdateStatus(4,'服务中',ids3);
}
if(ids4.length>0){
updateRet = await this.orderinfoDao.bulkUpdateStatus(8,'已完成',ids4);
}
if(ids5.length>0){
updateRet = await this.orderinfoDao.bulkUpdateStatus(16,'已退款',ids5);
}
if(ids6.length>0){
updateRet = await this.orderinfoDao.bulkUpdateStatus(32,'已作废',ids6);
}
if(ids7.length>0){
updateRet = await this.orderinfoDao.bulkUpdateStatus(64,'已付部分款',ids7);
}
if(updateRet.length > 0){
updateRet = await this.orderinfofqDao.bulkUpdate(setFqObj1);
}
}
//企服通 批量添加
if(createObj.length>0){
updateRet = await this.orderinfoDao.bulkCreate(createObj);
if(updateRet.length >0 ){
updateRet = await this.orderinfofqDao.bulkUpdate(setFqObj2);
}
}
return system.getResult(updateRet)
}
}
module.exports = OrderInfoService;
\ No newline at end of file
......@@ -391,7 +391,7 @@ class NeedinfoService extends ServiceBase {
"publishName": item.personName,
"publishMobile": item.personMobile,
"statusName": tx_need_status_name[item.status],
"STATUS": tx_need_status[item.status],
"status": tx_need_status[item.status],
"typeCode": typeCode,
"typeName": item.productType,
"created_at": item.createdAt
......
......@@ -10,6 +10,7 @@ class NeedinfoService extends ServiceBase {
this.needsolutionSve = system.getObject("service.dbneed.needsolutionSve");
this.needsolutionDao = system.getObject("db.dbneed.needsolutionDao");
this.needinfoDao = system.getObject("db.dbneed.needinfoDao");
this.needinfofqDao = system.getObject("db.dbneed.needinfofqDao");
}
async getItemByNeedNo (pobj) {
var item = await this.dao.getItemByNeedNo(pobj.actionBody.needNo);
......@@ -148,16 +149,16 @@ class NeedinfoService extends ServiceBase {
*/
async getStatisticsByUappId(pobj){
let ac = pobj.actionBody;
let sql = `SELECT uapp_id,count(*) count,DATE_FORMAT(created_at,'%Y-%m-%d') time FROM n_need_info WHERE deleted_at is null `;
let sql = `SELECT uapp_id,count(*) count,DATE_FORMAT(created_at,'%Y-%m-%d') time FROM n_need_info WHERE deleted_at is null AND channelTypeName!='商标交易'`;
let whereParam = {};
if(ac.start&&ac.end){
sql += ` AND created_at >= :start AND created_at <= :end`;
whereParam.start = ac.start;
whereParam.end = ac.end;
}
if(ac.type_code){
sql += ` AND typeCode = :type_code`;
whereParam.type_code = ac.type_code;
if(ac.type_name){
sql += ` AND typeCode = :type_name`;
whereParam.type_name = ac.type_name;
}
if(ac.status){
sql += ` AND status = :status`;
......@@ -175,28 +176,31 @@ class NeedinfoService extends ServiceBase {
*/
async getNeedFunnelStatistics(pobj){
let ac = pobj.actionBody;
let sql = `select count(*) count from n_need_info where deleted_at is null `;
let sql2 = `select count(DISTINCT(a.needNo)) count from n_need_solution a left join n_need_info b on a.needNo = b.needNo where a.deleted_at is null`;
let sql = `select count(*) count from n_need_info where deleted_at is null AND channelTypeName!='商标交易'`;
let sql2 = sql + ` and status in('ygj','ygb','ycd')`;
let sql3 = sql + ` and status = 'ycd'`;
let whereParams = {};
if (ac.start&&ac.end){
sql += ` AND created_at >= :start and created_at <= :end`;
sql2 += ` AND b.created_at >= :start and b.created_at <= :end`;
sql2 += ` AND created_at >= :start and created_at <= :end`;
sql3 += ` AND created_at >= :start and created_at <= :end`;
whereParams.start = ac.start;
whereParams.end = ac.end;
}
if(ac.uapp_id){
sql += ` and uapp_id = :uapp_id`;
sql2 += ` and b.uapp_id = :uapp_id`;
sql2 += ` and uapp_id = :uapp_id`;
sql3 += ` and uapp_id = :uapp_id`;
whereParams.uapp_id = ac.uapp_id;
}
if(ac.type_code){
sql += ` and typeCode = :type_code`;
sql2 += ` and b.typeCode = :type_code`;
whereParams.type_code = ac.type_code;
if(ac.type_name){
sql += ` and typeName = :type_name`;
sql2 += ` and typeName = :type_name`;
sql3 += ` and typeName = :type_name`;
whereParams.type_name = ac.type_name;
}
let total = await this.customQuery(sql,whereParams);
let middle = await this.customQuery(sql2,whereParams);
let sql3 = sql2 + ` and b.status = 'ycd'`
let finish = await this.customQuery(sql3,whereParams);
let result = {
total:total[0].count,
......@@ -207,41 +211,55 @@ class NeedinfoService extends ServiceBase {
}
/**
* 需求统计(产品维度
* 需求统计(产品类型
* @param pobj
* @returns {Promise<void>}
*/
async getStatisticsByProduct(pobj){
let ac = pobj.actionBody;
let sql = `select typeCode,uapp_id,count(*) count from n_need_info where typeCode is not null `;
let sql = `select typeName typeCode,uapp_id,count(*) count from n_need_info where typeName is not null AND channelTypeName!='商标交易'`;
let whereParams = {};
if(ac.start&&ac.end){
sql += ` and created_at >= :start and created_at <= :end `;
whereParams.start = ac.start;
whereParams.end = ac.end;
}
sql += ` GROUP BY typeCode,uapp_id`;
sql += ` GROUP BY typeName,uapp_id`;
let result = await this.customQuery(sql,whereParams);
return system.getResultSuccess(result);
}
/**
* 需求统计(获取产品类型)
* @param pobj
* @returns {Promise<void>}
*/
async getNeedProductType(pobj){
let sql = `select typeName,count(*) count from n_need_info where typeName is not null AND channelTypeName!='商标交易' GROUP BY typeName`;
let result = await this.customQuery(sql);
let typeNames = result.map(item =>{
return item.typeName;
})
return system.getResultSuccess(typeNames);
}
/**
* 需求统计(区域维度)
* @param pobj
* @returns {Promise<void>}
*/
async getStatisticsByCity(pobj){
let ac = pobj.actionBody;
let sql = `select typeCode,province,count(*) count from n_need_info where province is not null and typeCode is not null `;
let sql = `select typeCode,province,count(*) count from n_need_info where province is not null and typeCode is not null AND channelTypeName!='商标交易' `;
let whereParams = {};
if(ac.start&&ac.end){
sql += ` and created_at >= :start and created_at <= :end `;
whereParams.start = ac.start;
whereParams.end = ac.end;
}
if(ac.type_code){
if(ac.type_name){
sql += ` and typeCode = :typeCode`;
whereParams.typeCode = ac.type_code;
whereParams.typeCode = ac.type_name;
}
if(ac.uapp_id){
sql += ` and uapp_id = :uapp_id`;
......@@ -259,8 +277,8 @@ class NeedinfoService extends ServiceBase {
*/
async getNeedComparison(pobj){
let ab =pobj.actionBody;
let sql1 = `select count(DISTINCT(needNo)) count from n_need_info where deleted_at is null `;
let sql2 = `select count(DISTINCT(b.needNo)) count from n_need_solution a left join n_need_info b on a.needNo = b.needNo where a.deleted_at is null and b.status = 'ycd'`;
let sql1 = `select count(DISTINCT(needNo)) count from n_need_info where deleted_at is null AND channelTypeName!='商标交易' `;
let sql2 = `select count(DISTINCT(b.needNo)) count from n_need_solution a left join n_need_info b on a.needNo = b.needNo where a.deleted_at is null and b.status = 'ycd' AND b.channelTypeName!='商标交易'`;
let whereParams = {};
if(ab.startNow&&ab.endNow){
sql1 += ` and created_at >= :start and created_at <= :end`;
......@@ -273,10 +291,10 @@ class NeedinfoService extends ServiceBase {
sql2 += ` and b.uapp_id = :uapp_id`;
whereParams.uapp_id = ab.uapp_id;
}
if(ab.type_code){
sql1 += ` and typeCode = :type_code`;
sql2 += ` and b.typeCode = :type_code`;
whereParams.type_code = ab.type_code;
if(ab.type_name){
sql1 += ` and typeName = :type_name`;
sql2 += ` and b.typename = :type_name`;
whereParams.type_name = ab.type_name;
}
let totalRet1 = await this.customQuery(sql1,whereParams);
let orderRet1 = await this.customQuery(sql2,whereParams);
......@@ -314,13 +332,13 @@ class NeedinfoService extends ServiceBase {
}
let tag = actionBody.tag;
//需求列表
let needSql = `select DISTINCT(a.channelNeedNo),b.app_name,a.needNo,a.typeName,a.province,a.city,a.publishContent,a.publishName,a.publishMobile,a.statusName,a.created_at from center_order.n_need_info a left join center_app.p_app b on a.uapp_id = b.uapp_id where a.deleted_at is null`;
let needSql = `select DISTINCT(a.channelNeedNo),b.app_name,a.needNo,a.typeName,a.province,a.city,a.publishContent,a.publishName,a.publishMobile,a.statusName,a.created_at from center_order.n_need_info a left join center_app.p_app b on a.uapp_id = b.uapp_id where a.deleted_at is null AND a.channelTypeName!='商标交易' `;
//需求总数
let needTotalSql = `select count(DISTINCT(a.channelNeedNo)) count from center_order.n_need_info a left join center_app.p_app b on a.uapp_id = b.uapp_id where a.deleted_at is null`;
let needTotalSql = `select count(DISTINCT(a.channelNeedNo)) count from center_order.n_need_info a left join center_app.p_app b on a.uapp_id = b.uapp_id where a.deleted_at is null AND a.channelTypeName!='商标交易'`;
//需求成单
let needToOrderSql = `select DISTINCT(b.channelNeedNo),c.app_name,b.channelNeedNo,b.province,b.city,b.typeName,b.publishContent,b.publishName,b.publishMobile,b.statusName,b.created_at from center_order.n_need_solution a left join center_order.n_need_info b on a.needNo = b.needNo left join center_app.p_app c on b.uapp_id = c.uapp_id where a.deleted_at is null and b.status = 'ycd'`;
let needToOrderSql = `select DISTINCT(b.channelNeedNo),c.app_name,b.channelNeedNo,b.province,b.city,b.typeName,b.publishContent,b.publishName,b.publishMobile,b.statusName,b.created_at from center_order.n_need_solution a left join center_order.n_need_info b on a.needNo = b.needNo left join center_app.p_app c on b.uapp_id = c.uapp_id where a.deleted_at is null and b.status = 'ycd' AND b.channelTypeName!='商标交易'`;
//需求成单总数
let needToOrderTotalSql = `select count(DISTINCT(a.channelNeedNo)) count from n_need_solution a left join n_need_info b on a.needNo = b.needNo where a.deleted_at is null and b.status = 'ycd'`;
let needToOrderTotalSql = `select count(DISTINCT(a.channelNeedNo)) count from n_need_solution a left join n_need_info b on a.needNo = b.needNo where a.deleted_at is null and b.status = 'ycd' AND b.channelTypeName!='商标交易'`;
let whereParams = {};
if(actionBody.start&&actionBody.end){
needSql += ` and a.created_at >= :start and a.created_at <= :end`;
......@@ -338,12 +356,19 @@ class NeedinfoService extends ServiceBase {
needToOrderTotalSql += ` and b.uapp_id = :uapp_id`;
whereParams.uapp_id = actionBody.uapp_id;
}
if(actionBody.type_code){
needSql += ` and a.typeCode = :type_code`;
needTotalSql += ` and a.typeCode = :type_code`;
needToOrderSql += ` and b.typeCode = :type_code`;
needToOrderTotalSql += ` and b.typeCode = :type_code`;
whereParams.type_code = actionBody.type_code;
if(actionBody.type_name){
needSql += ` and a.typeName = :type_name`;
needTotalSql += ` and a.typeName = :type_name`;
needToOrderSql += ` and b.typeName = :type_name`;
needToOrderTotalSql += ` and b.typeName = :type_name`;
whereParams.type_name = actionBody.type_name;
}
if(actionBody.status){
needSql += ` and a.status = :status`;
needTotalSql += ` and a.status = :status`;
needToOrderSql += ` and b.status = :status`;
needToOrderTotalSql += ` and b.status = :status`;
whereParams.status = actionBody.status;
}
if(actionBody.fuzzy_code){
needSql += ` and ( a.needNo like :fuzzy_code or a.channelNeedNo like :fuzzy_code or a.publishMobile like :fuzzy_code)`;
......@@ -373,6 +398,161 @@ class NeedinfoService extends ServiceBase {
}
return system.getResult(data);
}
/**
* 修改需求商机推送状态
* @param actionBody
* @returns {Promise<void>}
*/
async updateNeedPushStatus(actionBody) {
let channelNeedNo = actionBody.intentionBizId;
let setObj = {
status: 'yts',
statusName: "已推送"
}
let whereObj = {
where: {
channelNeedNo: channelNeedNo
}
}
if (channelNeedNo) {
this.dao.updateByWhere(setObj, whereObj);
}
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,
publishMobile:fqNeed.publishMobile,
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;
......
......@@ -40,6 +40,9 @@ class BaseQcService {
107: "管局已受理"
};
this.icpApplicationStatusReference = {
504: "创建交付订单",
505: "资料收集完成",
506: "资料加工完成",
507: "完成账户注册",
508: "服务商完成提交资料到⼯信部",
509: "⼯信部已受理",
......
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