Commit 6f3412a1 by sxy

feat: 统计 分组 年月日

parent 0739419f
...@@ -4,7 +4,8 @@ var settings = require("../../../../config/settings"); ...@@ -4,7 +4,8 @@ var settings = require("../../../../config/settings");
class BizChanceAPI extends APIBase { class BizChanceAPI extends APIBase {
constructor() { constructor() {
super(); super();
this.bizChanceS=system.getObject("service.bizchance.bizoptSve") this.bizChanceS = system.getObject("service.bizchance.bizoptSve");
this.dateUtil = system.getObject("util.dateClient");
} }
/** /**
* 按照服务商进行分组统计 * 按照服务商进行分组统计
...@@ -13,11 +14,12 @@ class BizChanceAPI extends APIBase { ...@@ -13,11 +14,12 @@ class BizChanceAPI extends APIBase {
* @param {*} req * @param {*} req
*/ */
async statBizChanceCountBySp(p,q,req){ async statBizChanceCountBySp(p, q, req) {
let bizStatus=p.bizStatus let bizStatus = p.bizStatus
let rtn=await this.bizChanceS.statBizChanceCountBySp(bizStatus) let betweenTime = this.dateUtil.betweenTime(p.dateType);
return system.getResult(rtn) let rtn = await this.bizChanceS.statBizChanceCountBySp(bizStatus, betweenTime)
} return system.getResult(rtn)
}
/** /**
* 待处理商机beforeSubmission * 待处理商机beforeSubmission
...@@ -27,12 +29,13 @@ class BizChanceAPI extends APIBase { ...@@ -27,12 +29,13 @@ class BizChanceAPI extends APIBase {
* @param {*} q * @param {*} q
* @param {*} req * @param {*} req
*/ */
async statBizChance(p,q,req){ async statBizChance(p, q, req) {
let companyId=p.company_id let companyId = p.company_id
let userid=p.userid let userid = p.userid
let username=p.username let username = p.username
let opath=p.opath let opath = p.opath
let rtn=await this.bizChanceS.statBizChance(companyId,opath,username,userid) let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizChanceS.statBizChance(companyId, opath, username, userid, betweenTime);
return system.getResult(rtn) return system.getResult(rtn)
} }
classDesc() { classDesc() {
......
...@@ -4,16 +4,18 @@ var settings = require("../../../../config/settings"); ...@@ -4,16 +4,18 @@ var settings = require("../../../../config/settings");
class BizDeliverAPI extends APIBase { class BizDeliverAPI extends APIBase {
constructor() { constructor() {
super(); super();
this.bizDeliveryS=system.getObject("service.bizchance.deliverybillSve") this.bizDeliveryS = system.getObject("service.bizchance.deliverybillSve")
this.dateUtil = system.getObject("util.dateClient");
} }
async statBizDeliveryCountBySp(p,q,req){ async statBizDeliveryCountBySp(p, q, req) {
let bizStatus=p.bizStatus let bizStatus = p.bizStatus;
let rtn=await this.bizDeliveryS.statBizDeliveryCountBySp(bizStatus) let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizDeliveryS.statBizDeliveryCountBySp(bizStatus, betweenTime)
return system.getResult(rtn) return system.getResult(rtn)
} }
async statBizDeliverySettleAmountBySp(p,q,req){ async statBizDeliverySettleAmountBySp(p, q, req) {
let bizStatus=p.bizStatus let bizStatus = p.bizStatus
let rtn=await this.bizDeliveryS.statBizDeliverySettleAmountBySp(bizStatus) let rtn = await this.bizDeliveryS.statBizDeliverySettleAmountBySp(bizStatus)
return system.getResult(rtn) return system.getResult(rtn)
} }
/** /**
...@@ -24,12 +26,13 @@ class BizDeliverAPI extends APIBase { ...@@ -24,12 +26,13 @@ class BizDeliverAPI extends APIBase {
* @param {*} q * @param {*} q
* @param {*} req * @param {*} req
*/ */
async statBizDelivery(p,q,req){ async statBizDelivery(p, q, req) {
let companyId=p.company_id let companyId = p.company_id
let userid=p.userid let userid = p.userid
let username=p.username let username = p.username
let opath=p.opath let opath = p.opath
let rtn=await this.bizDeliveryS.statBizDelivery(companyId,opath,username,userid) let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizDeliveryS.statBizDelivery(companyId, opath, username, userid, betweenTime)
return system.getResult(rtn) return system.getResult(rtn)
} }
classDesc() { classDesc() {
......
...@@ -12,6 +12,7 @@ class BizOptCtl extends CtlBase { ...@@ -12,6 +12,7 @@ class BizOptCtl extends CtlBase {
this.logService = system.getObject("service.bizchance.statuslogSve"); this.logService = system.getObject("service.bizchance.statuslogSve");
this.receiveUrl = "http://192.168.1.140:4011/api/receive/entService/springBoard"; this.receiveUrl = "http://192.168.1.140:4011/api/receive/entService/springBoard";
this.queueUrl = "http://192.168.1.128:4018/api/queueAction/producer/springBoard"; this.queueUrl = "http://192.168.1.128:4018/api/queueAction/producer/springBoard";
this.dateUtil = system.getObject("util.dateClient");
} }
/*根据用户id获取商机信息,分页获取*/ /*根据用户id获取商机信息,分页获取*/
...@@ -19,7 +20,13 @@ class BizOptCtl extends CtlBase { ...@@ -19,7 +20,13 @@ class BizOptCtl extends CtlBase {
try { try {
//TODO 根据业务员id获取该业务员所有列表 //TODO 根据业务员id获取该业务员所有列表
//设置查询条件 //设置查询条件
console.log("pobj--",pobj) console.log("pobj--", pobj)
if (pobj.search && pobj.search.dateType) {
if (pobj.search.dateType !== '全部') {
pobj.search.created_at = this.dateUtil.betweenTime(pobj.search.dateType);
}
delete pobj.search.dateType
}
const rs = await this.service.findAndCountAll(pobj); const rs = await this.service.findAndCountAll(pobj);
let rarr = []; let rarr = [];
let results = rs.results.rows; let results = rs.results.rows;
...@@ -48,47 +55,46 @@ class BizOptCtl extends CtlBase { ...@@ -48,47 +55,46 @@ class BizOptCtl extends CtlBase {
} }
/*根据商机编号获取商机详情*/ /*根据商机编号获取商机详情*/
async findInfoByDemandCode(mobj,qobj,req){ async findInfoByDemandCode(mobj, qobj, req) {
var pobj = mobj.d; var pobj = mobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined') if (pobj.businessMode && pobj.businessMode != 'undefined') {
{ try {
try{
var rs = await this.service.findInfoByDemandCode(pobj); var rs = await this.service.findInfoByDemandCode(pobj);
var ms = await this.schemeService.findInfoByDemandCode(pobj); var ms = await this.schemeService.findInfoByDemandCode(pobj);
var rarr = {} var rarr = {}
if (rs){ if (rs) {
var statusInfo = {"currentStatus":rs.business_status};//商机状态 var statusInfo = { "currentStatus": rs.business_status };//商机状态
var businessInfo = {}; var businessInfo = {};
businessInfo.businessMode = rs.demand_code;//商机编号 businessInfo.businessMode = rs.demand_code;//商机编号
businessInfo.channelSource = appconfig.pdict.source[rs.source_name];///渠道来源 businessInfo.channelSource = appconfig.pdict.source[rs.source_name];///渠道来源
// businessInfo.businessType = rs.business_type;//商机类型代码 // businessInfo.businessType = rs.business_type;//商机类型代码
businessInfo.businessType = appconfig.pdict.businessType[rs.business_type];//商机类型名称 businessInfo.businessType = appconfig.pdict.businessType[rs.business_type];//商机类型名称
// businessInfo.serviceArea = rs.service_address;//服务地区 // businessInfo.serviceArea = rs.service_address;//服务地区
if (businessInfo.businessName == "云上园区注册"){ if (businessInfo.businessName == "云上园区注册") {
businessInfo.serviceArea = appconfig.pdict.registeredParkDict[rs.service_address];//服务地区名称 businessInfo.serviceArea = appconfig.pdict.registeredParkDict[rs.service_address];//服务地区名称
} }
else{ else {
businessInfo.serviceArea = appconfig.pdict.registeredAreaDict[rs.service_address];//服务地区名称 businessInfo.serviceArea = appconfig.pdict.registeredAreaDict[rs.service_address];//服务地区名称
} }
if (businessInfo.businessName == "注册地址"){ if (businessInfo.businessName == "注册地址") {
businessInfo.registeredAddress = appconfig.pdict.registeredAreaDict[rs.service_address];//注册地址名称 businessInfo.registeredAddress = appconfig.pdict.registeredAreaDict[rs.service_address];//注册地址名称
} }
businessInfo.statusReason = rs.close_reason;//商机关闭原因 businessInfo.statusReason = rs.close_reason;//商机关闭原因
businessInfo.memoInfo = rs.business_info.memoInfo;//备注信息 businessInfo.memoInfo = rs.business_info.memoInfo;//备注信息
businessInfo.contactsName = rs.business_info.contactsName;//联系人名称 businessInfo.contactsName = rs.business_info.contactsName;//联系人名称
businessInfo.contactsPhone = rs.business_info.contactsPhone;//联系人联系方式 businessInfo.contactsPhone = rs.business_info.contactsPhone;//联系人联系方式
businessInfo.createdTime = this.timeFormat(rs.created_at);//商机创建时间 businessInfo.createdTime = this.timeFormat(rs.created_at);//商机创建时间
rarr.statusInfo = statusInfo; rarr.statusInfo = statusInfo;
rarr.businessInfo = businessInfo; rarr.businessInfo = businessInfo;
} }
if (ms){ if (ms) {
var planInfo = ms.scheme_info; var planInfo = ms.scheme_info;
planInfo.schemeNumber = ms.scheme_number; planInfo.schemeNumber = ms.scheme_number;
planInfo.currentStatus = ms.scheme_status; planInfo.currentStatus = ms.scheme_status;
if ( ms.scheme_status && ms.scheme_status == "isReject"){ if (ms.scheme_status && ms.scheme_status == "isReject") {
planInfo.currentStatus = "已退回"; planInfo.currentStatus = "已退回";
} }
else{ else {
planInfo.currentStatus = ms.scheme_status; planInfo.currentStatus = ms.scheme_status;
} }
planInfo.statusReason = ms.reject_reason; planInfo.statusReason = ms.reject_reason;
...@@ -96,103 +102,103 @@ class BizOptCtl extends CtlBase { ...@@ -96,103 +102,103 @@ class BizOptCtl extends CtlBase {
} }
return system.getResult(rarr); return system.getResult(rarr);
} }
catch(error){ catch (error) {
console.log("eeeeeeeeeeeeeeeeeeeeee"); console.log("eeeeeeeeeeeeeeeeeeeeee");
console.log(error); console.log(error);
return system.getResultError(error); return system.getResultError(error);
} }
} }
else{ else {
return system.getResultError("参数错误!"); return system.getResultError("参数错误!");
} }
} }
/*根据商机编号更新商机状态*/ /*根据商机编号更新商机状态*/
async updateStatusByDemandCode(mobj,qobj,req){ async updateStatusByDemandCode(mobj, qobj, req) {
var pobj = mobj.d; var pobj = mobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.currentStatus && pobj.currentStatus != 'undefined'){ if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.currentStatus && pobj.currentStatus != 'undefined') {
try{ try {
await this.service.updateStatusByDemandCode(pobj); await this.service.updateStatusByDemandCode(pobj);
await this.schemeService.updateStatusByDemandCode(pobj);//同时更新方案的状态 await this.schemeService.updateStatusByDemandCode(pobj);//同时更新方案的状态
var res = this.service.findInfoByDemandCode(pobj); var res = this.service.findInfoByDemandCode(pobj);
if (res && res != 'undefined'){ if (res && res != 'undefined') {
var logInfo = { var logInfo = {
"flowType":"BIZ", "flowType": "BIZ",
"flowId":res.id, "flowId": res.id,
"statusCode":pobj.currentStatus, "statusCode": pobj.currentStatus,
"statusReason":res.close_reason, "statusReason": res.close_reason,
"clerkName":res.salesman_name, "clerkName": res.salesman_name,
"clerkId":res.salesman_id "clerkId": res.salesman_id
} }
await this.logService.insertInfo(logInfo);//插入状态日至表 await this.logService.insertInfo(logInfo);//插入状态日至表
} }
if (pobj.currentStatus == "isClosed"){ //关闭需求时调用 if (pobj.currentStatus == "isClosed") { //关闭需求时调用
var rc = system.getObject("util.execClient"); var rc = system.getObject("util.execClient");
var requrl = this.queueUrl; var requrl = this.queueUrl;
var params = { var params = {
"actionType":"produceData", "actionType": "produceData",
"actionBody":{ "actionBody": {
"pushUrl":this.receiveUrl, "pushUrl": this.receiveUrl,
"actionType":"closeNeed", "actionType": "closeNeed",
"identifyCode":"ic-manage", "identifyCode": "ic-manage",
"messageBody":{ "messageBody": {
"needNum": pobj.businessMode, "needNum": pobj.businessMode,
"note":pobj.statusReason "note": pobj.statusReason
} }
} }
} }
var rtn = await rc.execPost(params, requrl); var rtn = await rc.execPost(params, requrl);
var j = JSON.parse(rtn.stdout); var j = JSON.parse(rtn.stdout);
if (j.status == 1){ if (j.status == 1) {
return system.getResult("操作成功!"); return system.getResult("操作成功!");
} }
else{ else {
return system.getResultError("更新方案状态出错!"); return system.getResultError("更新方案状态出错!");
} }
} }
} }
catch (error){ catch (error) {
return system.getResultError(error); return system.getResultError(error);
} }
} }
else{ else {
return system.getResultError("参数错误!"); return system.getResultError("参数错误!");
} }
} }
/*插入数据信息 */ /*插入数据信息 */
async insertInfo(nobj,qobj,req){ async insertInfo(nobj, qobj, req) {
var pobj = nobj.d; var pobj = nobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.businessType && pobj.businessType != 'undefined'){ if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.businessType && pobj.businessType != 'undefined') {
try{ try {
pobj.currentStatus = "beforeSubmission";//加上当前状态为待提交方案 pobj.currentStatus = "beforeSubmission";//加上当前状态为待提交方案
pobj.channelSource = "tencentCloud";//目前渠道只有腾讯 pobj.channelSource = "tencentCloud";//目前渠道只有腾讯
pobj.sourceNumber = "1111111"; pobj.sourceNumber = "1111111";
pobj.businessType = appconfig.pdict.dyDict[pobj.businessType]; pobj.businessType = appconfig.pdict.dyDict[pobj.businessType];
var buInfo = await this.service.insertInfo(pobj); var buInfo = await this.service.insertInfo(pobj);
var logInfo = { var logInfo = {
"flowType":"BIZ", "flowType": "BIZ",
"flowId":buInfo.id, "flowId": buInfo.id,
"statusCode":pobj.currentStatus, "statusCode": pobj.currentStatus,
"clerkName":pobj.clerkName, "clerkName": pobj.clerkName,
"clerkId":pobj.salesmanId "clerkId": pobj.salesmanId
} }
await this.logService.insertInfo(logInfo);//插入状态日至表 await this.logService.insertInfo(logInfo);//插入状态日至表
return { return {
"status":1, //1代表成功,否则失败 "status": 1, //1代表成功,否则失败
"message":"操作成功", "message": "操作成功",
"data":"", "data": "",
"requestId":"" "requestId": ""
}; };
} }
catch(error){ catch (error) {
console.log("TTTTTTTTTTTTTTTTTTTTTTT"); console.log("TTTTTTTTTTTTTTTTTTTTTTT");
console.log(error); console.log(error);
return system.getResultError(error); return system.getResultError(error);
} }
} }
else{ else {
return system.getResultError("参数错误!"); return system.getResultError("参数错误!");
} }
} }
......
...@@ -15,12 +15,20 @@ class DeliverybillCtl extends CtlBase { ...@@ -15,12 +15,20 @@ class DeliverybillCtl extends CtlBase {
this.receiveUrl = "http://192.168.1.140:4011/api/receive/entService/springBoard"; this.receiveUrl = "http://192.168.1.140:4011/api/receive/entService/springBoard";
this.queueUrl = "http://192.168.1.128:4018/api/queueAction/producer/springBoard"; this.queueUrl = "http://192.168.1.128:4018/api/queueAction/producer/springBoard";
this.wdyUrl = "http://192.168.1.113:4011/api/action/order/springBoard"; this.wdyUrl = "http://192.168.1.113:4011/api/action/order/springBoard";
this.dateUtil = system.getObject("util.dateClient");
} }
/*根据用户id获取商机信息,分页获取*/ /*根据用户id获取商机信息,分页获取*/
async findAndCountAll(pobj, qobj, req) { async findAndCountAll(pobj, qobj, req) {
try { try {
//TODO 根据业务员id获取该业务员所有交付单列表 //TODO 根据业务员id获取该业务员所有交付单列表
if (pobj.search && pobj.search.dateType) {
if (pobj.search.dateType !== '全部') {
pobj.search.created_at = this.dateUtil.betweenTime(pobj.search.dateType);
}
delete pobj.search.dateType
}
const rs = await this.service.findAndCountAll(pobj); const rs = await this.service.findAndCountAll(pobj);
let rarr = []; let rarr = [];
let results = rs.results.rows; let results = rs.results.rows;
...@@ -51,7 +59,7 @@ class DeliverybillCtl extends CtlBase { ...@@ -51,7 +59,7 @@ class DeliverybillCtl extends CtlBase {
} }
else if (robj.businessName == '云上园区注册') { else if (robj.businessName == '云上园区注册') {
robj.registeredType = element.delivery_info.registeredType;//园区注册时,根据该值跳界面 robj.registeredType = element.delivery_info.registeredType;//园区注册时,根据该值跳界面
if (robj.baseInfo.isWhether == "yes"|| robj.baseInfo.financial == "yes") {//如果有刻章需求或者是财税服务 if (robj.baseInfo.isWhether == "yes" || robj.baseInfo.financial == "yes") {//如果有刻章需求或者是财税服务
robj.relatedProducts = '有'; robj.relatedProducts = '有';
} }
else { else {
...@@ -74,6 +82,7 @@ class DeliverybillCtl extends CtlBase { ...@@ -74,6 +82,7 @@ class DeliverybillCtl extends CtlBase {
rs.results.rows = rarr; rs.results.rows = rarr;
return system.getResult(rs); return system.getResult(rs);
} catch (error) { } catch (error) {
console.log(error)
return system.getResultError(error); return system.getResultError(error);
} }
} }
...@@ -184,9 +193,9 @@ class DeliverybillCtl extends CtlBase { ...@@ -184,9 +193,9 @@ class DeliverybillCtl extends CtlBase {
rarr.baseInfo.startTime = rs.delivery_info.startTime;//开始计费时间 rarr.baseInfo.startTime = rs.delivery_info.startTime;//开始计费时间
} }
if (rs.delivery_info.buyDuration && rs.delivery_info.buyDuration != 'undefined' && rarr.baseInfo.startTime && rarr.baseInfo.startTime != 'undefined') { if (rs.delivery_info.buyDuration && rs.delivery_info.buyDuration != 'undefined' && rarr.baseInfo.startTime && rarr.baseInfo.startTime != 'undefined') {
console.log("ddddddddddd____________________________"+ rarr.baseInfo.startTime ); console.log("ddddddddddd____________________________" + rarr.baseInfo.startTime);
var d = new Date(rarr.baseInfo.startTime); var d = new Date(rarr.baseInfo.startTime);
console.log("ddddddddddd____________________________"+ d ); console.log("ddddddddddd____________________________" + d);
rarr.baseInfo.endTime = this.oneYearPast(d, 1);//到期时间 rarr.baseInfo.endTime = this.oneYearPast(d, 1);//到期时间
var ss = moment(); var ss = moment();
rarr.baseInfo.surplusDuration = this.diffDays(ss, rarr.baseInfo.endTime);//剩余时长 rarr.baseInfo.surplusDuration = this.diffDays(ss, rarr.baseInfo.endTime);//剩余时长
...@@ -227,8 +236,8 @@ class DeliverybillCtl extends CtlBase { ...@@ -227,8 +236,8 @@ class DeliverybillCtl extends CtlBase {
async updatestartTimeByDeliverCode(mobj, qobj, red) {//根据交付单编号更新开始计费时间 async updatestartTimeByDeliverCode(mobj, qobj, red) {//根据交付单编号更新开始计费时间
var pobj = mobj.d; var pobj = mobj.d;
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined' && pobj.baseInfo.startTime && pobj.baseInfo.startTime != 'undefined'){ if (pobj.deliverNumber && pobj.deliverNumber != 'undefined' && pobj.baseInfo.startTime && pobj.baseInfo.startTime != 'undefined') {
try{ try {
var rs = await this.service.findInfoByDeliverCode(pobj)//先得到交付单详情 var rs = await this.service.findInfoByDeliverCode(pobj)//先得到交付单详情
if (rs && rs != 'undefined') { if (rs && rs != 'undefined') {
rs.delivery_info.startTime = pobj.baseInfo.startTime; rs.delivery_info.startTime = pobj.baseInfo.startTime;
...@@ -289,11 +298,11 @@ class DeliverybillCtl extends CtlBase { ...@@ -289,11 +298,11 @@ class DeliverybillCtl extends CtlBase {
return system.getResultError("数据不存在!"); return system.getResultError("数据不存在!");
} }
} }
catch(error){ catch (error) {
return system.getResultError(error); return system.getResultError(error);
} }
} }
else{ else {
return system.getResultError("参数错误!"); return system.getResultError("参数错误!");
} }
} }
...@@ -324,7 +333,7 @@ class DeliverybillCtl extends CtlBase { ...@@ -324,7 +333,7 @@ class DeliverybillCtl extends CtlBase {
var j = JSON.parse(rtn.stdout); var j = JSON.parse(rtn.stdout);
var j1status = 1; var j1status = 1;
if (pobj.deliverStatus == "closed"){//退款 if (pobj.deliverStatus == "closed") {//退款
params = { params = {
"actionType": "produceData", "actionType": "produceData",
"actionBody": { "actionBody": {
...@@ -781,7 +790,7 @@ class DeliverybillCtl extends CtlBase { ...@@ -781,7 +790,7 @@ class DeliverybillCtl extends CtlBase {
//time时间n年后的的前一天 //time时间n年后的的前一天
oneYearPast(time, n) { oneYearPast(time, n) {
//var time=new Date(); //var time=new Date();
try{ try {
var year = time.getFullYear() + n; var year = time.getFullYear() + n;
var d = time.setFullYear(year); var d = time.setFullYear(year);
var date = time.getDate(d) - 1; var date = time.getDate(d) - 1;
...@@ -796,7 +805,7 @@ class DeliverybillCtl extends CtlBase { ...@@ -796,7 +805,7 @@ class DeliverybillCtl extends CtlBase {
//计算俩日期相差多少天 //计算俩日期相差多少天
diffDays(time1, time2) { diffDays(time1, time2) {
try{ try {
var m1 = moment(time1); var m1 = moment(time1);
var m2 = moment(time2); var m2 = moment(time2);
return m2.diff(m1, 'day'); return m2.diff(m1, 'day');
...@@ -804,7 +813,7 @@ class DeliverybillCtl extends CtlBase { ...@@ -804,7 +813,7 @@ class DeliverybillCtl extends CtlBase {
catch{ catch{
return ""; return "";
} }
} }
} }
module.exports = DeliverybillCtl; module.exports = DeliverybillCtl;
......
...@@ -15,7 +15,7 @@ class BizoptDao extends Dao { ...@@ -15,7 +15,7 @@ class BizoptDao extends Dao {
qw["facilitator_id"] = Number(qobj.company_id) qw["facilitator_id"] = Number(qobj.company_id)
// 为空说明是管理员,不需设置组织结构过滤 // 为空说明是管理员,不需设置组织结构过滤
if (qobj.opath && qobj.opath != "") { if (qobj.opath && qobj.opath != "") {
qw["salesman_opcode"] = { [this.db.Op.like]:'%qobj.opath%'} qw["salesman_opcode"] = { [this.db.Op.like]: '%qobj.opath%' }
} }
//不是来自平台前端查询 //不是来自平台前端查询
if (qobj.bizpath && qobj.bizpath.indexOf("pmx") < 0) { if (qobj.bizpath && qobj.bizpath.indexOf("pmx") < 0) {
...@@ -45,7 +45,7 @@ class BizoptDao extends Dao { ...@@ -45,7 +45,7 @@ class BizoptDao extends Dao {
if (qobj.statusReason && qobj.statusReason != 'undefined') { if (qobj.statusReason && qobj.statusReason != 'undefined') {
setobj["close_reason"] = qobj.statusReason; setobj["close_reason"] = qobj.statusReason;
} }
else{ else {
setobj["close_reason"] = ""; setobj["close_reason"] = "";
} }
var whereobj = { "demand_code": qobj.businessMode }; var whereobj = { "demand_code": qobj.businessMode };
...@@ -58,7 +58,7 @@ class BizoptDao extends Dao { ...@@ -58,7 +58,7 @@ class BizoptDao extends Dao {
"demand_code": qobj.businessMode, "demand_code": qobj.businessMode,
"business_type": qobj.businessType, "business_type": qobj.businessType,
"business_status": qobj.currentStatus, "business_status": qobj.currentStatus,
"business_info":{} "business_info": {}
}; };
if (qobj.channelSource && qobj.channelSource != 'undefined') { if (qobj.channelSource && qobj.channelSource != 'undefined') {
obj.source_name = qobj.channelSource; obj.source_name = qobj.channelSource;
...@@ -81,16 +81,16 @@ class BizoptDao extends Dao { ...@@ -81,16 +81,16 @@ class BizoptDao extends Dao {
if (qobj.contactsPhone && qobj.contactsPhone != 'undefined') { if (qobj.contactsPhone && qobj.contactsPhone != 'undefined') {
obj.business_info.contactsPhone = qobj.contactsPhone; obj.business_info.contactsPhone = qobj.contactsPhone;
} }
if (qobj.serviceName && qobj.serviceName != 'undefined'){ if (qobj.serviceName && qobj.serviceName != 'undefined') {
obj.business_info.serviceName = qobj.serviceName; obj.business_info.serviceName = qobj.serviceName;
} }
if (qobj.businessName && qobj.businessName != 'undefined'){ if (qobj.businessName && qobj.businessName != 'undefined') {
obj.business_info.businessName = qobj.businessName; obj.business_info.businessName = qobj.businessName;
} }
if (qobj.UserName && qobj.UserName != 'undefined'){ if (qobj.UserName && qobj.UserName != 'undefined') {
obj.business_info.userName = qobj.UserNames; obj.business_info.userName = qobj.UserNames;
} }
if (qobj.companyName && qobj.companyName != 'undefined'){ if (qobj.companyName && qobj.companyName != 'undefined') {
obj.business_info.companyName = qobj.companyName; obj.business_info.companyName = qobj.companyName;
} }
if (qobj.servicerCode && qobj.servicerCode != 'undefined') { if (qobj.servicerCode && qobj.servicerCode != 'undefined') {
......
...@@ -6,19 +6,22 @@ class BizOptService extends ServiceBase { ...@@ -6,19 +6,22 @@ class BizOptService extends ServiceBase {
constructor() { constructor() {
super("bizchance", ServiceBase.getDaoName(BizOptService)); super("bizchance", ServiceBase.getDaoName(BizOptService));
} }
async statBizChanceCountBySp(bizStatus){ async statBizChanceCountBySp(bizStatus, betweenTime) {
let params={} let params = {}
params.group={ params.group = {
byFields:['facilitator_name'], byFields: ['facilitator_name'],
actionType:'count', actionType: 'count',
aggField:'id', aggField: 'id',
aliasField:' as chanceCount', aliasField: ' as chanceCount',
tblName:'bussiness_opportunity', tblName: 'bussiness_opportunity',
where:bizStatus!=""?`where business_status='${bizStatus}'`:'', where: bizStatus != "" ? `where business_status='${bizStatus}'` : '',
having:'', having: '',
} }
let s=await this.dao.statGroupBy(params,null) if (betweenTime.length > 0) {
return s params.group.where = `${params.group.where} ${params.group.where ? 'AND' : "WHERE"} (created_at BETWEEN '${betweenTime[0]}' AND '${betweenTime[1]}')`
}
let s = await this.dao.statGroupBy(params, null)
return s
} }
/** /**
* 公司id,平台公司ID为1 * 公司id,平台公司ID为1
...@@ -27,38 +30,46 @@ class BizOptService extends ServiceBase { ...@@ -27,38 +30,46 @@ class BizOptService extends ServiceBase {
* @param {*} username * @param {*} username
* @param {*} userid * @param {*} userid
*/ */
async statBizChance(companyId,opath,username,userid){ async statBizChance(companyId, opath, username, userid, betweenTime) {
// 时间 筛选
let andWhere = [];
if (betweenTime.length > 0) {
andWhere.push({
"created_at": { [this.db.Op.between]: betweenTime }
})
}
//如果当前登录人是平台,返回所有商机 //如果当前登录人是平台,返回所有商机
let waittoHandledCount=0 let waittoHandledCount = 0
let handlingCount=0 let handlingCount = 0
let finishedCount=0 let finishedCount = 0
let closedCount=0 let closedCount = 0
if(companyId==1){ if (companyId == 1) {
waittoHandledCount=await this.dao.findCount({where:{business_status:'beforeSubmission'}}) waittoHandledCount = await this.dao.findCount({ where: { business_status: 'beforeSubmission', [this.db.Op.and]: andWhere } })
handlingCount=await this.dao.findCount({where:{business_status:'beforeConfirmation'}}) handlingCount = await this.dao.findCount({ where: { business_status: 'beforeConfirmation', [this.db.Op.and]: andWhere } })
finishedCount=await this.dao.findCount({where:{business_status:'isFinished'}}) finishedCount = await this.dao.findCount({ where: { business_status: 'isFinished', [this.db.Op.and]: andWhere } })
closedCount=await this.dao.findCount({where:{business_status:'isClosed'}}) closedCount = await this.dao.findCount({ where: { business_status: 'isClosed', [this.db.Op.and]: andWhere } })
}else{ } else {
let opathstr='' let opathstr = ''
if(opath){ if (opath) {
opathstr=opath opathstr = opath
waittoHandledCount=await this.dao.findCount({where:{business_status:'beforeSubmission',salesman_opcode:{ [this.db.Op.like]:`%${opathstr}%`},'facilitator_id':companyId}}) waittoHandledCount = await this.dao.findCount({ where: { business_status: 'beforeSubmission', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
handlingCount=await this.dao.findCount({where:{business_status:'beforeConfirmation',salesman_opcode:{ [this.db.Op.like]:`%${opathstr}%`},'facilitator_id':companyId}}) handlingCount = await this.dao.findCount({ where: { business_status: 'beforeConfirmation', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
finishedCount=await this.dao.findCount({where:{business_status:'isFinished',salesman_opcode:{ [this.db.Op.like]:`%${opathstr}%`},'facilitator_id':companyId}}) finishedCount = await this.dao.findCount({ where: { business_status: 'isFinished', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
closedCount=await this.dao.findCount({where:{business_status:'isClosed',salesman_opcode:{[this.db.Op.like]:`%${opathstr}%`},'facilitator_id':companyId}}) closedCount = await this.dao.findCount({ where: { business_status: 'isClosed', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
}else{ } else {
waittoHandledCount=await this.dao.findCount({where:{business_status:'beforeSubmission','facilitator_id':companyId}}) waittoHandledCount = await this.dao.findCount({ where: { business_status: 'beforeSubmission', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
handlingCount=await this.dao.findCount({where:{business_status:'beforeConfirmation','facilitator_id':companyId}}) handlingCount = await this.dao.findCount({ where: { business_status: 'beforeConfirmation', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
finishedCount=await this.dao.findCount({where:{business_status:'isFinished','facilitator_id':companyId}}) finishedCount = await this.dao.findCount({ where: { business_status: 'isFinished', 'facilitator_id': companyId }, [this.db.Op.and]: andWhere })
closedCount=await this.dao.findCount({where:{business_status:'isClosed','facilitator_id':companyId}}) closedCount = await this.dao.findCount({ where: { business_status: 'isClosed', 'facilitator_id': companyId }, [this.db.Op.and]: andWhere })
} }
} }
//成单率 //成单率
let allChance=waittoHandledCount+handlingCount+finishedCount+closedCount let allChance = waittoHandledCount + handlingCount + finishedCount + closedCount
let successRadio=Math.ceil((finishedCount/allChance) * 100) let successRadio = Math.ceil((finishedCount / allChance) * 100)
//如果当前登录人不是平台,那么需要按照opath查询 //如果当前登录人不是平台,那么需要按照opath查询
return {waittoHandledCount:waittoHandledCount,handlingCount:handlingCount,finishedCount:finishedCount,closedCount:closedCount,successRadio:successRadio} return { waittoHandledCount: waittoHandledCount, handlingCount: handlingCount, finishedCount: finishedCount, closedCount: closedCount, successRadio: successRadio }
} }
async findAndCountAll(obj) { async findAndCountAll(obj) {
var self = this; var self = this;
...@@ -67,23 +78,23 @@ class BizOptService extends ServiceBase { ...@@ -67,23 +78,23 @@ class BizOptService extends ServiceBase {
} }
/*根据商机编号获取商机详情*/ /*根据商机编号获取商机详情*/
async findInfoByDemandCode(qobj){ async findInfoByDemandCode(qobj) {
return await this.dao.findInfoByDemandCode(qobj); return await this.dao.findInfoByDemandCode(qobj);
} }
/* 根据商机编号更新商机状态 */ /* 根据商机编号更新商机状态 */
async updateStatusByDemandCode(qobj){ async updateStatusByDemandCode(qobj) {
var self=this; var self = this;
return self.db.transaction(async function (t) { return self.db.transaction(async function (t) {
return await self.dao.updateStatusByDemandCode(qobj,t); return await self.dao.updateStatusByDemandCode(qobj, t);
}); });
} }
/*插入商机信息*/ /*插入商机信息*/
async insertInfo(qobj){ async insertInfo(qobj) {
var self=this; var self = this;
return self.db.transaction(async function (t) { return self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj,t); return await self.dao.insertInfo(qobj, t);
}); });
} }
......
...@@ -9,42 +9,52 @@ class DeliverybillService extends ServiceBase { ...@@ -9,42 +9,52 @@ class DeliverybillService extends ServiceBase {
this.logDao = system.getObject("db.bizchance.statuslogDao"); this.logDao = system.getObject("db.bizchance.statuslogDao");
this.cacheDao = system.getObject("db.bizchance.cacheinfoDao"); this.cacheDao = system.getObject("db.bizchance.cacheinfoDao");
} }
async statBizDeliverySettleAmountBySp(settleStatus){ async statBizDeliverySettleAmountBySp(settleStatus) {
let params={} let params = {}
let where=settleStatus!=""?`where settle_status='${settleStatus}'`:'' let where = settleStatus != "" ? `where settle_status='${settleStatus}'` : ''
params.group={ params.group = {
byFields:['facilitator_name'], byFields: ['facilitator_name'],
actionType:'sum', actionType: 'sum',
aggField:'cost_price', aggField: 'cost_price',
aliasField:' as chanceCount', aliasField: ' as chanceCount',
tblName:'delivery_bill', tblName: 'delivery_bill',
where:where, where: where,
having:'', having: '',
} }
let s=await this.dao.statGroupBy(params,null) let s = await this.dao.statGroupBy(params, null)
return s return s
} }
async statBizDeliveryCountBySp(deliverStatus){ async statBizDeliveryCountBySp(deliverStatus, betweenTime) {
let params={} let params = {}
let where=deliverStatus!=""?`where delivery_status='${deliverStatus}'`:'' let where = deliverStatus != "" ? `where delivery_status='${deliverStatus}'` : ''
if(deliverStatus=="handling"){ if (deliverStatus == "handling") {
where= `where delivery_status not in ('received', 'success', 'closed')` where = `where delivery_status not in ('received', 'success', 'closed')`
}
params.group = {
byFields: ['facilitator_name'],
actionType: 'count',
aggField: 'id',
aliasField: ' as chanceCount',
tblName: 'delivery_bill',
where: where,
having: '',
} }
params.group={ if (betweenTime.length > 0) {
byFields:['facilitator_name'], params.group.where = `${params.group.where} ${params.group.where ? 'AND' : "WHERE"} (created_at BETWEEN '${betweenTime[0]}' AND '${betweenTime[1]}')`
actionType:'count',
aggField:'id',
aliasField:' as chanceCount',
tblName:'delivery_bill',
where:where,
having:'',
} }
let s=await this.dao.statGroupBy(params,null) let s = await this.dao.statGroupBy(params, null)
return s return s
} }
async statBizDelivery(companyId, opath, username, userid) { async statBizDelivery(companyId, opath, username, userid, betweenTime) {
// 时间 筛选
let andWhere = [];
if (betweenTime.length > 0) {
andWhere.push({
"created_at": { [this.db.Op.between]: betweenTime }
})
}
//如果当前登录人是平台,返回所有商机 //如果当前登录人是平台,返回所有商机
let waittoHandledCount = 0//received let waittoHandledCount = 0//received
let handlingCount = 0 let handlingCount = 0
...@@ -57,41 +67,41 @@ class DeliverybillService extends ServiceBase { ...@@ -57,41 +67,41 @@ class DeliverybillService extends ServiceBase {
let settled = 0 let settled = 0
let settledAmount = 0 let settledAmount = 0
if (companyId == 1) { if (companyId == 1) {
waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received' } }) waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] } } }) handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] }, [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success' } }) finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { delivery_status: 'closed' } }) closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', [this.db.Op.and]: andWhere } })
toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle' } }) toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle', [this.db.Op.and]: andWhere } })
toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle' } }) toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle', [this.db.Op.and]: andWhere } })
settling = await this.dao.findCount({ where: { settle_status: 'settling' } }) settling = await this.dao.findCount({ where: { settle_status: 'settling', [this.db.Op.and]: andWhere } })
settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling' } }) settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling', [this.db.Op.and]: andWhere } })
settled = await this.dao.findCount({ where: { settle_status: 'settled' } }) settled = await this.dao.findCount({ where: { settle_status: 'settled', [this.db.Op.and]: andWhere } })
settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled' } }) settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled', [this.db.Op.and]: andWhere } })
} else { } else {
let opathstr = '' let opathstr = ''
if (opath) { if (opath) {
opathstr = opath opathstr = opath
waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] }, salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] }, salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settling = await this.dao.findCount({ where: { settle_status: 'settling', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) settling = await this.dao.findCount({ where: { settle_status: 'settling', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settled = await this.dao.findCount({ where: { settle_status: 'settled', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) settled = await this.dao.findCount({ where: { settle_status: 'settled', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId } }) settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
} else { } else {
waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', 'facilitator_id': companyId } }) waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] }, 'facilitator_id': companyId } }) handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', 'facilitator_id': companyId } }) finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', 'facilitator_id': companyId } }) closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle', 'facilitator_id': companyId } }) toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle', 'facilitator_id': companyId } }) toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settling = await this.dao.findCount({ where: { settle_status: 'settling', 'facilitator_id': companyId } }) settling = await this.dao.findCount({ where: { settle_status: 'settling', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling', 'facilitator_id': companyId } }) settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settled = await this.dao.findCount({ where: { settle_status: 'settled', 'facilitator_id': companyId } }) settled = await this.dao.findCount({ where: { settle_status: 'settled', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled', 'facilitator_id': companyId } }) settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
} }
} }
...@@ -115,66 +125,70 @@ class DeliverybillService extends ServiceBase { ...@@ -115,66 +125,70 @@ class DeliverybillService extends ServiceBase {
} }
//为租户自己给交付打标记,表示中台已经给予结算,自己记账用 //为租户自己给交付打标记,表示中台已经给予结算,自己记账用
//租户自己临时记录结算情况 //租户自己临时记录结算情况
async settleApplyForTacent(ids,uid,uname,spname,spid){ async settleApplyForTacent(ids, uid, uname, spname, spid) {
var self=this var self = this
return this.db.transaction(async function (t){ return this.db.transaction(async function (t) {
//先按照ids查询出交付单的合计服务成本 //先按照ids查询出交付单的合计服务成本
let d= await self.dao.customQuery("select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)",{idstr:ids}); let d = await self.dao.customQuery("select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)", { idstr: ids });
// let settleAmount=await self.dao.model.sum("cost_price",{where:{id:{[self.db.Op.In]:['40','41','42']}},transaction:t}) // let settleAmount=await self.dao.model.sum("cost_price",{where:{id:{[self.db.Op.In]:['40','41','42']}},transaction:t})
let settleAmount=d[0].settleAmount let settleAmount = d[0].settleAmount
settleAmount=isNaN(settleAmount)?0:settleAmount settleAmount = isNaN(settleAmount) ? 0 : settleAmount
let settlecode=await self. getBusUid("JSD") let settlecode = await self.getBusUid("JSD")
let settleObj={ let settleObj = {
code:settlecode, code: settlecode,
settle_amount:settleAmount, settle_amount: settleAmount,
creator_id:uid, creator_id: uid,
creator:uname, creator: uname,
facilitator_name:spname, facilitator_name: spname,
facilitator_id:spid, facilitator_id: spid,
isPayedStatus:false, isPayedStatus: false,
auditedStatus:true, auditedStatus: true,
payer_id:uid, payer_id: uid,
payer:uname, payer: uname,
auditor_id:uid, auditor_id: uid,
auditor:uname auditor: uname
} }
//生成结算单,结算单状态直接更改为已经付款 //生成结算单,结算单状态直接更改为已经付款
let newentity=await self.db.models.settlebill.create(settleObj,{transaction:t}) let newentity = await self.db.models.settlebill.create(settleObj, { transaction: t })
//然后按照ids更新交付单的状态为结算中,更新结算单的id到交付单表 //然后按照ids更新交付单的状态为结算中,更新结算单的id到交付单表
for(let idstr of ids){ for (let idstr of ids) {
let up = await self.dao.updateByWhere({settle_status:'settling', let up = await self.dao.updateByWhere({
settlebill_id:newentity.id }, { id: idstr }, t); settle_status: 'settling',
} settlebill_id: newentity.id
return newentity }, { id: idstr }, t);
}); }
return newentity
});
} }
async settleApply(ids,uid,uname,spname,spid){ async settleApply(ids, uid, uname, spname, spid) {
var self=this var self = this
return this.db.transaction(async function (t){ return this.db.transaction(async function (t) {
//先按照ids查询出交付单的合计服务成本 //先按照ids查询出交付单的合计服务成本
let d= await self.dao.customQuery("select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)",{idstr:ids}); let d = await self.dao.customQuery("select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)", { idstr: ids });
// let settleAmount=await self.dao.model.sum("cost_price",{where:{id:{[self.db.Op.In]:['40','41','42']}},transaction:t}) // let settleAmount=await self.dao.model.sum("cost_price",{where:{id:{[self.db.Op.In]:['40','41','42']}},transaction:t})
let settleAmount=d[0].settleAmount let settleAmount = d[0].settleAmount
settleAmount=isNaN(settleAmount)?0:settleAmount settleAmount = isNaN(settleAmount) ? 0 : settleAmount
let settlecode=await self. getBusUid("JSD") let settlecode = await self.getBusUid("JSD")
let settleObj={ let settleObj = {
code:settlecode, code: settlecode,
settle_amount:settleAmount, settle_amount: settleAmount,
creator_id:uid, creator_id: uid,
creator:uname, creator: uname,
facilitator_name:spname, facilitator_name: spname,
facilitator_id:spid facilitator_id: spid
} }
//生成结算单,结算单状态为待审核 //生成结算单,结算单状态为待审核
let newentity=await self.db.models.settlebill.create(settleObj,{transaction:t}) let newentity = await self.db.models.settlebill.create(settleObj, { transaction: t })
//然后按照ids更新交付单的状态为结算中,更新结算单的id到交付单表 //然后按照ids更新交付单的状态为结算中,更新结算单的id到交付单表
for(let idstr of ids){ for (let idstr of ids) {
let up = await self.dao.updateByWhere({settle_status:'settling', let up = await self.dao.updateByWhere({
settlebill_id:newentity.id }, { id: idstr }, t); settle_status: 'settling',
} settlebill_id: newentity.id
return newentity }, { id: idstr }, t);
}); }
return newentity
});
} }
async findAndCountAll(obj) { async findAndCountAll(obj) {
var self = this; var self = this;
...@@ -210,7 +224,7 @@ class DeliverybillService extends ServiceBase { ...@@ -210,7 +224,7 @@ class DeliverybillService extends ServiceBase {
async insertInfoall(pobj) {//*插入交付单信息,大事务*/从队列取数据的时候用 async insertInfoall(pobj) {//*插入交付单信息,大事务*/从队列取数据的时候用
var self = this; var self = this;
return await self.db.transaction(async function (t) { return await self.db.transaction(async function (t) {
var res = await self.dao.insertInfo(pobj);//插入交付单列表 var res = await self.dao.insertInfo(pobj);//插入交付单列表
pobj.deliverId = res.id; pobj.deliverId = res.id;
//插入暂存 //插入暂存
......
...@@ -14,6 +14,7 @@ class SchemeService extends ServiceBase { ...@@ -14,6 +14,7 @@ class SchemeService extends ServiceBase {
async findInfoByDemandCode(qobj){//根据方案编号获取方案详情 async findInfoByDemandCode(qobj){//根据方案编号获取方案详情
return await this.dao.findInfoByDemandCode(qobj); return await this.dao.findInfoByDemandCode(qobj);
} }
async updateStatusByDemandCode(qobj){//根据商机编号号更新方案状态及原因 async updateStatusByDemandCode(qobj){//根据商机编号号更新方案状态及原因
......
const moment = require('moment');
class DateClient {
constructor() {
}
betweenDay() {
return [moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'), moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')]
}
betweenMonth() {
return [moment().startOf('month').format('YYYY-MM-DD HH:mm:ss'), moment().endOf('month').format('YYYY-MM-DD HH:mm:ss')]
}
betweenYear() {
return [moment().startOf('year').format('YYYY-MM-DD HH:mm:ss'), moment().endOf('year').format('YYYY-MM-DD HH:mm:ss')]
}
betweenTime(type) {
let times = [];
switch (type) {
case "日":
times = this.betweenDay();
break
case "月":
times = this.betweenMonth();
break
case "年":
times = this.betweenYear();
break
case "全部":
break
}
return times
}
}
module.exports = DateClient;
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