|
@@ -13,6 +13,7 @@ const smsTypeConst = require('../const/sms_type');
|
|
const SMS = require('../lib/sms');
|
|
const SMS = require('../lib/sms');
|
|
const SmsAliConst = require('../const/sms_alitemplate');
|
|
const SmsAliConst = require('../const/sms_alitemplate');
|
|
const wxConst = require('../const/wechat_template');
|
|
const wxConst = require('../const/wechat_template');
|
|
|
|
+const shenpiConst = require('../const/shenpi');
|
|
const payConst = require('../const/deal_pay');
|
|
const payConst = require('../const/deal_pay');
|
|
const pushType = require('../const/audit').pushType;
|
|
const pushType = require('../const/audit').pushType;
|
|
|
|
|
|
@@ -163,18 +164,29 @@ module.exports = app => {
|
|
* @param {Number} times - 第几次审批
|
|
* @param {Number} times - 第几次审批
|
|
* @return {Promise<number>}
|
|
* @return {Promise<number>}
|
|
*/
|
|
*/
|
|
- async addAuditor(stageId, auditorId, times = 1) {
|
|
|
|
- const newOrder = await this.getNewOrder(stageId, times);
|
|
|
|
- const data = {
|
|
|
|
- tid: this.ctx.tender.id,
|
|
|
|
- sid: stageId,
|
|
|
|
- aid: auditorId,
|
|
|
|
- times,
|
|
|
|
- order: newOrder,
|
|
|
|
- status: auditConst.status.uncheck,
|
|
|
|
- };
|
|
|
|
- const result = await this.db.insert(this.tableName, data);
|
|
|
|
- return (result.effectRows = 1);
|
|
|
|
|
|
+ async addAuditor(stageId, auditorId, times = 1, is_gdzs = 0) {
|
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ let newOrder = await this.getNewOrder(stageId, times);
|
|
|
|
+ // 判断是否存在固定终审,存在则newOrder - 1并使终审order+1
|
|
|
|
+ newOrder = is_gdzs === 1 ? newOrder - 1 : newOrder;
|
|
|
|
+ if (is_gdzs) await this._syncOrderByDelete(transaction, stageId, newOrder, times, '+');
|
|
|
|
+ const data = {
|
|
|
|
+ tid: this.ctx.tender.id,
|
|
|
|
+ sid: stageId,
|
|
|
|
+ aid: auditorId,
|
|
|
|
+ times,
|
|
|
|
+ order: newOrder,
|
|
|
|
+ status: auditConst.status.uncheck,
|
|
|
|
+ };
|
|
|
|
+ const result = await transaction.insert(this.tableName, data);
|
|
|
|
+ await transaction.commit();
|
|
|
|
+ return result.effectRows = 1;
|
|
|
|
+ } catch (err) {
|
|
|
|
+ await transaction.rollback();
|
|
|
|
+ throw err;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -186,7 +198,7 @@ module.exports = app => {
|
|
* @return {Promise<*>}
|
|
* @return {Promise<*>}
|
|
* @private
|
|
* @private
|
|
*/
|
|
*/
|
|
- async _syncOrderByDelete(transaction, stageId, order, times) {
|
|
|
|
|
|
+ async _syncOrderByDelete(transaction, stageId, order, times, selfOperate = '-') {
|
|
this.initSqlBuilder();
|
|
this.initSqlBuilder();
|
|
this.sqlBuilder.setAndWhere('sid', {
|
|
this.sqlBuilder.setAndWhere('sid', {
|
|
value: stageId,
|
|
value: stageId,
|
|
@@ -202,7 +214,7 @@ module.exports = app => {
|
|
});
|
|
});
|
|
this.sqlBuilder.setUpdateData('order', {
|
|
this.sqlBuilder.setUpdateData('order', {
|
|
value: 1,
|
|
value: 1,
|
|
- selfOperate: '-',
|
|
|
|
|
|
+ selfOperate: selfOperate,
|
|
});
|
|
});
|
|
const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'update');
|
|
const data = await transaction.query(sql, sqlParam);
|
|
const data = await transaction.query(sql, sqlParam);
|
|
@@ -246,7 +258,11 @@ module.exports = app => {
|
|
async start(stageId, times = 1) {
|
|
async start(stageId, times = 1) {
|
|
const audit = await this.getDataByCondition({ sid: stageId, times, order: 1 });
|
|
const audit = await this.getDataByCondition({ sid: stageId, times, order: 1 });
|
|
if (!audit) {
|
|
if (!audit) {
|
|
- throw '请先选择审批人,再上报数据';
|
|
|
|
|
|
+ if(this.ctx.tender.info.shenpi.stage === shenpiConst.sp_status.gdspl) {
|
|
|
|
+ throw '请联系管理员添加审批人';
|
|
|
|
+ } else {
|
|
|
|
+ throw '请先选择审批人,再上报数据';
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
const transaction = await this.db.beginTransaction();
|
|
@@ -1238,6 +1254,57 @@ module.exports = app => {
|
|
throw err;
|
|
throw err;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 固定审批流-更新
|
|
|
|
+ async updateNewAuditList(stage, newIdList) {
|
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ // 先删除旧的审批流,再添加新的
|
|
|
|
+ transaction.delete(this.tableName, { sid: stage.id, times: stage.times });
|
|
|
|
+ const newAuditors = [];
|
|
|
|
+ let order = 1;
|
|
|
|
+ for (const aid of newIdList) {
|
|
|
|
+ newAuditors.push({
|
|
|
|
+ tid: stage.tid, sid: stage.id, aid,
|
|
|
|
+ times: stage.times, order, status: auditConst.status.uncheck,
|
|
|
|
+ });
|
|
|
|
+ order++;
|
|
|
|
+ }
|
|
|
|
+ if(newAuditors.length > 0) await transaction.insert(this.tableName, newAuditors);
|
|
|
|
+ await transaction.commit();
|
|
|
|
+ } catch (err) {
|
|
|
|
+ await transaction.rollback();
|
|
|
|
+ throw err;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 固定终审-更新
|
|
|
|
+ async updateLastAudit(stage, auditList, lastId) {
|
|
|
|
+ const transaction = await this.db.beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ // 先判断auditList里的aid是否与lastId相同,相同则删除并重新更新order
|
|
|
|
+ const idList = this._.map(auditList, 'aid');
|
|
|
|
+ let order = idList.length + 1;
|
|
|
|
+ if (idList.indexOf(lastId) !== -1) {
|
|
|
|
+ transaction.delete(this.tableName, { sid: stage.id, times: stage.times, aid: lastId });
|
|
|
|
+ const audit = this._.find(auditList, { 'aid': lastId });
|
|
|
|
+ // 顺移之后审核人流程顺序
|
|
|
|
+ await this._syncOrderByDelete(transaction, stage.id, audit.order, stage.times);
|
|
|
|
+ order = order - 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 添加终审
|
|
|
|
+ const newAuditor = {
|
|
|
|
+ tid: stage.tid, sid: stage.id, aid: lastId,
|
|
|
|
+ times: stage.times, order, status: auditConst.status.uncheck,
|
|
|
|
+ };
|
|
|
|
+ await transaction.insert(this.tableName, newAuditor);
|
|
|
|
+ await transaction.commit();
|
|
|
|
+ } catch (err) {
|
|
|
|
+ await transaction.rollback();
|
|
|
|
+ throw err;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
return StageAudit;
|
|
return StageAudit;
|