1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 'use strict';
- /**
- * Created by EllisRan on 2020/3/3.
- */
- const BaseService = require('../base/base_service');
- module.exports = app => {
- class FinancialPayAtt extends BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'financial_pay_attachment';
- this.dataId = 'id';
- }
- async getAtt(fpid, fpcid = null) {
- const fpcidSql = fpcid ? ' AND fpcid = ' + fpcid : ' AND fpcid IS NULL';
- const sql = 'SELECT a.*, b.name as username FROM ?? as a LEFT JOIN ?? as b ON a.`uid` = b.`id` WHERE a.`fpid` = ?' + fpcidSql + ' ORDER BY `upload_time` DESC';
- const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, fpid];
- const result = await this.db.query(sql, sqlParam);
- return result.map(item => {
- item.orginpath = this.ctx.app.config.fujianOssPath + item.filepath;
- if (!this.ctx.helper.canPreview(item.fileext)) {
- item.filepath = `/financial/${item.spid}/pay/${item.fpid}/file/${item.id}/download`;
- } else {
- item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
- item.viewpath = item.filepath;
- }
- return item;
- });
- }
- async updateBill(id, bill) {
- return await this.db.update(this.tableName, { id, bill });
- }
- /**
- * 存储上传的文件信息至数据库
- * @param {Array} payload 载荷
- * @return {Promise<void>} 数据库插入执行实例
- */
- async saveFileMsgToDb(payload) {
- return await this.db.insert(this.tableName, payload);
- }
- /**
- * 删除附件
- * @param {Number} id - 附件id
- * @return {void}
- */
- async delete(id) {
- return await this.deleteById(id);
- }
- }
- return FinancialPayAtt;
- };
|