|
|
@@ -1,7 +1,7 @@
|
|
|
'use strict';
|
|
|
const auditConst = require('../const/audit');
|
|
|
const measureType = require('../const/tender').measureType;
|
|
|
-
|
|
|
+const advanceConst = require('../const/advance');
|
|
|
|
|
|
module.exports = app => {
|
|
|
class WeappTenderController extends app.BaseController {
|
|
|
@@ -34,17 +34,13 @@ module.exports = app => {
|
|
|
|
|
|
async detail(ctx) {
|
|
|
try {
|
|
|
- const { id: tenderId } = ctx.query;
|
|
|
- const tender = await this.service.tender.getTender(tenderId);
|
|
|
- const tenderInfo = await this.service.tenderInfo.getTenderInfo(tenderId);
|
|
|
- if (!tender || !tenderInfo) {
|
|
|
- throw '标段信息不存在';
|
|
|
- }
|
|
|
- let bCalcTp = tender.user_id === ctx.session.sessionUser.accountId && (
|
|
|
- tender.ledger_status === auditConst.ledger.status.checkNo || tender.ledger_status === auditConst.ledger.status.uncheck);
|
|
|
- const stages = await ctx.service.stage.getValidStages(tenderId);
|
|
|
+ const tender = ctx.tender.data;
|
|
|
+
|
|
|
+ let bCalcTp = ctx.tender.data.user_id === ctx.session.sessionUser.accountId && (
|
|
|
+ ctx.tender.ledger_status === auditConst.ledger.status.checkNo || ctx.tender.ledger_status === auditConst.ledger.status.uncheck);
|
|
|
+ const stages = await ctx.service.stage.getValidStages(ctx.tender.id);
|
|
|
const lastStage = stages.length > 0 ? stages[0] : null; // await ctx.service.stage.getLastestStage(ctx.tender.id);
|
|
|
- const [change_tp, change_p_tp, change_n_tp, change_valuation_tp, change_unvaluation_tp] = await ctx.service.change.getChangeTp(tenderId);
|
|
|
+ const [change_tp, change_p_tp, change_n_tp, change_valuation_tp, change_unvaluation_tp] = await ctx.service.change.getChangeTp(ctx.tender.id);
|
|
|
tender.change_tp = change_tp;
|
|
|
tender.change_p_tp = change_p_tp;
|
|
|
tender.change_n_tp = change_n_tp;
|
|
|
@@ -56,11 +52,11 @@ module.exports = app => {
|
|
|
bCalcTp = lastStage.status !== auditConst.stage.status.checked && !lastStage.readOnly;
|
|
|
}
|
|
|
if (bCalcTp) {
|
|
|
- const sum = await this.ctx.service.ledger.addUp({ tender_id: tenderId/* , is_leaf: true*/ });
|
|
|
+ const sum = await this.ctx.service.ledger.addUp({ tender_id: ctx.tender.id/* , is_leaf: true*/ });
|
|
|
tender.total_price = sum.total_price;
|
|
|
tender.deal_tp = sum.deal_tp;
|
|
|
}
|
|
|
- tender.sum = tenderInfo.calc_type === 'tp' ? ctx.helper.add(tender.total_price, tender.change_valuation_tp) : ctx.helper.add(tender.total_price, tender.change_tp);
|
|
|
+ tender.sum = ctx.tender.info.calc_type === 'tp' ? ctx.helper.add(tender.total_price, tender.change_valuation_tp) : ctx.helper.add(tender.total_price, tender.change_tp);
|
|
|
tender.gather_tp = ctx.helper.sum([lastStage.contract_tp, lastStage.qc_tp, lastStage.pc_tp]);
|
|
|
tender.end_contract_tp = ctx.helper.sum([lastStage.contract_tp, lastStage.pre_contract_tp, lastStage.contract_pc_tp]);
|
|
|
tender.end_qc_tp = ctx.helper.sum([lastStage.qc_tp, lastStage.pre_qc_tp, lastStage.qc_pc_tp]);
|
|
|
@@ -70,7 +66,7 @@ module.exports = app => {
|
|
|
tender.pre_gather_tp = ctx.helper.add(lastStage.pre_contract_tp, lastStage.pre_qc_tp);
|
|
|
tender.yf_tp = lastStage.yf_tp;
|
|
|
tender.sf_tp = lastStage.sf_tp;
|
|
|
- tender.qc_ratio = ctx.helper.mul(ctx.helper.div(tender.end_qc_tp, tenderInfo.deal_param.contractPrice, 2), 100);
|
|
|
+ tender.qc_ratio = ctx.helper.mul(ctx.helper.div(tender.end_qc_tp, ctx.tender.info.deal_param.contractPrice, 2), 100);
|
|
|
tender.pre_ratio = ctx.helper.mul(ctx.helper.div(tender.pre_gather_tp, tender.sum, 2), 100);
|
|
|
tender.cur_ratio = ctx.helper.mul(ctx.helper.div(tender.gather_tp, tender.sum, 2), 100);
|
|
|
tender.other_tp = ctx.helper.sub(ctx.helper.sub(tender.sum, tender.pre_gather_tp), tender.gather_tp);
|
|
|
@@ -80,36 +76,36 @@ module.exports = app => {
|
|
|
tender.undone_tp = ctx.helper.sub(ctx.helper.sub(ctx.helper.add(tender.total_price, change_tp), tender.end_contract_tp), tender.end_qc_tp);
|
|
|
} else {
|
|
|
if (bCalcTp) {
|
|
|
- const sum = await this.ctx.service.ledger.addUp({ tender_id: tenderId/* , is_leaf: true*/ });
|
|
|
+ const sum = await this.ctx.service.ledger.addUp({ tender_id: ctx.tender.id/* , is_leaf: true*/ });
|
|
|
tender.total_price = sum.total_price;
|
|
|
tender.deal_tp = sum.deal_tp;
|
|
|
}
|
|
|
tender.sum = ctx.helper.add(tender.total_price, tender.change_tp);
|
|
|
}
|
|
|
|
|
|
- const monthProgress = [];
|
|
|
- for (const s of stages) {
|
|
|
- if (s.s_time) {
|
|
|
- let progress = monthProgress.find(function (x) {
|
|
|
- return x.month === s.s_time;
|
|
|
- });
|
|
|
- if (!progress) {
|
|
|
- progress = { month: s.s_time };
|
|
|
- monthProgress.push(progress);
|
|
|
- }
|
|
|
- progress.tp = ctx.helper.add(ctx.helper.add(progress.tp, s.contract_tp), s.qc_tp);
|
|
|
- }
|
|
|
- }
|
|
|
- monthProgress.sort(function (x, y) {
|
|
|
- return Date.parse(x.month) - Date.parse(y.month);
|
|
|
- });
|
|
|
- let sum = 0;
|
|
|
- for (const p of monthProgress) {
|
|
|
- p.ratio = ctx.helper.mul(ctx.helper.div(p.tp, tender.sum, 4), 100);
|
|
|
- sum = ctx.helper.add(sum, p.tp);
|
|
|
- p.end_tp = sum;
|
|
|
- p.end_ratio = ctx.helper.mul(ctx.helper.div(p.end_tp, tender.sum, 4), 100);
|
|
|
- }
|
|
|
+ // const monthProgress = [];
|
|
|
+ // for (const s of stages) {
|
|
|
+ // if (s.s_time) {
|
|
|
+ // let progress = monthProgress.find(function(x) {
|
|
|
+ // return x.month === s.s_time;
|
|
|
+ // });
|
|
|
+ // if (!progress) {
|
|
|
+ // progress = { month: s.s_time };
|
|
|
+ // monthProgress.push(progress);
|
|
|
+ // }
|
|
|
+ // progress.tp = ctx.helper.add(ctx.helper.add(progress.tp, s.contract_tp), s.qc_tp);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // monthProgress.sort(function(x, y) {
|
|
|
+ // return Date.parse(x.month) - Date.parse(y.month);
|
|
|
+ // });
|
|
|
+ // let sum = 0;
|
|
|
+ // for (const p of monthProgress) {
|
|
|
+ // p.ratio = ctx.helper.mul(ctx.helper.div(p.tp, tender.sum, 4), 100);
|
|
|
+ // sum = ctx.helper.add(sum, p.tp);
|
|
|
+ // p.end_tp = sum;
|
|
|
+ // p.end_ratio = ctx.helper.mul(ctx.helper.div(p.end_tp, tender.sum, 4), 100);
|
|
|
+ // }
|
|
|
|
|
|
ctx.body = {
|
|
|
code: 0, msg: '', data: {
|
|
|
@@ -124,6 +120,44 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ async advanceList(ctx) {
|
|
|
+ try {
|
|
|
+ const { advanceType } = ctx.query;
|
|
|
+ const typeCol = advanceConst.typeCol.find(x => x.type === Number(advanceType));
|
|
|
+ if (!typeCol) {
|
|
|
+ ctx.body = { code: -1, msg: '预付款类型错误', data: null };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const { decimal } = ctx.tender.info;
|
|
|
+ const advancePayTotal = ctx.tender.info.deal_param[typeCol.key + 'Advance'];
|
|
|
+ const advances = await ctx.service.advance.getAdvanceList(ctx.tender.id, typeCol.type, decimal.pay ? decimal.payTp : decimal.tp, advancePayTotal);
|
|
|
+ ctx.body = { code: 0, msg: '', data: advances };
|
|
|
+ } catch (error) {
|
|
|
+ this.log(error);
|
|
|
+ ctx.body = { code: -1, msg: error.toString(), data: null };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async advanceDetail(ctx) {
|
|
|
+ try {
|
|
|
+ // const { advanceType } = ctx.query;
|
|
|
+ // const typeCol = advanceConst.typeCol.find(x => x.type === Number(advanceType));
|
|
|
+ // if (!typeCol) {
|
|
|
+ // ctx.body = { code: -1, msg: '预付款类型错误', data: null };
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // const tenderInfo = await this.service.tenderInfo.getTenderInfo(ctx.tender.id);
|
|
|
+ // const { decimal } = tenderInfo;
|
|
|
+ // this.decimal = decimal.pay ? decimal.payTp : decimal.tp;
|
|
|
+ // const advancePayTotal = ctx.tender.info.deal_param[typeCol.key + 'Advance'];
|
|
|
+ // const advances = await ctx.service.advance.getAdvanceList(ctx.tender.id, typeCol.type, this.decimal, advancePayTotal);
|
|
|
+ ctx.body = { code: 0, msg: '', data: {} };
|
|
|
+ } catch (error) {
|
|
|
+ this.log(error);
|
|
|
+ ctx.body = { code: -1, msg: error.toString(), data: null };
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return WeappTenderController;
|