lrf402788946 hace 4 años
commit
955e1c2584
Se han modificado 52 ficheros con 1129 adiciones y 0 borrados
  1. 29 0
      .autod.conf.js
  2. 1 0
      .eslintignore
  3. 3 0
      .eslintrc
  4. 42 0
      .github/workflows/nodejs.yml
  5. 14 0
      .gitignore
  6. 12 0
      .travis.yml
  7. 33 0
      README.md
  8. 38 0
      app/controller/.arrange.js
  9. 38 0
      app/controller/.credit.js
  10. 59 0
      app/controller/.order.js
  11. 37 0
      app/controller/.setting.js
  12. 40 0
      app/controller/.space.js
  13. 38 0
      app/controller/.vip.js
  14. 13 0
      app/controller/arrange.js
  15. 13 0
      app/controller/credit.js
  16. 12 0
      app/controller/home.js
  17. 13 0
      app/controller/order.js
  18. 13 0
      app/controller/setting.js
  19. 13 0
      app/controller/space.js
  20. 38 0
      app/controller/system/.admin.js
  21. 13 0
      app/controller/system/admin.js
  22. 13 0
      app/controller/vip.js
  23. 29 0
      app/model/arrange.js
  24. 23 0
      app/model/credit.js
  25. 29 0
      app/model/order.js
  26. 21 0
      app/model/setting.js
  27. 22 0
      app/model/space.js
  28. 23 0
      app/model/system/admin.js
  29. 24 0
      app/model/vip.js
  30. 16 0
      app/router.js
  31. 10 0
      app/router/arrange.js
  32. 10 0
      app/router/credit.js
  33. 10 0
      app/router/order.js
  34. 10 0
      app/router/setting.js
  35. 10 0
      app/router/space.js
  36. 12 0
      app/router/system/admin.js
  37. 10 0
      app/router/vip.js
  38. 24 0
      app/service/arrange.js
  39. 15 0
      app/service/credit.js
  40. 15 0
      app/service/order.js
  41. 20 0
      app/service/setting.js
  42. 15 0
      app/service/space.js
  43. 37 0
      app/service/system/admin.js
  44. 15 0
      app/service/vip.js
  45. 14 0
      appveyor.yml
  46. 61 0
      config/config.default.js
  47. 32 0
      config/config.prod.js
  48. 7 0
      config/config.secret.js
  49. 12 0
      config/plugin.js
  50. 5 0
      jsconfig.json
  51. 53 0
      package.json
  52. 20 0
      test/app/controller/home.test.js

+ 29 - 0
.autod.conf.js

@@ -0,0 +1,29 @@
+'use strict';
+
+module.exports = {
+  write: true,
+  prefix: '^',
+  plugin: 'autod-egg',
+  test: [
+    'test',
+    'benchmark',
+  ],
+  dep: [
+    'egg',
+    'egg-scripts',
+  ],
+  devdep: [
+    'egg-ci',
+    'egg-bin',
+    'egg-mock',
+    'autod',
+    'autod-egg',
+    'eslint',
+    'eslint-config-egg',
+  ],
+  exclude: [
+    './test/fixtures',
+    './dist',
+  ],
+};
+

+ 1 - 0
.eslintignore

@@ -0,0 +1 @@
+coverage

+ 3 - 0
.eslintrc

@@ -0,0 +1,3 @@
+{
+  "extends": "eslint-config-egg"
+}

+ 42 - 0
.github/workflows/nodejs.yml

@@ -0,0 +1,42 @@
+# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
+# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
+
+name: Node.js CI
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: [ master ]
+  schedule:
+    - cron: '0 2 * * *'
+
+jobs:
+  build:
+    runs-on: ${{ matrix.os }}
+
+    strategy:
+      fail-fast: false
+      matrix:
+        node-version: [10]
+        os: [ubuntu-latest, windows-latest, macos-latest]
+
+    steps:
+    - name: Checkout Git Source
+      uses: actions/checkout@v2
+
+    - name: Use Node.js ${{ matrix.node-version }}
+      uses: actions/setup-node@v1
+      with:
+        node-version: ${{ matrix.node-version }}
+
+    - name: Install Dependencies
+      run: npm i -g npminstall && npminstall
+
+    - name: Continuous Integration
+      run: npm run ci
+
+    - name: Code Coverage
+      uses: codecov/codecov-action@v1
+      with:
+        token: ${{ secrets.CODECOV_TOKEN }}

+ 14 - 0
.gitignore

@@ -0,0 +1,14 @@
+logs/
+npm-debug.log
+yarn-error.log
+node_modules/
+package-lock.json
+yarn.lock
+coverage/
+.idea/
+run/
+.DS_Store
+*.sw*
+*.un~
+typings/
+.nyc_output/

+ 12 - 0
.travis.yml

@@ -0,0 +1,12 @@
+
+language: node_js
+node_js:
+  - '10'
+before_install:
+  - npm i npminstall -g
+install:
+  - npminstall
+script:
+  - npm run ci
+after_script:
+  - npminstall codecov && codecov

+ 33 - 0
README.md

@@ -0,0 +1,33 @@
+# service
+
+
+
+## QuickStart
+
+<!-- add docs here for user -->
+
+see [egg docs][egg] for more detail.
+
+### Development
+
+```bash
+$ npm i
+$ npm run dev
+$ open http://localhost:7001/
+```
+
+### Deploy
+
+```bash
+$ npm start
+$ npm stop
+```
+
+### npm scripts
+
+- Use `npm run lint` to check code style.
+- Use `npm test` to run unit test.
+- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail.
+
+
+[egg]: https://eggjs.org

+ 38 - 0
app/controller/.arrange.js

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

+ 38 - 0
app/controller/.credit.js

@@ -0,0 +1,38 @@
+module.exports = {
+  create: {
+    requestBody: ["vip_id", "order_no", "money", "status"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["vip_id", "order_no", "money", "status"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        vip_id: "vip_id",
+        order_no: "order_no",
+        status: "status",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 59 - 0
app/controller/.order.js

@@ -0,0 +1,59 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "date",
+      "arrange_id",
+      "openid",
+      "order_no",
+      "phone",
+      "name",
+      "status",
+      "pay_way",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "date",
+      "arrange_id",
+      "openid",
+      "order_no",
+      "phone",
+      "name",
+      "status",
+      "pay_way",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        date: "date",
+        openid: "openid",
+        order_no: "order_no",
+        status: "status",
+        "date@start": "date@start",
+        "date@end": "date@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 37 - 0
app/controller/.setting.js

@@ -0,0 +1,37 @@
+module.exports = {
+  create: {
+    requestBody: ["name", "time", "images", "brief"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["name", "time", "images", "brief"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        time: "time",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 40 - 0
app/controller/.space.js

@@ -0,0 +1,40 @@
+module.exports = {
+  create: {
+    requestBody: ["name", "price", "images", "is_use"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["name", "price", "images", "is_use"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        price: "price",
+        is_use: "is_use",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 38 - 0
app/controller/.vip.js

@@ -0,0 +1,38 @@
+module.exports = {
+  create: {
+    requestBody: ["openid", "name", "phone", "money"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["openid", "name", "phone", "money"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        openid: "openid",
+        name: "name",
+        phone: "phone",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/arrange.js

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

+ 13 - 0
app/controller/credit.js

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

+ 12 - 0
app/controller/home.js

@@ -0,0 +1,12 @@
+'use strict';
+
+const Controller = require('egg').Controller;
+
+class HomeController extends Controller {
+  async index() {
+    const { ctx } = this;
+    ctx.body = 'hi, egg';
+  }
+}
+
+module.exports = HomeController;

+ 13 - 0
app/controller/order.js

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

+ 13 - 0
app/controller/setting.js

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

+ 13 - 0
app/controller/space.js

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

+ 38 - 0
app/controller/system/.admin.js

@@ -0,0 +1,38 @@
+"use strict";
+module.exports = {
+  create: {
+    requestBody: ["name", "login_id", "password"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["name", "login_id", "password"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+  login: {
+    requestBody: ["login_id", "password"],
+    service: "login",
+  },
+};

+ 13 - 0
app/controller/system/admin.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.admin.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 管理员
+class AdminController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.system.admin;
+  }
+}
+module.exports = CrudController(AdminController, meta);

+ 13 - 0
app/controller/vip.js

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

+ 29 - 0
app/model/arrange.js

@@ -0,0 +1,29 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+
+// 安排
+const object = new Schema({
+  time: { type: Array }, // 时间
+  money: { type: Number, default: 0 }, // 金额
+  space_id: { type: ObjectId }, // 场地id
+  is_use: { type: Boolean, default: true }, // 0-允许使用;1-禁止使用
+});
+
+// 场地安排表
+const arrange = {
+  date: { type: String }, // 日期
+  arrange: { type: [ object ] }, // 安排
+  remark: { type: String },
+};
+const schema = new Schema(arrange, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ date: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Arrange', schema, 'arrange');
+};

+ 23 - 0
app/model/credit.js

@@ -0,0 +1,23 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 充值表
+const credit = {
+  vip_id: { type: ObjectId }, // 会员id
+  order_no: { type: String }, // 支付订单号
+  money: { type: Number }, // 充值金额
+  status: { type: String, default: '0' }, // 状态
+  remark: { type: String },
+};
+const schema = new Schema(credit, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ vip_id: 1 });
+schema.index({ order_no: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Credit', schema, 'credit');
+};

+ 29 - 0
app/model/order.js

@@ -0,0 +1,29 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 订单表
+const order = {
+  date: { type: String }, // 下单日期
+  arrange_id: { type: ObjectId }, // 安排内容的数据id,arrange中arrange的id
+  openid: { type: String }, // 微信openid
+  order_no: { type: String }, // 订单号
+  phone: { type: String }, // 预留电话
+  name: { type: String }, // 预留姓名
+  status: { type: String, default: '0' }, // 状态0-未支付;1-支付完成
+  pay_way: { type: String }, // 0-微信直接支付;1-vip账户划走;
+  remark: { type: String },
+};
+const schema = new Schema(order, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ date: 1 });
+schema.index({ openid: 1 });
+schema.index({ order_no: 1 });
+schema.index({ status: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Order', schema, 'order');
+};

+ 21 - 0
app/model/setting.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 设置表
+const setting = {
+  name: { type: String }, // 本馆名称
+  time: { type: Array }, // 营业时间
+  images: { type: Array }, // 宣传图
+  brief: { type: String }, // 简介
+  remark: { type: String },
+};
+const schema = new Schema(setting, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Setting', schema, 'setting');
+};

+ 22 - 0
app/model/space.js

@@ -0,0 +1,22 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 场地表
+const space = {
+  name: { type: String }, // 场地名
+  price: { type: Number, default: 0 }, // 价格
+  images: { type: Array }, // 场地图片
+  is_use: { type: Boolean, default: true }, // 场地是否使用
+  remark: { type: String },
+};
+const schema = new Schema(space, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ name: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Space', schema, 'space');
+};

+ 23 - 0
app/model/system/admin.js

@@ -0,0 +1,23 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+const { Secret } = require('naf-framework-mongoose/lib/model/schema');
+// 管理员表
+const admin = {
+  name: { type: String }, // 昵称
+  login_id: { type: String }, // 登陆id
+  password: { type: Secret, select: false }, // 密码
+  openid: { type: String }, // 微信openid
+  is_root: { type: Boolean, default: false }, // 是总管理员
+  remark: { type: String },
+};
+const schema = new Schema(admin, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Admin', schema, 'admin');
+};

+ 24 - 0
app/model/vip.js

@@ -0,0 +1,24 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 会员表
+const vip = {
+  openid: { type: String }, // 微信openid
+  name: { type: String }, // 姓名
+  phone: { type: String }, // 电话
+  money: { type: Number }, // 金额
+  remark: { type: String },
+};
+const schema = new Schema(vip, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ openid: 1 });
+schema.index({ name: 1 });
+schema.index({ phone: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Vip', schema, 'vip');
+};

+ 16 - 0
app/router.js

@@ -0,0 +1,16 @@
+'use strict';
+
+/**
+ * @param {Egg.Application} app - egg application
+ */
+module.exports = app => {
+  const { router, controller } = app;
+  router.get('/', controller.home.index);
+  require('./router/system/admin')(app); // 管理员
+  require('./router/setting')(app); // 设置
+  require('./router/space')(app); // 场地
+  require('./router/arrange')(app); // 安排
+  require('./router/order')(app); // 订单
+  require('./router/vip')(app); // 会员
+  require('./router/credit')(app); // 充值
+};

+ 10 - 0
app/router/arrange.js

@@ -0,0 +1,10 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/qiuguan/';
+  const target = 'arrange';
+  router.resources(target, `${profix}/${target}`, controller[target]); // index、create、show、destroy
+  router.post(target, `${profix}/${target}/update/:id`, controller[target].update);
+};

+ 10 - 0
app/router/credit.js

@@ -0,0 +1,10 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/qiuguan/';
+  const target = 'credit';
+  router.resources(target, `${profix}/${target}`, controller[target]); // index、create、show、destroy
+  router.post(target, `${profix}/${target}/update/:id`, controller[target].update);
+};

+ 10 - 0
app/router/order.js

@@ -0,0 +1,10 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/qiuguan/';
+  const target = 'order';
+  router.resources(target, `${profix}/${target}`, controller[target]); // index、create、show、destroy
+  router.post(target, `${profix}/${target}/update/:id`, controller[target].update);
+};

+ 10 - 0
app/router/setting.js

@@ -0,0 +1,10 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/qiuguan/';
+  const target = 'setting';
+  router.resources(target, `${profix}/${target}`, controller[target]); // index、create、show、destroy
+  router.post(target, `${profix}/${target}/update/:id`, controller[target].update);
+};

+ 10 - 0
app/router/space.js

@@ -0,0 +1,10 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/qiuguan/';
+  const target = 'space';
+  router.resources(target, `${profix}/${target}`, controller[target]); // index、create、show、destroy
+  router.post(target, `${profix}/${target}/update/:id`, controller[target].update);
+};

+ 12 - 0
app/router/system/admin.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/qiuguan/';
+  const index = 'system';
+  const target = 'admin';
+  router.post(target, `${profix}${index}/${target}/login`, controller[index][target].login);
+  router.resources(target, `${profix}${index}/${target}`, controller[index][target]); // index、create、show、destroy
+  router.post(target, `${profix}${index}/${target}/update/:id`, controller[index][target].update);
+};

+ 10 - 0
app/router/vip.js

@@ -0,0 +1,10 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/qiuguan/';
+  const target = 'vip';
+  router.resources(target, `${profix}/${target}`, controller[target]); // index、create、show、destroy
+  router.post(target, `${profix}/${target}/update/:id`, controller[target].update);
+};

+ 24 - 0
app/service/arrange.js

@@ -0,0 +1,24 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 安排
+class ArrangeService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'arrange');
+    this.model = this.ctx.model.Arrange;
+  }
+
+  /**
+   * 获取安排的内容
+   * @param {Object} query 地址栏
+   * @property id arrange.id
+   */
+  async getContext({ id }) {
+    console.log('in function:');
+  }
+}
+
+module.exports = ArrangeService;

+ 15 - 0
app/service/credit.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 充值记录
+class CreditService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'credit');
+    this.model = this.ctx.model.Credit;
+  }
+}
+
+module.exports = CreditService;

+ 15 - 0
app/service/order.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 订单
+class OrderService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'order');
+    this.model = this.ctx.model.Order;
+  }
+}
+
+module.exports = OrderService;

+ 20 - 0
app/service/setting.js

@@ -0,0 +1,20 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 设置
+class SettingService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'setting');
+    this.model = this.ctx.model.Setting;
+  }
+  async query() {
+    let data = await this.model.findOne();
+    if (!data) data = await this.model.create();
+    return data;
+  }
+}
+
+module.exports = SettingService;

+ 15 - 0
app/service/space.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 场地
+class SpaceService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'space');
+    this.model = this.ctx.model.Space;
+  }
+}
+
+module.exports = SpaceService;

+ 37 - 0
app/service/system/admin.js

@@ -0,0 +1,37 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+const jwt = require('jsonwebtoken');
+
+// 管理员
+class AdminService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'admin');
+    this.model = this.ctx.model.System.Admin;
+  }
+  /**
+   * 管理员登陆
+   * @param {Object} body
+   * @property login_id 登陆用户名
+   * @property password 密码
+   */
+  async login({ login_id, password }) {
+    const user = await this.model.findOne({ login_id }, '+password');
+    if (!user) { throw new BusinessError(ErrorCode.USER_NOT_EXIST, '管理员不存在'); }
+    const { secret } = user.password;
+    if (secret !== password) { throw new BusinessError(ErrorCode.BAD_PASSWORD, '密码错误'); }
+    const data = _.omit(JSON.parse(JSON.stringify(user)), [
+      'meta',
+      'passwd',
+      '__v',
+      'password',
+    ]);
+    const { secret: secrets } = this.config.jwt;
+    const token = jwt.sign(data, secrets);
+    return token;
+  }
+}
+
+module.exports = AdminService;

+ 15 - 0
app/service/vip.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 会员
+class VipService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'vip');
+    this.model = this.ctx.model.Vip;
+  }
+}
+
+module.exports = VipService;

+ 14 - 0
appveyor.yml

@@ -0,0 +1,14 @@
+environment:
+  matrix:
+    - nodejs_version: '10'
+
+install:
+  - ps: Install-Product node $env:nodejs_version
+  - npm i npminstall && node_modules\.bin\npminstall
+
+test_script:
+  - node --version
+  - npm --version
+  - npm run test
+
+build: off

+ 61 - 0
config/config.default.js

@@ -0,0 +1,61 @@
+/* eslint valid-jsdoc: "off" */
+
+'use strict';
+
+const { jwt } = require('./config.secret');
+/**
+ * @param {Egg.EggAppInfo} appInfo app info
+ */
+module.exports = appInfo => {
+  /**
+   * built-in config
+   * @type {Egg.EggAppConfig}
+   **/
+  const config = exports = {};
+
+  // use for cookie sign key, should change to your own and keep security
+  config.keys = appInfo.name + '_1624958614917_1342';
+
+  // add your middleware config here
+  config.middleware = [];
+
+  // add your user config here
+  const userConfig = {
+    // myAppName: 'egg',
+  };
+  config.jwt = {
+    ...jwt,
+    expiresIn: '1d',
+    issuer: 'qiuguan',
+  };
+  config.cluster = {
+    listen: {
+      port: 11001,
+    },
+  };
+  config.dbName = 'qiuguan';
+  config.mongoose = {
+    url: `mongodb://localhost:27017/${config.dbName}`,
+    options: {
+      // user: 'admin',
+      // pass: '111111',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
+    },
+  };
+
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '127.0.0.1', // Redis host
+      password: '123456',
+      db: 4,
+    },
+  };
+
+  return {
+    ...config,
+    ...userConfig,
+  };
+};

+ 32 - 0
config/config.prod.js

@@ -0,0 +1,32 @@
+'use strict';
+
+module.exports = () => {
+  const config = exports = {};
+
+  config.logger = {
+    level: 'INFO',
+    consoleLevel: 'INFO',
+  };
+  config.dbName = 'qiuguan';
+  config.mongoose = {
+    url: `mongodb://localhost:27017/${config.dbName}`,
+    options: {
+      user: 'admin',
+      pass: 'admin',
+      authSource: 'admin',
+      useNewUrlParser: true,
+      useCreateIndex: true,
+    },
+  };
+  // redis config
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '127.0.0.1', // Redis host
+      password: 123456,
+      db: 4,
+    },
+  };
+
+  return config;
+};

+ 7 - 0
config/config.secret.js

@@ -0,0 +1,7 @@
+'use strict';
+
+module.exports = {
+  jwt: {
+    secret: 'Ziyouyanfa!@#',
+  },
+};

+ 12 - 0
config/plugin.js

@@ -0,0 +1,12 @@
+'use strict';
+
+/** @type Egg.EggPlugin */
+exports.amqp = {
+  enable: true,
+  package: 'egg-naf-amqp',
+};
+exports.redis = {
+  enable: true,
+  package: 'egg-redis',
+};
+

+ 5 - 0
jsconfig.json

@@ -0,0 +1,5 @@
+{
+  "include": [
+    "**/*"
+  ]
+}

+ 53 - 0
package.json

@@ -0,0 +1,53 @@
+{
+  "name": "service",
+  "version": "1.0.0",
+  "description": "",
+  "private": true,
+  "egg": {
+    "framework": "naf-framework-mongoose"
+  },
+  "dependencies": {
+    "egg": "^2.15.1",
+    "egg-naf-amqp": "0.0.13",
+    "egg-redis": "^2.4.0",
+    "egg-scripts": "^2.11.0",
+    "jsonwebtoken": "^8.5.1",
+    "lodash": "^4.17.21",
+    "moment": "^2.29.1",
+    "naf-framework-mongoose": "^0.6.11",
+    "string-random": "^0.1.3"
+  },
+  "devDependencies": {
+    "autod": "^3.0.1",
+    "autod-egg": "^1.1.0",
+    "egg-bin": "^4.11.0",
+    "egg-ci": "^1.11.0",
+    "egg-mock": "^3.21.0",
+    "eslint": "^5.13.0",
+    "eslint-config-egg": "^7.1.0"
+  },
+  "engines": {
+    "node": ">=10.0.0"
+  },
+  "scripts": {
+    "start": "egg-scripts start --daemon --title=egg-server-service",
+    "stop": "egg-scripts stop --title=egg-server-service",
+    "dev": "egg-bin dev",
+    "debug": "egg-bin debug",
+    "test": "npm run lint -- --fix && npm run test-local",
+    "test-local": "egg-bin test",
+    "cov": "egg-bin cov",
+    "lint": "eslint .",
+    "ci": "npm run lint && npm run cov",
+    "autod": "autod"
+  },
+  "ci": {
+    "version": "10"
+  },
+  "repository": {
+    "type": "git",
+    "url": ""
+  },
+  "author": "",
+  "license": "MIT"
+}

+ 20 - 0
test/app/controller/home.test.js

@@ -0,0 +1,20 @@
+'use strict';
+
+const { app, assert } = require('egg-mock/bootstrap');
+
+describe('test/app/controller/home.test.js', () => {
+  it('should assert', () => {
+    const pkg = require('../../../package.json');
+    assert(app.config.keys.startsWith(pkg.name));
+
+    // const ctx = app.mockContext({});
+    // yield ctx.service.xx();
+  });
+
+  it('should GET /', () => {
+    return app.httpRequest()
+      .get('/')
+      .expect('hi, egg')
+      .expect(200);
+  });
+});