| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 | 
							- 'use strict';
 
- /**
 
-  *
 
-  *
 
-  * @author Mai
 
-  * @date 2018/6/1
 
-  * @version
 
-  */
 
- module.exports = app => {
 
-     class LedgerCooperation extends app.BaseService {
 
-         /**
 
-          * 构造函数
 
-          *
 
-          * @param {Object} ctx - egg全局变量
 
-          * @return {void}
 
-          */
 
-         constructor(ctx) {
 
-             super(ctx);
 
-             this.tableName = 'ledger_cooperation';
 
-         }
 
-         async save(data) {
 
-             delete data.type;
 
-             data.tid = this.ctx.tender.id;
 
-             const info = await this.getDataByCondition({ tid: this.ctx.tender.id, ledger_id: data.ledger_id, user_id: data.user_id });
 
-             if (data.pwd === '' && info) {
 
-                 await this.deleteById(info.id);
 
-             } else if (data.pwd !== '' && !info) {
 
-                 // const ledgerInfo = await this.ctx.service.ledger.getDataByCondition({ ledger_id: data.ledger_id });
 
-                 // if (ledgerInfo) {
 
-                 //     data.lid = ledgerInfo.id;
 
-                 const result = await this.db.insert(this.tableName, data);
 
-                 data.id = result.insertId;
 
-                 data.sign_path = null;
 
-                 data.status = 1;
 
-                 // }
 
-             } else if (data.pwd !== '' && info) {
 
-                 data.id = info.id;
 
-                 await this.db.update(this.tableName, data);
 
-                 data.sign_path = info.sign_path;
 
-             }
 
-             return data;
 
-         }
 
-         async changeAllStatus(status) {
 
-             const options = {
 
-                 where: {
 
-                     tid: this.ctx.tender.id,
 
-                 },
 
-             };
 
-             const updateData = {
 
-                 status,
 
-             };
 
-             return await this.db.update(this.ctx.service.ledgerCooperation.tableName, updateData, options);
 
-         }
 
-         async saveSign(id, path) {
 
-             const updateData = {
 
-                 id,
 
-                 sign_path: path,
 
-             };
 
-             return await this.db.update(this.tableName, updateData);
 
-         }
 
-         async getValidData(tid, uid) {
 
-             const condition = { where: { tid, status: 1 } };
 
-             if (uid) {
 
-                 condition.where.user_id = uid;
 
-                 condition.colums = ['ledger_id', 'pwd'];
 
-             }
 
-             return await this.getAllDataByCondition(condition);
 
-         }
 
-     }
 
-     return LedgerCooperation;
 
- };
 
 
  |