ledger_cooperation.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 result = await this.db.insert(this.tableName, data);
  29. data.id = result.insertId;
  30. data.sign_path = null;
  31. } else if (data.pwd !== '' && info) {
  32. data.id = info.id;
  33. await this.db.update(this.tableName, data);
  34. data.sign_path = info.sign_path;
  35. }
  36. return data;
  37. }
  38. async changeAllStatus(status) {
  39. const options = {
  40. where: {
  41. tid: this.ctx.tender.id,
  42. },
  43. };
  44. const updateData = {
  45. status,
  46. };
  47. return await this.db.update(this.ctx.service.ledgerCooperation.tableName, updateData, options);
  48. }
  49. async saveSign(id, path) {
  50. const updateData = {
  51. id,
  52. sign_path: path,
  53. };
  54. return await this.db.update(this.tableName, updateData);
  55. }
  56. async getValidData(tid, uid) {
  57. const condition = { where: { tid, status: 1 } };
  58. if (uid) {
  59. condition.where.user_id = uid;
  60. condition.colums = ['ledger_id', 'pwd'];
  61. }
  62. return await this.getAllDataByCondition(condition);
  63. }
  64. }
  65. return LedgerCooperation;
  66. };