cooperation_pwd.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/6/1
  7. * @version
  8. */
  9. module.exports = app => {
  10. class CooperationPwd 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_pwd';
  20. }
  21. async save(data) {
  22. const info = await this.getDataByCondition({ tid: this.ctx.tender.id, ledger_id: data.ledger_id, uid: this.ctx.session.sessionUser.accountId });
  23. if (info) {
  24. const updateData = {
  25. id: info.id,
  26. pwd: data.pwd,
  27. create_time: new Date(),
  28. };
  29. return await this.db.update(this.tableName, updateData);
  30. }
  31. const insertData = {
  32. tid: this.ctx.tender.id,
  33. uid: this.ctx.session.sessionUser.accountId,
  34. ledger_id: data.ledger_id,
  35. pwd: data.pwd,
  36. create_time: new Date(),
  37. };
  38. return await this.db.insert(this.tableName, insertData);
  39. }
  40. async getValidData(tid, uid) {
  41. const condition = { where: { tid } };
  42. if (uid) {
  43. condition.where.uid = uid;
  44. condition.colums = ['ledger_id', 'pwd'];
  45. }
  46. return await this.getAllDataByCondition(condition);
  47. }
  48. }
  49. return CooperationPwd;
  50. };