| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- module.exports = app => {
- class PayAtt extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'pay_attachment';
- }
- async getStageData(condition) {
- const files = await this.getAllDataByCondition({
- where: condition,
- orders: [['id', 'desc']]
- });
- for (const f of files) {
- f.filepath = this.ctx.app.config.fujianOssPath + f.filepath;
- if (this.ctx.helper.canPreview(f.fileext)) f.viewpath = f.filepath;
- }
- return files;
- }
- async addFiles(files) {
- await this.db.insert(this.tableName, files);
- return await this.getStageData({ sid: files[0].sid, pid: files[0].pid });
- }
- async delFiles(fileId) {
- const fileInfo = await this.getDataById(fileId);
- if (!fileInfo) throw '不存在该文件';
- if (fileInfo.uid !== this.ctx.session.sessionUser.accountId) throw '您无权删除该文件';
- await this.db.delete(this.tableName, { id: fileId });
- return await this.getStageData({ sid: fileInfo.sid, pid: fileInfo.pid });
- }
- }
- return PayAtt;
- };
|