Selaa lähdekoodia

1. 期计量,显示期当前流程
2. 部位数据,查询sql问题

MaiXinRong 6 vuotta sitten
vanhempi
commit
72ea2b8249

+ 3 - 2
app.js

@@ -12,7 +12,8 @@ const fs = require('fs');
 const moment = require('moment');
 const uuid = require('node-uuid');
 const _ = require('lodash');
-const calc = require('number-precision');
+const crypto = require('crypto');
+//const calc = require('number-precision');
 
 const BaseService = require('./app/base/base_service');
 const BaseController = require('./app/base/base_controller');
@@ -24,7 +25,7 @@ module.exports = app => {
     app.uuid = uuid;
     app.moment = moment;
     app._ = _;
-    app.calc = calc;
+    //app.calc = calc;
     app.menu = menu;
     // 数据模型基类
     app.BaseService = BaseService;

+ 54 - 2
app/const/audit.js

@@ -45,7 +45,7 @@ const stage = (function () {
     const statusString = [];
     statusString[status.uncheck] = '待上报';
     statusString[status.checking] = '审批中';
-    statusString[status.checked] = '审批完成';
+    statusString[status.checked] = '审批通过';
     statusString[status.checkNo] = '审批退回';
     statusString[status.checkNoPre] = '审批退回';
 
@@ -57,11 +57,63 @@ const stage = (function () {
     statusClass[status.checkNo] = 'text-warning';
     statusClass[status.checkNoPre] = 'text-warning';
 
+    /**
+     * 期列表,审批状态一列
+      */
+    // 按钮
+    const statusButton = [];
+    statusButton[status.uncheck] = '待上报';
+    statusButton[status.checking] = '审批';
+    statusButton[status.checked] = '';
+    statusButton[status.checkNo] = '重新上报';
+    statusButton[status.checkNoPre] = '重新审批';
+    // 按钮样式
+    const statusButtonClass = [];
+    statusButtonClass[status.uncheck] = 'btn-primary';
+    statusButtonClass[status.checking] = 'btn-success';
+    statusButtonClass[status.checked] = '';
+    statusButtonClass[status.checkNo] = 'btn-warning';
+    statusButtonClass[status.checkNoPre] = 'btn-warning';
+    // 描述文本
+    const auditString = [];
+    auditString[status.uncheck] = '';
+    auditString[status.checking] = '审批中';
+    auditString[status.checked] = '完成';
+    auditString[status.checkNo] = '退回';
+    auditString[status.checkNoPre] = '退回';
+    // 文字样式
+    const auditStringClass = [];
+    auditStringClass[status.uncheck] = '';
+    auditStringClass[status.checking] = 'text-warning';
+    auditStringClass[status.checked] = 'text-success';
+    auditStringClass[status.checkNo] = 'text-warning';
+    auditStringClass[status.checkNoPre] = 'text-warning';
+    /* ------------------------------------------------------- */
+
+    /**
+     * 期列表,审批进度一列
+    */
+    // 描述文本
+    const auditProgress = [];
+    auditProgress[status.uncheck] = '待上报';
+    auditProgress[status.checking] = '审批中';
+    auditProgress[status.checked] = '审批通过';
+    auditProgress[status.checkNo] = '审批退回';
+    auditProgress[status.checkNoPre] = '审批退回';
+    // 样式
+    const auditProgressClass = [];
+    auditProgressClass[status.uncheck] = '';
+    auditProgressClass[status.checking] = 'text-warning';
+    auditProgressClass[status.checked] = 'text-success';
+    auditProgressClass[status.checkNo] = 'text-warning';
+    auditProgressClass[status.checkNoPre] = 'text-warning';
+    /* ------------------------------------------------------- */
+
     const backType = {
         org: 1,
         pre: 2,
     };
-    return { status, statusString, statusClass, backType }
+    return { status, statusString, statusClass, statusButton, statusButtonClass, auditString, auditStringClass, auditProgress, auditProgressClass, backType }
 })();
 
 

+ 0 - 1
app/controller/ledger_controller.js

@@ -528,7 +528,6 @@ module.exports = app => {
          */
         async posUpdate(ctx) {
             try {
-                console.log(1);
                 await this.checkMeasureType(measureType.tz.value);
                 const data = JSON.parse(ctx.request.body.data);
                 const responseData = await ctx.service.pos.savePosData(data, ctx.tender.id);

+ 1 - 1
app/controller/measure_controller.js

@@ -10,7 +10,7 @@
 
 const spreadConst = require('../const/spread');
 const codeRuleConst = require('../const/code_rule');
-const auditConst = require('../const/audit').flow;
+const auditConst = require('../const/audit').stage;
 const moment = require('moment');
 const measureType = require('../const/tender').measureType;
 

+ 3 - 1
app/controller/stage_controller.js

@@ -108,9 +108,11 @@ module.exports = app => {
                 tid: ctx.tender.id,
                 order: stageOrder,
             });
+            if (ctx.stage.status === auditConst.status.uncheck && ctx.stage.user_id !== ctx.session.sessionUser.accountId) {
+                throw '数据错误';
+            }
             ctx.stage.auditors = await ctx.service.stageAudit.getAuditors(ctx.stage.id, ctx.stage.times);
             ctx.stage.curAuditor = await ctx.service.stageAudit.getCurAuditor(ctx.stage.id, ctx.stage.times);
-            console.log(ctx.stage.curAuditor);
             ctx.stage.user = await ctx.service.projectAccount.getAccountInfoById(ctx.stage.user_id);
             ctx.stage.auditHistory = [];
             if (ctx.stage.times > 1) {

+ 12 - 6
app/service/stage.js

@@ -8,7 +8,7 @@
  * @version
  */
 
-const audit = require('../const/audit');
+const auditConst = require('../const/audit').stage;
 const payConst = require('../const/deal_pay.js');
 
 module.exports = app => {
@@ -30,10 +30,17 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async getValidStages(tenderId) {
-            return await this.db.select(this.tableName, {
+            const stages = await this.db.select(this.tableName, {
                 where: {tid: tenderId},
                 orders: [['order', 'desc']],
             });
+            if (stages.length !== 0) {
+                const lastStage = stages[stages.length - 1];
+                if (lastStage.status === auditConst.status.uncheck && lastStage.user_id !== this.ctx.session.sessionUser.accountId) {
+                    stages.splice(stages.length - 1, 1);
+                }
+            }
+            return stages;
         }
 
         /**
@@ -48,7 +55,7 @@ module.exports = app => {
                 where: {tid: tenderId},
                 order: ['order'],
             });
-            if (stages.length > 0 && stages[stages.length - 1].status !== audit.flow.status.checked) {
+            if (stages.length > 0 && stages[stages.length - 1].status !== auditConst.status.checked) {
                 throw '上一期未审批通过,请等待上一期审批通过后,再新增数据';
             };
             const order = stages.length + 1;
@@ -60,14 +67,13 @@ module.exports = app => {
                 s_time: date,
                 period: period,
                 times: 1,
-                status: audit.flow.status.uncheck,
+                status: auditConst.status.uncheck,
                 user_id: this.ctx.session.sessionUser.accountId,
             };
             const transaction = await this.db.beginTransaction();
             try {
                 // 新增期记录
                 const result = await transaction.insert(this.tableName, newStage);
-                console.log(result);
                 if (result.affectedRows === 1) {
                     newStage.id = result.insertId;
                 } else {
@@ -134,7 +140,7 @@ module.exports = app => {
                         cb.value = param.zanLiePrice;
                         break;
                     case 'htjszl':
-                        cb.value = this.app.calc.minus(param.contractPrice, param.zanLiePrice);
+                        cb.value = this.ctx.helper.minus(param.contractPrice, param.zanLiePrice);
                         break;
                     case 'kgyfk':
                         cb.value = param.startAdvance;

+ 2 - 1
app/service/stage_audit.js

@@ -68,7 +68,6 @@ module.exports = app => {
                 'WHERE la.`sid` = ? and la.`status` = ? and la.`times` = ?' +
                 '    and la.`aid` = pa.`id`';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, stageId, auditConst.status.checking, times];
-            console.log(this.db.format(sql, sqlParam));
             return await this.db.queryOne(sql, sqlParam);
         }
 
@@ -287,6 +286,8 @@ module.exports = app => {
                     } else {
                         throw '审核数据错误';
                     }
+                } else {
+                    throw '无效审批操作';
                 }
 
                 await transaction.commit();

+ 11 - 9
app/service/stage_pay.js

@@ -67,16 +67,20 @@ module.exports = app => {
             if (!stage) {
                 throw '初始化期合同支付数据失败';
             }
-            const pays = await this.ctx.service.pay.getAllDataByCondition({where: { tid: this.ctx.tender.id } });
+            let pays = await this.ctx.service.pay.getAllDataByCondition({where: { tid: this.ctx.tender.id } });
+            // 兼容旧项目,无初始化合同支付数据
+            if (!pays || pays.length === 0) {
+                const result = await this.ctx.service.pay.addDefaultPayData(this.ctx.tender.id, transaction);
+                if (!result) {
+                    throw '初始化合同支付数据失败';
+                }
+                pays = await transaction.select(this.ctx.service.pay.tableName, {where: { tid: this.ctx.tender.id } });
+            }
             const stagePays = [];
             for (const p of pays) {
                 stagePays.push({
-                    tid: p.tid,
-                    sid: stage.id,
-                    pid: p.id,
-                    stimes: stage.times,
-                    sorder: 0,
-                    expr: p.expr,
+                    tid: p.tid, sid: stage.id, pid: p.id,
+                    stimes: stage.times, sorder: 0, expr: p.expr,
                 });
             }
             // 获取截止上期数据
@@ -228,8 +232,6 @@ module.exports = app => {
          * @returns {Promise<*>}
          */
         async copyAuditStagePays(stage, times, order, transaction) {
-            console.log(times);
-            console.log(order);
             if (!stage || !transaction || !times || !order) {
                 throw '数据错误';
             }

+ 1 - 1
app/service/stage_pos.js

@@ -63,7 +63,7 @@ module.exports = app => {
             if (pid instanceof Array) {
                 pidSql = pid.length > 0 ? ' And Pos.pid in (' + pid.join(', ') + ')' : '';
             } else {
-                pidSql = 'And Pos.pid = ' + pid.toString();
+                pidSql = pid ? 'And Pos.pid = ' + pid.toString() : '';
             }
             const sql = 'SELECT * FROM ' + this.tableName + ' As Pos ' +
                 '  INNER JOIN ( ' +

+ 12 - 3
app/view/measure/stage.ejs

@@ -44,12 +44,21 @@
                     <td class="text-right"></td>
                     <td class="text-right"></td>
                     <td class="text-right"></td>
-                    <td class="text-center"><a href="" class="btn <%- auditConst.statusButtonClass[s.status] %> btn-sm"><%- auditConst.auditStatusString[s.status] %></a></td>
-                    <td class="<%- auditConst.statusClass[s.status] %>">
+                    <td class="text-center">
+                    <% if (s.status === auditConst.status.uncheck && s.user_id === ctx.session.sessionUser.accountId) { %>
+                        <a href="" class="btn <%- auditConst.statusButtonClass[s.status] %> btn-sm"><%- auditConst.statusButton[s.status] %></a>
+                    <% } else if (s.status !== auditConst.status.checked && s.curAuditor && s.curAuditor === ctx.session.sessionUser.accountId) { %>
+                        <a href="" class="btn <%- auditConst.statusButtonClass[s.status] %> btn-sm"><%- auditConst.statusButton[s.status] %></a>
+                    <% } else { %>
+                        <span class="<%- auditConst.auditStringClass[s.status] %>"><%- auditConst.auditString[s.status] %></span>
+                    <% } %>
+                    </td>
+
+                    <td class="<%- auditConst.auditProgressClass[s.status] %>">
                         <% if (s.curAuditor) { %>
                         <a href="#sp-list" data-toggle="modal" data-target="#sp-list" s-order="<%- s.order %>"><%- s.curAuditor.name %>-<%s.curAuditor.role %></a>
                         <% } %>
-                        <%- auditConst.auditStatusString[s.status] %>
+                        <%- auditConst.auditProgress[s.status] %>
                     </td>
                 </tr>
                 <% } %>