|
@@ -12,6 +12,7 @@ const auditConst = require('../const/audit').stage;
|
|
|
const smsTypeConst = require('../const/sms_type');
|
|
|
const SMS = require('../lib/sms');
|
|
|
const SmsAliConst = require('../const/sms_alitemplate');
|
|
|
+const wxConst = require('../const/wechat_template');
|
|
|
const payConst = require('../const/deal_pay');
|
|
|
const pushType = require('../const/audit').pushType;
|
|
|
|
|
@@ -37,7 +38,8 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getAuditor(stageId, auditorId, times = 1) {
|
|
|
- const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
|
|
|
+ const sql =
|
|
|
+ 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
|
|
|
'FROM ?? AS la, ?? AS pa ' +
|
|
|
'WHERE la.`sid` = ? and la.`aid` = ? and la.`times` = ?' +
|
|
|
' and la.`aid` = pa.`id`';
|
|
@@ -54,9 +56,11 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getAuditors(stageId, times = 1, order_sort = 'asc') {
|
|
|
- const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
|
|
|
+ const sql =
|
|
|
+ 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time`, g.`sort` ' +
|
|
|
'FROM ?? AS la, ?? AS pa, (SELECT `aid`,(@i:=@i+1) as `sort` FROM ??, (select @i:=0) as it WHERE `sid` = ? AND `times` = ? GROUP BY `aid`) as g ' +
|
|
|
- 'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` and g.`aid` = la.`aid` order by la.`order` ' + order_sort;
|
|
|
+ 'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` and g.`aid` = la.`aid` order by la.`order` ' +
|
|
|
+ order_sort;
|
|
|
const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.tableName, stageId, times, stageId, times];
|
|
|
const result = await this.db.query(sql, sqlParam);
|
|
|
const sql2 = 'SELECT COUNT(a.`aid`) as num FROM (SELECT `aid` FROM ?? WHERE `sid` = ? AND `times` = ? GROUP BY `aid`) as a';
|
|
@@ -69,8 +73,13 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async getAllAuditors(tenderId) {
|
|
|
- const sql = 'SELECT sa.aid, sa.tid FROM ' + this.tableName + ' sa' +
|
|
|
- ' LEFT JOIN ' + this.ctx.service.tender.tableName + ' t On sa.tid = t.id' +
|
|
|
+ const sql =
|
|
|
+ 'SELECT sa.aid, sa.tid FROM ' +
|
|
|
+ this.tableName +
|
|
|
+ ' sa' +
|
|
|
+ ' LEFT JOIN ' +
|
|
|
+ this.ctx.service.tender.tableName +
|
|
|
+ ' t On sa.tid = t.id' +
|
|
|
' WHERE t.id = ?' +
|
|
|
' GROUP BY sa.aid';
|
|
|
const sqlParam = [tenderId];
|
|
@@ -86,7 +95,8 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getStatusName(stageId) {
|
|
|
- const sql = 'SELECT pa.`name` ' +
|
|
|
+ const sql =
|
|
|
+ 'SELECT pa.`name` ' +
|
|
|
'FROM ?? AS sa, ?? AS pa ' +
|
|
|
'WHERE sa.`sid` = ?' +
|
|
|
' and sa.`aid` = pa.`id` and sa.`status` != ? ORDER BY sa.`times` DESC, sa.`order` DESC';
|
|
@@ -102,7 +112,8 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getCurAuditor(stageId, times = 1) {
|
|
|
- const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
|
|
|
+ const sql =
|
|
|
+ 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, pa.`mobile`, pa.`telephone`, la.`times`, la.`order`, la.`status`, la.`opinion`, la.`begin_time`, la.`end_time` ' +
|
|
|
'FROM ?? AS la, ?? AS pa ' +
|
|
|
'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ?' +
|
|
|
' and la.`aid` = pa.`id`';
|
|
@@ -143,7 +154,7 @@ module.exports = app => {
|
|
|
status: auditConst.status.uncheck,
|
|
|
};
|
|
|
const result = await this.db.insert(this.tableName, data);
|
|
|
- return result.effectRows = 1;
|
|
|
+ return (result.effectRows = 1);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -220,7 +231,11 @@ module.exports = app => {
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
- await transaction.update(this.tableName, { id: audit.id, status: auditConst.status.checking, begin_time: new Date() });
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: audit.id,
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ begin_time: new Date(),
|
|
|
+ });
|
|
|
// 计算原报最终数据
|
|
|
const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
// 复制一份下一审核人数据
|
|
@@ -231,14 +246,16 @@ module.exports = app => {
|
|
|
// 更新期数据
|
|
|
const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
this.ctx.stage.tp_history.push({
|
|
|
- times: this.ctx.stage.curTimes, order: 0,
|
|
|
+ times: this.ctx.stage.curTimes,
|
|
|
+ order: 0,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
yf_tp: yfPay.tp,
|
|
|
sf_tp: sfPay.tp,
|
|
|
});
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: stageId, status: auditConst.status.checking,
|
|
|
+ id: stageId,
|
|
|
+ status: auditConst.status.checking,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
yf_tp: yfPay.tp,
|
|
@@ -264,9 +281,21 @@ module.exports = app => {
|
|
|
// }
|
|
|
// }
|
|
|
const stageInfo = await this.ctx.service.stage.getDataById(audit.sid);
|
|
|
- const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
- await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL,
|
|
|
- smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, { qi: stageInfo.order, code: shenpiUrl });
|
|
|
+ const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
+ await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
|
|
|
+ qi: stageInfo.order,
|
|
|
+ code: shenpiUrl,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 微信模板通知
|
|
|
+ const wechatData = {
|
|
|
+ wap_url: shenpiUrl,
|
|
|
+ qi: stageInfo.order,
|
|
|
+ status: wxConst.status.check,
|
|
|
+ tips: wxConst.tips.check,
|
|
|
+ code: this.ctx.session.sessionProject.code,
|
|
|
+ };
|
|
|
+ await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
|
|
|
|
|
|
// todo 更新标段tender状态 ?
|
|
|
await transaction.commit();
|
|
@@ -287,23 +316,35 @@ module.exports = app => {
|
|
|
const nextAudit = await this.getDataByCondition({ sid: stageId, times, order: audit.order + 1 });
|
|
|
const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
|
|
|
-
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
|
|
|
try {
|
|
|
// 添加推送
|
|
|
- const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
|
|
|
- const records = [{ pid, type: pushType.stage, uid: this.ctx.stage.user_id, status: auditConst.status.checkNo, content: noticeContent }]
|
|
|
- this.ctx.stage.auditors.forEach( audit => {
|
|
|
- records.push({ pid, type: pushType.stage, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent })
|
|
|
- })
|
|
|
+ const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid);
|
|
|
+ const auditors = await this.getAuditGroupByListWithOwner(stageId, times);
|
|
|
+ const records = [];
|
|
|
+ auditors.forEach(audit => {
|
|
|
+ records.push({
|
|
|
+ pid,
|
|
|
+ type: pushType.stage,
|
|
|
+ uid: audit.aid,
|
|
|
+ status: auditConst.status.checked,
|
|
|
+ content: noticeContent,
|
|
|
+ });
|
|
|
+ });
|
|
|
await transaction.insert('zh_notice', records);
|
|
|
|
|
|
- await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: audit.id,
|
|
|
+ status: checkData.checkType,
|
|
|
+ opinion: checkData.opinion,
|
|
|
+ end_time: time,
|
|
|
+ });
|
|
|
// 计算并合同支付最终数据
|
|
|
const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
this.ctx.stage.tp_history.push({
|
|
|
- times, order: audit.order,
|
|
|
+ times,
|
|
|
+ order: audit.order,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
yf_tp: yfPay.tp,
|
|
@@ -317,10 +358,15 @@ module.exports = app => {
|
|
|
await this.ctx.service.stageBonus.updateHistory(this.ctx.stage, transaction);
|
|
|
await this.ctx.service.stageOther.updateHistory(this.ctx.stage, transaction);
|
|
|
// 流程至下一审批人
|
|
|
- await transaction.update(this.tableName, { id: nextAudit.id, status: auditConst.status.checking, begin_time: time });
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: nextAudit.id,
|
|
|
+ status: auditConst.status.checking,
|
|
|
+ begin_time: time,
|
|
|
+ });
|
|
|
// 同步 期信息
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: stageId, status: auditConst.status.checking,
|
|
|
+ id: stageId,
|
|
|
+ status: auditConst.status.checking,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
yf_tp: yfPay.tp,
|
|
@@ -347,19 +393,29 @@ module.exports = app => {
|
|
|
// }
|
|
|
// }
|
|
|
const stageInfo = await this.ctx.service.stage.getDataById(nextAudit.sid);
|
|
|
- const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
- await this.ctx.helper.sendAliSms(nextAudit.aid, smsTypeConst.const.JL,
|
|
|
- smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, { qi: stageInfo.order, code: shenpiUrl });
|
|
|
+ const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
+ await this.ctx.helper.sendAliSms(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
|
|
|
+ qi: stageInfo.order,
|
|
|
+ code: shenpiUrl,
|
|
|
+ });
|
|
|
+ // 微信模板通知
|
|
|
+ const wechatData = {
|
|
|
+ wap_url: shenpiUrl,
|
|
|
+ qi: stageInfo.order,
|
|
|
+ status: wxConst.status.check,
|
|
|
+ tips: wxConst.tips.check,
|
|
|
+ code: this.ctx.session.sessionProject.code,
|
|
|
+ };
|
|
|
+ await this.ctx.helper.sendWechat(nextAudit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
|
|
|
} else {
|
|
|
// 本期结束
|
|
|
// 生成截止本期数据 final数据
|
|
|
- console.time('generatePre');
|
|
|
await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
await this.ctx.service.stagePosFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
- console.timeEnd('generatePre');
|
|
|
// 同步 期信息
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: stageId, status: checkData.checkType,
|
|
|
+ id: stageId,
|
|
|
+ status: checkData.checkType,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
yf_tp: yfPay.tp,
|
|
@@ -397,9 +453,22 @@ module.exports = app => {
|
|
|
// const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,审批通过。';
|
|
|
// sms.send(mobile_array, content);
|
|
|
// }
|
|
|
- const users = this._.pull(this._.map(auditList, 'aid'), stageInfo.user_id);
|
|
|
- await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL,
|
|
|
- smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, { qi: stageInfo.order, status: SmsAliConst.status.success });
|
|
|
+ const users = this._.uniq(this._.concat(this._.map(auditList, 'aid'), stageInfo.user_id));
|
|
|
+ await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, {
|
|
|
+ qi: stageInfo.order,
|
|
|
+ status: SmsAliConst.status.success,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 微信模板通知
|
|
|
+ const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
+ const wechatData = {
|
|
|
+ wap_url: shenpiUrl,
|
|
|
+ qi: stageInfo.order,
|
|
|
+ status: wxConst.status.success,
|
|
|
+ tips: wxConst.tips.success,
|
|
|
+ code: this.ctx.session.sessionProject.code,
|
|
|
+ };
|
|
|
+ await this.ctx.helper.sendWechat(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), wxConst.template.stage, wechatData);
|
|
|
}
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
@@ -430,26 +499,47 @@ module.exports = app => {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 添加推送
|
|
|
- const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
|
|
|
- const records = [{ pid, type: pushType.stage, uid: this.ctx.stage.user_id, status: auditConst.status.checkNo, content: noticeContent }]
|
|
|
- auditors.forEach( audit => {
|
|
|
- records.push({ pid, type: pushType.stage, uid: audit.aid, status: auditConst.status.checkNo, content: noticeContent })
|
|
|
- })
|
|
|
+ const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid);
|
|
|
+ const records = [
|
|
|
+ {
|
|
|
+ pid,
|
|
|
+ type: pushType.stage,
|
|
|
+ uid: this.ctx.stage.user_id,
|
|
|
+ status: auditConst.status.checkNo,
|
|
|
+ content: noticeContent,
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ auditors.forEach(audit => {
|
|
|
+ records.push({
|
|
|
+ pid,
|
|
|
+ type: pushType.stage,
|
|
|
+ uid: audit.aid,
|
|
|
+ status: auditConst.status.checkNo,
|
|
|
+ content: noticeContent,
|
|
|
+ });
|
|
|
+ });
|
|
|
await transaction.insert('zh_notice', records);
|
|
|
|
|
|
// 计算并合同支付最终数据
|
|
|
const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
this.ctx.stage.tp_history.push({
|
|
|
- times, order: audit.order,
|
|
|
+ times,
|
|
|
+ order: audit.order,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
yf_tp: yfPay.tp,
|
|
|
sf_tp: sfPay.tp,
|
|
|
});
|
|
|
- await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: audit.id,
|
|
|
+ status: checkData.checkType,
|
|
|
+ opinion: checkData.opinion,
|
|
|
+ end_time: time,
|
|
|
+ });
|
|
|
// 同步 期信息
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: stageId, status: checkData.checkType,
|
|
|
+ id: stageId,
|
|
|
+ status: checkData.checkType,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
times: times + 1,
|
|
@@ -496,9 +586,22 @@ module.exports = app => {
|
|
|
// const content = '【纵横计量支付】' + ptmsg + '第' + stageInfo.order + '期,审批退回。';
|
|
|
// sms.send(mobile_array, content);
|
|
|
// }
|
|
|
- const users = this._.pull(this._.map(auditList, 'aid'), stageInfo.user_id);
|
|
|
- await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL,
|
|
|
- smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, { qi: stageInfo.order, status: SmsAliConst.status.back });
|
|
|
+ const users = this._.uniq(this._.concat(this._.map(auditList, 'aid'), stageInfo.user_id));
|
|
|
+ await this.ctx.helper.sendAliSms(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), SmsAliConst.template.stage_result, {
|
|
|
+ qi: stageInfo.order,
|
|
|
+ status: SmsAliConst.status.back,
|
|
|
+ });
|
|
|
+ // 微信模板通知
|
|
|
+ const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
+ const wechatData = {
|
|
|
+ wap_url: shenpiUrl,
|
|
|
+ qi: stageInfo.order,
|
|
|
+ status: wxConst.status.back,
|
|
|
+ tips: wxConst.tips.back,
|
|
|
+ code: this.ctx.session.sessionProject.code,
|
|
|
+ };
|
|
|
+ await this.ctx.helper.sendWechat(users, smsTypeConst.const.JL, smsTypeConst.judge.result.toString(), wxConst.template.stage, wechatData);
|
|
|
+
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
@@ -506,7 +609,7 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async _checkNoPre(stageId, checkData, times) {
|
|
|
+ async _checkNoPre(pid, stageId, checkData, times) {
|
|
|
const time = new Date();
|
|
|
// 整理当前流程审核人状态更新
|
|
|
const audit = await this.getDataByCondition({ sid: stageId, times, status: auditConst.status.checking });
|
|
@@ -525,19 +628,33 @@ module.exports = app => {
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 添加推送
|
|
|
- const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId)
|
|
|
- const records = [{ pid, type: pushType.stage, uid: this.ctx.stage.user_id, status: auditConst.status.checkNoPre, content: noticeContent }]
|
|
|
- auditors2.forEach( audit => {
|
|
|
- records.push({ pid, type: pushType.stage, uid: audit.aid, status: auditConst.status.checkNoPre, content: noticeContent })
|
|
|
- })
|
|
|
+ const noticeContent = await this.getNoticeContent(pid, audit.tid, stageId, audit.aid);
|
|
|
+ const records = [
|
|
|
+ {
|
|
|
+ pid,
|
|
|
+ type: pushType.stage,
|
|
|
+ uid: this.ctx.stage.user_id,
|
|
|
+ status: auditConst.status.checkNoPre,
|
|
|
+ content: noticeContent,
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ auditors2.forEach(audit => {
|
|
|
+ records.push({
|
|
|
+ pid,
|
|
|
+ type: pushType.stage,
|
|
|
+ uid: audit.aid,
|
|
|
+ status: auditConst.status.checkNoPre,
|
|
|
+ content: noticeContent,
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
await transaction.insert('zh_notice', records);
|
|
|
|
|
|
-
|
|
|
// 计算并合同支付最终数据
|
|
|
const [yfPay, sfPay] = await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
this.ctx.stage.tp_history.push({
|
|
|
- times, order: audit.order,
|
|
|
+ times,
|
|
|
+ order: audit.order,
|
|
|
contract_tp: tpData.contract_tp,
|
|
|
qc_tp: tpData.qc_tp,
|
|
|
yf_tp: yfPay.tp,
|
|
@@ -554,7 +671,12 @@ module.exports = app => {
|
|
|
tp_history: JSON.stringify(this.ctx.stage.tp_history),
|
|
|
cache_time_r: this.ctx.stage.cache_time_l,
|
|
|
});
|
|
|
- await transaction.update(this.tableName, { id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time });
|
|
|
+ await transaction.update(this.tableName, {
|
|
|
+ id: audit.id,
|
|
|
+ status: checkData.checkType,
|
|
|
+ opinion: checkData.opinion,
|
|
|
+ end_time: time,
|
|
|
+ });
|
|
|
// 顺移气候审核人流程顺序
|
|
|
this.initSqlBuilder();
|
|
|
this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=' });
|
|
@@ -565,13 +687,21 @@ module.exports = app => {
|
|
|
// 上一审批人,当前审批人 再次添加至流程
|
|
|
const newAuditors = [];
|
|
|
newAuditors.push({
|
|
|
- tid: audit.tid, sid: audit.sid, aid: preAuditor.aid,
|
|
|
- times: audit.times, order: audit.order + 1, status: auditConst.status.checking,
|
|
|
+ tid: audit.tid,
|
|
|
+ sid: audit.sid,
|
|
|
+ aid: preAuditor.aid,
|
|
|
+ times: audit.times,
|
|
|
+ order: audit.order + 1,
|
|
|
+ status: auditConst.status.checking,
|
|
|
begin_time: time,
|
|
|
});
|
|
|
newAuditors.push({
|
|
|
- tid: audit.tid, sid: audit.sid, aid: audit.aid,
|
|
|
- times: audit.times, order: audit.order + 2, status: auditConst.status.uncheck,
|
|
|
+ tid: audit.tid,
|
|
|
+ sid: audit.sid,
|
|
|
+ aid: audit.aid,
|
|
|
+ times: audit.times,
|
|
|
+ order: audit.order + 2,
|
|
|
+ status: auditConst.status.uncheck,
|
|
|
});
|
|
|
await transaction.insert(this.tableName, newAuditors);
|
|
|
// 计算该审批人最终数据
|
|
@@ -584,7 +714,8 @@ module.exports = app => {
|
|
|
|
|
|
// 同步 期信息
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: stageId, status: checkData.checkType,
|
|
|
+ id: stageId,
|
|
|
+ status: checkData.checkType,
|
|
|
cache_time_r: this.ctx.stage.cache_time_l,
|
|
|
});
|
|
|
// 添加短信通知-需要审批提醒功能
|
|
@@ -605,9 +736,20 @@ module.exports = app => {
|
|
|
// }
|
|
|
// }
|
|
|
const stageInfo = await this.ctx.service.stage.getDataById(audit.sid);
|
|
|
- const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
- await this.ctx.helper.sendAliSms(preAuditor.aid, smsTypeConst.const.JL,
|
|
|
- smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, { qi: stageInfo.order, code: shenpiUrl });
|
|
|
+ const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
+ await this.ctx.helper.sendAliSms(preAuditor.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
|
|
|
+ qi: stageInfo.order,
|
|
|
+ code: shenpiUrl,
|
|
|
+ });
|
|
|
+ // 微信模板通知
|
|
|
+ const wechatData = {
|
|
|
+ wap_url: shenpiUrl,
|
|
|
+ qi: stageInfo.order,
|
|
|
+ status: wxConst.status.check,
|
|
|
+ tips: wxConst.tips.check,
|
|
|
+ code: this.ctx.session.sessionProject.code,
|
|
|
+ };
|
|
|
+ await this.ctx.helper.sendWechat(preAuditor.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
|
|
|
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
@@ -642,125 +784,11 @@ module.exports = app => {
|
|
|
await this._checkNo(pid, stageId, checkData, times);
|
|
|
break;
|
|
|
case auditConst.status.checkNoPre:
|
|
|
- await this._checkNoPre(stageId, checkData, times);
|
|
|
+ await this._checkNoPre(pid, stageId, checkData, times);
|
|
|
break;
|
|
|
default:
|
|
|
throw '无效审批操作';
|
|
|
}
|
|
|
-
|
|
|
- // const transaction = await this.db.beginTransaction();
|
|
|
- // try {
|
|
|
- // // 更新当前审核流程
|
|
|
- // await transaction.update(this.tableName, {id: audit.id, status: checkData.checkType, opinion: checkData.opinion, end_time: time});
|
|
|
- // if (checkData.checkType === auditConst.status.checked) { // 审批通过
|
|
|
- // const nextAudit = await this.getDataByCondition({sid: stageId, times: times, order: audit.order + 1});
|
|
|
- // // 无下一审核人表示,审核结束
|
|
|
- // if (nextAudit) {
|
|
|
- // // 计算该审批人最终数据
|
|
|
- // await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
- // // 复制一份下一审核人数据
|
|
|
- // await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, nextAudit.order, transaction);
|
|
|
- // // 流程至下一审批人
|
|
|
- // await transaction.update(this.tableName, {id: nextAudit.id, status: auditConst.status.checking, begin_time: time});
|
|
|
- // // 同步 期信息
|
|
|
- // const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
- // await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- // id: stageId, status: auditConst.status.checking,
|
|
|
- // contract_tp: tpData.contract_tp,
|
|
|
- // qc_tp: tpData.qc_tp,
|
|
|
- // });
|
|
|
- // } else {
|
|
|
- // // 本期结束
|
|
|
- // // 生成截止本期数据 final数据
|
|
|
- // await this.ctx.service.stageBillsFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
- // await this.ctx.service.stagePosFinal.generateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
- // // 计算并合同支付最终数据
|
|
|
- // await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
- // // 同步 期信息
|
|
|
- // const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
- // await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- // id: stageId, status: checkData.checkType,
|
|
|
- // contract_tp: tpData.contract_tp,
|
|
|
- // qc_tp: tpData.qc_tp,
|
|
|
- // });
|
|
|
- // }
|
|
|
- // } else if (checkData.checkType === auditConst.status.checkNo) { // 审批退回 原报, times+1
|
|
|
- // // 同步 期信息
|
|
|
- // const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
- // await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- // id: stageId, status: checkData.checkType,
|
|
|
- // contract_tp: tpData.contract_tp,
|
|
|
- // qc_tp: tpData.qc_tp,
|
|
|
- // times: times + 1,
|
|
|
- // });
|
|
|
- // // 拷贝新一次审核流程列表
|
|
|
- // // const auditors = await this.getAllDataByCondition({
|
|
|
- // // where: {sid: stageId, times: times},
|
|
|
- // // columns: ['tid', 'sid', 'aid', 'order']
|
|
|
- // // });
|
|
|
- // const sql = 'SELECT `tid`, `sid`, `aid`, `order` FROM ?? WHERE `sid` = ? and `times` = ? GROUP BY `aid`';
|
|
|
- // const sqlParam = [this.tableName, stageId, times];
|
|
|
- // const auditors = await this.db.query(sql, sqlParam);
|
|
|
- // let order = 1;
|
|
|
- // for (const a of auditors) {
|
|
|
- // a.times = times + 1;
|
|
|
- // a.order = order;
|
|
|
- // a.status = auditConst.status.uncheck;
|
|
|
- // order++;
|
|
|
- // }
|
|
|
- // await transaction.insert(this.tableName, auditors);
|
|
|
- // // 计算该审批人最终数据
|
|
|
- // await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
- // // 复制一份最新数据给原报
|
|
|
- // await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times + 1, 0, transaction);
|
|
|
- // } else if (checkData.checkType === auditConst.status.checkNoPre) { // 审批退回 上一审批人
|
|
|
- // // 同步 期信息
|
|
|
- // const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
- // await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- // id: stageId, status: checkData.checkType,
|
|
|
- // contract_tp: tpData.contract_tp,
|
|
|
- // qc_tp: tpData.qc_tp,
|
|
|
- // });
|
|
|
- // // 将当前审批人 与 上一审批人再次添加至流程,顺移其后审批人流程顺序
|
|
|
- // if (audit.order > 1) {
|
|
|
- // // 顺移气候审核人流程顺序
|
|
|
- // this.initSqlBuilder();
|
|
|
- // this.sqlBuilder.setAndWhere('sid', { value: this.ctx.stage.id, operate: '=', });
|
|
|
- // this.sqlBuilder.setAndWhere('order', { value: audit.order, operate: '>', });
|
|
|
- // this.sqlBuilder.setUpdateData('order', { value: 2, selfOperate: '+', });
|
|
|
- // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
|
- // const data = await transaction.query(sql, sqlParam);
|
|
|
- //
|
|
|
- // // 上一审批人,当前审批人 再次添加至流程
|
|
|
- // const preAuditor = await this.getDataByCondition({sid: stageId, times: times, order: audit.order - 1});
|
|
|
- // const newAuditors = [];
|
|
|
- // newAuditors.push({
|
|
|
- // tid: preAuditor.tid, sid: preAuditor.sid, aid: preAuditor.aid,
|
|
|
- // times: preAuditor.times, order: preAuditor.order + 2, status: auditConst.status.checking,
|
|
|
- // begin_time: time,
|
|
|
- // });
|
|
|
- // newAuditors.push({
|
|
|
- // tid: audit.tid, sid: audit.sid, aid: audit.aid,
|
|
|
- // times: audit.times, order: audit.order + 2, status: auditConst.status.uncheck
|
|
|
- // });
|
|
|
- // await transaction.insert(this.tableName, newAuditors);
|
|
|
- //
|
|
|
- // // 计算该审批人最终数据
|
|
|
- // await this.ctx.service.stagePay.calcAllStagePays(this.ctx.stage, transaction);
|
|
|
- // // 复制一份最新数据给上一人
|
|
|
- // await this.ctx.service.stagePay.copyAuditStagePays(this.ctx.stage, this.ctx.stage.times, audit.order + 1, transaction);
|
|
|
- // } else {
|
|
|
- // throw '审核数据错误';
|
|
|
- // }
|
|
|
- // } else {
|
|
|
- // throw '无效审批操作';
|
|
|
- // }
|
|
|
- //
|
|
|
- // await transaction.commit();
|
|
|
- // } catch (err) {
|
|
|
- // await transaction.rollback();
|
|
|
- // throw err;
|
|
|
- // }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -772,7 +800,14 @@ module.exports = app => {
|
|
|
async checkAgain(stageId, times = 1) {
|
|
|
const time = new Date();
|
|
|
// 整理当前流程审核人状态更新
|
|
|
- const audit = (await this.getAllDataByCondition({ where: { sid: stageId, times }, orders: [['order', 'desc']], limit: 1, offset: 0 }))[0];
|
|
|
+ const audit = (
|
|
|
+ await this.getAllDataByCondition({
|
|
|
+ where: { sid: stageId, times },
|
|
|
+ orders: [['order', 'desc']],
|
|
|
+ limit: 1,
|
|
|
+ offset: 0,
|
|
|
+ })
|
|
|
+ )[0];
|
|
|
if (!audit || audit.order < 1) {
|
|
|
throw '审核数据错误';
|
|
|
}
|
|
@@ -781,13 +816,23 @@ module.exports = app => {
|
|
|
// 当前审批人2次添加至流程中
|
|
|
const newAuditors = [];
|
|
|
newAuditors.push({
|
|
|
- tid: audit.tid, sid: audit.sid, aid: audit.aid,
|
|
|
- times: audit.times, order: audit.order + 1, status: auditConst.status.checkAgain,
|
|
|
- begin_time: time, end_time: time, opinion: '',
|
|
|
+ tid: audit.tid,
|
|
|
+ sid: audit.sid,
|
|
|
+ aid: audit.aid,
|
|
|
+ times: audit.times,
|
|
|
+ order: audit.order + 1,
|
|
|
+ status: auditConst.status.checkAgain,
|
|
|
+ begin_time: time,
|
|
|
+ end_time: time,
|
|
|
+ opinion: '',
|
|
|
});
|
|
|
newAuditors.push({
|
|
|
- tid: audit.tid, sid: audit.sid, aid: audit.aid,
|
|
|
- times: audit.times, order: audit.order + 2, status: auditConst.status.checking,
|
|
|
+ tid: audit.tid,
|
|
|
+ sid: audit.sid,
|
|
|
+ aid: audit.aid,
|
|
|
+ times: audit.times,
|
|
|
+ order: audit.order + 2,
|
|
|
+ status: auditConst.status.checking,
|
|
|
begin_time: time,
|
|
|
});
|
|
|
await transaction.insert(this.tableName, newAuditors);
|
|
@@ -805,7 +850,8 @@ module.exports = app => {
|
|
|
await this.ctx.service.stagePosFinal.delGenerateFinalData(transaction, this.ctx.tender, this.ctx.stage);
|
|
|
// 同步 期信息
|
|
|
await transaction.update(this.ctx.service.stage.tableName, {
|
|
|
- id: stageId, status: auditConst.status.checking,
|
|
|
+ id: stageId,
|
|
|
+ status: auditConst.status.checking,
|
|
|
cache_time_r: this.ctx.stage.cache_time_l,
|
|
|
});
|
|
|
|
|
@@ -826,9 +872,21 @@ module.exports = app => {
|
|
|
// }
|
|
|
// }
|
|
|
const stageInfo = await this.ctx.service.stage.getDataById(audit.sid);
|
|
|
- const shenpiUrl = await this.ctx.helper.urlToShort('http://' + this.ctx.request.header.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
- await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL,
|
|
|
- smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, { qi: stageInfo.order, code: shenpiUrl });
|
|
|
+ const shenpiUrl = await this.ctx.helper.urlToShort(this.ctx.protocol + '://' + this.ctx.host + '/wap/tender/' + this.ctx.tender.id + '/stage/' + stageInfo.order);
|
|
|
+ await this.ctx.helper.sendAliSms(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), SmsAliConst.template.stage_check, {
|
|
|
+ qi: stageInfo.order,
|
|
|
+ code: shenpiUrl,
|
|
|
+ });
|
|
|
+ // 微信模板通知
|
|
|
+ const wechatData = {
|
|
|
+ wap_url: shenpiUrl,
|
|
|
+ qi: stageInfo.order,
|
|
|
+ status: wxConst.status.check,
|
|
|
+ tips: wxConst.tips.check,
|
|
|
+ code: this.ctx.session.sessionProject.code,
|
|
|
+ };
|
|
|
+ await this.ctx.helper.sendWechat(audit.aid, smsTypeConst.const.JL, smsTypeConst.judge.approval.toString(), wxConst.template.stage, wechatData);
|
|
|
+
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
@@ -843,13 +901,23 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getAuditStage(auditorId) {
|
|
|
- const sql = 'SELECT sa.`aid`, sa.`times`, sa.`order`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
|
|
|
- ' s.`order` As `sorder`, s.`status` As `sstatus`,' +
|
|
|
- ' t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
|
|
|
- ' FROM ?? AS sa, ?? AS s, ?? As t ' +
|
|
|
- ' WHERE ((sa.`aid` = ? and sa.`status` = ?) OR (s.`user_id` = ? and sa.`status` = ? and s.`status` = ? and sa.`times` = (s.`times`-1)))' +
|
|
|
- ' and sa.`sid` = s.`id` and sa.`tid` = t.`id`';
|
|
|
- const sqlParam = [this.tableName, this.ctx.service.stage.tableName, this.ctx.service.tender.tableName, auditorId, auditConst.status.checking, auditorId, auditConst.status.checkNo, auditConst.status.checkNo];
|
|
|
+ const sql =
|
|
|
+ 'SELECT sa.`aid`, sa.`times`, sa.`order`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
|
|
|
+ ' s.`order` As `sorder`, s.`status` As `sstatus`,' +
|
|
|
+ ' t.`name`, t.`project_id`, t.`type`, t.`user_id` ' +
|
|
|
+ ' FROM ?? AS sa, ?? AS s, ?? As t ' +
|
|
|
+ ' WHERE ((sa.`aid` = ? and sa.`status` = ?) OR (s.`user_id` = ? and sa.`status` = ? and s.`status` = ? and sa.`times` = (s.`times`-1)))' +
|
|
|
+ ' and sa.`sid` = s.`id` and sa.`tid` = t.`id` ORDER BY sa.`begin_time` DESC';
|
|
|
+ const sqlParam = [
|
|
|
+ this.tableName,
|
|
|
+ this.ctx.service.stage.tableName,
|
|
|
+ this.ctx.service.tender.tableName,
|
|
|
+ auditorId,
|
|
|
+ auditConst.status.checking,
|
|
|
+ auditorId,
|
|
|
+ auditConst.status.checkNo,
|
|
|
+ auditConst.status.checkNo,
|
|
|
+ ];
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
|
|
@@ -875,16 +943,17 @@ module.exports = app => {
|
|
|
// const sqlParam = [this.ctx.service.tender.tableName, uid, this.tableName, uid, this.ctx.service.stage.tableName, this.tableName,
|
|
|
// this.ctx.service.projectAccount.tableName, time, pid];
|
|
|
// return await this.db.query(sql, sqlParam);
|
|
|
- let notice = await this.db.select('zh_notice', {
|
|
|
+ let notice = await this.db.select('zh_notice', {
|
|
|
where: { pid, type: pushType.stage, uid },
|
|
|
orders: [['create_time', 'desc']],
|
|
|
- limit: 10, offset: 0
|
|
|
+ limit: 10,
|
|
|
+ offset: 0,
|
|
|
});
|
|
|
notice = notice.map(v => {
|
|
|
- const extra = JSON.parse(v.content)
|
|
|
- delete v.content
|
|
|
- return { ...v, ...extra }
|
|
|
- })
|
|
|
+ const extra = JSON.parse(v.content);
|
|
|
+ delete v.content;
|
|
|
+ return { ...v, ...extra };
|
|
|
+ });
|
|
|
return notice;
|
|
|
}
|
|
|
|
|
@@ -896,13 +965,14 @@ module.exports = app => {
|
|
|
* @param {Number} uid 审核人id
|
|
|
*/
|
|
|
async getNoticeContent(pid, tid, sid, uid) {
|
|
|
- const noticeSql = 'SELECT * FROM (SELECT ' +
|
|
|
+ const noticeSql =
|
|
|
+ 'SELECT * FROM (SELECT ' +
|
|
|
' t.`id` As `tid`, t.`name`, s.`order`, pa.`name` As `su_name`, pa.role As `su_role`' +
|
|
|
' FROM (SELECT * FROM ?? WHERE `id` = ? ) As t' +
|
|
|
' LEFT JOIN ?? As s On s.`id` = ?' +
|
|
|
' LEFT JOIN ?? As pa ON pa.`id` = ?' +
|
|
|
' WHERE t.`project_id` = ? ) as new_t GROUP BY new_t.`tid`';
|
|
|
- const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.stage.tableName, sid, this.ctx.service.projectAccount.tableName, uid, pid];
|
|
|
+ const noticeSqlParam = [this.ctx.service.tender.tableName, tid, this.ctx.service.stage.tableName, sid, this.ctx.service.projectAccount.tableName, uid, pid];
|
|
|
const content = await this.db.query(noticeSql, noticeSqlParam);
|
|
|
return content.length ? JSON.stringify(content[0]) : '';
|
|
|
}
|
|
@@ -914,7 +984,8 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getAuditGroupByList(stageId, times) {
|
|
|
- const sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`aid`, la.`order` ' +
|
|
|
+ const sql =
|
|
|
+ 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`aid`, la.`order` ' +
|
|
|
'FROM ?? AS la, ?? AS pa ' +
|
|
|
'WHERE la.`sid` = ? and la.`times` = ? and la.`aid` = pa.`id` GROUP BY la.`aid` ORDER BY la.`order`';
|
|
|
const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, times];
|
|
@@ -932,9 +1003,14 @@ module.exports = app => {
|
|
|
*/
|
|
|
async getAuditGroupByListWithOwner(stageId, times) {
|
|
|
const result = await this.getAuditGroupByList(stageId, times);
|
|
|
- const sql = 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As sid, 0 As `order`' +
|
|
|
- ' FROM ' + this.ctx.service.stage.tableName + ' As s' +
|
|
|
- ' LEFT JOIN ' + this.ctx.service.projectAccount.tableName + ' As pa' +
|
|
|
+ const sql =
|
|
|
+ 'SELECT pa.`id` As aid, pa.`name`, pa.`company`, pa.`role`, ? As times, ? As sid, 0 As `order`' +
|
|
|
+ ' FROM ' +
|
|
|
+ this.ctx.service.stage.tableName +
|
|
|
+ ' As s' +
|
|
|
+ ' LEFT JOIN ' +
|
|
|
+ this.ctx.service.projectAccount.tableName +
|
|
|
+ ' As pa' +
|
|
|
' ON s.user_id = pa.id' +
|
|
|
' WHERE s.id = ?';
|
|
|
const sqlParam = [times, stageId, stageId];
|
|
@@ -966,7 +1042,7 @@ module.exports = app => {
|
|
|
newAuditors.push(na);
|
|
|
}
|
|
|
const result = await transaction.insert(this.tableName, newAuditors);
|
|
|
- return result.effectRows = auditors.length;
|
|
|
+ return (result.effectRows = auditors.length);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -982,24 +1058,27 @@ module.exports = app => {
|
|
|
let sql = '';
|
|
|
let sqlParam = '';
|
|
|
switch (status) {
|
|
|
- case auditConst.status.checking :
|
|
|
- case auditConst.status.checked :
|
|
|
- case auditConst.status.checkNoPre :
|
|
|
- sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
|
|
|
+ case auditConst.status.checking:
|
|
|
+ case auditConst.status.checked:
|
|
|
+ case auditConst.status.checkNoPre:
|
|
|
+ sql =
|
|
|
+ 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
|
|
|
'FROM ?? AS la, ?? AS pa ' +
|
|
|
'WHERE la.`sid` = ? and la.`status` = ? and la.`aid` = pa.`id` order by la.`times` desc, la.`order` desc';
|
|
|
sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, status];
|
|
|
auditor = await this.db.queryOne(sql, sqlParam);
|
|
|
break;
|
|
|
- case auditConst.status.checkNo :
|
|
|
- sql = 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
|
|
|
+ case auditConst.status.checkNo:
|
|
|
+ sql =
|
|
|
+ 'SELECT la.`aid`, pa.`name`, pa.`company`, pa.`role`, la.`times`, la.`sid`, la.`order` ' +
|
|
|
'FROM ?? AS la, ?? AS pa ' +
|
|
|
'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ? and la.`aid` = pa.`id` order by la.`times` desc, la.`order` desc';
|
|
|
sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.checkNo, parseInt(times) - 1];
|
|
|
auditor = await this.db.queryOne(sql, sqlParam);
|
|
|
break;
|
|
|
- case auditConst.status.uncheck :
|
|
|
- default:break;
|
|
|
+ case auditConst.status.uncheck:
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
return auditor;
|
|
|
}
|
|
@@ -1012,17 +1091,12 @@ module.exports = app => {
|
|
|
* @return {Promise<boolean>}
|
|
|
*/
|
|
|
async getStageAudit(stageId, times = 1) {
|
|
|
- const sql = 'SELECT a1.aid, a1.begin_time, a1.end_time, a1.status, a1.opinion ' +
|
|
|
- 'FROM ?? AS a1 ' +
|
|
|
- 'WHERE a1.`sid` = ? and a1.`times` = ? ' +
|
|
|
- 'ORDER BY a1.order'
|
|
|
- ;
|
|
|
+ const sql = 'SELECT a1.aid, a1.begin_time, a1.end_time, a1.status, a1.opinion ' + 'FROM ?? AS a1 ' + 'WHERE a1.`sid` = ? and a1.`times` = ? ' + 'ORDER BY a1.order';
|
|
|
const sqlParam = [this.tableName, stageId, times];
|
|
|
const rst = await this.db.query(sql, sqlParam);
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 取待审批期列表(wap用)
|
|
|
*
|
|
@@ -1030,7 +1104,8 @@ module.exports = app => {
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
async getAuditStageByWap(auditorId) {
|
|
|
- const sql = 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
|
|
|
+ const sql =
|
|
|
+ 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
|
|
|
// ' s.`order` As `sorder`, s.`status` As `sstatus`, s.`s_time`, s.`contract_tp`, s.`qc_tp`, s.`pre_contract_tp`, s.`pre_qc_tp`, s.`yf_tp`, s.`pre_yf_tp`, ' +
|
|
|
' s.*,' +
|
|
|
' t.`name`, t.`project_id`, t.`type`, t.`user_id`,' +
|
|
@@ -1038,7 +1113,14 @@ module.exports = app => {
|
|
|
' FROM ?? AS sa, ?? AS s, ?? As t, ?? AS ti ' +
|
|
|
' WHERE sa.`aid` = ? and sa.`status` = ?' +
|
|
|
' and sa.`sid` = s.`id` and sa.`tid` = t.`id` and ti.`tid` = t.`id`';
|
|
|
- const sqlParam = [this.tableName, this.ctx.service.stage.tableName, this.ctx.service.tender.tableName, this.ctx.service.tenderInfo.tableName, auditorId, auditConst.status.checking];
|
|
|
+ const sqlParam = [
|
|
|
+ this.tableName,
|
|
|
+ this.ctx.service.stage.tableName,
|
|
|
+ this.ctx.service.tender.tableName,
|
|
|
+ this.ctx.service.tenderInfo.tableName,
|
|
|
+ auditorId,
|
|
|
+ auditConst.status.checking,
|
|
|
+ ];
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
|
|
@@ -1052,13 +1134,13 @@ module.exports = app => {
|
|
|
*/
|
|
|
async _timesDelete(sid, times, transaction) {
|
|
|
// 审批流程
|
|
|
- await transaction.delete(this.tableName, { sid: sid, times: times });
|
|
|
- await transaction.delete(this.ctx.service.pos.tableName, {add_stage: sid, add_times: times});
|
|
|
- await transaction.delete(this.ctx.service.stageBills.tableName, { sid: sid, times: times });
|
|
|
- await transaction.delete(this.ctx.service.stagePos.tableName, { sid: sid, times: times });
|
|
|
- await transaction.delete(this.ctx.service.stageDetail.tableName, { sid: sid, times: times });
|
|
|
- await transaction.delete(this.ctx.service.stageChange.tableName, { sid: sid, stimes: times });
|
|
|
- await transaction.delete(this.ctx.service.stagePay.tableName, { sid: sid, stimes: times });
|
|
|
+ await transaction.delete(this.tableName, { sid, times });
|
|
|
+ await transaction.delete(this.ctx.service.pos.tableName, { add_stage: sid, add_times: times });
|
|
|
+ await transaction.delete(this.ctx.service.stageBills.tableName, { sid, times });
|
|
|
+ await transaction.delete(this.ctx.service.stagePos.tableName, { sid, times });
|
|
|
+ await transaction.delete(this.ctx.service.stageDetail.tableName, { sid, times });
|
|
|
+ await transaction.delete(this.ctx.service.stageChange.tableName, { sid, stimes: times });
|
|
|
+ await transaction.delete(this.ctx.service.stagePay.tableName, { sid, stimes: times });
|
|
|
await transaction.delete(this.ctx.service.pay.tableName, { csid: sid, cstimes: times });
|
|
|
// 其他台账
|
|
|
await this.ctx.service.stageJgcl.deleteStageTimesData(sid, times, transaction);
|
|
@@ -1101,15 +1183,19 @@ module.exports = app => {
|
|
|
// 计算缓存
|
|
|
const tpData = await this.ctx.service.stageBills.getSumTotalPrice(this.ctx.stage);
|
|
|
// 计算并合同支付最终数据
|
|
|
- const lastAudit = await this.getDataByCondition({sid: this.ctx.stage.id, times: nowTimes - 1, status: auditConst.status.checkNo});
|
|
|
+ const lastAudit = await this.getDataByCondition({
|
|
|
+ sid: this.ctx.stage.id,
|
|
|
+ times: nowTimes - 1,
|
|
|
+ status: auditConst.status.checkNo,
|
|
|
+ });
|
|
|
if (!lastAudit) throw '审批数据错误';
|
|
|
|
|
|
await this.ctx.service.stagePay.copyStagePays4DeleteTimes(this.ctx.stage, nowTimes, 0, lastAudit.times, lastAudit.order, transaction);
|
|
|
const stagePay = await this.ctx.service.stagePay.getAuditorStageData(this.ctx.stage.id, lastAudit.times, lastAudit.order);
|
|
|
- const yfPay = stagePay.find(function (x) {
|
|
|
+ const yfPay = stagePay.find(function(x) {
|
|
|
return x.ptype === payConst.payType.yf;
|
|
|
});
|
|
|
- const sfPay = stagePay.find(function (x) {
|
|
|
+ const sfPay = stagePay.find(function(x) {
|
|
|
return x.ptype === payConst.payType.sf;
|
|
|
});
|
|
|
// 同步 期信息
|