123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 'use strict';
- /**
- * Created by EllisRan on 2020/3/3.
- */
- const BaseService = require('../base/base_service');
- module.exports = app => {
- class FinancialTransfer extends BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'financial_transfer';
- }
- async getList(spid) {
- const sql = 'SELECT ft.*, pa.`name` as username, pa.`company` FROM ?? as ft LEFT JOIN ?? as pa ON ft.`uid` = pa.`id` WHERE ft.`spid` = ? ORDER BY ft.`id` DESC';
- const sqlParams = [this.tableName, this.ctx.service.projectAccount.tableName, spid];
- const list = await this.db.query(sql, sqlParams);
- for (const l of list) {
- l.files = await this.ctx.service.financialTransferAtt.getAtt(l.id);
- }
- return list;
- }
- async addTransfer(spid, date, remark) {
- const node = await this.getDataByCondition({ spid, t_time: date });
- if (node) {
- throw '资金划拨年月已存在,请勿重复';
- }
- const insertData = {
- spid,
- t_time: date,
- create_time: new Date(),
- remark,
- uid: this.ctx.session.sessionUser.accountId,
- };
- const result = await this.db.insert(this.tableName, insertData);
- if (result.affectedRows === 1) {
- return result.insertId;
- }
- return false;
- }
- async delTransfer(trid) {
- if (!trid) {
- throw '参数有误';
- }
- const node = await this.getDataById(trid);
- if (!node) {
- throw '资金划拨不存在';
- }
- const transaction = await this.db.beginTransaction();
- try {
- await transaction.delete(this.tableName, { id: node.id });
- // 删除合同附件
- const attList = await this.ctx.service.financialTransferAtt.getAllDataByCondition({ where: { trid } });
- const tenderAttList = await this.ctx.service.financialTransferTenderAtt.getAllDataByCondition({ where: { trid } });
- await this.ctx.helper.delFiles(this._.concat(attList, tenderAttList));
- await transaction.delete(this.ctx.service.financialTransferTender.tableName, { trid });
- await transaction.commit();
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- return true;
- }
- async lockTransfer(trid, lock) {
- if (!trid) {
- throw '参数有误';
- }
- const node = await this.getDataById(trid);
- if (!node) {
- throw '该资金划拨不存在';
- }
- if (node.uid !== this.ctx.session.sessionUser.accountId) {
- throw '您没有权限操作';
- }
- const result = await this.db.update(this.tableName, { id: node.id, is_lock: lock });
- return result.affectedRows === 1;
- }
- async saveTransfer(data) {
- if (!data.id) {
- throw '参数有误';
- }
- const node = await this.getDataById(data.id);
- if (!node) {
- throw '该资金划拨不存在';
- }
- if (node.uid !== this.ctx.session.sessionUser.accountId) {
- throw '您没有权限操作';
- }
- const result = await this.db.update(this.tableName, data);
- return result.affectedRows === 1;
- }
- }
- return FinancialTransfer;
- };
|