ledger_cooperation.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.company = '';
  35. data.status = 1;
  36. // }
  37. } else if (data.pwd !== '' && info) {
  38. data.id = info.id;
  39. await this.db.update(this.tableName, data);
  40. data.sign_path = info.sign_path;
  41. data.company = info.company;
  42. }
  43. return data;
  44. }
  45. async changeAllStatus(status) {
  46. const options = {
  47. where: {
  48. tid: this.ctx.tender.id,
  49. },
  50. };
  51. const updateData = {
  52. status,
  53. };
  54. return await this.db.update(this.ctx.service.ledgerCooperation.tableName, updateData, options);
  55. }
  56. async saveSign(id, path) {
  57. const updateData = {
  58. id,
  59. sign_path: path,
  60. };
  61. return await this.db.update(this.tableName, updateData);
  62. }
  63. async saveCompany(data) {
  64. const updateData = {
  65. id: data.id,
  66. company: data.company,
  67. };
  68. return await this.db.update(this.tableName, updateData);
  69. }
  70. async getValidData(tid, uid) {
  71. const condition = { where: { tid, status: 1 } };
  72. if (uid) {
  73. condition.where.user_id = uid;
  74. condition.colums = ['ledger_id', 'pwd'];
  75. }
  76. return await this.getAllDataByCondition(condition);
  77. }
  78. }
  79. return LedgerCooperation;
  80. };