Ver código fonte

查看标段权限

laiguoran 6 anos atrás
pai
commit
4293e6f524

+ 1 - 1
app/base/base_controller.js

@@ -59,7 +59,7 @@ class BaseController extends Controller {
         const postError = this.ctx.session.postError;
         // 取出后删除
         this.ctx.session.postError = null;
-        if (message === null && postError !== null) {
+        if (message === null && postError !== null && postError !== undefined) {
             message = {
                 type: 'error',
                 icon: 'exclamation-circle',

+ 5 - 4
app/controller/tender_controller.js

@@ -33,15 +33,16 @@ module.exports = app => {
 
         async _list(view, setting, modal = '', listStatus = '') {
             try {
-                const tenderList = await this.ctx.service.tender.getList(listStatus);
+                // 获取用户新建标段权利
+                const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
+                const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
+
+                const tenderList = await this.ctx.service.tender.getList(listStatus, userPermission);
                 for (const t of tenderList) {
                     t.lastStage = await this.ctx.service.stage.getLastestStage(t.id, true);
                     t.completeStage = await this.ctx.service.stage.getLastestCompleteStage(t.id);
                 }
                 const categoryData = await this.ctx.service.category.getAllCategory(this.ctx.session.sessionProject.id);
-                // 获取用户新建标段权利
-                const accountInfo = await this.ctx.service.projectAccount.getDataById(this.ctx.session.sessionUser.accountId);
-                const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
                 const renderData = {
                     tenderList,
                     tenderConst,

+ 12 - 1
app/service/tender.js

@@ -77,7 +77,7 @@ module.exports = app => {
          *
          * @return {Array} - 返回标段数据
          */
-        async getList(listStatus) {
+        async getList(listStatus, permission) {
             // 获取当前项目信息
             const session = this.ctx.session;
             let sql = '';
@@ -91,7 +91,18 @@ module.exports = app => {
                     '  ON t.`user_id` = pa.`id` ' +
                     '  WHERE t.`project_id` = ? AND t.`user_id` = ?';
                 sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id, session.sessionUser.accountId];
+            } else if (permission !== null && permission.tender !== undefined && permission.tender.indexOf('2') !== -1) {
+                // 具有查看所有标段权限的用户查阅标段
+                sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, ' +
+                    '    pa.`name` As `user_name`, pa.`role` As `user_role`, pa.`company` As `user_company` ' +
+                    '  FROM ?? As t ' +
+                    '  Left Join ?? As pa ' +
+                    '  ON t.`user_id` = pa.`id` ' +
+                    '  WHERE t.`project_id` = ?';
+                sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, session.sessionProject.id];
             } else {
+                // 根据用户权限查阅标段
+
                 // tender 163条数据,project_account 68条数据测试
                 // 查询两张表耗时0.003s,查询tender左连接project_account耗时0.002s
                 sql = 'SELECT t.`id`, t.`project_id`, t.`name`, t.`status`, t.`category`, t.`ledger_times`, t.`ledger_status`, t.`measure_type`, t.`user_id`, t.`create_time`, ' +