|
@@ -0,0 +1,68 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by EllisRan on 2020/3/3.
|
|
|
+ */
|
|
|
+
|
|
|
+const BaseService = require('../base/base_service');
|
|
|
+
|
|
|
+module.exports = app => {
|
|
|
+
|
|
|
+ class SignatureUsed extends BaseService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx);
|
|
|
+ this.tableName = 'signature_used';
|
|
|
+ this.dataId = 'id';
|
|
|
+ }
|
|
|
+
|
|
|
+ async getSignatureUsedByTenderId(tenderId) {
|
|
|
+ this.initSqlBuilder();
|
|
|
+ this.sqlBuilder.setAndWhere('tender_id', {
|
|
|
+ value: tenderId,
|
|
|
+ operate: '=',
|
|
|
+ });
|
|
|
+ // this.sqlBuilder.columns = ['id', 'uid', 'prj_id', 'tender_id', 'used_time'];
|
|
|
+ const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
|
|
|
+ const list = await this.db.query(sql, sqlParam);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ async updateUsed(data, used_time) {
|
|
|
+ let rst = null;
|
|
|
+ this.transaction = await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ const used = await this.getDataByCondition({ uid: data.uid, prj_id: data.prj_id, tender_id: data.tender_id });
|
|
|
+ if (!used) {
|
|
|
+ const insertData = {
|
|
|
+ uid: data.uid,
|
|
|
+ prj_id: data.prj_id,
|
|
|
+ tender_id: data.tender_id,
|
|
|
+ used_time,
|
|
|
+ };
|
|
|
+ rst = await this.transaction.insert(this.tableName, insertData);
|
|
|
+ } else {
|
|
|
+ const updateData = {
|
|
|
+ id: used.id,
|
|
|
+ used_time,
|
|
|
+ };
|
|
|
+ rst = await this.transaction.insert(this.tableName, updateData);
|
|
|
+ }
|
|
|
+ await this.transaction.commit();
|
|
|
+ } catch (ex) {
|
|
|
+ console.log(ex);
|
|
|
+ // 回滚
|
|
|
+ await this.transaction.rollback();
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return SignatureUsed;
|
|
|
+};
|