ledger_cooperation.js 1.8 KB

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