lrf 2 years ago
parent
commit
b79b8448bd

+ 13 - 0
app/controller/business/billApply.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.billApply.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+//
+class BillApplyController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.billApply;
+  }
+}
+module.exports = CrudController(BillApplyController, meta);

+ 13 - 0
app/controller/business/coachInBill.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.coachInBill.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+//
+class CoachInBillController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.business.coachInBill;
+  }
+}
+module.exports = CrudController(CoachInBillController, meta);

+ 39 - 0
app/controller/business/config/.billApply.js

@@ -0,0 +1,39 @@
+module.exports = {
+  create: {
+    requestBody: ['school_id', 'coach_id', 'salary', 'reason', 'result'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['school_id', 'coach_id', 'salary', 'reason', 'result'],
+  },
+  show: {
+    parameters: {
+      params: ['!id'],
+    },
+    service: 'fetch',
+  },
+  index: {
+    parameters: {
+      query: {
+        'meta.createdAt@start': 'meta.createdAt@start',
+        'meta.createdAt@end': 'meta.createdAt@end',
+        school_id: 'school_id',
+        coach_id: 'coach_id',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 39 - 0
app/controller/business/config/.coachInBill.js

@@ -0,0 +1,39 @@
+module.exports = {
+  create: {
+    requestBody: ['lesson_id', 'type', 'school_id', 'coach_id', 'money'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['lesson_id', 'type', 'school_id', 'coach_id', 'money'],
+  },
+  show: {
+    parameters: {
+      params: ['!id'],
+    },
+    service: 'fetch',
+  },
+  index: {
+    parameters: {
+      query: {
+        'meta.createdAt@start': 'meta.createdAt@start',
+        'meta.createdAt@end': 'meta.createdAt@end',
+        school_id: 'school_id',
+        coach_id: 'coach_id',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 2 - 2
app/controller/relation/config/.relationCoachSchool.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['!coach_id', '!school_id', 'doc'],
+    requestBody: ['!coach_id', '!school_id', 'doc', 'salary'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['coach_id', 'school_id', 'doc'],
+    requestBody: ['coach_id', 'school_id', 'doc', 'salary'],
   },
   show: {
     parameters: {

+ 23 - 0
app/model/business/billApply.js

@@ -0,0 +1,23 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 提现申请
+const billApply = {
+  school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
+  coach_id: { type: String, required: false, zh: '教练id', ref: 'Coach', getProp: [ 'name' ] }, //
+  salary: { type: Number, required: false, zh: '提现金额' }, //
+  reason: { type: String, required: false, zh: '原因' }, //
+  result: { type: String, required: false, default: '0', zh: '审核结果' }, // 0:未审核;1审核成功;2:审核失败
+};
+const schema = new Schema(billApply, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ school_id: 1 });
+schema.index({ coach_id: 1 });
+
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('BillApply', schema, 'billApply');
+};

+ 23 - 0
app/model/business/coachInBill.js

@@ -0,0 +1,23 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 教练费明细
+const coachInBill = {
+  lesson_id: { type: String, required: false, zh: '课程id' }, //
+  type: { type: String, required: false, zh: '类型' }, // 0:公开课收入;1私教课收入;2提现
+  school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
+  coach_id: { type: String, required: false, zh: '教练id', ref: 'Coach', getProp: [ 'name' ] }, //
+  money: { type: Number, required: false, zh: '金额' }, //
+};
+const schema = new Schema(coachInBill, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ school_id: 1 });
+schema.index({ coach_id: 1 });
+
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('CoachInBill', schema, 'coachInBill');
+};

+ 1 - 0
app/model/relation/relationCoachSchool.js

@@ -7,6 +7,7 @@ const relationCoachSchool = {
   coach_id: { type: String, required: true, zh: '教练id', ref: 'Coach', getProp: [ 'name', 'phone', 'level', 'icon' ] }, //
   school_id: { type: String, required: true, zh: '学校id', ref: 'School', getProp: [ 'name', 'phone' ] }, //
   doc: { type: Object, required: false, zh: '教练档案' }, //
+  salary: { type: Number, zh: '工资' },
 };
 const schema = new Schema(relationCoachSchool, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });

+ 2 - 0
app/router.js

@@ -35,4 +35,6 @@ module.exports = app => {
   require('./z_router/relation/studentApplyForSchool')(app); // 学员入学申请
   require('./z_router/business/lessonPrivate')(app); // 私教课
   require('./z_router/business/lessonPublic')(app); // 公开课
+  require('./z_router/business/coachInBill')(app); // 教练费明细
+  require('./z_router/business/billApply')(app); // 教练费申请
 };

+ 15 - 0
app/service/business/billApply.js

@@ -0,0 +1,15 @@
+'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 BillApplyService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'billapply');
+    this.model = this.ctx.model.Business.BillApply;
+  }
+}
+
+module.exports = BillApplyService;

+ 22 - 0
app/service/business/coachInBill.js

@@ -0,0 +1,22 @@
+'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;
+  }
+  // 查重,重了不加
+  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;
+  }
+}
+
+module.exports = CoachInBillService;

+ 21 - 1
app/service/business/lessonPrivate.js

@@ -4,11 +4,31 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const assert = require('assert');
 
-// 
+//
 class LessonPrivateService extends CrudService {
   constructor(ctx) {
     super(ctx, 'lessonprivate');
     this.model = this.ctx.model.Business.LessonPrivate;
+    this.cibService = this.ctx.service.business.coachInBill;
+  }
+  /**
+   * 处理下课的课程进行结算
+   * @param {Object} filter 修改条件
+   * @param {Object} body 修改内容
+   * @param {Object} data 修改后的结果
+   * @return {Object} 返回整理后的内容
+   */
+  async afterUpdate(filter, body, data) {
+    const { status, limit, money, student, _id: lesson_id, school_id, coach_id } = data;
+    if (status !== '4') return data;
+    // 4 是下课,下了课,就给老师结钱
+    // 目前按学生人数进行结款,限制的人数不一定是上课的学生人数,可能会临时加人
+    const num = student.length;
+    const total = num * money;
+    // 添加明细,通过明细那边,将工资处理了,这边就不处理了.因为公开课那边也是一样这么做
+    const obj = { lesson_id, type: '1', school_id, coach_id, money: total };
+    await this.cibService.create(obj);
+    return data;
   }
 }
 

+ 19 - 0
app/z_router/business/billApply.js

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'billApply';
+const ckey = 'business.billApply';
+const keyZh = '教练费申请';
+const routes = [
+  { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
+  { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
+  { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },
+  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
+  { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
+];
+
+module.exports = app => {
+  routerRegister(app, routes, keyZh, rkey, ckey);
+};

+ 19 - 0
app/z_router/business/coachInBill.js

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'coachInBill';
+const ckey = 'business.coachInBill';
+const keyZh = '教练费明细';
+const routes = [
+  { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
+  { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
+  { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },
+  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
+  { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
+];
+
+module.exports = app => {
+  routerRegister(app, routes, keyZh, rkey, ckey);
+};

+ 1 - 1
config/config.default.js

@@ -109,7 +109,7 @@ module.exports = appInfo => {
   // 数据库设置
   config.dbName = 'court_v2';
   config.mongoose = {
-    url: `mongodb://127.0.0.1:27017/${config.dbName}`, // 120.48.146.1
+    url: `mongodb://127.0.0.1:27017/${config.dbName}`, // 120.48.146.1 127.0.0.1
     options: {
       user: 'admin',
       pass: 'admin',