Commit 0ca979a1 by 王勇飞

gyq

parents ecd0e8cc 4eff5374
#!/bin/bash
FROM registry.cn-beijing.aliyuncs.com/hantang2/node105:v2
MAINTAINER jy "jiangyong@gongsibao.com"
ADD icp-deliver /apps/icp-deliver/
WORKDIR /apps/icp-deliver/
ADD ic-deliver /apps/ic-deliver/
WORKDIR /apps/ic-deliver/
RUN cnpm install -S
CMD ["node","/apps/icp-deliver/main.js"]
CMD ["node","/apps/ic-deliver/main.js"]
......
......@@ -4,7 +4,8 @@ var settings = require("../../../../config/settings");
class BizChanceAPI extends APIBase {
constructor() {
super();
this.bizChanceS=system.getObject("service.bizchance.bizoptSve")
this.bizChanceS = system.getObject("service.bizchance.bizoptSve");
this.dateUtil = system.getObject("util.dateClient");
}
/**
* 按照服务商进行分组统计
......@@ -13,9 +14,10 @@ class BizChanceAPI extends APIBase {
* @param {*} req
*/
async statBizChanceCountBySp(p,q,req){
let bizStatus=p.bizStatus
let rtn=await this.bizChanceS.statBizChanceCountBySp(bizStatus)
async statBizChanceCountBySp(p, q, req) {
let bizStatus = p.bizStatus
let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizChanceS.statBizChanceCountBySp(bizStatus, betweenTime)
return system.getResult(rtn)
}
......@@ -27,12 +29,13 @@ class BizChanceAPI extends APIBase {
* @param {*} q
* @param {*} req
*/
async statBizChance(p,q,req){
let companyId=p.company_id
let userid=p.userid
let username=p.username
let opath=p.opath
let rtn=await this.bizChanceS.statBizChance(companyId,opath,username,userid)
async statBizChance(p, q, req) {
let companyId = p.company_id
let userid = p.userid
let username = p.username
let opath = p.opath
let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizChanceS.statBizChance(companyId, opath, username, userid, betweenTime);
return system.getResult(rtn)
}
classDesc() {
......
......@@ -4,16 +4,18 @@ var settings = require("../../../../config/settings");
class BizDeliverAPI extends APIBase {
constructor() {
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){
let bizStatus=p.bizStatus
let rtn=await this.bizDeliveryS.statBizDeliveryCountBySp(bizStatus)
async statBizDeliveryCountBySp(p, q, req) {
let bizStatus = p.bizStatus;
let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizDeliveryS.statBizDeliveryCountBySp(bizStatus, betweenTime)
return system.getResult(rtn)
}
async statBizDeliverySettleAmountBySp(p,q,req){
let bizStatus=p.bizStatus
let rtn=await this.bizDeliveryS.statBizDeliverySettleAmountBySp(bizStatus)
async statBizDeliverySettleAmountBySp(p, q, req) {
let bizStatus = p.bizStatus
let rtn = await this.bizDeliveryS.statBizDeliverySettleAmountBySp(bizStatus)
return system.getResult(rtn)
}
/**
......@@ -24,12 +26,13 @@ class BizDeliverAPI extends APIBase {
* @param {*} q
* @param {*} req
*/
async statBizDelivery(p,q,req){
let companyId=p.company_id
let userid=p.userid
let username=p.username
let opath=p.opath
let rtn=await this.bizDeliveryS.statBizDelivery(companyId,opath,username,userid)
async statBizDelivery(p, q, req) {
let companyId = p.company_id
let userid = p.userid
let username = p.username
let opath = p.opath
let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizDeliveryS.statBizDelivery(companyId, opath, username, userid, betweenTime)
return system.getResult(rtn)
}
classDesc() {
......
......@@ -13,6 +13,7 @@ class BizOptCtl extends CtlBase {
this.receiveUrl = settings.receiveUrl();
this.queueUrl = settings.queueUrl();
//this.wdyUrl = settings.wdyUrl();
this.dateUtil = system.getObject("util.dateClient");
}
/*根据用户id获取商机信息,分页获取*/
......@@ -21,6 +22,12 @@ class BizOptCtl extends CtlBase {
//TODO 根据业务员id获取该业务员所有列表
//设置查询条件
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);
let rarr = [];
let results = rs.results.rows;
......
......@@ -16,12 +16,20 @@ class DeliverybillCtl extends CtlBase {
this.receiveUrl = settings.receiveUrl();
this.queueUrl = settings.queueUrl();
this.wdyUrl = settings.wdyUrl();
this.dateUtil = system.getObject("util.dateClient");
}
/*根据用户id获取商机信息,分页获取*/
async findAndCountAll(pobj, qobj, req) {
try {
//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);
let rarr = [];
let results = rs.results.rows;
......@@ -52,7 +60,7 @@ class DeliverybillCtl extends CtlBase {
}
else if (robj.businessName == '云上园区注册') {
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 = '有';
}
else {
......@@ -75,6 +83,7 @@ class DeliverybillCtl extends CtlBase {
rs.results.rows = rarr;
return system.getResult(rs);
} catch (error) {
console.log(error)
return system.getResultError(error);
}
}
......@@ -185,9 +194,9 @@ class DeliverybillCtl extends CtlBase {
rarr.baseInfo.startTime = rs.delivery_info.startTime;//开始计费时间
}
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);
console.log("ddddddddddd____________________________"+ d );
console.log("ddddddddddd____________________________" + d);
rarr.baseInfo.endTime = this.oneYearPast(d, 1);//到期时间
var ss = moment();
rarr.baseInfo.surplusDuration = this.diffDays(ss, rarr.baseInfo.endTime);//剩余时长
......@@ -228,8 +237,8 @@ class DeliverybillCtl extends CtlBase {
async updatestartTimeByDeliverCode(mobj, qobj, red) {//根据交付单编号更新开始计费时间
var pobj = mobj.d;
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined' && pobj.baseInfo.startTime && pobj.baseInfo.startTime != 'undefined'){
try{
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined' && pobj.baseInfo.startTime && pobj.baseInfo.startTime != 'undefined') {
try {
var rs = await this.service.findInfoByDeliverCode(pobj)//先得到交付单详情
if (rs && rs != 'undefined') {
rs.delivery_info.startTime = pobj.baseInfo.startTime;
......@@ -290,11 +299,11 @@ class DeliverybillCtl extends CtlBase {
return system.getResultError("数据不存在!");
}
}
catch(error){
catch (error) {
return system.getResultError(error);
}
}
else{
else {
return system.getResultError("参数错误!");
}
}
......@@ -325,7 +334,7 @@ class DeliverybillCtl extends CtlBase {
var j = JSON.parse(rtn.stdout);
var j1status = 1;
if (pobj.deliverStatus == "closed"){//退款
if (pobj.deliverStatus == "closed") {//退款
params = {
"actionType": "produceData",
"actionBody": {
......@@ -787,7 +796,7 @@ class DeliverybillCtl extends CtlBase {
//time时间n年后的的前一天
oneYearPast(time, n) {
//var time=new Date();
try{
try {
var year = time.getFullYear() + n;
var d = time.setFullYear(year);
var date = time.getDate(d) - 1;
......@@ -802,7 +811,7 @@ class DeliverybillCtl extends CtlBase {
//计算俩日期相差多少天
diffDays(time1, time2) {
try{
try {
var m1 = moment(time1);
var m2 = moment(time2);
return m2.diff(m1, 'day');
......
......@@ -15,7 +15,7 @@ class BizoptDao extends Dao {
qw["facilitator_id"] = Number(qobj.company_id)
// 为空说明是管理员,不需设置组织结构过滤
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) {
......@@ -45,7 +45,7 @@ class BizoptDao extends Dao {
if (qobj.statusReason && qobj.statusReason != 'undefined') {
setobj["close_reason"] = qobj.statusReason;
}
else{
else {
setobj["close_reason"] = "";
}
var whereobj = { "demand_code": qobj.businessMode };
......@@ -58,7 +58,7 @@ class BizoptDao extends Dao {
"demand_code": qobj.businessMode,
"business_type": qobj.businessType,
"business_status": qobj.currentStatus,
"business_info":{}
"business_info": {}
};
if (qobj.channelSource && qobj.channelSource != 'undefined') {
obj.source_name = qobj.channelSource;
......@@ -81,16 +81,16 @@ class BizoptDao extends Dao {
if (qobj.contactsPhone && qobj.contactsPhone != 'undefined') {
obj.business_info.contactsPhone = qobj.contactsPhone;
}
if (qobj.serviceName && qobj.serviceName != 'undefined'){
if (qobj.serviceName && qobj.serviceName != 'undefined') {
obj.business_info.serviceName = qobj.serviceName;
}
if (qobj.businessName && qobj.businessName != 'undefined'){
if (qobj.businessName && qobj.businessName != 'undefined') {
obj.business_info.businessName = qobj.businessName;
}
if (qobj.UserName && qobj.UserName != 'undefined'){
if (qobj.UserName && qobj.UserName != 'undefined') {
obj.business_info.userName = qobj.UserNames;
}
if (qobj.companyName && qobj.companyName != 'undefined'){
if (qobj.companyName && qobj.companyName != 'undefined') {
obj.business_info.companyName = qobj.companyName;
}
if (qobj.servicerCode && qobj.servicerCode != 'undefined') {
......
......@@ -6,18 +6,21 @@ class BizOptService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(BizOptService));
}
async statBizChanceCountBySp(bizStatus){
let params={}
params.group={
byFields:['facilitator_name'],
actionType:'count',
aggField:'id',
aliasField:' as chanceCount',
tblName:'bussiness_opportunity',
where:bizStatus!=""?`where business_status='${bizStatus}'`:'',
having:'',
async statBizChanceCountBySp(bizStatus, betweenTime) {
let params = {}
params.group = {
byFields: ['facilitator_name'],
actionType: 'count',
aggField: 'id',
aliasField: ' as chanceCount',
tblName: 'bussiness_opportunity',
where: bizStatus != "" ? `where business_status='${bizStatus}'` : '',
having: '',
}
let s=await this.dao.statGroupBy(params,null)
if (betweenTime.length > 0) {
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
}
/**
......@@ -27,38 +30,46 @@ class BizOptService extends ServiceBase {
* @param {*} username
* @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 handlingCount=0
let finishedCount=0
let closedCount=0
if(companyId==1){
waittoHandledCount=await this.dao.findCount({where:{business_status:'beforeSubmission'}})
handlingCount=await this.dao.findCount({where:{business_status:'beforeConfirmation'}})
finishedCount=await this.dao.findCount({where:{business_status:'isFinished'}})
closedCount=await this.dao.findCount({where:{business_status:'isClosed'}})
}else{
let opathstr=''
if(opath){
opathstr=opath
waittoHandledCount=await this.dao.findCount({where:{business_status:'beforeSubmission',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}})
finishedCount=await this.dao.findCount({where:{business_status:'isFinished',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}})
}else{
waittoHandledCount=await this.dao.findCount({where:{business_status:'beforeSubmission','facilitator_id':companyId}})
handlingCount=await this.dao.findCount({where:{business_status:'beforeConfirmation','facilitator_id':companyId}})
finishedCount=await this.dao.findCount({where:{business_status:'isFinished','facilitator_id':companyId}})
closedCount=await this.dao.findCount({where:{business_status:'isClosed','facilitator_id':companyId}})
let waittoHandledCount = 0
let handlingCount = 0
let finishedCount = 0
let closedCount = 0
if (companyId == 1) {
waittoHandledCount = await this.dao.findCount({ where: { business_status: 'beforeSubmission', [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { business_status: 'beforeConfirmation', [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { business_status: 'isFinished', [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { business_status: 'isClosed', [this.db.Op.and]: andWhere } })
} else {
let opathstr = ''
if (opath) {
opathstr = opath
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, [this.db.Op.and]: andWhere } })
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, [this.db.Op.and]: andWhere } })
} else {
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, [this.db.Op.and]: andWhere } })
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 }, [this.db.Op.and]: andWhere })
}
}
//成单率
let allChance=waittoHandledCount+handlingCount+finishedCount+closedCount
let successRadio=Math.ceil((finishedCount/allChance) * 100)
let allChance = waittoHandledCount + handlingCount + finishedCount + closedCount
let successRadio = Math.ceil((finishedCount / allChance) * 100)
//如果当前登录人不是平台,那么需要按照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) {
var self = this;
......@@ -67,23 +78,23 @@ class BizOptService extends ServiceBase {
}
/*根据商机编号获取商机详情*/
async findInfoByDemandCode(qobj){
async findInfoByDemandCode(qobj) {
return await this.dao.findInfoByDemandCode(qobj);
}
/* 根据商机编号更新商机状态 */
async updateStatusByDemandCode(qobj){
var self=this;
async updateStatusByDemandCode(qobj) {
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateStatusByDemandCode(qobj,t);
return await self.dao.updateStatusByDemandCode(qobj, t);
});
}
/*插入商机信息*/
async insertInfo(qobj){
var self=this;
async insertInfo(qobj) {
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj,t);
return await self.dao.insertInfo(qobj, t);
});
}
......
......@@ -10,41 +10,51 @@ class DeliverybillService extends ServiceBase {
this.cacheDao = system.getObject("db.bizchance.cacheinfoDao");
}
async statBizDeliverySettleAmountBySp(settleStatus){
let params={}
let where=settleStatus!=""?`where settle_status='${settleStatus}'`:''
async statBizDeliverySettleAmountBySp(settleStatus) {
let params = {}
let where = settleStatus != "" ? `where settle_status='${settleStatus}'` : ''
params.group={
byFields:['facilitator_name'],
actionType:'sum',
aggField:'cost_price',
aliasField:' as chanceCount',
tblName:'delivery_bill',
where:where,
having:'',
}
let s=await this.dao.statGroupBy(params,null)
params.group = {
byFields: ['facilitator_name'],
actionType: 'sum',
aggField: 'cost_price',
aliasField: ' as chanceCount',
tblName: 'delivery_bill',
where: where,
having: '',
}
let s = await this.dao.statGroupBy(params, null)
return s
}
async statBizDeliveryCountBySp(deliverStatus){
let params={}
let where=deliverStatus!=""?`where delivery_status='${deliverStatus}'`:''
if(deliverStatus=="handling"){
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:'',
}
let s=await this.dao.statGroupBy(params,null)
async statBizDeliveryCountBySp(deliverStatus, betweenTime) {
let params = {}
let where = deliverStatus != "" ? `where delivery_status='${deliverStatus}'` : ''
if (deliverStatus == "handling") {
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: '',
}
if (betweenTime.length > 0) {
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
}
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 handlingCount = 0
......@@ -57,41 +67,41 @@ class DeliverybillService extends ServiceBase {
let settled = 0
let settledAmount = 0
if (companyId == 1) {
waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received' } })
handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] } } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success' } })
closedCount = await this.dao.findCount({ where: { delivery_status: 'closed' } })
toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle' } })
toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle' } })
settling = await this.dao.findCount({ where: { settle_status: 'settling' } })
settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling' } })
settled = await this.dao.findCount({ where: { settle_status: 'settled' } })
settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled' } })
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'] }, [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', [this.db.Op.and]: andWhere } })
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', [this.db.Op.and]: andWhere } })
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', [this.db.Op.and]: andWhere } })
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', [this.db.Op.and]: andWhere } })
} else {
let opathstr = ''
if (opath) {
opathstr = opath
waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', 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 } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', 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 } })
toSettle = await this.dao.findCount({ 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 } })
settling = await this.dao.findCount({ 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 } })
settled = await this.dao.findCount({ 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 } })
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, [this.db.Op.and]: andWhere } })
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, [this.db.Op.and]: andWhere } })
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, [this.db.Op.and]: andWhere } })
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, [this.db.Op.and]: andWhere } })
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, [this.db.Op.and]: andWhere } })
} else {
waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', 'facilitator_id': companyId } })
handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] }, 'facilitator_id': companyId } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', 'facilitator_id': companyId } })
closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', 'facilitator_id': companyId } })
toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle', 'facilitator_id': companyId } })
toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle', 'facilitator_id': companyId } })
settling = await this.dao.findCount({ where: { settle_status: 'settling', 'facilitator_id': companyId } })
settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling', 'facilitator_id': companyId } })
settled = await this.dao.findCount({ where: { settle_status: 'settled', 'facilitator_id': companyId } })
settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled', '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, [this.db.Op.and]: andWhere } })
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, [this.db.Op.and]: andWhere } })
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, [this.db.Op.and]: andWhere } })
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, [this.db.Op.and]: andWhere } })
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, [this.db.Op.and]: andWhere } })
}
}
......@@ -115,63 +125,67 @@ class DeliverybillService extends ServiceBase {
}
//为租户自己给交付打标记,表示中台已经给予结算,自己记账用
//租户自己临时记录结算情况
async settleApplyForTacent(ids,uid,uname,spname,spid){
var self=this
return this.db.transaction(async function (t){
async settleApplyForTacent(ids, uid, uname, spname, spid) {
var self = this
return this.db.transaction(async function (t) {
//先按照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=d[0].settleAmount
settleAmount=isNaN(settleAmount)?0:settleAmount
let settlecode=await self. getBusUid("JSD")
let settleObj={
code:settlecode,
settle_amount:settleAmount,
creator_id:uid,
creator:uname,
facilitator_name:spname,
facilitator_id:spid,
isPayedStatus:false,
auditedStatus:true,
payer_id:uid,
payer:uname,
auditor_id:uid,
auditor:uname
let settleAmount = d[0].settleAmount
settleAmount = isNaN(settleAmount) ? 0 : settleAmount
let settlecode = await self.getBusUid("JSD")
let settleObj = {
code: settlecode,
settle_amount: settleAmount,
creator_id: uid,
creator: uname,
facilitator_name: spname,
facilitator_id: spid,
isPayedStatus: false,
auditedStatus: true,
payer_id: uid,
payer: uname,
auditor_id: uid,
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到交付单表
for(let idstr of ids){
let up = await self.dao.updateByWhere({settle_status:'settling',
settlebill_id:newentity.id }, { id: idstr }, t);
for (let idstr of ids) {
let up = await self.dao.updateByWhere({
settle_status: 'settling',
settlebill_id: newentity.id
}, { id: idstr }, t);
}
return newentity
});
}
async settleApply(ids,uid,uname,spname,spid){
var self=this
return this.db.transaction(async function (t){
async settleApply(ids, uid, uname, spname, spid) {
var self = this
return this.db.transaction(async function (t) {
//先按照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=d[0].settleAmount
settleAmount=isNaN(settleAmount)?0:settleAmount
let settlecode=await self. getBusUid("JSD")
let settleObj={
code:settlecode,
settle_amount:settleAmount,
creator_id:uid,
creator:uname,
facilitator_name:spname,
facilitator_id:spid
let settleAmount = d[0].settleAmount
settleAmount = isNaN(settleAmount) ? 0 : settleAmount
let settlecode = await self.getBusUid("JSD")
let settleObj = {
code: settlecode,
settle_amount: settleAmount,
creator_id: uid,
creator: uname,
facilitator_name: spname,
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到交付单表
for(let idstr of ids){
let up = await self.dao.updateByWhere({settle_status:'settling',
settlebill_id:newentity.id }, { id: idstr }, t);
for (let idstr of ids) {
let up = await self.dao.updateByWhere({
settle_status: 'settling',
settlebill_id: newentity.id
}, { id: idstr }, t);
}
return newentity
});
......
......@@ -14,6 +14,7 @@ class SchemeService extends ServiceBase {
async findInfoByDemandCode(qobj){//根据方案编号获取方案详情
return await this.dao.findInfoByDemandCode(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