financial_audit.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. 'use strict';
  2. /**
  3. * Created by EllisRan on 2020/3/3.
  4. */
  5. const BaseService = require('../base/base_service');
  6. module.exports = app => {
  7. class FinancialAudit extends BaseService {
  8. /**
  9. * 构造函数
  10. *
  11. * @param {Object} ctx - egg全局变量
  12. * @return {void}
  13. */
  14. constructor(ctx) {
  15. super(ctx);
  16. this.tableName = 'financial_audit';
  17. this.dataId = 'id';
  18. }
  19. async getList(spid) {
  20. const list = await this.db.select(this.tableName, { where: { spid }, orders: [['id', 'desc']] });
  21. for (const l of list) {
  22. const accountInfo = await this.ctx.service.projectAccount.getDataById(l.uid);
  23. l.name = accountInfo.name;
  24. l.role = accountInfo.role;
  25. l.company = accountInfo.company;
  26. l.mobile = accountInfo.mobile;
  27. }
  28. return list;
  29. }
  30. async saveAudits(spid, accountList, transaction = null) {
  31. // 判断是否已存在该用户,存在则不插入
  32. const pauditList = await this.getAllDataByCondition({ where: { spid } });
  33. const pushData = [];
  34. for (const a of this._.uniqBy(accountList, 'id')) {
  35. if (this._.findIndex(pauditList, { uid: a.id }) === -1) {
  36. const data = {
  37. spid,
  38. uid: a.id,
  39. create_time: new Date(),
  40. };
  41. pushData.push(data);
  42. }
  43. }
  44. if (pushData.length > 0) {
  45. return transaction ? await transaction.insert(this.tableName, pushData) : await this.db.insert(this.tableName, pushData);
  46. }
  47. return false;
  48. }
  49. async delAudit(id) {
  50. return await this.db.delete(this.tableName, { id });
  51. }
  52. async updatePermission(updateData) {
  53. if (!updateData.id) {
  54. return false;
  55. }
  56. return await this.db.update(this.tableName, updateData);
  57. }
  58. async checkPermission(spid, uid) {
  59. if (this.ctx.session.sessionUser.is_admin) {
  60. return true;
  61. }
  62. let flag = false;
  63. const info = await this.getDataByCondition({ spid, uid });
  64. if (info) {
  65. flag = true;
  66. }
  67. return flag;
  68. }
  69. async getPermission(spid, uid) {
  70. const permission = {
  71. transfer_show: false,
  72. transfer_add: false,
  73. transfer_file: false,
  74. pay_show: false,
  75. pay_file: false,
  76. };
  77. if (this.ctx.session.sessionUser.is_admin) {
  78. permission.transfer_show = true;
  79. permission.transfer_add = true;
  80. permission.transfer_file = true;
  81. permission.pay_show = true;
  82. permission.pay_file = true;
  83. } else {
  84. const auditInfo = await this.getDataByCondition({ spid, uid });
  85. if (auditInfo) {
  86. permission.transfer_show = auditInfo.permission_transfer_show === 1;
  87. permission.transfer_add = auditInfo.permission_transfer_add === 1;
  88. permission.transfer_file = auditInfo.permission_transfer_file === 1;
  89. permission.pay_show = auditInfo.permission_pay_show === 1;
  90. permission.pay_file = auditInfo.permission_pay_file === 1;
  91. }
  92. }
  93. return permission;
  94. }
  95. }
  96. return FinancialAudit;
  97. };