ledger_cooperation.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/6/1
  7. * @version
  8. */
  9. module.exports = app => {
  10. class LedgerCooperation extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'ledger_cooperation';
  20. }
  21. async save(data) {
  22. delete data.type;
  23. data.tid = this.ctx.tender.id;
  24. const info = await this.getDataByCondition({ tid: this.ctx.tender.id, ledger_id: data.ledger_id, user_id: data.user_id });
  25. if (data.pwd === '' && info) {
  26. await this.deleteById(info.id);
  27. } else if (data.pwd !== '' && !info) {
  28. // const ledgerInfo = await this.ctx.service.ledger.getDataByCondition({ ledger_id: data.ledger_id });
  29. // if (ledgerInfo) {
  30. // data.lid = ledgerInfo.id;
  31. const result = await this.db.insert(this.tableName, data);
  32. data.id = result.insertId;
  33. data.sign_path = null;
  34. data.status = 1;
  35. // }
  36. } else if (data.pwd !== '' && info) {
  37. data.id = info.id;
  38. await this.db.update(this.tableName, data);
  39. data.sign_path = info.sign_path;
  40. }
  41. return data;
  42. }
  43. async changeAllStatus(status) {
  44. const options = {
  45. where: {
  46. tid: this.ctx.tender.id,
  47. },
  48. };
  49. const updateData = {
  50. status,
  51. };
  52. return await this.db.update(this.ctx.service.ledgerCooperation.tableName, updateData, options);
  53. }
  54. async saveSign(id, path) {
  55. const updateData = {
  56. id,
  57. sign_path: path,
  58. };
  59. return await this.db.update(this.tableName, updateData);
  60. }
  61. async saveCompany(data) {
  62. const updateData = {
  63. id: data.id,
  64. company: data.company,
  65. };
  66. return await this.db.update(this.tableName, updateData);
  67. }
  68. async getValidData(tid, uid) {
  69. const condition = { where: { tid, status: 1 } };
  70. if (uid) {
  71. condition.where.user_id = uid;
  72. condition.colums = ['ledger_id', 'pwd'];
  73. }
  74. return await this.getAllDataByCondition(condition);
  75. }
  76. }
  77. return LedgerCooperation;
  78. };