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 { ...@@ -28,7 +28,7 @@ class APIBase {
return system.getResultSuccess(); return system.getResultSuccess();
} }
} }
if (["updateTmStatus"].indexOf(methodname) >= 0) { if (["updateTmStatus","bulkCreateNeeds","bulkCreateOrders"].indexOf(methodname) >= 0) {
return system.getResultSuccess(); return system.getResultSuccess();
} }
if (!pobj.appInfo) { if (!pobj.appInfo) {
......
...@@ -48,6 +48,9 @@ class IcAPI extends APIBase { ...@@ -48,6 +48,9 @@ class IcAPI extends APIBase {
case "getStatisticsByProduct": case "getStatisticsByProduct":
opResult = await this.opNeedInfoSve.getStatisticsByProduct(pobj); opResult = await this.opNeedInfoSve.getStatisticsByProduct(pobj);
break; break;
case "getNeedProductType":
opResult = await this.opNeedInfoSve.getNeedProductType(pobj);
break;
case "getStatisticsByArea": case "getStatisticsByArea":
opResult = await this.opNeedInfoSve.getStatisticsByCity(pobj); opResult = await this.opNeedInfoSve.getStatisticsByCity(pobj);
break; break;
...@@ -60,6 +63,9 @@ class IcAPI extends APIBase { ...@@ -60,6 +63,9 @@ class IcAPI extends APIBase {
case "getNeedComparisonList": case "getNeedComparisonList":
opResult = await this.opNeedInfoSve.getNeedComparisonList(pobj,pobj.actionBody); opResult = await this.opNeedInfoSve.getNeedComparisonList(pobj,pobj.actionBody);
break; break;
case "updateNeedPushStatus":
opResult = await this.opNeedInfoSve.updateNeedPushStatus(pobj.actionBody);
break;
default: default:
opResult = system.getResult(null, "action_type参数错误"); opResult = system.getResult(null, "action_type参数错误");
break; break;
......
...@@ -5,18 +5,27 @@ class TaskAction extends APIBase { ...@@ -5,18 +5,27 @@ 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请求 * 需求商机同步
* action_process 执行的流程 * action_process 执行的流程
* action_type 执行的类型 * action_type 执行的类型
* action_body 执行的参数 * action_body 执行的参数
*/ */
async taskNeed(pobj, qobj, req) { async taskNeed(pobj, qobj, req) {
if (!pobj.actionType) { var result = await this.opneedinfoSve.syncNeedBusiness();
return system.getResult(null, "actionType参数不能为空"); return result;
} }
var result = await this.opActionProcess(pobj, pobj.actionType, req);
/**
* 订单商机同步
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async taskOrder(pobj, qobj, req) {
var result = await this.orderinfoSve.syncOrderBusiness();
return result; return result;
} }
......
...@@ -50,6 +50,11 @@ class Dao { ...@@ -50,6 +50,11 @@ class Dao {
return this.model.findAll({ attributes: qobj.fields }); return this.model.findAll({ attributes: qobj.fields });
} }
} }
async findAll(qobj, t) {
var apps = await this.model.findAll(qobj);
return apps;
}
async bulkDeleteByWhere(whereParam, t) { async bulkDeleteByWhere(whereParam, t) {
var en = null; var en = null;
if (t != null && t != 'undefined') { if (t != null && t != 'undefined') {
......
const system = require("../../../system"); const system = require("../../../system");
const Dao = require("../../dao.base"); const Dao = require("../../dao.base");
const {Op} = require("sequelize");
class OrderInfoDao extends Dao { class OrderInfoDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(OrderInfoDao)); super(Dao.getModelName(OrderInfoDao));
...@@ -56,5 +57,50 @@ class OrderInfoDao extends Dao { ...@@ -56,5 +57,50 @@ class OrderInfoDao extends Dao {
await this.customInsert(sql, null, t); await this.customInsert(sql, null, t);
return system.getResultSuccess() 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; 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 system = require("../../../system");
const Dao = require("../../dao.base"); const Dao = require("../../dao.base");
const {Op} = require("sequelize");
class NeedinfoDao extends Dao { class NeedinfoDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(NeedinfoDao)); super(Dao.getModelName(NeedinfoDao));
...@@ -72,5 +73,50 @@ class NeedinfoDao extends Dao { ...@@ -72,5 +73,50 @@ class NeedinfoDao extends Dao {
raw: true 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; 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 { ...@@ -17,13 +17,14 @@ class OrderInfoService extends ServiceBase {
this.needsolutionDao = system.getObject("db.dbneed.needsolutionDao"); this.needsolutionDao = system.getObject("db.dbneed.needsolutionDao");
this.orderRegionDao = system.getObject("db.dbcorder.orderregionDao"); this.orderRegionDao = system.getObject("db.dbcorder.orderregionDao");
this.push360Sve = system.getObject('service.common.push360Sve'); this.push360Sve = system.getObject('service.common.push360Sve');
this.orderinfoDao = system.getObject('db.dbcorder.orderinfoDao');
this.orderinfofqDao = system.getObject('db.dbcorder.orderinfofqDao');
} }
//--------------------task----------------start------------------- //--------------------task----------------start-------------------
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---------------------
...@@ -1205,7 +1206,7 @@ class OrderInfoService extends ServiceBase { ...@@ -1205,7 +1206,7 @@ class OrderInfoService extends ServiceBase {
} }
/** /**
* 需求统计(产品维度) * 订单统计(产品维度)
* @param pobj * @param pobj
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
...@@ -1223,7 +1224,7 @@ class OrderInfoService extends ServiceBase { ...@@ -1223,7 +1224,7 @@ class OrderInfoService extends ServiceBase {
whereParam.type_code = ac.type_code; whereParam.type_code = ac.type_code;
} }
if(ac.status){ if(ac.status){
sql += ` AND status = :status`; sql += ` AND orderStatus = :status`;
whereParam.status = ac.status; whereParam.status = ac.status;
} }
sql += ` GROUP BY uapp_id,DATE_FORMAT(created_at,'%Y-%m-%d') ORDER BY created_at ASC` 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 { ...@@ -1232,20 +1233,20 @@ class OrderInfoService extends ServiceBase {
} }
/** /**
* 需求统计(产品维度) * 订单统计(产品维度)
* @param pobj * @param pobj
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async getOrdersStatisticsByProduct(pobj){ async getOrdersStatisticsByProduct(pobj){
let ac = pobj.actionBody; 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 = {}; let whereParams = {};
if(ac.start&&ac.end){ if(ac.start&&ac.end){
sql += ` and a.created_at >= :start and a.created_at <= :end `; sql += ` and a.created_at >= :start and a.created_at <= :end `;
whereParams.start = ac.start; whereParams.start = ac.start;
whereParams.end = ac.end; 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); let result = await this.customQuery(sql,whereParams);
return system.getResultSuccess(result); return system.getResultSuccess(result);
} }
...@@ -1332,6 +1333,11 @@ class OrderInfoService extends ServiceBase { ...@@ -1332,6 +1333,11 @@ class OrderInfoService extends ServiceBase {
totalSql += ` and a.uapp_id = :uapp_id`; totalSql += ` and a.uapp_id = :uapp_id`;
whereParams.uapp_id = ab.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){ if(ab.type_code){
listSql += ` and b.itemCode = :type_code`; listSql += ` and b.itemCode = :type_code`;
totalSql += ` and b.itemCode = :type_code`; totalSql += ` and b.itemCode = :type_code`;
...@@ -2275,5 +2281,141 @@ class OrderInfoService extends ServiceBase { ...@@ -2275,5 +2281,141 @@ class OrderInfoService extends ServiceBase {
} }
return system.getResultSuccess(orRet); 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; module.exports = OrderInfoService;
\ No newline at end of file
...@@ -391,7 +391,7 @@ class NeedinfoService extends ServiceBase { ...@@ -391,7 +391,7 @@ class NeedinfoService extends ServiceBase {
"publishName": item.personName, "publishName": item.personName,
"publishMobile": item.personMobile, "publishMobile": item.personMobile,
"statusName": tx_need_status_name[item.status], "statusName": tx_need_status_name[item.status],
"STATUS": tx_need_status[item.status], "status": tx_need_status[item.status],
"typeCode": typeCode, "typeCode": typeCode,
"typeName": item.productType, "typeName": item.productType,
"created_at": item.createdAt "created_at": item.createdAt
......
...@@ -40,6 +40,9 @@ class BaseQcService { ...@@ -40,6 +40,9 @@ class BaseQcService {
107: "管局已受理" 107: "管局已受理"
}; };
this.icpApplicationStatusReference = { this.icpApplicationStatusReference = {
504: "创建交付订单",
505: "资料收集完成",
506: "资料加工完成",
507: "完成账户注册", 507: "完成账户注册",
508: "服务商完成提交资料到⼯信部", 508: "服务商完成提交资料到⼯信部",
509: "⼯信部已受理", 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