Commit cd8cda67 by 王勇飞

Merge branch 'tx-fi-tax' of gitlab.gongsibao.com:jiangyong/zhichan into tx-fi-tax

parents e414aaa3 e48d9a08
......@@ -5,6 +5,7 @@ var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const moment = require('moment');
const appconfig = system.getSysConfig();
const sha235 = require("sha256");
class BizOptCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(BizOptCtl));
......@@ -12,7 +13,7 @@ class BizOptCtl extends CtlBase {
this.schemeSve = system.getObject("service.bizchance.fitaxschemeSve"); //财税-方案信息
this.fitaxcompanySve = system.getObject("service.bizchance.fitaxcompanySve"); //财税-企业信息
this.operationrecordSve = system.getObject("service.bizchance.operationrecordSve"); //财税-需求分配记录
this.deliverbillSve = system.getObject("service.bizchance.deliverybillSve");//财税-需求分配
this.deliverbillSve = system.getObject("service.bizchance.deliverybillSve"); //财税-需求分配
this.logService = system.getObject("service.bizchance.statuslogSve");
this.shisService = system.getObject("service.bizchance.salesmanhisSve");
this.receiveUrl = settings.receiveUrl();
......@@ -247,45 +248,45 @@ class BizOptCtl extends CtlBase {
/*更新业务员信息*/
async updateSalesmanInfoByDemandCode(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined') {
try {
var res = await this.service.findInfoByDemandCode(pobj);
if (res) {
var sInfo = {
"flowType": "BIZ",
"flowId": res.id,
"flowCode": pobj.businessMode,
"salesmanInfo": {
"oldOpcode": res.salesman_opcode,
"oldClerkName": res.salesman_name,
"oldClerkId": res.salesman_id,
"oldClerkPhone": res.salesman_phone,
"oldFacilitatorId": res.facilitator_id,
"oldFacilitatorName": res.facilitator_name,
"newOpcode": pobj.salesmanOpcode,
"newClerkName": pobj.salesmanName,
"newClerkId": pobj.salesmanId,
"newClerkPhone": pobj.salesmanPhone,
"newFacilitatorId": pobj.facilitatorId,
"newFacilitatorName": pobj.facilitatorName
var pobj = mobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined') {
try {
var res = await this.service.findInfoByDemandCode(pobj);
if (res) {
var sInfo = {
"flowType": "BIZ",
"flowId": res.id,
"flowCode": pobj.businessMode,
"salesmanInfo": {
"oldOpcode": res.salesman_opcode,
"oldClerkName": res.salesman_name,
"oldClerkId": res.salesman_id,
"oldClerkPhone": res.salesman_phone,
"oldFacilitatorId": res.facilitator_id,
"oldFacilitatorName": res.facilitator_name,
"newOpcode": pobj.salesmanOpcode,
"newClerkName": pobj.salesmanName,
"newClerkId": pobj.salesmanId,
"newClerkPhone": pobj.salesmanPhone,
"newFacilitatorId": pobj.facilitatorId,
"newFacilitatorName": pobj.facilitatorName
}
}
await this.shisService.insertInfo(sInfo); //之前业务员转历史
await this.service.updateSalesmanInfoByDemandCode(pobj); //更新业务员信息
return system.getResult("操作成功!");
} else {
return system.getResultError("未找到相关数据");
}
await this.shisService.insertInfo(sInfo); //之前业务员转历史
await this.service.updateSalesmanInfoByDemandCode(pobj); //更新业务员信息
return system.getResult("操作成功!");
} else {
return system.getResultError("未找到相关数据");
}
} catch (error) {
return system.getResultError(error);
} catch (error) {
return system.getResultError(error);
}
} else {
return system.getResultError("参数错误!");
}
} else {
return system.getResultError("参数错误!");
}
}
/*根据商机编号更新商机状态*/
/*根据商机编号更新商机状态*/
async updateStatusByDemandCode(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.currentStatus && pobj.currentStatus != 'undefined') {
......@@ -340,57 +341,76 @@ class BizOptCtl extends CtlBase {
/*插入数据信息 */
async insertInfo(nobj, qobj, req) {
var pobj = nobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.businessType && pobj.businessType != 'undefined') {
var pobj = nobj.actionBody.messageBody;
if (pobj.intentionBizId && pobj.intentionBizId != 'undefined') {
try {
//pobj.currentStatus = "beforeSubmission";//加上当前状态为待提交方案
// pobj.channelSource = "tencentCloud";//目前渠道只有腾讯
// pobj.sourceNumber = "1111111";
// pobj.businessType = appconfig.pdict.dyDict[pobj.businessType];
var buInfo = await this.service.insertInfo(pobj);
var  cachestr  =  sha235(JSON.stringify(nobj));      
var  cacheInfo  =  await  this.cacheManager["TxCache"].getCache(cachestr); 
if  (cacheInfo  &&  cacheInfo  !=  'undefined')  {        
return  {          
"status":  1,
  //1代表成功,否则失败
"msg": "已处理成功!",
"data": cachestr ,
"requestId": nobj.requestId
}      
} else {
pobj.businessStatus = 'received';
pobj.sourceNumber = 'tx';
pobj.facilitatorId = '10';
pobj.facilitatorName = '公司宝';
pobj.sourceName = 'tencentCloud';
//插入操作
var buInfo = await this.service.insertInfo(pobj);
if (buInfo) {
await this.cacheManager["TxCache"].cache(cachestr, JSON.stringify({ cachestr: cachestr }), 180);
//日志
var logInfo = {
"flowType": "BIZ",
"flowId": buInfo.id,
"statusCode": pobj.bussinessStatus,
"clerkName": pobj.salesmanName,
"clerkId": pobj.salesmanId
}
await this.logService.insertInfo(logInfo); //插入状态日至表
return {
"status": 1, //1代表成功,否则失败
"message": "操作成功",
"data": buInfo,
"requestId": nobj.requestId
};
var logInfo = {
"flowType": "BIZ",
"flowId": buInfo.id,
"statusCode": pobj.bussinessStatus,
"clerkName": pobj.salesmanName,
"clerkId": pobj.salesmanId
}
}
await this.logService.insertInfo(logInfo); //插入状态日至表
return {
"status": 1, //1代表成功,否则失败
"message": "操作成功",
"data": "",
"requestId": ""
};
} catch (error) {
//异常处理
console.log("TTTTTTTTTTTTTTTTTTTTTTT");
console.log(error);
return system.getResultError(error);
}
} else {
//字段错误处理
return system.getResultError("参数错误!");
}
}
timeFormat(date) {
let localTime = moment.utc(date).toDate();
localTime = moment(localTime).format("YYYY-MM-DD");
return localTime;
}
//根据bizId查询商机表中的所有信息
async getInfo(pobj,qobj,req){
try{
if(!pobj.bizId){
let localTime = moment.utc(date).toDate();
localTime = moment(localTime).format("YYYY-MM-DD");
return localTime;
}
//根据bizId查询商机表中的所有信息
async getInfo(pobj, qobj, req) {
try {
if (!pobj.bizId) {
throw new Error("bizId 不能为空");
}
const rs=await this.service.getInfo(pobj);
const rs = await this.service.getInfo(pobj);
//console.log("got message");
return system.getResult(rs);
}catch(err){
return system.getResult(null,err.message)
} catch (err) {
return system.getResult(null, err.message)
}
}
}
......@@ -421,4 +441,4 @@ module.exports = BizOptCtl;
// }
// task.findInfoByDemandCode(obj,{},{}).then(d=>{
// console.log(JSON.stringify(d));
// })
// })
\ No newline at end of file
const system = require("../../../system");
const Dao = require("../../dao.base");
class BizoptDao extends Dao {
constructor() {
super(Dao.getModelName(BizoptDao));
}
constructor() {
super(Dao.getModelName(BizoptDao));
}
extraWhere(qobj, qw, qc) { //根据业务员id获取商机信息的组装条件
qc.raw = true;
//检查查询的用户所属公司是否是平台运营公司-1,如果是则不需要添加公司查询条件添加公司查询条件, 不添加路径条件,返回所有数据
if (qobj.company_id == 1) {
return qw
} else {
//需要添加公司查询条件
qw["facilitator_id"] = Number(qobj.company_id)
/**
* 数据权限过滤
* 1. 管理员 (opath 为空)、 销售主管(isPrincipal = true) 、 销售 (isPrincipal = false && opath不为空)
*/
if (!qobj.opath) { // 管理员 不做处理
} else if (qobj.isPrincipal) { // 销售主管 查询为空和自己组织结构下的
qw["$or"] = [{
salesman_opcode: {
$eq: null
}
}, {
salesman_opcode: { $like: `%${qobj.opath}%` }
}]
} else { // 销售 查询自己的
qw["salesman_opcode"] = { $like: `%${qobj.opath}%` }
}
//不是来自平台前端查询
if (qobj.bizpath && qobj.bizpath.indexOf("pmx") < 0) {
console.log("bizpath-------------" + qobj.bizpath);
qc.where.business_type = qc.where.business_type || {
[this.db.Op.eq]: "bookkeeping"
}
if (qobj.bizpath && qobj.bizpath != "") {
if (qobj.bizpath.indexOf("demandAllocation") > 0) { //从需求分配列表过来的
qw["business_status"] = {
[this.db.Op.eq]: "received"
};
}
if (qobj.bizpath.indexOf("demandfollow") > 0 || qobj.bizpath.indexOf("distributionManagement") > 0) { //从需求跟进列表或分配记录列表过来的
qw["business_status"] = {
[this.db.Op.ne]: "received"
};
}
}
extraWhere(qobj, qw, qc) {//根据业务员id获取商机信息的组装条件
qc.raw = true;
//检查查询的用户所属公司是否是平台运营公司-1,如果是则不需要添加公司查询条件添加公司查询条件, 不添加路径条件,返回所有数据
if (qobj.company_id == 1) {
return qw
} else {
//需要添加公司查询条件
qw["facilitator_id"] = Number(qobj.company_id)
/**
* 数据权限过滤
* 1. 管理员 (opath 为空)、 销售主管(isPrincipal = true) 、 销售 (isPrincipal = false && opath不为空)
*/
if (!qobj.opath) { // 管理员 不做处理
} else if (qobj.isPrincipal) { // 销售主管 查询为空和自己组织结构下的
qw["$or"] = [
{
salesman_opcode: {
$eq: null
}
}, {
salesman_opcode: { $like: `%${qobj.opath}%` }
}
]
} else { // 销售 查询自己的
qw["salesman_opcode"] = { $like: `%${qobj.opath}%` }
}
//不是来自平台前端查询
if (qobj.bizpath && qobj.bizpath.indexOf("pmx") < 0) {
console.log("bizpath-------------" + qobj.bizpath);
qc.where.business_type = qc.where.business_type || {
[this.db.Op.eq]: "bookkeeping"
}
if (qobj.bizpath && qobj.bizpath != "") {
if (qobj.bizpath.indexOf("demandAllocation") > 0) {//从需求分配列表过来的
qw["business_status"] = {
[this.db.Op.eq]: "received"
};
}
if (qobj.bizpath.indexOf("demandfollow") > 0 || qobj.bizpath.indexOf("distributionManagement") > 0) {//从需求跟进列表或分配记录列表过来的
qw["business_status"] = {
[this.db.Op.ne]: "received"
};
}
}
return qw;
}
}
/*根据商机编号获取商机详情*/
async findInfoByDemandCode(qobj) {
var qcwhere = { "demand_code": qobj.demand_code };
return await this.findOne(qcwhere);
}
return qw;
}
/*根据商机编号获取商机详情*/
async findInfoByDemandCode(qobj) {
var qcwhere = { "demand_code": qobj.demand_code };
return await this.findOne(qcwhere);
}
/*更新商机状态*/
async updateStatusByDemandCode(qobj, t) {
var setobj = { "business_status": qobj.business_status };
if (qobj.close_reason && qobj.close_reason != 'undefined') {
setobj["close_reason"] = qobj.close_reason;
} else {
setobj["close_reason"] = "";
}
var whereobj = { "demand_code": qobj.demand_code };
return await this.updateByWhere(setobj, whereobj, t);
}
/*更新商机状态*/
async updateStatusByDemandCode(qobj, t) {
var setobj = { "business_status": qobj.business_status };
if (qobj.close_reason && qobj.close_reason != 'undefined') {
setobj["close_reason"] = qobj.close_reason;
} else {
setobj["close_reason"] = "";
/*更新业务员信息*/
async updateSalesmanInfoByDemandCode(qobj, t) {
var setobj = {};
if (qobj.salesmanId && qobj.salesmanId != 'undefined') {
setobj.salesman_id = qobj.salesmanId;
};
if (qobj.salesmanName && qobj.salesmanName != 'undefined') {
setobj.salesman_name = qobj.salesmanName;
};
if (qobj.salesmanOpcode && qobj.salesmanOpcode != 'undefined') {
setobj.salesman_opcode = qobj.salesmanOpcode;
};
if (qobj.salesmanPhone && qobj.salesmanPhone != 'undefined') {
setobj.salesman_phone = qobj.salesmanPhone;
};
if (qobj.facilitatorId && qobj.facilitatorId != 'undefined') {
setobj.facilitator_id = qobj.facilitatorId;
};
if (qobj.facilitatorName && qobj.facilitatorName != 'undefined') {
setobj.facilitator_name = qobj.facilitatorName;
};
var whereobj = { "demand_code": qobj.businessMode };
return await this.updateByWhere(setobj, whereobj, t);
}
var whereobj = { "demand_code": qobj.demand_code };
return await this.updateByWhere(setobj, whereobj, t);
}
/*更新业务员信息*/
async updateSalesmanInfoByDemandCode(qobj, t) {
var setobj = {};
if (qobj.salesmanId && qobj.salesmanId != 'undefined') {
setobj.salesman_id = qobj.salesmanId;
};
if (qobj.salesmanName && qobj.salesmanName != 'undefined') {
setobj.salesman_name = qobj.salesmanName;
};
if (qobj.salesmanOpcode && qobj.salesmanOpcode != 'undefined') {
setobj.salesman_opcode = qobj.salesmanOpcode;
};
if (qobj.salesmanPhone && qobj.salesmanPhone != 'undefined') {
setobj.salesman_phone = qobj.salesmanPhone;
};
if (qobj.facilitatorId && qobj.facilitatorId != 'undefined') {
setobj.facilitator_id = qobj.facilitatorId;
};
if (qobj.facilitatorName && qobj.facilitatorName != 'undefined') {
setobj.facilitator_name = qobj.facilitatorName;
};
var whereobj = { "demand_code": qobj.businessMode };
return await this.updateByWhere(setobj, whereobj, t);
}
/*插入商机信息*/
async insertInfo(qobj, t) {
var obj = {
"demand_code": qobj.intentionBizId,
"business_type": qobj.type,
"business_status": qobj.bussinessStatus,
"business_info": {},
"source_number": qobj.sourceNumber,
"service_address": qobj.area,
"facilitator_id": qobj.favilitatorId,
"facilitator_name": qobj.favilitatorName,
"source_name": qobj.sourceName,
};
//business_info START
if (qobj.topOrgCode && qobj.topOrgCode != 'undefined') {
obj.business_info.topOrgCode = qobj.topOrgCode
}
if (qobj.requestId && qobj.requestId != 'undefined') {
obj.business_info.requestId = qobj.requestId;
}
if (qobj.mobile && qobj.mobile != 'undefined') {
obj.business_info.contactsPhone = qobj.mobile; //已经加密
}
//bussiness_info END
//other
if (qobj.closeReason && qobj.closeReason != 'undefined') {
obj.close_reason = qobj.closeReason;
}
if (qobj.salesmanOpcode && qobj.salesmanOpcode != 'undefined') {
obj.salesman_opcode = qobj.salesmanOpcode;
}
if (qobj.salesmanId && qobj.salesmanId != 'undefined') {
obj.salesman_id = qobj.salesmanId;
}
if (qobj.salesmanName && qobj.salesmanName != 'undefined') {
obj.salesman_name = qobj.salesmanName;
}
if (qobj.salesmanPhone && qobj.salesmanPhone != 'undefined') {
obj.salesman_phone = qobj.salesmanPhone;
}
/*插入商机信息*/
async insertInfo(qobj, t) {
var obj = {
"demand_code": qobj.businessMode,
"business_type": qobj.businessType,
"business_status": qobj.bussinessStatus,
"business_info": {},
"source_number": qobj.sourceNumber,
"service_address": qobj.serviceAddress,
"facilitator_id": qobj.favilitatorID,
"facilitator_name": qobj.favilitatorName,
"source_name": qobj.sourceName,
};
//business_info START
if (qobj.topOrgCode && qobj.topOrgCode != 'undefined') {
obj.business_info.topOrgCode = qobj.topOrgCode
}
if (qobj.intentionBizId && qobj.intentionBizId != 'undefined') {
obj.business_info.intentionBizId = qobj.intentionBizId;
}
if (qobj.contactsPhone && qobj.contactsPhone != 'undefined') {
obj.business_info.contactsPhone = qobj.contactsPhone; //已经加密
}
if (qobj.contactsName && qobj.contactsName != 'undefined') {
obj.business_info.contactsName = qobj.contactsName;
}
if (qobj.serviceName && qobj.serviceName != 'undefined') {
obj.business_info.serviceName = qobj.serviceName;
return await this.create(obj, t);
}
//bussiness_info END
//other
if (qobj.closeReason && qobj.closeReason != 'undefined') {
obj.close_reason = qobj.closeReason;
}
if (qobj.salesmanOpcode && qobj.salesmanOpcode != 'undefined') {
obj.salesman_opcode = qobj.salesmanOpcode;
}
if (qobj.salesmanId && qobj.salesmanId != 'undefined') {
obj.salesman_id = qobj.salesmanId;
}
if (qobj.salesmanName && qobj.salesmanName != 'undefined') {
obj.salesman_name = qobj.salesmanName;
}
if (qobj.salesmanPhone && qobj.salesmanPhone != 'undefined') {
obj.salesman_phone = qobj.salesmanPhone;
/**
* 根据服务实例id查找服务所有信息
*/
async findByBizId(pobj) {
var oid = pobj.bizId;
return await this.findOne({ biz_id: oid });
}
return await this.create(obj, t);
}
/**
* 根据服务实例id查找服务所有信息
*/
async findByBizId(pobj){
var oid=pobj.bizId;
return await this.findOne({biz_id:oid});
}
}
module.exports = BizoptDao;
module.exports = BizoptDao;
\ No newline at end of file
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