financial_pay_att.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 FinancialPayAtt extends BaseService {
  8. /**
  9. * 构造函数
  10. *
  11. * @param {Object} ctx - egg全局变量
  12. * @return {void}
  13. */
  14. constructor(ctx) {
  15. super(ctx);
  16. this.tableName = 'financial_pay_attachment';
  17. this.dataId = 'id';
  18. }
  19. async getAtt(fpid, fpcid = null) {
  20. const fpcidSql = fpcid ? ' AND fpcid = ' + fpcid : ' AND fpcid IS NULL';
  21. 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';
  22. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, fpid];
  23. const result = await this.db.query(sql, sqlParam);
  24. return result.map(item => {
  25. item.orginpath = this.ctx.app.config.fujianOssPath + item.filepath;
  26. if (!this.ctx.helper.canPreview(item.fileext)) {
  27. item.filepath = `/financial/${item.spid}/pay/${item.fpid}/file/${item.id}/download`;
  28. } else {
  29. item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
  30. item.viewpath = item.filepath;
  31. }
  32. return item;
  33. });
  34. }
  35. async updateBill(id, bill) {
  36. return await this.db.update(this.tableName, { id, bill });
  37. }
  38. /**
  39. * 存储上传的文件信息至数据库
  40. * @param {Array} payload 载荷
  41. * @return {Promise<void>} 数据库插入执行实例
  42. */
  43. async saveFileMsgToDb(payload) {
  44. return await this.db.insert(this.tableName, payload);
  45. }
  46. /**
  47. * 删除附件
  48. * @param {Number} id - 附件id
  49. * @return {void}
  50. */
  51. async delete(id) {
  52. return await this.deleteById(id);
  53. }
  54. }
  55. return FinancialPayAtt;
  56. };