123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date 2018/6/1
- * @version
- */
- const auditConst = require('../const/audit');
- module.exports = app => {
- class CooperationConfirm extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'cooperation_confirm';
- }
- async save(data) {
- const info = await this.getDataByCondition({ tid: this.ctx.tender.id, sid: this.ctx.stage.id, times: this.ctx.stage.times, ledger_id: data.ledger_id, uid: this.ctx.session.sessionUser.accountId });
- if (info) {
- const updateData = {
- id: info.id,
- create_time: new Date(),
- };
- return await this.db.update(this.tableName, updateData);
- }
- const insertData = {
- tid: this.ctx.tender.id,
- sid: this.ctx.stage.id,
- times: this.ctx.stage.times,
- uid: this.ctx.session.sessionUser.accountId,
- ledger_id: data.ledger_id,
- create_time: new Date(),
- };
- return await this.db.insert(this.tableName, insertData);
- }
- async del(data) {
- return await this.db.delete(this.tableName, { tid: this.ctx.tender.id, sid: this.ctx.stage.id, times: this.ctx.stage.times, ledger_id: data.ledger_id, uid: this.ctx.session.sessionUser.accountId });
- }
- async getValidData(tid, sid, times, uid) {
- const condition = { where: { tid, sid, times, uid } };
- // if (uid) {
- // condition.where.uid = uid;
- // condition.colums = ['ledger_id', 'pwd'];
- // }
- return await this.getAllDataByCondition(condition);
- }
- async delBycheckNoPre(uid, stage, transaction) {
- return await transaction.delete(this.tableName, { tid: stage.tid, sid: stage.id, times: stage.times, uid });
- }
- async lockConfirm4CheckNoPre(stage, uid, pre_uid, transaction) {
- if (!transaction) throw '缺少参数';
- const locked = await this.getAllDataByCondition({ where: { sid: stage.sid, locked: 1, times: stage.curTimes } });
- // 审批人数据锁定
- const locking = await this.getAllDataByCondition({ where: { sid: stage.sid, times: stage.curTimes, uid: uid } });
- if (locking.length > 0) {
- const updateLock = locking.map(x => { return { id: x.id, locked: 1 }; });
- await transaction.updateRows(this.tableName, updateLock);
- }
- const preConfirm = await this.getAllDataByCondition({ where: { sid: stage.sid, times: stage.curTimes, uid: pre_uid } });
- // 前审批人数据,与被锁定数据相关数据确认状态保留
- locked.push(...locking);
- if (preConfirm.length > 0) {
- const delConfirm = [];
- for (const pc of preConfirm) {
- const bills = await this.ctx.service.ledger.getDataByCondition({ tender_id: stage.tid, ledger_id: pc.ledger_id });
- const billsOwner = bills.full_path.split('-');
- const exist = locked.find(x => { return billsOwner.indexOf(x.ledger_id + '') >= 0; });
- if (!exist) delConfirm.push(pc.id);
- }
- if (delConfirm.length > 0) await transaction.delete(this.tableName, { id: delConfirm });
- }
- }
- async lockComfirm4CheckNo(stage, uid, auditors, transaction) {
- if (!transaction) throw '缺少参数';
- // 审批人数据锁定
- const lockConfirm = await this.getAllDataByCondition({ where: { sid: stage.id, times: stage.curTimes, uid: uid } });
- const insertData = [];
- lockConfirm.forEach(x => {
- delete x.id;
- x.locked = 1;
- insertData.push(x);
- });
- // 审批人前所有角色,与锁定数据相关确认状态保留
- const keepUid = [ stage.user_id ];
- for (const a of auditors) {
- if (a.aid === uid) break;
- keepUid.push(a.aid);
- }
- const keepConfirm = await this.getAllDataByCondition({ where: { sid: stage.id, times: stage.curTimes, uid: keepUid } });
- for (const kc of keepConfirm) {
- const bills = await this.ctx.service.ledger.getDataByCondition({ tender_id: stage.tid, ledger_id: kc.ledger_id });
- const billsOwner = bills.full_path.split('-');
- const exist = lockConfirm.find(x => { return billsOwner.indexOf(x.ledger_id + '') >= 0; });
- if (exist) {
- delete kc.id;
- kc.locked = 0;
- insertData.push(kc);
- }
- }
- await transaction.insert(this.tableName, insertData);
- }
- async getLockedId(tender, stage) {
- // const lockedCoop = await this.getAllDataByCondition({ where: { sid: stage.id, times: stage.curTimes, locked: 1 } });
- const sql = `SELECT cc.ledger_id, cc.uid, pa.name FROM ${this.tableName} cc` +
- ` LEFT JOIN ${this.ctx.service.projectAccount.tableName} pa ON cc.uid = pa.id` +
- ' WHERE cc.sid = ? AND cc.times = ? AND cc.locked = 1';
- return await this.db.query(sql, [stage.id, stage.curTimes]);
- }
- }
- return CooperationConfirm;
- };
|