| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | 
							- 'use strict';
 
- /**
 
-  *
 
-  *
 
-  * @author Mai
 
-  * @date 2021/6/17
 
-  * @version
 
-  */
 
- const thirdPartyConst = require('../const/third_party');
 
- module.exports = app => {
 
-     class S2bProj extends app.BaseService {
 
-         /**
 
-          * 构造函数
 
-          *
 
-          * @param {Object} ctx - egg全局变量
 
-          * @return {void}
 
-          */
 
-         constructor(ctx) {
 
-             super(ctx);
 
-             this.tableName = 's2b_proj';
 
-         }
 
-         async getDataByPid(pid) {
 
-             const sp = await this.getDataByCondition({ pid });
 
-             if (sp) {
 
-                 sp.gxby_option = sp.gxby_option ? JSON.parse(sp.gxby_option) : null;
 
-                 sp.dagl_option = sp.dagl_option ? JSON.parse(sp.dagl_option) : null;
 
-                 sp.gxby_status = sp.gxby_status ? JSON.parse(sp.gxby_status) : thirdPartyConst.gxby;
 
-                 sp.dagl_status = sp.dagl_status ? JSON.parse(sp.dagl_status) : thirdPartyConst.dagl;
 
-             }
 
-             return sp;
 
-         }
 
-         async refreshSessionS2b() {
 
-             const s2bProj = await this.getDataByPid(this.ctx.session.sessionProject.id);
 
-             this.ctx.session.sessionProject.gxby = s2bProj ? s2bProj.gxby : false;
 
-             this.ctx.session.sessionProject.gxby_status = s2bProj ? s2bProj.gxby_status : thirdPartyConst.gxby;
 
-             this.ctx.session.sessionProject.dagl = s2bProj ? s2bProj.dagl : false;
 
-             this.ctx.session.sessionProject.dagl_status = s2bProj ? s2bProj.dagl_status : thirdPartyConst.dagl;
 
-         }
 
-         async updateGxbyStatus(pid, status, limit, ratio) {
 
-             const sp = await this.getDataByPid(pid);
 
-             const gs = sp.gxby_status.find(x => { return x.value === status; });
 
-             if (!gs) throw '提交数据错误';
 
-             if (limit !== undefined && limit !== null) gs.limit = limit;
 
-             if (ratio !== undefined && ratio !== null) gs.ratio = this.ctx.helper.round(ratio, 2);
 
-             await this.db.update(this.tableName, { gxby_status: JSON.stringify(sp.gxby_status) }, { where: { pid } });
 
-             return gs;
 
-         }
 
-         async updateDaglStatus(pid, status, limit, ratio) {
 
-             const sp = await this.getDataByPid(pid);
 
-             const ds = sp.dagl_status.find(x => { return x.value === status; });
 
-             if (!ds) throw '提交数据错误';
 
-             if (limit !== undefined && limit !== null) ds.limit = limit;
 
-             if (ratio !== undefined && ratio !== null) ds.ratio = this.ctx.helper.round(ratio, 2);
 
-             await this.db.update(this.tableName, { dagl_status: JSON.stringify(sp.dagl_status) }, { where: { pid } });
 
-             return ds;
 
-         }
 
-     }
 
-     return S2bProj;
 
- };
 
 
  |