cooperation_confirm.js 2.1 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 CooperationConfirm extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'cooperation_confirm';
  20. }
  21. async save(data) {
  22. const info = await this.getDataByCondition({ tid: this.ctx.tender.id, sid: this.ctx.stage.id, times: this.ctx.stage.times, ledger_id: data.ledger_id, uid: this.ctx.session.sessionUser.accountId });
  23. if (info) {
  24. const updateData = {
  25. id: info.id,
  26. create_time: new Date(),
  27. };
  28. return await this.db.update(this.tableName, updateData);
  29. }
  30. const insertData = {
  31. tid: this.ctx.tender.id,
  32. sid: this.ctx.stage.id,
  33. times: this.ctx.stage.times,
  34. uid: this.ctx.session.sessionUser.accountId,
  35. ledger_id: data.ledger_id,
  36. create_time: new Date(),
  37. };
  38. return await this.db.insert(this.tableName, insertData);
  39. }
  40. async del(data) {
  41. return await this.db.delete(this.tableName, { tid: this.ctx.tender.id, sid: this.ctx.stage.id, times: this.ctx.stage.times, ledger_id: data.ledger_id, uid: this.ctx.session.sessionUser.accountId });
  42. }
  43. async getValidData(tid, sid, times, uid) {
  44. const condition = { where: { tid, sid, times, uid } };
  45. // if (uid) {
  46. // condition.where.uid = uid;
  47. // condition.colums = ['ledger_id', 'pwd'];
  48. // }
  49. return await this.getAllDataByCondition(condition);
  50. }
  51. async delBycheckNoPre(uid, stage, transaction) {
  52. return await transaction.delete(this.tableName, { tid: stage.tid, sid: stage.id, times: stage.times, uid });
  53. }
  54. }
  55. return CooperationConfirm;
  56. };