| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 'use strict';
- /**
- * Created by EllisRan on 2020/3/3.
- */
- const BaseService = require('../base/base_service');
- module.exports = app => {
- class FinancialAudit extends BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'financial_audit';
- this.dataId = 'id';
- }
- async getList(spid) {
- const list = await this.db.select(this.tableName, { where: { spid }, 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;
- l.mobile = accountInfo.mobile;
- }
- return list;
- }
- async saveAudits(spid, accountList, transaction = null) {
- // 判断是否已存在该用户,存在则不插入
- const pauditList = await this.getAllDataByCondition({ where: { spid } });
- const pushData = [];
- for (const a of this._.uniqBy(accountList, 'id')) {
- if (this._.findIndex(pauditList, { uid: a.id }) === -1) {
- const data = {
- spid,
- uid: a.id,
- create_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 updatePermission(updateData) {
- if (!updateData.id) {
- return false;
- }
- return await this.db.update(this.tableName, updateData);
- }
- async checkPermission(spid, uid) {
- if (this.ctx.session.sessionUser.is_admin) {
- return true;
- }
- let flag = false;
- const info = await this.getDataByCondition({ spid, uid });
- if (info) {
- flag = true;
- }
- return flag;
- }
- async getPermission(spid, uid) {
- const permission = {
- transfer_show: false,
- transfer_add: false,
- transfer_file: false,
- pay_show: false,
- pay_file: false,
- };
- if (this.ctx.session.sessionUser.is_admin) {
- permission.transfer_show = true;
- permission.transfer_add = true;
- permission.transfer_file = true;
- permission.pay_show = true;
- permission.pay_file = true;
- } else {
- const auditInfo = await this.getDataByCondition({ spid, uid });
- if (auditInfo) {
- permission.transfer_show = auditInfo.permission_transfer_show === 1;
- permission.transfer_add = auditInfo.permission_transfer_add === 1;
- permission.transfer_file = auditInfo.permission_transfer_file === 1;
- permission.pay_show = auditInfo.permission_pay_show === 1;
- permission.pay_file = auditInfo.permission_pay_file === 1;
- }
- }
- return permission;
- }
- }
- return FinancialAudit;
- };
|