1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 'use strict';
- /**
- * Created by EllisRan on 2020/3/3.
- */
- const BaseService = require('../base/base_service');
- module.exports = app => {
- class ConstructionAudit extends BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'construction_audit';
- this.dataId = 'id';
- }
- async getList(tid) {
- const list = await this.db.select(this.tableName, { where: { tid }, orders: [['id', 'desc']] });
- for (const l of list) {
- const accountInfo = await this.ctx.service.projectAccount.getDataById(l.uid);
- l.name = accountInfo.name;
- l.role = accountInfo.role;
- l.company = accountInfo.company;
- }
- return list;
- }
- async saveAudits(tid, accountList, transaction = null) {
- // 判断是否已存在该用户,存在则不插入
- const pauditList = await this.getAllDataByCondition({ where: { tid } });
- const pushData = [];
- for (const a of this._.uniqBy(accountList, 'id')) {
- if (this._.findIndex(pauditList, { uid: a.id }) === -1) {
- const data = {
- tid,
- uid: a.id,
- in_time: new Date(),
- };
- pushData.push(data);
- }
- }
- if (pushData.length > 0) {
- return transaction ? await transaction.insert(this.tableName, pushData) : await this.db.insert(this.tableName, pushData);
- }
- return false;
- }
- async delAudit(id) {
- return await this.db.delete(this.tableName, { id });
- }
- async updateReport(updateData) {
- if (!updateData.id || updateData.is_report === undefined) {
- return false;
- }
- return await this.db.update(this.tableName, updateData);
- }
- async checkPermission(tender, uid) {
- let flag = false;
- const accountInfo = await this.ctx.service.projectAccount.getDataById(uid);
- const permission = accountInfo !== undefined && accountInfo.permission !== ''
- ? JSON.parse(accountInfo.permission) : null;
- if (accountInfo.project_id === tender.project_id && (accountInfo.is_admin || (permission !== null && permission.construction !== undefined && permission.construction.indexOf('1') !== -1))) {
- flag = true;
- } else {
- const info = await this.getDataByCondition({ tid: tender.id, uid });
- if (info) {
- flag = true;
- }
- }
- return flag;
- }
- async getUserList(tid, is_report = null) {
- const reportSql = is_report !== null ? ' AND ca.`is_report` = ' + is_report : '';
- const sql = 'SELECT ca.*, pa.name as user_name FROM ?? AS ca LEFT JOIN ?? AS pa ON ca.`uid` = pa.`id` ' +
- 'WHERE ca.`tid` = ?' + reportSql + ' ORDER BY ca.`id` DESC';
- const params = [this.tableName, this.ctx.service.projectAccount.tableName, tid];
- return await this.db.query(sql, params);
- }
- }
- return ConstructionAudit;
- };
|