12345678910111213141516171819202122232425262728293031323334353637 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- //
- class CoachInBillService extends CrudService {
- constructor(ctx) {
- super(ctx, 'coachinbill');
- this.model = this.ctx.model.Business.CoachInBill;
- this.rcsModel = this.ctx.model.Relation.RelationCoachSchool;
- }
- // 查重,重了不加
- async beforeCreate(body) {
- const query = _.pick(body, [ 'lesson_id', 'type', 'school_id', 'coach_id' ]);
- const num = await this.model.count(query);
- if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '已经存在 该节课已经存在明细,请核对数据');
- return body;
- }
- // 改工资(结算变为周期性结算,而不是实时性结算)
- // async afterCreate(body, data) {
- // const { money } = data;
- // const query = _.pick(data, [ 'school_id', 'coach_id' ]);
- // // 查学校与教练的关联数据
- // const rcsData = await this.rcsModel.findOne(query);
- // if (!rcsData) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到教练在该学校下任教的信息');
- // // 累加工资
- // let salary = _.get(rcsData, 'salary', 0);
- // salary += money;
- // rcsData.salary = salary;
- // await rcsData.save();
- // return data;
- // }
- }
- module.exports = CoachInBillService;
|