pay_att.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. f.filepath = this.ctx.app.config.fujianOssPath + f.filepath;
  28. if (this.ctx.helper.canPreview(f.fileext)) f.viewpath = f.filepath;
  29. }
  30. return files;
  31. }
  32. async addFiles(files) {
  33. await this.db.insert(this.tableName, files);
  34. return await this.getStageData({ sid: files[0].sid, pid: files[0].pid });
  35. }
  36. async delFiles(fileId) {
  37. const fileInfo = await this.getDataById(fileId);
  38. if (!fileInfo) throw '不存在该文件';
  39. if (fileInfo.uid !== this.ctx.session.sessionUser.accountId) throw '您无权删除该文件';
  40. await this.db.delete(this.tableName, { id: fileId });
  41. return await this.getStageData({ sid: fileInfo.sid, pid: fileInfo.pid });
  42. }
  43. }
  44. return PayAtt;
  45. };