|  | @@ -189,54 +189,36 @@ module.exports = app => {
 | 
												
													
														
															|  |                  if (!transferInfo) {
 |  |                  if (!transferInfo) {
 | 
												
													
														
															|  |                      throw '该资金划拨信息不存在';
 |  |                      throw '该资金划拨信息不存在';
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  | 
 |  | +                const categoryData = await this.ctx.service.category.getAllCategory(ctx.subProject);
 | 
												
													
														
															|  |                  const transferTenderList = await ctx.service.financialTransferTender.getList(trid, true);
 |  |                  const transferTenderList = await ctx.service.financialTransferTender.getList(trid, true);
 | 
												
													
														
															|  | -                const total = await ctx.service.financialTransferTender.count({ trid });
 |  | 
 | 
												
													
														
															|  | -                // 分页相关
 |  | 
 | 
												
													
														
															|  | -                const page = ctx.page;
 |  | 
 | 
												
													
														
															|  | -                const pageSize = ctx.pageSize;
 |  | 
 | 
												
													
														
															|  | -                const pageInfo = {
 |  | 
 | 
												
													
														
															|  | -                    page,
 |  | 
 | 
												
													
														
															|  | -                    pageSizeSelect: 1,
 |  | 
 | 
												
													
														
															|  | -                    pageSize,
 |  | 
 | 
												
													
														
															|  | -                    total_num: total,
 |  | 
 | 
												
													
														
															|  | -                    total: Math.ceil(total / pageSize),
 |  | 
 | 
												
													
														
															|  | -                    queryData: JSON.stringify(ctx.urlInfo.query),
 |  | 
 | 
												
													
														
															|  | -                };
 |  | 
 | 
												
													
														
															|  |                  const tenders = await ctx.service.tender.getAllDataByCondition({ where: { spid: ctx.subProject.id, filter_fund: 0 } });
 |  |                  const tenders = await ctx.service.tender.getAllDataByCondition({ where: { spid: ctx.subProject.id, filter_fund: 0 } });
 | 
												
													
														
															|  | -                for (const tt of transferTenderList) {
 |  | 
 | 
												
													
														
															|  | -                    const tenderIndex = ctx.helper._.findIndex(tenders, { id: tt.tid });
 |  | 
 | 
												
													
														
															|  | -                    if (tenderIndex !== -1) {
 |  | 
 | 
												
													
														
															|  | -                        tenders.splice(tenderIndex, 1);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                const needTenders = [];
 | 
												
													
														
															|  | 
 |  | +                for (const t of tenders) {
 | 
												
													
														
															|  | 
 |  | +                    await ctx.service.tenderCache.loadTenderCache(t, this.ctx.session.sessionUser.accountId);
 | 
												
													
														
															|  | 
 |  | +                    if (t.stage_complete_count && t.stage_complete_count >= 1) {
 | 
												
													
														
															|  | 
 |  | +                        t.category = t.category && t.category !== '' ? JSON.parse(t.category) : null;
 | 
												
													
														
															|  | 
 |  | +                        needTenders.push(t);
 | 
												
													
														
															|  |                      }
 |  |                      }
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  | -                const allTransferTenders = await ctx.service.financialTransferTender.getAllDataByCondition({ where: { spid: ctx.subProject.id } });
 |  | 
 | 
												
													
														
															|  | -                for (const t of tenders) {
 |  | 
 | 
												
													
														
															|  | -                    const stages = await ctx.service.stage.getAllDataByCondition({ where: { tid: t.id, status: auditConst.stage.status.checked } });
 |  | 
 | 
												
													
														
															|  | -                    const allTenderStages = ctx.helper._.filter(allTransferTenders, { tid: t.id });
 |  | 
 | 
												
													
														
															|  | -                    for (const ts of allTenderStages) {
 |  | 
 | 
												
													
														
															|  | -                        const sorderArray = ts.sorder ? ts.sorder.split(',') : [];
 |  | 
 | 
												
													
														
															|  | -                        for (const sorder of sorderArray) {
 |  | 
 | 
												
													
														
															|  | -                            const stageIndex = ctx.helper._.findIndex(stages, function(item) {
 |  | 
 | 
												
													
														
															|  | -                                return item.order === parseInt(sorder);
 |  | 
 | 
												
													
														
															|  | -                            });
 |  | 
 | 
												
													
														
															|  | -                            if (stageIndex !== -1) {
 |  | 
 | 
												
													
														
															|  | -                                stages.splice(stageIndex, 1);
 |  | 
 | 
												
													
														
															|  | -                            }
 |  | 
 | 
												
													
														
															|  | -                        }
 |  | 
 | 
												
													
														
															|  | 
 |  | +                for (const tt of transferTenderList) {
 | 
												
													
														
															|  | 
 |  | +                    const tenderIndex = ctx.helper._.findIndex(needTenders, { id: tt.tid });
 | 
												
													
														
															|  | 
 |  | +                    if (tenderIndex !== -1) {
 | 
												
													
														
															|  | 
 |  | +                        // 合并tenders[tenderIndex]到tt
 | 
												
													
														
															|  | 
 |  | +                        const cloneTender = ctx.helper._.cloneDeep(needTenders[tenderIndex]);
 | 
												
													
														
															|  | 
 |  | +                        delete cloneTender.id;
 | 
												
													
														
															|  | 
 |  | +                        Object.assign(tt, cloneTender);
 | 
												
													
														
															|  |                      }
 |  |                      }
 | 
												
													
														
															|  | -                    t.stages = stages;
 |  | 
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  |                  const renderData = {
 |  |                  const renderData = {
 | 
												
													
														
															|  |                      financialPermission,
 |  |                      financialPermission,
 | 
												
													
														
															|  |                      transferInfo,
 |  |                      transferInfo,
 | 
												
													
														
															|  |                      transferTenderList,
 |  |                      transferTenderList,
 | 
												
													
														
															|  | -                    tenders,
 |  | 
 | 
												
													
														
															|  | 
 |  | +                    categoryData,
 | 
												
													
														
															|  | 
 |  | +                    tenders: needTenders,
 | 
												
													
														
															|  |                      moment,
 |  |                      moment,
 | 
												
													
														
															|  |                      preUrl: '/sp/' + ctx.subProject.id + '/financial/transfer',
 |  |                      preUrl: '/sp/' + ctx.subProject.id + '/financial/transfer',
 | 
												
													
														
															|  |                      jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.transferTender),
 |  |                      jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.transferTender),
 | 
												
													
														
															|  |                      whiteList: ctx.app.config.multipart.whitelist,
 |  |                      whiteList: ctx.app.config.multipart.whitelist,
 | 
												
													
														
															|  | -                    pageInfo,
 |  | 
 | 
												
													
														
															|  |                  };
 |  |                  };
 | 
												
													
														
															|  |                  await this.layout('financial/transfer_tender.ejs', renderData, 'financial/transfer_tender_modal.ejs');
 |  |                  await this.layout('financial/transfer_tender.ejs', renderData, 'financial/transfer_tender_modal.ejs');
 | 
												
													
														
															|  |              } catch (err) {
 |  |              } catch (err) {
 | 
												
											
												
													
														
															|  | @@ -298,10 +280,13 @@ module.exports = app => {
 | 
												
													
														
															|  |                          }
 |  |                          }
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  |                      case 'del-tender':
 |  |                      case 'del-tender':
 | 
												
													
														
															|  | -                        responseData.data = await ctx.service.financialTransferTender.delTenders(data.postData.node);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialTransferTender.delTenders(transferInfo, data.postData.node);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  |                      case 'update-hb_tp':
 |  |                      case 'update-hb_tp':
 | 
												
													
														
															|  | -                        responseData.data = await ctx.service.financialTransferTender.updateHbTp(data.postData.node, data.postData.hb_tp);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialTransferTender.updateHbTp(transferInfo, data.postData.node, data.postData.hb_tp);
 | 
												
													
														
															|  | 
 |  | +                        break;
 | 
												
													
														
															|  | 
 |  | +                    case 'update-tender':
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialTransferTender.updateTender(transferInfo, data.postData);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  |                      default:
 |  |                      default:
 | 
												
													
														
															|  |                          throw '未知操作';
 |  |                          throw '未知操作';
 | 
												
											
												
													
														
															|  | @@ -584,36 +569,18 @@ module.exports = app => {
 | 
												
													
														
															|  |           * @param {Object} ctx - egg全局变量
 |  |           * @param {Object} ctx - egg全局变量
 | 
												
													
														
															|  |           * @return {void}
 |  |           * @return {void}
 | 
												
													
														
															|  |           */
 |  |           */
 | 
												
													
														
															|  | -        async pay(ctx) {
 |  | 
 | 
												
													
														
															|  | 
 |  | +        async payStage(ctx) {
 | 
												
													
														
															|  |              try {
 |  |              try {
 | 
												
													
														
															|  | -                const status = parseInt(ctx.query.status) || 0;
 |  | 
 | 
												
													
														
															|  | -                const tid = parseInt(ctx.query.tid) || null;
 |  | 
 | 
												
													
														
															|  | -                const used = ctx.query.used || null;
 |  | 
 | 
												
													
														
															|  | -                await this._filterPay(ctx, status, tid, used);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                const company = ctx.query.company || null;
 | 
												
													
														
															|  | 
 |  | +                const qi = parseInt(ctx.query.qi) || null;
 | 
												
													
														
															|  | 
 |  | +                await this._filterPayStage(ctx, company, qi);
 | 
												
													
														
															|  |              } catch (err) {
 |  |              } catch (err) {
 | 
												
													
														
															|  |                  this.log(err);
 |  |                  this.log(err);
 | 
												
													
														
															|  |                  ctx.redirect(`/sp/${ctx.subProject.id}/dashboard`);
 |  |                  ctx.redirect(`/sp/${ctx.subProject.id}/dashboard`);
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  |          }
 |  |          }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -        // /**
 |  | 
 | 
												
													
														
															|  | -        //  * 变更管理 状态筛选 页面 (Get)
 |  | 
 | 
												
													
														
															|  | -        //  * @param {Object} ctx - egg全局变量
 |  | 
 | 
												
													
														
															|  | -        //  * @return {void}
 |  | 
 | 
												
													
														
															|  | -        //  */
 |  | 
 | 
												
													
														
															|  | -        // async payStatus(ctx) {
 |  | 
 | 
												
													
														
															|  | -        //     try {
 |  | 
 | 
												
													
														
															|  | -        //         const status = parseInt(ctx.query.status);
 |  | 
 | 
												
													
														
															|  | -        //         const tid = parseInt(ctx.params.tid) || null;
 |  | 
 | 
												
													
														
															|  | -        //         const used = ctx.params.used || null;
 |  | 
 | 
												
													
														
															|  | -        //         await this._filterPay(ctx, status, tid, used);
 |  | 
 | 
												
													
														
															|  | -        //     } catch (err) {
 |  | 
 | 
												
													
														
															|  | -        //         this.logger.error(err);
 |  | 
 | 
												
													
														
															|  | -        //         ctx.redirect('/financial');
 |  | 
 | 
												
													
														
															|  | -        //     }
 |  | 
 | 
												
													
														
															|  | -        // }
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -        async _filterPay(ctx, status = 0, tid = null, used = null) {
 |  | 
 | 
												
													
														
															|  | 
 |  | +        async _filterPayStage(ctx, company = null, qi = null) {
 | 
												
													
														
															|  |              const financialPermission = await ctx.service.subProjPermission.getFinancailPermission(ctx.subProject.permission.fund_trans_permission, ctx.subProject.permission.fund_pay_permission);
 |  |              const financialPermission = await ctx.service.subProjPermission.getFinancailPermission(ctx.subProject.permission.fund_trans_permission, ctx.subProject.permission.fund_pay_permission);
 | 
												
													
														
															|  |              if (!financialPermission.pay_show) {
 |  |              if (!financialPermission.pay_show) {
 | 
												
													
														
															|  |                  throw '没有查看权限';
 |  |                  throw '没有查看权限';
 | 
												
											
												
													
														
															|  | @@ -621,7 +588,7 @@ module.exports = app => {
 | 
												
													
														
															|  |              const fptAudits = await ctx.service.financialPayTenderAudit.getAllDataByCondition({ where: { spid: ctx.subProject.id, uid: ctx.session.sessionUser.accountId } });
 |  |              const fptAudits = await ctx.service.financialPayTenderAudit.getAllDataByCondition({ where: { spid: ctx.subProject.id, uid: ctx.session.sessionUser.accountId } });
 | 
												
													
														
															|  |              const fptAuditTids = ctx.helper._.map(fptAudits, 'tid');
 |  |              const fptAuditTids = ctx.helper._.map(fptAudits, 'tid');
 | 
												
													
														
															|  |              const fptReportTids = ctx.helper._.map(ctx.helper._.filter(fptAudits, { is_report: 1 }), 'tid');
 |  |              const fptReportTids = ctx.helper._.map(ctx.helper._.filter(fptAudits, { is_report: 1 }), 'tid');
 | 
												
													
														
															|  | -            const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : fptAuditTids) : [tid];
 |  | 
 | 
												
													
														
															|  | 
 |  | +            const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
 | 
												
													
														
															|  |              const tenderCondition = { spid: ctx.subProject.id, filter_fund: 0 };
 |  |              const tenderCondition = { spid: ctx.subProject.id, filter_fund: 0 };
 | 
												
													
														
															|  |              let hadTender = false;
 |  |              let hadTender = false;
 | 
												
													
														
															|  |              if (ctx.session.sessionUser.is_admin) {
 |  |              if (ctx.session.sessionUser.is_admin) {
 | 
												
											
												
													
														
															|  | @@ -633,15 +600,19 @@ module.exports = app => {
 | 
												
													
														
															|  |                  hadTender = false;
 |  |                  hadTender = false;
 | 
												
													
														
															|  |                  tenderCondition.id = -1;
 |  |                  tenderCondition.id = -1;
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  | -            const tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name'] }) : [];
 |  | 
 | 
												
													
														
															|  | -            const filter = JSON.parse(JSON.stringify(auditConst.financial.filter));
 |  | 
 | 
												
													
														
															|  | -            filter.count = [];
 |  | 
 | 
												
													
														
															|  | -            filter.count[filter.status.pending] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, filter.status.pending, filterTids, used);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
 |  | 
 | 
												
													
														
															|  | -            filter.count[filter.status.uncheck] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, filter.status.uncheck, filterTids, used);// await ctx.service.change.checkingDatas(tender.id, ctx.session.sessionUser.accountId);
 |  | 
 | 
												
													
														
															|  | -            filter.count[filter.status.checking] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, filter.status.checking, filterTids, used);// await ctx.service.change.checkedDatas(tender.id, ctx.session.sessionUser.accountId);
 |  | 
 | 
												
													
														
															|  | -            filter.count[filter.status.checked] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, filter.status.checked, filterTids, used);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
 |  | 
 | 
												
													
														
															|  | -            const payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, status, filterTids, used, 1);
 |  | 
 | 
												
													
														
															|  | -            const total = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, status, filterTids, used);
 |  | 
 | 
												
													
														
															|  | 
 |  | +            const categoryData = await this.ctx.service.category.getAllCategory(ctx.subProject);
 | 
												
													
														
															|  | 
 |  | +            const tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name', 'category'] }) : [];
 | 
												
													
														
															|  | 
 |  | +            const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject, ['id', 'account', 'name', 'company', 'company_id', 'role', 'enable', 'is_admin', 'account_group', 'mobile']);
 | 
												
													
														
															|  | 
 |  | +            const user = accountList.find(item => item.id === ctx.session.sessionUser.accountId) || null;
 | 
												
													
														
															|  | 
 |  | +            const userCompany = user ? ctx.helper._.find(unitList, { name: user.company }) : null;
 | 
												
													
														
															|  | 
 |  | +            if (!userCompany) {
 | 
												
													
														
															|  | 
 |  | +                throw '请联系管理员添加用户所在单位信息';
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const userOrderList = await ctx.service.financialPayStage.getUserOrderList(ctx.subProject.id, userCompany ? userCompany.id : 0);
 | 
												
													
														
															|  | 
 |  | +            const userCompanyList = await ctx.service.financialPayStage.getUserCompanyList(ctx.subProject.id, userCompany ? userCompany.id : 0, unitList);
 | 
												
													
														
															|  | 
 |  | +            const companyInfo = company ? ctx.helper._.find(unitList, { name: company }) : null;
 | 
												
													
														
															|  | 
 |  | +            const payList = await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, companyInfo ? companyInfo.id : null, userCompany ? userCompany.id : 0, qi);
 | 
												
													
														
															|  | 
 |  | +            const total = await ctx.service.financialPayStage.getCountByStatus(ctx.subProject.id, companyInfo ? companyInfo.id : null, userCompany ? userCompany.id : 0, qi);
 | 
												
													
														
															|  |              // 分页相关
 |  |              // 分页相关
 | 
												
													
														
															|  |              const page = ctx.page;
 |  |              const page = ctx.page;
 | 
												
													
														
															|  |              const pageSize = ctx.pageSize;
 |  |              const pageSize = ctx.pageSize;
 | 
												
											
												
													
														
															|  | @@ -653,45 +624,25 @@ module.exports = app => {
 | 
												
													
														
															|  |                  total: Math.ceil(total / pageSize),
 |  |                  total: Math.ceil(total / pageSize),
 | 
												
													
														
															|  |                  queryData: JSON.stringify(ctx.urlInfo.query),
 |  |                  queryData: JSON.stringify(ctx.urlInfo.query),
 | 
												
													
														
															|  |              };
 |  |              };
 | 
												
													
														
															|  | -            // 获取所有项目参与者
 |  | 
 | 
												
													
														
															|  | -            const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject, ['id', 'account', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile']);
 |  | 
 | 
												
													
														
															|  |              const payTenders = await ctx.service.financialPayTender.getAllDataByCondition({ where: { spid: ctx.subProject.id } });
 |  |              const payTenders = await ctx.service.financialPayTender.getAllDataByCondition({ where: { spid: ctx.subProject.id } });
 | 
												
													
														
															|  |              if (tenders.length > 0) {
 |  |              if (tenders.length > 0) {
 | 
												
													
														
															|  | -                const allLastPay = await ctx.service.financialPay.getAllDataByCondition({ where: { spid: ctx.subProject.id, tid: ctx.helper._.map(tenders, 'id') }, columns: ['id', 'code'], orders: [['id', 'desc']] });
 |  | 
 | 
												
													
														
															|  |                  const tenderInfos = await ctx.service.tenderInfo.getAllDataByCondition({ where: { tid: ctx.helper._.map(tenders, 'id') }, columns: ['tid', 'pay_account', 'deal_info'] });
 |  |                  const tenderInfos = await ctx.service.tenderInfo.getAllDataByCondition({ where: { tid: ctx.helper._.map(tenders, 'id') }, columns: ['tid', 'pay_account', 'deal_info'] });
 | 
												
													
														
															|  |                  for (const t of tenders) {
 |  |                  for (const t of tenders) {
 | 
												
													
														
															|  | 
 |  | +                    t.category = t.category && t.category !== '' ? JSON.parse(t.category) : null;
 | 
												
													
														
															|  |                      const info = ctx.helper._.find(tenderInfos, { tid: t.id });
 |  |                      const info = ctx.helper._.find(tenderInfos, { tid: t.id });
 | 
												
													
														
															|  |                      t.pay_account = info && info.pay_account ? JSON.parse(info.pay_account).project : '';
 |  |                      t.pay_account = info && info.pay_account ? JSON.parse(info.pay_account).project : '';
 | 
												
													
														
															|  |                      const pt = ctx.helper._.find(payTenders, { tid: t.id });
 |  |                      const pt = ctx.helper._.find(payTenders, { tid: t.id });
 | 
												
													
														
															|  |                      t.pt = pt ? pt : { id: 0, tid: t.id, name: '', bank: '', bank_account: '', contact: '', phone: '' };
 |  |                      t.pt = pt ? pt : { id: 0, tid: t.id, name: '', bank: '', bank_account: '', contact: '', phone: '' };
 | 
												
													
														
															|  |                      if (ctx.session.sessionUser.is_admin || ctx.helper._.includes(fptReportTids, t.id)) {
 |  |                      if (ctx.session.sessionUser.is_admin || ctx.helper._.includes(fptReportTids, t.id)) {
 | 
												
													
														
															|  |                          t.dealCode = info && info.deal_info ? JSON.parse(info.deal_info).dealCode : '';
 |  |                          t.dealCode = info && info.deal_info ? JSON.parse(info.deal_info).dealCode : '';
 | 
												
													
														
															|  | -                        const lastPay = ctx.helper._.filter(allLastPay, { tid: t.id });
 |  | 
 | 
												
													
														
															|  | -                        t.startNum = 1;
 |  | 
 | 
												
													
														
															|  | -                        if (lastPay.length > 0) {
 |  | 
 | 
												
													
														
															|  | -                            const startArray = lastPay[0].code.split('-');
 |  | 
 | 
												
													
														
															|  | -                            t.startNum = parseInt(startArray[startArray.length - 1]) + 1;
 |  | 
 | 
												
													
														
															|  | -                        }
 |  | 
 | 
												
													
														
															|  |                      }
 |  |                      }
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  |              for (const pay of payList) {
 |  |              for (const pay of payList) {
 | 
												
													
														
															|  | -                const t = ctx.helper._.find(tenders, { id: pay.tid });
 |  | 
 | 
												
													
														
															|  | -                pay.tenderName = t ? t.name : '';
 |  | 
 | 
												
													
														
															|  | 
 |  | +                const t = ctx.helper._.find(unitList, { id: pay.company_id });
 | 
												
													
														
															|  | 
 |  | +                pay.company = t ? t.name : '';
 | 
												
													
														
															|  |                  const userInfo = ctx.helper._.find(accountList, { id: pay.uid });
 |  |                  const userInfo = ctx.helper._.find(accountList, { id: pay.uid });
 | 
												
													
														
															|  |                  pay.username = userInfo ? userInfo.name : '';
 |  |                  pay.username = userInfo ? userInfo.name : '';
 | 
												
													
														
															|  | -                if (pay.status !== auditConst.financial.status.checked || !pay.final_auditor_str) {
 |  | 
 | 
												
													
														
															|  | -                    pay.curAuditors = await ctx.service.financialPayAudit.getAuditorsByStatus(pay.id, pay.status, pay.times);
 |  | 
 | 
												
													
														
															|  | -                    if (pay.status === auditConst.financial.status.checked && pay.curAuditors.length > 0) {
 |  | 
 | 
												
													
														
															|  | -                        const final_auditor_str = pay.curAuditors[0].audit_type === auditConst.auditType.key.common
 |  | 
 | 
												
													
														
															|  | -                            ? pay.curAuditors[0].name + (pay.curAuditors[0].role ? '-' + pay.curAuditors[0].role : '')
 |  | 
 | 
												
													
														
															|  | -                            : ctx.helper.transFormToChinese(pay.curAuditors[0].audit_order) + '审';
 |  | 
 | 
												
													
														
															|  | -                        await ctx.service.financialPay.defaultUpdate({ final_auditor_str }, { where: { id: pay.id } });
 |  | 
 | 
												
													
														
															|  | -                    }
 |  | 
 | 
												
													
														
															|  | -                }
 |  | 
 | 
												
													
														
															|  | -                if (pay.status !== auditConst.financial.status.checked) {
 |  | 
 | 
												
													
														
															|  | -                    pay.entities = await ctx.service.financialPayContract.getEntities(pay.id);
 |  | 
 | 
												
													
														
															|  | -                }
 |  | 
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  |              if (ctx.session.sessionUser.is_admin && tenders.length > 0) {
 |  |              if (ctx.session.sessionUser.is_admin && tenders.length > 0) {
 | 
												
													
														
															|  |                  const allPermissionList = await ctx.service.financialPayTenderAudit.getAllList(ctx.subProject.id, ctx.helper._.map(tenders, 'id'), accountList);
 |  |                  const allPermissionList = await ctx.service.financialPayTenderAudit.getAllList(ctx.subProject.id, ctx.helper._.map(tenders, 'id'), accountList);
 | 
												
											
												
													
														
															|  | @@ -703,25 +654,26 @@ module.exports = app => {
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  |              const renderData = {
 |  |              const renderData = {
 | 
												
													
														
															|  | 
 |  | +                categoryData,
 | 
												
													
														
															|  |                  tenders,
 |  |                  tenders,
 | 
												
													
														
															|  |                  financialPermission,
 |  |                  financialPermission,
 | 
												
													
														
															|  |                  usedList: financialConst.used,
 |  |                  usedList: financialConst.used,
 | 
												
													
														
															|  |                  auditConst: auditConst.financial,
 |  |                  auditConst: auditConst.financial,
 | 
												
													
														
															|  | -                filter,
 |  | 
 | 
												
													
														
															|  | -                tid,
 |  | 
 | 
												
													
														
															|  | -                status,
 |  | 
 | 
												
													
														
															|  | -                used,
 |  | 
 | 
												
													
														
															|  | 
 |  | +                company,
 | 
												
													
														
															|  | 
 |  | +                qi,
 | 
												
													
														
															|  |                  payList,
 |  |                  payList,
 | 
												
													
														
															|  |                  fptAuditTids,
 |  |                  fptAuditTids,
 | 
												
													
														
															|  |                  fptReportTids,
 |  |                  fptReportTids,
 | 
												
													
														
															|  | 
 |  | +                userCompanyList,
 | 
												
													
														
															|  | 
 |  | +                userOrderList,
 | 
												
													
														
															|  | 
 |  | +                unitList,
 | 
												
													
														
															|  |                  moment,
 |  |                  moment,
 | 
												
													
														
															|  | 
 |  | +                user,
 | 
												
													
														
															|  |                  auditType: auditConst.auditType,
 |  |                  auditType: auditConst.auditType,
 | 
												
													
														
															|  | -                // preUrl: '/financial',
 |  | 
 | 
												
													
														
															|  | -                jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.pay),
 |  | 
 | 
												
													
														
															|  | 
 |  | +                jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.payStage),
 | 
												
													
														
															|  |                  pageInfo,
 |  |                  pageInfo,
 | 
												
													
														
															|  |              };
 |  |              };
 | 
												
													
														
															|  |              if (ctx.session.sessionUser.is_admin) {
 |  |              if (ctx.session.sessionUser.is_admin) {
 | 
												
													
														
															|  | -                const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
 |  | 
 | 
												
													
														
															|  |                  renderData.accountList = accountList;
 |  |                  renderData.accountList = accountList;
 | 
												
													
														
															|  |                  renderData.accountGroup = unitList.map(item => {
 |  |                  renderData.accountGroup = unitList.map(item => {
 | 
												
													
														
															|  |                      const groupList = accountList.filter(item1 => item1.company === item.name);
 |  |                      const groupList = accountList.filter(item1 => item1.company === item.name);
 | 
												
											
												
													
														
															|  | @@ -730,10 +682,10 @@ module.exports = app => {
 | 
												
													
														
															|  |                  renderData.auditType = auditConst.auditType;
 |  |                  renderData.auditType = auditConst.auditType;
 | 
												
													
														
															|  |                  renderData.shenpi = shenpiConst;
 |  |                  renderData.shenpi = shenpiConst;
 | 
												
													
														
															|  |              }
 |  |              }
 | 
												
													
														
															|  | -            await this.layout('financial/pay.ejs', renderData, 'financial/pay_modal.ejs');
 |  | 
 | 
												
													
														
															|  | 
 |  | +            await this.layout('financial/pay_stage.ejs', renderData, 'financial/pay_stage_modal.ejs');
 | 
												
													
														
															|  |          }
 |  |          }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -        async paySave(ctx) {
 |  | 
 | 
												
													
														
															|  | 
 |  | +        async payStageSave(ctx) {
 | 
												
													
														
															|  |              try {
 |  |              try {
 | 
												
													
														
															|  |                  const responseData = {
 |  |                  const responseData = {
 | 
												
													
														
															|  |                      err: 0, msg: '', data: {},
 |  |                      err: 0, msg: '', data: {},
 | 
												
											
												
													
														
															|  | @@ -785,15 +737,208 @@ module.exports = app => {
 | 
												
													
														
															|  |                      case 'copy-shenpi-audit':
 |  |                      case 'copy-shenpi-audit':
 | 
												
													
														
															|  |                          responseData.data = await ctx.service.financialPayTenderAudit.copyShenpi2otherTender(ctx.subProject.id, data, data.this_tid);
 |  |                          responseData.data = await ctx.service.financialPayTenderAudit.copyShenpi2otherTender(ctx.subProject.id, data, data.this_tid);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  | -                    case 'add-pay':
 |  | 
 | 
												
													
														
															|  | -                        responseData.data = await ctx.service.financialPay.addPay(ctx.subProject.id, data.updateData);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                    case 'copy-tender-bank':
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPayTender.copyBank2otherTender(ctx.subProject.id, data.tenders, data.this_tender);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  | -                    case 'del-pay':
 |  | 
 | 
												
													
														
															|  | -                        responseData.data = await ctx.service.financialPay.delPay(data.postData.node);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                    case 'add-pay-stage':
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPayStage.addPayStage(ctx.subProject.id, data.updateData);
 | 
												
													
														
															|  | 
 |  | +                        break;
 | 
												
													
														
															|  | 
 |  | +                    case 'del-pay-stage':
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPayStage.delPayStage(data.postData.node);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  |                      case 'set-pay-tender':
 |  |                      case 'set-pay-tender':
 | 
												
													
														
															|  |                          responseData.data = await ctx.service.financialPayTender.savePayTender(ctx.subProject.id, data.updateData);
 |  |                          responseData.data = await ctx.service.financialPayTender.savePayTender(ctx.subProject.id, data.updateData);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  | 
 |  | +                    default: throw '参数有误';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +                ctx.body = responseData;
 | 
												
													
														
															|  | 
 |  | +            } catch (err) {
 | 
												
													
														
															|  | 
 |  | +                this.log(err);
 | 
												
													
														
															|  | 
 |  | +                ctx.body = { err: 1, msg: err.toString(), data: {} };
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +        /**
 | 
												
													
														
															|  | 
 |  | +         * 变更管理 页面 (Get)
 | 
												
													
														
															|  | 
 |  | +         *
 | 
												
													
														
															|  | 
 |  | +         * @param {Object} ctx - egg全局变量
 | 
												
													
														
															|  | 
 |  | +         * @return {void}
 | 
												
													
														
															|  | 
 |  | +         */
 | 
												
													
														
															|  | 
 |  | +        async pay(ctx) {
 | 
												
													
														
															|  | 
 |  | +            try {
 | 
												
													
														
															|  | 
 |  | +                const status = parseInt(ctx.query.status) || 0;
 | 
												
													
														
															|  | 
 |  | +                const tid = parseInt(ctx.query.tid) || null;
 | 
												
													
														
															|  | 
 |  | +                const used = ctx.query.used || null;
 | 
												
													
														
															|  | 
 |  | +                const from = ctx.query.from || null;
 | 
												
													
														
															|  | 
 |  | +                await this._filterPay(ctx, status, tid, used, from);
 | 
												
													
														
															|  | 
 |  | +            } catch (err) {
 | 
												
													
														
															|  | 
 |  | +                this.log(err);
 | 
												
													
														
															|  | 
 |  | +                ctx.redirect(`/sp/${ctx.subProject.id}/dashboard`);
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +        async _filterPay(ctx, status = 0, tid = null, used = null, from) {
 | 
												
													
														
															|  | 
 |  | +            const financialPermission = await ctx.service.subProjPermission.getFinancailPermission(ctx.subProject.permission.fund_trans_permission, ctx.subProject.permission.fund_pay_permission);
 | 
												
													
														
															|  | 
 |  | +            if (!financialPermission.pay_show) {
 | 
												
													
														
															|  | 
 |  | +                throw '没有查看权限';
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const payStage = await ctx.service.financialPayStage.getOnePayStage(ctx.params.fpsid);
 | 
												
													
														
															|  | 
 |  | +            if (!payStage) {
 | 
												
													
														
															|  | 
 |  | +                throw '该支付单位期不存在';
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const fptAudits = await ctx.service.financialPayTenderAudit.getAllDataByCondition({ where: { spid: ctx.subProject.id, uid: ctx.session.sessionUser.accountId } });
 | 
												
													
														
															|  | 
 |  | +            const fptAuditTids = ctx.helper._.map(fptAudits, 'tid');
 | 
												
													
														
															|  | 
 |  | +            const fptReportTids = ctx.helper._.map(ctx.helper._.filter(fptAudits, { is_report: 1 }), 'tid');
 | 
												
													
														
															|  | 
 |  | +            const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
 | 
												
													
														
															|  | 
 |  | +            const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : fptAuditTids) : [tid];
 | 
												
													
														
															|  | 
 |  | +            const tenderCondition = { spid: ctx.subProject.id, filter_fund: 0 };
 | 
												
													
														
															|  | 
 |  | +            let hadTender = false;
 | 
												
													
														
															|  | 
 |  | +            if (ctx.session.sessionUser.is_admin) {
 | 
												
													
														
															|  | 
 |  | +                hadTender = true;
 | 
												
													
														
															|  | 
 |  | +            } else if (fptAuditTids.length !== 0) {
 | 
												
													
														
															|  | 
 |  | +                hadTender = true;
 | 
												
													
														
															|  | 
 |  | +                tenderCondition.id = fptAuditTids;
 | 
												
													
														
															|  | 
 |  | +            } else {
 | 
												
													
														
															|  | 
 |  | +                hadTender = false;
 | 
												
													
														
															|  | 
 |  | +                tenderCondition.id = -1;
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const categoryData = await this.ctx.service.category.getAllCategory(ctx.subProject);
 | 
												
													
														
															|  | 
 |  | +            const tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name', 'category'] }) : [];
 | 
												
													
														
															|  | 
 |  | +            const filter = JSON.parse(JSON.stringify(auditConst.financial.filter));
 | 
												
													
														
															|  | 
 |  | +            filter.count = [];
 | 
												
													
														
															|  | 
 |  | +            filter.count[filter.status.pending] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, filter.status.pending, filterTids, used);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
 | 
												
													
														
															|  | 
 |  | +            filter.count[filter.status.uncheck] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, filter.status.uncheck, filterTids, used);// await ctx.service.change.checkingDatas(tender.id, ctx.session.sessionUser.accountId);
 | 
												
													
														
															|  | 
 |  | +            filter.count[filter.status.checking] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, filter.status.checking, filterTids, used);// await ctx.service.change.checkedDatas(tender.id, ctx.session.sessionUser.accountId);
 | 
												
													
														
															|  | 
 |  | +            filter.count[filter.status.checked] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, filter.status.checked, filterTids, used);// await ctx.service.change.pendingDatas(tender.id, ctx.session.sessionUser.accountId);
 | 
												
													
														
															|  | 
 |  | +            const payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, payStage.id, status, filterTids, used, 1);
 | 
												
													
														
															|  | 
 |  | +            const total = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, payStage.id, status, filterTids, used);
 | 
												
													
														
															|  | 
 |  | +            // 分页相关
 | 
												
													
														
															|  | 
 |  | +            const page = ctx.page;
 | 
												
													
														
															|  | 
 |  | +            const pageSize = ctx.pageSize;
 | 
												
													
														
															|  | 
 |  | +            const pageInfo = {
 | 
												
													
														
															|  | 
 |  | +                page,
 | 
												
													
														
															|  | 
 |  | +                pageSizeSelect: 1,
 | 
												
													
														
															|  | 
 |  | +                pageSize,
 | 
												
													
														
															|  | 
 |  | +                total_num: total,
 | 
												
													
														
															|  | 
 |  | +                total: Math.ceil(total / pageSize),
 | 
												
													
														
															|  | 
 |  | +                queryData: JSON.stringify(ctx.urlInfo.query),
 | 
												
													
														
															|  | 
 |  | +            };
 | 
												
													
														
															|  | 
 |  | +            // 获取所有项目参与者
 | 
												
													
														
															|  | 
 |  | +            const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject, ['id', 'account', 'name', 'company', 'company_id', 'role', 'enable', 'is_admin', 'account_group', 'mobile']);
 | 
												
													
														
															|  | 
 |  | +            const payTenders = await ctx.service.financialPayTender.getAllDataByCondition({ where: { spid: ctx.subProject.id } });
 | 
												
													
														
															|  | 
 |  | +            if (tenders.length > 0) {
 | 
												
													
														
															|  | 
 |  | +                const allLastPay = await ctx.service.financialPay.getAllDataByCondition({ where: { spid: ctx.subProject.id, tid: ctx.helper._.map(tenders, 'id') }, columns: ['id', 'tid', 'code'], orders: [['id', 'desc']] });
 | 
												
													
														
															|  | 
 |  | +                const tenderInfos = await ctx.service.tenderInfo.getAllDataByCondition({ where: { tid: ctx.helper._.map(tenders, 'id') }, columns: ['tid', 'pay_account', 'deal_info'] });
 | 
												
													
														
															|  | 
 |  | +                for (const t of tenders) {
 | 
												
													
														
															|  | 
 |  | +                    t.category = t.category && t.category !== '' ? JSON.parse(t.category) : null;
 | 
												
													
														
															|  | 
 |  | +                    const info = ctx.helper._.find(tenderInfos, { tid: t.id });
 | 
												
													
														
															|  | 
 |  | +                    t.pay_account = info && info.pay_account ? JSON.parse(info.pay_account).project : '';
 | 
												
													
														
															|  | 
 |  | +                    const pt = ctx.helper._.find(payTenders, { tid: t.id });
 | 
												
													
														
															|  | 
 |  | +                    t.pt = pt ? pt : { id: 0, tid: t.id, name: '', bank: '', bank_account: '', contact: '', phone: '' };
 | 
												
													
														
															|  | 
 |  | +                    if (ctx.session.sessionUser.is_admin || ctx.helper._.includes(fptReportTids, t.id)) {
 | 
												
													
														
															|  | 
 |  | +                        t.dealCode = info && info.deal_info ? JSON.parse(info.deal_info).dealCode : '';
 | 
												
													
														
															|  | 
 |  | +                        const lastPay = ctx.helper._.filter(allLastPay, { tid: t.id });
 | 
												
													
														
															|  | 
 |  | +                        t.startNum = 1;
 | 
												
													
														
															|  | 
 |  | +                        if (lastPay.length > 0) {
 | 
												
													
														
															|  | 
 |  | +                            const startArray = lastPay[0].code.split('-');
 | 
												
													
														
															|  | 
 |  | +                            t.startNum = parseInt(startArray[startArray.length - 1]) + 1;
 | 
												
													
														
															|  | 
 |  | +                        }
 | 
												
													
														
															|  | 
 |  | +                    }
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            for (const pay of payList) {
 | 
												
													
														
															|  | 
 |  | +                const t = ctx.helper._.find(tenders, { id: pay.tid });
 | 
												
													
														
															|  | 
 |  | +                pay.tenderName = t ? t.name : '';
 | 
												
													
														
															|  | 
 |  | +                const userInfo = ctx.helper._.find(accountList, { id: pay.uid });
 | 
												
													
														
															|  | 
 |  | +                pay.username = userInfo ? userInfo.name : '';
 | 
												
													
														
															|  | 
 |  | +                if (pay.status !== auditConst.financial.status.checked || !pay.final_auditor_str) {
 | 
												
													
														
															|  | 
 |  | +                    pay.curAuditors = await ctx.service.financialPayAudit.getAuditorsByStatus(pay.id, pay.status, pay.times);
 | 
												
													
														
															|  | 
 |  | +                    if (pay.status === auditConst.financial.status.checked && pay.curAuditors.length > 0) {
 | 
												
													
														
															|  | 
 |  | +                        const final_auditor_str = pay.curAuditors[0].audit_type === auditConst.auditType.key.common
 | 
												
													
														
															|  | 
 |  | +                            ? pay.curAuditors[0].name + (pay.curAuditors[0].role ? '-' + pay.curAuditors[0].role : '')
 | 
												
													
														
															|  | 
 |  | +                            : ctx.helper.transFormToChinese(pay.curAuditors[0].audit_order) + '审';
 | 
												
													
														
															|  | 
 |  | +                        await ctx.service.financialPay.defaultUpdate({ final_auditor_str }, { where: { id: pay.id } });
 | 
												
													
														
															|  | 
 |  | +                    }
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +                if (pay.status !== auditConst.financial.status.checked) {
 | 
												
													
														
															|  | 
 |  | +                    pay.entities = await ctx.service.financialPayContract.getEntities(pay.id);
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            if (ctx.session.sessionUser.is_admin && tenders.length > 0) {
 | 
												
													
														
															|  | 
 |  | +                const allPermissionList = await ctx.service.financialPayTenderAudit.getAllList(ctx.subProject.id, ctx.helper._.map(tenders, 'id'), accountList);
 | 
												
													
														
															|  | 
 |  | +                const allAuditGroupList = await ctx.service.shenpiAudit.getAllAuditGroupList(ctx.helper._.map(tenders, 'id'), shenpiConst.sp_other_type.financial, shenpiConst.sp_status.gdspl);
 | 
												
													
														
															|  | 
 |  | +                for (const t of tenders) {
 | 
												
													
														
															|  | 
 |  | +                    t.permissionList = ctx.helper._.filter(allPermissionList, { tid: t.id }) || [];
 | 
												
													
														
															|  | 
 |  | +                    // t.auditGroupList = await ctx.service.shenpiAudit.getAuditGroupList(t.id, shenpiConst.sp_other_type.financial, shenpiConst.sp_status.gdspl);
 | 
												
													
														
															|  | 
 |  | +                    t.auditGroupList = ctx.helper._.find(allAuditGroupList, { tid: t.id }) ? ctx.helper._.find(allAuditGroupList, { tid: t.id }).audits : [];
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const notStagePays = await ctx.service.financialPay.getAllDataByCondition({ where: { spid: ctx.subProject.id, fpsid: null } });
 | 
												
													
														
															|  | 
 |  | +            for (const pay of notStagePays) {
 | 
												
													
														
															|  | 
 |  | +                const t = ctx.helper._.find(tenders, { id: pay.tid });
 | 
												
													
														
															|  | 
 |  | +                pay.tenderName = t ? t.name : '';
 | 
												
													
														
															|  | 
 |  | +                const userInfo = ctx.helper._.find(accountList, { id: pay.uid });
 | 
												
													
														
															|  | 
 |  | +                pay.username = userInfo ? userInfo.name : '';
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const renderData = {
 | 
												
													
														
															|  | 
 |  | +                categoryData,
 | 
												
													
														
															|  | 
 |  | +                tenders,
 | 
												
													
														
															|  | 
 |  | +                financialPermission,
 | 
												
													
														
															|  | 
 |  | +                usedList: financialConst.used,
 | 
												
													
														
															|  | 
 |  | +                auditConst: auditConst.financial,
 | 
												
													
														
															|  | 
 |  | +                filter,
 | 
												
													
														
															|  | 
 |  | +                tid,
 | 
												
													
														
															|  | 
 |  | +                status,
 | 
												
													
														
															|  | 
 |  | +                used,
 | 
												
													
														
															|  | 
 |  | +                from,
 | 
												
													
														
															|  | 
 |  | +                payList,
 | 
												
													
														
															|  | 
 |  | +                payStage,
 | 
												
													
														
															|  | 
 |  | +                notStagePays,
 | 
												
													
														
															|  | 
 |  | +                fptAuditTids,
 | 
												
													
														
															|  | 
 |  | +                fptReportTids,
 | 
												
													
														
															|  | 
 |  | +                unitList,
 | 
												
													
														
															|  | 
 |  | +                moment,
 | 
												
													
														
															|  | 
 |  | +                auditType: auditConst.auditType,
 | 
												
													
														
															|  | 
 |  | +                preUrl: '/sp/' + ctx.subProject.id + '/financial/pay' + (from ? '/list' : '/stage'),
 | 
												
													
														
															|  | 
 |  | +                jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.pay),
 | 
												
													
														
															|  | 
 |  | +                pageInfo,
 | 
												
													
														
															|  | 
 |  | +            };
 | 
												
													
														
															|  | 
 |  | +            if (ctx.session.sessionUser.is_admin) {
 | 
												
													
														
															|  | 
 |  | +                renderData.accountList = accountList;
 | 
												
													
														
															|  | 
 |  | +                renderData.accountGroup = unitList.map(item => {
 | 
												
													
														
															|  | 
 |  | +                    const groupList = accountList.filter(item1 => item1.company === item.name);
 | 
												
													
														
															|  | 
 |  | +                    return { groupName: item.name, groupList };
 | 
												
													
														
															|  | 
 |  | +                }).filter(x => { return x.groupList.length > 0; });
 | 
												
													
														
															|  | 
 |  | +                renderData.auditType = auditConst.auditType;
 | 
												
													
														
															|  | 
 |  | +                renderData.shenpi = shenpiConst;
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            await this.layout('financial/pay.ejs', renderData, 'financial/pay_modal.ejs');
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +        async paySave(ctx) {
 | 
												
													
														
															|  | 
 |  | +            try {
 | 
												
													
														
															|  | 
 |  | +                const responseData = {
 | 
												
													
														
															|  | 
 |  | +                    err: 0, msg: '', data: {},
 | 
												
													
														
															|  | 
 |  | +                };
 | 
												
													
														
															|  | 
 |  | +                const data = JSON.parse(ctx.request.body.data);
 | 
												
													
														
															|  | 
 |  | +                if (!data.type) {
 | 
												
													
														
															|  | 
 |  | +                    throw '提交数据错误';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +                const payStage = await ctx.service.financialPayStage.getDataById(ctx.params.fpsid);
 | 
												
													
														
															|  | 
 |  | +                const fileds = ['batch-old-pays', 'add-pay'];
 | 
												
													
														
															|  | 
 |  | +                if (!payStage && fileds.indexOf(data.type) !== -1) {
 | 
												
													
														
															|  | 
 |  | +                    throw '资金支付单位期不存在';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +                switch (data.type) {
 | 
												
													
														
															|  | 
 |  | +                    case 'batch-old-pays':
 | 
												
													
														
															|  | 
 |  | +                        await ctx.service.financialPay.batchOldPays(ctx.subProject.id, payStage, data.postData.payIds);
 | 
												
													
														
															|  | 
 |  | +                        break;
 | 
												
													
														
															|  | 
 |  | +                    case 'add-pay':
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPay.addPay(ctx.subProject.id, payStage, data.updateData);
 | 
												
													
														
															|  | 
 |  | +                        break;
 | 
												
													
														
															|  | 
 |  | +                    case 'del-pay':
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPay.delPay(data.postData.node);
 | 
												
													
														
															|  | 
 |  | +                        break;
 | 
												
													
														
															|  |                      case 'get-auditors':
 |  |                      case 'get-auditors':
 | 
												
													
														
															|  |                          const fpInfo = await ctx.service.financialPay.getDataById(data.id);
 |  |                          const fpInfo = await ctx.service.financialPay.getDataById(data.id);
 | 
												
													
														
															|  |                          await ctx.service.financialPay.loadPayUser(fpInfo);
 |  |                          await ctx.service.financialPay.loadPayUser(fpInfo);
 | 
												
											
												
													
														
															|  | @@ -810,6 +955,161 @@ module.exports = app => {
 | 
												
													
														
															|  |          }
 |  |          }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |          /**
 |  |          /**
 | 
												
													
														
															|  | 
 |  | +         * 变更管理 页面 (Get)
 | 
												
													
														
															|  | 
 |  | +         *
 | 
												
													
														
															|  | 
 |  | +         * @param {Object} ctx - egg全局变量
 | 
												
													
														
															|  | 
 |  | +         * @return {void}
 | 
												
													
														
															|  | 
 |  | +         */
 | 
												
													
														
															|  | 
 |  | +        async payList(ctx) {
 | 
												
													
														
															|  | 
 |  | +            try {
 | 
												
													
														
															|  | 
 |  | +                const company = ctx.query.company || null;
 | 
												
													
														
															|  | 
 |  | +                const qi = parseInt(ctx.query.qi) || null;
 | 
												
													
														
															|  | 
 |  | +                const status = parseInt(ctx.query.status) || 0;
 | 
												
													
														
															|  | 
 |  | +                const tid = parseInt(ctx.query.tid) || null;
 | 
												
													
														
															|  | 
 |  | +                const used = ctx.query.used || null;
 | 
												
													
														
															|  | 
 |  | +                await this._filterPayList(ctx, company, qi, status, tid, used);
 | 
												
													
														
															|  | 
 |  | +            } catch (err) {
 | 
												
													
														
															|  | 
 |  | +                this.log(err);
 | 
												
													
														
															|  | 
 |  | +                ctx.redirect(`/sp/${ctx.subProject.id}/dashboard`);
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +        async _filterPayList(ctx, company = null, qi = null, status = 0, tid = null, used = null) {
 | 
												
													
														
															|  | 
 |  | +            const financialPermission = await ctx.service.subProjPermission.getFinancailPermission(ctx.subProject.permission.fund_trans_permission, ctx.subProject.permission.fund_pay_permission);
 | 
												
													
														
															|  | 
 |  | +            if (!financialPermission.pay_show) {
 | 
												
													
														
															|  | 
 |  | +                throw '没有查看权限';
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const fptAudits = await ctx.service.financialPayTenderAudit.getAllDataByCondition({ where: { spid: ctx.subProject.id, uid: ctx.session.sessionUser.accountId } });
 | 
												
													
														
															|  | 
 |  | +            const fptAuditTids = ctx.helper._.map(fptAudits, 'tid');
 | 
												
													
														
															|  | 
 |  | +            const fptReportTids = ctx.helper._.map(ctx.helper._.filter(fptAudits, { is_report: 1 }), 'tid');
 | 
												
													
														
															|  | 
 |  | +            const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: ctx.session.sessionProject.id } });
 | 
												
													
														
															|  | 
 |  | +            const filterTids = tid === null ? (ctx.session.sessionUser.is_admin ? null : fptAuditTids) : [tid];
 | 
												
													
														
															|  | 
 |  | +            const tenderCondition = { spid: ctx.subProject.id, filter_fund: 0 };
 | 
												
													
														
															|  | 
 |  | +            let hadTender = false;
 | 
												
													
														
															|  | 
 |  | +            if (ctx.session.sessionUser.is_admin) {
 | 
												
													
														
															|  | 
 |  | +                hadTender = true;
 | 
												
													
														
															|  | 
 |  | +            } else if (fptAuditTids.length !== 0) {
 | 
												
													
														
															|  | 
 |  | +                hadTender = true;
 | 
												
													
														
															|  | 
 |  | +                tenderCondition.id = fptAuditTids;
 | 
												
													
														
															|  | 
 |  | +            } else {
 | 
												
													
														
															|  | 
 |  | +                hadTender = false;
 | 
												
													
														
															|  | 
 |  | +                tenderCondition.id = -1;
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const categoryData = await this.ctx.service.category.getAllCategory(ctx.subProject);
 | 
												
													
														
															|  | 
 |  | +            const tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name', 'category'] }) : [];
 | 
												
													
														
															|  | 
 |  | +            const accountList = await ctx.service.projectAccount.getAllSubProjectAccount(ctx.subProject, ['id', 'account', 'name', 'company', 'company_id', 'role', 'enable', 'is_admin', 'account_group', 'mobile']);
 | 
												
													
														
															|  | 
 |  | +            const user = accountList.find(item => item.id === ctx.session.sessionUser.accountId) || null;
 | 
												
													
														
															|  | 
 |  | +            const userCompany = user ? ctx.helper._.find(unitList, { name: user.company }) : null;
 | 
												
													
														
															|  | 
 |  | +            if (!userCompany) {
 | 
												
													
														
															|  | 
 |  | +                throw '请联系管理员添加用户所在单位信息';
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const userOrderList = await ctx.service.financialPayStage.getUserOrderList(ctx.subProject.id, userCompany ? userCompany.id : 0);
 | 
												
													
														
															|  | 
 |  | +            const userCompanyList = await ctx.service.financialPayStage.getUserCompanyList(ctx.subProject.id, userCompany ? userCompany.id : 0, unitList);
 | 
												
													
														
															|  | 
 |  | +            let fpsidList = [];
 | 
												
													
														
															|  | 
 |  | +            if (company || qi) {
 | 
												
													
														
															|  | 
 |  | +                const companyInfo = company ? ctx.helper._.find(unitList, { name: company }) : null;
 | 
												
													
														
															|  | 
 |  | +                const fpstageList = await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, companyInfo ? companyInfo.id : null, userCompany ? userCompany.id : 0, qi, 0);
 | 
												
													
														
															|  | 
 |  | +                fpsidList = ctx.helper._.map(fpstageList, 'id');
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            // const payList = await ctx.service.financialPayStage.getListByStatus(ctx.subProject.id, companyInfo ? companyInfo.id : null, userCompany ? userCompany.id : 0, qi);
 | 
												
													
														
															|  | 
 |  | +            const filter = JSON.parse(JSON.stringify(auditConst.financial.filter));
 | 
												
													
														
															|  | 
 |  | +            filter.count = [];
 | 
												
													
														
															|  | 
 |  | +            filter.count[filter.status.pending] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, filter.status.pending, filterTids, used);
 | 
												
													
														
															|  | 
 |  | +            filter.count[filter.status.uncheck] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, filter.status.uncheck, filterTids, used);
 | 
												
													
														
															|  | 
 |  | +            filter.count[filter.status.checking] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, filter.status.checking, filterTids, used);
 | 
												
													
														
															|  | 
 |  | +            filter.count[filter.status.checked] = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, filter.status.checked, filterTids, used);
 | 
												
													
														
															|  | 
 |  | +            const payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, status, filterTids, used, 1);
 | 
												
													
														
															|  | 
 |  | +            const total = await ctx.service.financialPay.getCountByStatus(ctx.subProject.id, fpsidList.length > 0 ? fpsidList : null, status, filterTids, used);
 | 
												
													
														
															|  | 
 |  | +            // 分页相关
 | 
												
													
														
															|  | 
 |  | +            const page = ctx.page;
 | 
												
													
														
															|  | 
 |  | +            const pageSize = ctx.pageSize;
 | 
												
													
														
															|  | 
 |  | +            const pageInfo = {
 | 
												
													
														
															|  | 
 |  | +                page,
 | 
												
													
														
															|  | 
 |  | +                pageSizeSelect: 1,
 | 
												
													
														
															|  | 
 |  | +                pageSize,
 | 
												
													
														
															|  | 
 |  | +                total_num: total,
 | 
												
													
														
															|  | 
 |  | +                total: Math.ceil(total / pageSize),
 | 
												
													
														
															|  | 
 |  | +                queryData: JSON.stringify(ctx.urlInfo.query),
 | 
												
													
														
															|  | 
 |  | +            };
 | 
												
													
														
															|  | 
 |  | +            for (const pay of payList) {
 | 
												
													
														
															|  | 
 |  | +                const t = ctx.helper._.find(tenders, { id: pay.tid });
 | 
												
													
														
															|  | 
 |  | +                pay.tenderName = t ? t.name : '';
 | 
												
													
														
															|  | 
 |  | +                const userInfo = ctx.helper._.find(accountList, { id: pay.uid });
 | 
												
													
														
															|  | 
 |  | +                pay.username = userInfo ? userInfo.name : '';
 | 
												
													
														
															|  | 
 |  | +                if (pay.status !== auditConst.financial.status.checked || !pay.final_auditor_str) {
 | 
												
													
														
															|  | 
 |  | +                    pay.curAuditors = await ctx.service.financialPayAudit.getAuditorsByStatus(pay.id, pay.status, pay.times);
 | 
												
													
														
															|  | 
 |  | +                    if (pay.status === auditConst.financial.status.checked && pay.curAuditors.length > 0) {
 | 
												
													
														
															|  | 
 |  | +                        const final_auditor_str = pay.curAuditors[0].audit_type === auditConst.auditType.key.common
 | 
												
													
														
															|  | 
 |  | +                            ? pay.curAuditors[0].name + (pay.curAuditors[0].role ? '-' + pay.curAuditors[0].role : '')
 | 
												
													
														
															|  | 
 |  | +                            : ctx.helper.transFormToChinese(pay.curAuditors[0].audit_order) + '审';
 | 
												
													
														
															|  | 
 |  | +                        await ctx.service.financialPay.defaultUpdate({ final_auditor_str }, { where: { id: pay.id } });
 | 
												
													
														
															|  | 
 |  | +                    }
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +                if (pay.status !== auditConst.financial.status.checked) {
 | 
												
													
														
															|  | 
 |  | +                    pay.entities = await ctx.service.financialPayContract.getEntities(pay.id);
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +                pay.stage = pay.fpsid ? await ctx.service.financialPayStage.getOnePayStage(pay.fpsid) : null;
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +            const renderData = {
 | 
												
													
														
															|  | 
 |  | +                categoryData,
 | 
												
													
														
															|  | 
 |  | +                tenders,
 | 
												
													
														
															|  | 
 |  | +                financialPermission,
 | 
												
													
														
															|  | 
 |  | +                usedList: financialConst.used,
 | 
												
													
														
															|  | 
 |  | +                auditConst: auditConst.financial,
 | 
												
													
														
															|  | 
 |  | +                filter,
 | 
												
													
														
															|  | 
 |  | +                tid,
 | 
												
													
														
															|  | 
 |  | +                status,
 | 
												
													
														
															|  | 
 |  | +                used,
 | 
												
													
														
															|  | 
 |  | +                company,
 | 
												
													
														
															|  | 
 |  | +                qi,
 | 
												
													
														
															|  | 
 |  | +                userCompanyList,
 | 
												
													
														
															|  | 
 |  | +                userOrderList,
 | 
												
													
														
															|  | 
 |  | +                payList,
 | 
												
													
														
															|  | 
 |  | +                fptAuditTids,
 | 
												
													
														
															|  | 
 |  | +                fptReportTids,
 | 
												
													
														
															|  | 
 |  | +                unitList,
 | 
												
													
														
															|  | 
 |  | +                moment,
 | 
												
													
														
															|  | 
 |  | +                auditType: auditConst.auditType,
 | 
												
													
														
															|  | 
 |  | +                // preUrl: '/sp/' + ctx.subProject.id + '/financial/pay' + (from === 'list' ? '/list/?from=' + from : '/stage'),
 | 
												
													
														
															|  | 
 |  | +                jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.payList),
 | 
												
													
														
															|  | 
 |  | +                pageInfo,
 | 
												
													
														
															|  | 
 |  | +            };
 | 
												
													
														
															|  | 
 |  | +            await this.layout('financial/pay_list.ejs', renderData, 'financial/pay_list_modal.ejs');
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +        async payListSave(ctx) {
 | 
												
													
														
															|  | 
 |  | +            try {
 | 
												
													
														
															|  | 
 |  | +                const responseData = {
 | 
												
													
														
															|  | 
 |  | +                    err: 0, msg: '', data: {},
 | 
												
													
														
															|  | 
 |  | +                };
 | 
												
													
														
															|  | 
 |  | +                const data = JSON.parse(ctx.request.body.data);
 | 
												
													
														
															|  | 
 |  | +                if (!data.type) {
 | 
												
													
														
															|  | 
 |  | +                    throw '提交数据错误';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +                const payStage = await ctx.service.financialPayStage.getDataById(ctx.params.fpsid);
 | 
												
													
														
															|  | 
 |  | +                if (!payStage) {
 | 
												
													
														
															|  | 
 |  | +                    throw '资金支付单位期不存在';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +                switch (data.type) {
 | 
												
													
														
															|  | 
 |  | +                    case 'batch-old-pays':
 | 
												
													
														
															|  | 
 |  | +                        await ctx.service.financialPay.batchOldPays(ctx.subProject.id, payStage, data.postData.payIds);
 | 
												
													
														
															|  | 
 |  | +                        break;
 | 
												
													
														
															|  | 
 |  | +                    case 'add-pay':
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPay.addPay(ctx.subProject.id, payStage, data.updateData);
 | 
												
													
														
															|  | 
 |  | +                        break;
 | 
												
													
														
															|  | 
 |  | +                    case 'del-pay':
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPay.delPay(payStage, data.postData.node);
 | 
												
													
														
															|  | 
 |  | +                        break;
 | 
												
													
														
															|  | 
 |  | +                    default: throw '参数有误';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  | 
 |  | +                ctx.body = responseData;
 | 
												
													
														
															|  | 
 |  | +            } catch (err) {
 | 
												
													
														
															|  | 
 |  | +                this.log(err);
 | 
												
													
														
															|  | 
 |  | +                ctx.body = { err: 1, msg: err.toString(), data: {} };
 | 
												
													
														
															|  | 
 |  | +            }
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +        /**
 | 
												
													
														
															|  |           * 获取审批界面所需的 原报、审批人数据等
 |  |           * 获取审批界面所需的 原报、审批人数据等
 | 
												
													
														
															|  |           * @param ctx
 |  |           * @param ctx
 | 
												
													
														
															|  |           * @return {Promise<void>}
 |  |           * @return {Promise<void>}
 | 
												
											
												
													
														
															|  | @@ -826,6 +1126,7 @@ module.exports = app => {
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  |                  await this._getFinancialAuditViewData(ctx);
 |  |                  await this._getFinancialAuditViewData(ctx);
 | 
												
													
														
															|  |                  // 获取附件列表
 |  |                  // 获取附件列表
 | 
												
													
														
															|  | 
 |  | +                const from = ctx.query.from || null;
 | 
												
													
														
															|  |                  const fileList = await ctx.service.financialPayAtt.getAtt(ctx.financialPay.id);
 |  |                  const fileList = await ctx.service.financialPayAtt.getAtt(ctx.financialPay.id);
 | 
												
													
														
															|  |                  const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
 |  |                  const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
 | 
												
													
														
															|  |                  const auth_mobile = pa.auth_mobile;
 |  |                  const auth_mobile = pa.auth_mobile;
 | 
												
											
												
													
														
															|  | @@ -838,8 +1139,10 @@ module.exports = app => {
 | 
												
													
														
															|  |                      auditType: auditConst.auditType,
 |  |                      auditType: auditConst.auditType,
 | 
												
													
														
															|  |                      whiteList: ctx.app.config.multipart.whitelist,
 |  |                      whiteList: ctx.app.config.multipart.whitelist,
 | 
												
													
														
															|  |                      moment,
 |  |                      moment,
 | 
												
													
														
															|  | 
 |  | +                    from,
 | 
												
													
														
															|  |                      fileList,
 |  |                      fileList,
 | 
												
													
														
															|  |                      authMobile: auth_mobile,
 |  |                      authMobile: auth_mobile,
 | 
												
													
														
															|  | 
 |  | +                    returnUrl: `/sp/${ctx.subProject.id}/financial/pay/${from === 'list' ? 'list' : 'stage/' + ctx.financialPay.fpsid}`,
 | 
												
													
														
															|  |                      preUrl: `/sp/${ctx.subProject.id}/financial/pay`,
 |  |                      preUrl: `/sp/${ctx.subProject.id}/financial/pay`,
 | 
												
													
														
															|  |                      preUrl2: `/sp/${ctx.subProject.id}/financial/pay/` + ctx.financialPay.id,
 |  |                      preUrl2: `/sp/${ctx.subProject.id}/financial/pay/` + ctx.financialPay.id,
 | 
												
													
														
															|  |                      jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.payDetail),
 |  |                      jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.financial.payDetail),
 | 
												
											
												
													
														
															|  | @@ -862,6 +1165,9 @@ module.exports = app => {
 | 
												
													
														
															|  |                  if (!ctx.financialPay) {
 |  |                  if (!ctx.financialPay) {
 | 
												
													
														
															|  |                      throw '数据错误';
 |  |                      throw '数据错误';
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  | 
 |  | +                if (!ctx.financialPay.fpsid || !ctx.financialPay.payStage) {
 | 
												
													
														
															|  | 
 |  | +                    throw '未关联资金支付单位期无法进行任何操作';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  |                  if (ctx.financialPay.uid !== ctx.session.sessionUser.accountId) {
 |  |                  if (ctx.financialPay.uid !== ctx.session.sessionUser.accountId) {
 | 
												
													
														
															|  |                      throw '您无权上报该资金支付数据';
 |  |                      throw '您无权上报该资金支付数据';
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
											
												
													
														
															|  | @@ -889,6 +1195,9 @@ module.exports = app => {
 | 
												
													
														
															|  |                  if (!ctx.financialPay || ctx.financialPay.status !== auditConst.financial.status.checking) {
 |  |                  if (!ctx.financialPay || ctx.financialPay.status !== auditConst.financial.status.checking) {
 | 
												
													
														
															|  |                      throw '当前资金支付数据有误';
 |  |                      throw '当前资金支付数据有误';
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
													
														
															|  | 
 |  | +                if (!ctx.financialPay.fpsid || !ctx.financialPay.payStage) {
 | 
												
													
														
															|  | 
 |  | +                    throw '未关联资金支付单位期无法进行任何操作';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  |                  if (ctx.financialPay.curAuditorIds.length === 0 || ctx.financialPay.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) === -1) {
 |  |                  if (ctx.financialPay.curAuditorIds.length === 0 || ctx.financialPay.curAuditorIds.indexOf(ctx.session.sessionUser.accountId) === -1) {
 | 
												
													
														
															|  |                      throw '您无权进行该操作';
 |  |                      throw '您无权进行该操作';
 | 
												
													
														
															|  |                  }
 |  |                  }
 | 
												
											
												
													
														
															|  | @@ -916,6 +1225,9 @@ module.exports = app => {
 | 
												
													
														
															|  |           */
 |  |           */
 | 
												
													
														
															|  |          async checkPayAgain(ctx) {
 |  |          async checkPayAgain(ctx) {
 | 
												
													
														
															|  |              try {
 |  |              try {
 | 
												
													
														
															|  | 
 |  | +                if (!ctx.financialPay.fpsid || !ctx.financialPay.payStage) {
 | 
												
													
														
															|  | 
 |  | +                    throw '未关联资金支付单位期无法进行任何操作';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  |                  // 获取终审
 |  |                  // 获取终审
 | 
												
													
														
															|  |                  // const auditInfo = await this.ctx.service.changeProjectAudit.getAuditorByStatus(ctx.change.id, audit.changeProject.status.checked);
 |  |                  // const auditInfo = await this.ctx.service.changeProjectAudit.getAuditorByStatus(ctx.change.id, audit.changeProject.status.checked);
 | 
												
													
														
															|  |                  // if (ctx.change.status !== audit.changeProject.status.checked || ctx.session.sessionUser.accountId !== auditInfo.aid) {
 |  |                  // if (ctx.change.status !== audit.changeProject.status.checked || ctx.session.sessionUser.accountId !== auditInfo.aid) {
 | 
												
											
												
													
														
															|  | @@ -964,6 +1276,9 @@ module.exports = app => {
 | 
												
													
														
															|  |                  const responseData = {
 |  |                  const responseData = {
 | 
												
													
														
															|  |                      err: 0, msg: '', data: {},
 |  |                      err: 0, msg: '', data: {},
 | 
												
													
														
															|  |                  };
 |  |                  };
 | 
												
													
														
															|  | 
 |  | +                if (!ctx.financialPay.fpsid || !ctx.financialPay.payStage) {
 | 
												
													
														
															|  | 
 |  | +                    throw '未关联资金支付单位期无法进行任何操作';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  |                  const data = JSON.parse(ctx.request.body.data);
 |  |                  const data = JSON.parse(ctx.request.body.data);
 | 
												
													
														
															|  |                  if (!data.type) {
 |  |                  if (!data.type) {
 | 
												
													
														
															|  |                      throw '提交数据错误';
 |  |                      throw '提交数据错误';
 | 
												
											
												
													
														
															|  | @@ -994,13 +1309,13 @@ module.exports = app => {
 | 
												
													
														
															|  |                          responseData.data = await ctx.service.financialPayContract.addContracts(ctx.financialPay, data.contract_ids);
 |  |                          responseData.data = await ctx.service.financialPayContract.addContracts(ctx.financialPay, data.contract_ids);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  |                      case 'contract_del':
 |  |                      case 'contract_del':
 | 
												
													
														
															|  | -                        responseData.data = await ctx.service.financialPayContract.delContract(ctx.financialPay.id, data.ids);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPayContract.delContract(ctx.financialPay.id, ctx.financialPay.payStage, data.ids);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  |                      case 'contract_update':
 |  |                      case 'contract_update':
 | 
												
													
														
															|  | -                        responseData.data = await ctx.service.financialPayContract.updateContract(ctx.financialPay.id, data.updateData);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPayContract.updateContract(ctx.financialPay.id, ctx.financialPay.payStage, data.updateData);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  |                      case 'contract_paste':
 |  |                      case 'contract_paste':
 | 
												
													
														
															|  | -                        responseData.data = await ctx.service.financialPayContract.updateContracts(ctx.financialPay.id, data.updateData);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                        responseData.data = await ctx.service.financialPayContract.updateContracts(ctx.financialPay.id, ctx.financialPay.payStage, data.updateData);
 | 
												
													
														
															|  |                          break;
 |  |                          break;
 | 
												
													
														
															|  |                      case 'file_bill':
 |  |                      case 'file_bill':
 | 
												
													
														
															|  |                          responseData.data = await ctx.service.financialPayAtt.updateBill(data.id, data.bill);
 |  |                          responseData.data = await ctx.service.financialPayAtt.updateBill(data.id, data.bill);
 | 
												
											
												
													
														
															|  | @@ -1024,6 +1339,9 @@ module.exports = app => {
 | 
												
													
														
															|  |                  const parts = this.ctx.multipart({
 |  |                  const parts = this.ctx.multipart({
 | 
												
													
														
															|  |                      autoFields: true,
 |  |                      autoFields: true,
 | 
												
													
														
															|  |                  });
 |  |                  });
 | 
												
													
														
															|  | 
 |  | +                if (!ctx.financialPay.fpsid || !ctx.financialPay.payStage) {
 | 
												
													
														
															|  | 
 |  | +                    throw '未关联资金支付单位期无法进行任何操作';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  |                  const files = [];
 |  |                  const files = [];
 | 
												
													
														
															|  |                  const create_time = Date.parse(new Date()) / 1000;
 |  |                  const create_time = Date.parse(new Date()) / 1000;
 | 
												
													
														
															|  |                  let idx = 0;
 |  |                  let idx = 0;
 | 
												
											
												
													
														
															|  | @@ -1083,6 +1401,9 @@ module.exports = app => {
 | 
												
													
														
															|  |           */
 |  |           */
 | 
												
													
														
															|  |          async payDeleteFile(ctx) {
 |  |          async payDeleteFile(ctx) {
 | 
												
													
														
															|  |              try {
 |  |              try {
 | 
												
													
														
															|  | 
 |  | +                if (!ctx.financialPay.fpsid || !ctx.financialPay.payStage) {
 | 
												
													
														
															|  | 
 |  | +                    throw '未关联资金支付单位期无法进行任何操作';
 | 
												
													
														
															|  | 
 |  | +                }
 | 
												
													
														
															|  |                  const { fpcid, id } = JSON.parse(ctx.request.body.data);
 |  |                  const { fpcid, id } = JSON.parse(ctx.request.body.data);
 | 
												
													
														
															|  |                  const fileInfo = await ctx.service.financialPayAtt.getDataById(id);
 |  |                  const fileInfo = await ctx.service.financialPayAtt.getDataById(id);
 | 
												
													
														
															|  |                  if (fileInfo || Object.keys(fileInfo).length) {
 |  |                  if (fileInfo || Object.keys(fileInfo).length) {
 | 
												
											
												
													
														
															|  | @@ -1184,7 +1505,7 @@ module.exports = app => {
 | 
												
													
														
															|  |                  responseData.data.tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name'] }) : [];
 |  |                  responseData.data.tenders = hadTender ? await ctx.service.tender.getAllDataByCondition({ where: tenderCondition, columns: ['id', 'name'] }) : [];
 | 
												
													
														
															|  |                  responseData.data.transferList = tid === null ? await ctx.service.financialTransfer.getAllDataByCondition({ where: { spid: ctx.subProject.id } }) : [];
 |  |                  responseData.data.transferList = tid === null ? await ctx.service.financialTransfer.getAllDataByCondition({ where: { spid: ctx.subProject.id } }) : [];
 | 
												
													
														
															|  |                  responseData.data.transferTenderList = tid === null ? await ctx.service.financialTransferTender.getAllDataByCondition({ where: { spid: ctx.subProject.id } }) : [];
 |  |                  responseData.data.transferTenderList = tid === null ? await ctx.service.financialTransferTender.getAllDataByCondition({ where: { spid: ctx.subProject.id } }) : [];
 | 
												
													
														
															|  | -                responseData.data.payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, 0, filterTids);
 |  | 
 | 
												
													
														
															|  | 
 |  | +                responseData.data.payList = await ctx.service.financialPay.getListByStatus(ctx.subProject.id, null, 0, filterTids);
 | 
												
													
														
															|  |                  ctx.body = responseData;
 |  |                  ctx.body = responseData;
 | 
												
													
														
															|  |              } catch (err) {
 |  |              } catch (err) {
 | 
												
													
														
															|  |                  this.log(err);
 |  |                  this.log(err);
 |