lrf %!s(int64=2) %!d(string=hai) anos
pai
achega
19c4f58273

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

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

+ 41 - 0
app/controller/business/config/.charge.js

@@ -0,0 +1,41 @@
+module.exports = {
+  create: {
+    requestBody: ['school_id', 'payer_id', 'payer_role', 'money', 'pay_id', 'is_pay', 'time'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['school_id', 'payer_id', 'payer_role', 'money', 'pay_id', 'is_pay', 'time'],
+  },
+  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',
+        payer_id: 'payer_id',
+        payer_role: 'payer_role',
+        is_pay: 'is_pay',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 27 - 0
app/model/business/charge.js

@@ -0,0 +1,27 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 充值记录
+const charge = {
+  school_id: { type: String, required: false, zh: '学校id', ref: 'School', getProp: [ 'name' ] }, //
+  payer_id: { type: String, required: false, zh: '充值用户角色id', refPath: 'payer_role', getProp: [ 'name' ] }, //
+  payer_role: { type: String, required: false, zh: '充值用户角色' }, //
+  money: { type: Number, required: false, zh: '充值金额' }, //
+  pay_id: { type: String, required: false, zh: '支付id', ref: 'Payorder' }, //
+  is_pay: { type: String, required: false, zh: '支付状态' }, // 0:未支付;1:支付成功;-1:支付失败;-3:已退款
+  time: { type: String, required: false, zh: '时间' }, //
+};
+const schema = new Schema(charge, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ school_id: 1 });
+schema.index({ payer_id: 1 });
+schema.index({ payer_role: 1 });
+schema.index({ is_pay: 1 });
+
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Charge', schema, 'charge');
+};

+ 1 - 0
app/router.js

@@ -40,6 +40,7 @@ module.exports = app => {
   require('./z_router/business/lessonStudent')(app); // 课程-学员
   require('./z_router/business/coachInBill')(app); // 教练费明细
   require('./z_router/business/payOrder')(app); // 支付订单
+  require('./z_router/business/charge')(app); // 充值
 
   require('./z_router/apply/billApply')(app); // 教练费申请
   require('./z_router/apply/tryLessonApply')(app); // 试课申请

+ 15 - 0
app/service/business/charge.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 ChargeService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'charge');
+    this.model = this.ctx.model.Business.Charge;
+  }
+}
+
+module.exports = ChargeService;

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

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'charge';
+const ckey = 'business.charge';
+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`, 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://120.48.146.1:27017/${config.dbName}`, // 120.48.146.1 127.0.0.1
+    url: `mongodb://127.0.0.1:27017/${config.dbName}`, // 120.48.146.1 127.0.0.1
     options: {
       user: 'admin',
       pass: 'admin',