소스 검색

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

MaiXinRong 5 시간 전
부모
커밋
e686c42a81
3개의 변경된 파일53개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 0
      app/service/contract.js
  2. 18 2
      app/service/contract_pay.js
  3. 34 0
      app/service/contract_sp_audit.js

+ 1 - 0
app/service/contract.js

@@ -73,6 +73,7 @@ module.exports = app => {
                     await transaction.update(this.ctx.service.contractTree.tableName, { id: node.id, is_leaf: 0 });
                 }
                 this.ctx.service.contractTree._cacheMaxLid(options, maxId + 1);
+                await this.ctx.service.contractSpAudit.makeAudits(transaction, options, insertId, null, this.ctx.session.sessionUser.accountId);
                 await transaction.commit();
             } catch (err) {
                 await transaction.rollback();

+ 18 - 2
app/service/contract_pay.js

@@ -80,8 +80,9 @@ module.exports = app => {
                     create_time: new Date(),
                     need_shenpi: options.spid ? this.ctx.subProject.page_show.openContractPaySubProjectShenpi : this.ctx.subProject.page_show.openContractPayTenderShenpi,
                 };
-                await transaction.insert(this.tableName, insertData);
+                const result = await transaction.insert(this.tableName, insertData);
                 await this.calcContract(transaction, node);
+                await this.ctx.service.contractSpAudit.makeAudits(transaction, options, cid, result.insertId, this.ctx.session.sessionUser.accountId);
                 await transaction.commit();
             } catch (err) {
                 await transaction.rollback();
@@ -193,10 +194,17 @@ module.exports = app => {
                 }
             }
             if (addPays.length > 0) {
-                await transaction.insert(this.tableName, addPays);
+                const result = await transaction.insert(this.tableName, addPays);
                 for (const c of contracts) {
                     await this.calcContract(transaction, c);
                 }
+                // 获取刚批量添加的所有list
+                for (let j = 0; j < addPays.length; j++) {
+                    addPays[j].id = result.insertId + j;
+                }
+                for (const p of addPays) {
+                    await this.ctx.service.contractSpAudit.makeAudits(transaction, p, p.cid, p.id, uid);
+                }
                 const commonJson = this.ctx.subProject.common_json ? JSON.parse(this.ctx.subProject.common_json) : {};
                 const used = commonJson && commonJson.tender_contract_used ? commonJson.tender_contract_used : [];
                 const addUsed = this._.uniq(this._.map(pays, 'used'));
@@ -216,6 +224,14 @@ module.exports = app => {
 
         async removeContractPays(transaction, fpid, pays) {
             await transaction.delete(this.tableName, { fpid });
+            // 删除合同附件, 删除审批人列表
+            for (const p of pays) {
+                // 删除合同附件
+                const attList = await this.ctx.service.contractPayAtt.getAllDataByCondition({ where: { cpid: p.id } });
+                await this.ctx.helper.delFiles(attList);
+                await transaction.delete(this.ctx.service.contractPayAtt.tableName, { cpid: p.id });
+                await transaction.delete(this.ctx.service.contractSpAudit.tableName, { cpid: p.id });
+            }
             const contracts = await transaction.select(this.ctx.service.contract.tableName, { where: { id: this._.uniq(this._.map(pays, 'cid')) } });
             if (contracts.length > 0) {
                 for (const c of contracts) {

+ 34 - 0
app/service/contract_sp_audit.js

@@ -947,6 +947,40 @@ module.exports = app => {
             return result;
         }
 
+        async makeAudits(transaction, options, cid, cpid = null, uid) {
+            // 创建审批人列表
+            const lastContractInfo = await this.getHaveAuditLastInfo(options, cid, cpid, uid);
+            if (lastContractInfo) {
+                // 再获取非原报审批人
+                const auditList = await this.getUniqAuditor(lastContractInfo.cid ? lastContractInfo.cid : lastContractInfo.id, lastContractInfo.cid ? lastContractInfo.id : null, lastContractInfo.times, true); // 全部参与的审批人
+                if (auditList.length > 0) {
+                    const spAudits = [];
+                    for (const x of auditList) {
+                        if (x.audit_order !== 0) {
+                            spAudits.push({
+                                spid: options.spid || null,
+                                tid: options.tid || null,
+                                cid, cpid, aid: x.aid,
+                                times: 1, order: x.audit_order, status: auditConst.status.uncheck,
+                                audit_type: x.audit_type, audit_order: x.audit_order,
+                            });
+                        }
+                    }
+                    if (spAudits.length > 0) await transaction.insert(this.ctx.service.contractSpAudit.tableName, spAudits);
+                }
+            }
+        }
+
+        async getHaveAuditLastInfo(options, cid, cpid, uid) {
+            const optionsSql = options.spid ? 'c.spid = "' + options.spid + '"' : 'c.tid = ' + options.tid;
+            const tableName = cpid ? this.ctx.service.contractPay.tableName : this.ctx.service.contract.tableName;
+            const joinSql = cpid ? 'ca.cpid' : 'ca.cid';
+            const cpidSql = cpid ? 'AND ca.`cpid` is not null' : 'AND ca.`cpid` is null';
+            const sql = 'SELECT a.* FROM ?? as c LEFT JOIN ?? as ca ON c.`id` = ' + joinSql + ' WHERE ' + optionsSql + ' AND c.`contract_type` = ? AND c.`uid` = ? ' + cpidSql + ' AND ca.`audit_order` > 0 ORDER BY c.`create_time` DESC';
+            const sqlParam = [tableName, this.tableName, options[this.setting.type], uid];
+            return await this.db.queryOne(sql, sqlParam);
+        }
+
         async saveAudit(contract, times, sp_group, data) {
             const transaction = await this.db.beginTransaction();
             try {