pay_att.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class PayAtt extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'pay_attachment';
  20. }
  21. async getStageData(condition) {
  22. const files = await this.getAllDataByCondition({
  23. where: condition,
  24. orders: [['id', 'desc']]
  25. });
  26. for (const f of files) {
  27. delete f.filepath;
  28. }
  29. return files;
  30. }
  31. async addFiles(files) {
  32. await this.db.insert(this.tableName, files);
  33. return await this.getStageData({ sid: files[0].sid, pid: files[0].pid });
  34. }
  35. async delFiles(fileId) {
  36. const fileInfo = await this.getDataById(fileId);
  37. if (!fileInfo) throw '不存在该文件';
  38. if (fileInfo.uid !== this.ctx.session.sessionUser.accountId) throw '您无权删除该文件';
  39. await this.db.delete(this.tableName, { id: fileId });
  40. return await this.getStageData({ sid: fileInfo.sid, pid: fileInfo.pid });
  41. }
  42. }
  43. return PayAtt;
  44. };