Ver Fonte

连接口

zs há 2 anos atrás
pai
commit
4f96db82bf

+ 15 - 0
app/controller/cart.js

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

+ 2 - 2
app/controller/config/.admin.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["account", "name", "password"],
+    requestBody: ["account", "name", "password", "shop"],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["account", "name", "password"],
+    requestBody: ["account", "name", "password", "shop"],
   },
   show: {
     parameters: {

+ 45 - 0
app/controller/config/.cart.js

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

+ 41 - 0
app/controller/config/.goods.js

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

+ 43 - 0
app/controller/config/.goodsTags.js

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

+ 55 - 0
app/controller/config/.order.js

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

+ 37 - 0
app/controller/config/.shop.js

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

+ 37 - 0
app/controller/config/.table.js

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

+ 15 - 0
app/controller/goods.js

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

+ 15 - 0
app/controller/goodsTags.js

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

+ 15 - 0
app/controller/order.js

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

+ 11 - 10
app/controller/shop.js

@@ -1,14 +1,15 @@
 'use strict';
+const meta = require('./config/.shop.js');
 const Controller = require('egg').Controller;
-class Shop extends Controller {
-  async Shop() {
-    const { ctx } = this;
-    const req = ctx.request.body;
-    const res = await ctx.service.shopService.Shop(req);
-    ctx.body = {
-      state: 200,
-      msg: res,
-    };
+const {
+  CrudController,
+} = require('naf-framework-mongoose-free/lib/controller');
+
+// 店铺
+class ShopController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.shop;
   }
 }
-module.exports = Shop;
+module.exports = CrudController(ShopController, meta);

+ 15 - 0
app/controller/table.js

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

+ 10 - 0
app/middleware/shop.js

@@ -0,0 +1,10 @@
+'use strict';
+const _ = require('lodash');
+module.exports = options => {
+  return async function shop(ctx, next) {
+    await next();
+    let body = ctx.response.body;
+    body = await ctx.service.shop.getAdmin(body);
+    ctx.response.body = body;
+  };
+};

+ 0 - 17
app/model/ShopModel.js

@@ -1,17 +0,0 @@
-'use strict';
-const Schema = require('mongoose').Schema;
-// 店铺
-const shop = {
-  name: { type: String, zh: '店铺名称' },
-  notice: { type: String, zh: '公告内容' },
-  logo: { type: Object, zh: '首页图片' }, //
-};
-const Shopschema = new Schema(shop, {
-  toJSON: { getters: true, virtuals: true },
-});
-Shopschema.index({ notice: 1 });
-Shopschema.index({ name: 1 });
-module.exports = app => {
-  const { mongoose } = app;
-  return mongoose.model('ShopModel', Shopschema, 'shop');
-};

+ 2 - 0
app/model/admin.js

@@ -7,12 +7,14 @@ const { Secret } = require('naf-framework-mongoose-free/lib/model/schema');
 const admin = {
   name: { type: String, zh: '昵称' },
   account: { type: String, zh: '账号' },
+  shop: { type: String, zh: '店铺id' },
   password: { type: Secret, select: false, zh: '密码' }, //
 };
 const schema = new Schema(admin, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ name: 1 });
 schema.index({ account: 1 });
+schema.index({ shop: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 module.exports = app => {

+ 21 - 0
app/model/cart.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 购物车表
+const cart = {
+  list: { type: Array, zh: '购买商品' }, //
+  total: { type: Number, zh: '总价' }, //
+  table: { type: String, zh: '桌号' }, //
+};
+const schema = new Schema(cart, {
+  toJSON: { getters: true, virtuals: true },
+});
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Cart', schema, 'cart');
+};

+ 31 - 0
app/model/goods.js

@@ -0,0 +1,31 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 商品表
+const goods = {
+  name: { type: String, required: false, zh: '商品名称' }, //
+  type: { type: String, required: false, zh: '商品类型' }, //
+  spec: { type: String, required: false, zh: '商品规格' }, //
+  stock: { type: Number, required: false, zh: '商品库存' }, //
+  price: { type: Number, required: false, zh: '商品价格' }, //
+  file: { type: Array, zh: '商品图片' }, //
+  is_use: { type: String, required: false, zh: '是否启用', default: '0' }, //
+};
+const schema = new Schema(goods, {
+  toJSON: { getters: true, virtuals: true },
+});
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ name: 1 });
+schema.index({ type: 1 });
+schema.index({ spec: 1 });
+schema.index({ stock: 1 });
+schema.index({ price: 1 });
+schema.index({ is_use: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Goods', schema, 'goods');
+};

+ 29 - 0
app/model/goodsTags.js

@@ -0,0 +1,29 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 标签表
+const goodsTags = {
+  name: { type: String, required: false, zh: '标签名称' }, //
+  code: { type: String, required: false, zh: '标签编码' }, //
+  icon: { type: String, required: false, zh: '标签图标' }, //
+  is_use: { type: String, required: false, zh: '是否启用', default: '0' }, //
+  sort: { type: Number, required: false, zh: '排序', default: 1 }, //
+};
+const schema = new Schema(goodsTags, {
+  toJSON: { getters: true, virtuals: true },
+});
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ code: 1 });
+schema.index({ name: 1 });
+schema.index({ icon: 1 });
+schema.index({ path: 1 });
+schema.index({ is_use: 1 });
+schema.index({ sort: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('GoodsTags', schema, 'goodsTags');
+};

+ 32 - 0
app/model/order.js

@@ -0,0 +1,32 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 订单表
+const order = {
+  time: { type: String, required: false, zh: '下单时间' }, //
+  table: { type: String, required: false, zh: '下单桌号id' }, //
+  money: { type: Number, required: false, zh: '支付金额' }, //
+  money_num: { type: Number, required: false, zh: '餐位费' }, //
+  num: { type: Number, required: false, zh: '用餐人数' }, //
+  list: { type: Array, required: false, zh: '商品' }, //
+  type: { type: String, required: false, zh: '订单类型' }, //
+  remark: { type: String, required: false, zh: '备注' }, //
+};
+const schema = new Schema(order, {
+  toJSON: { getters: true, virtuals: true },
+});
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ time: 1 });
+schema.index({ table: 1 });
+schema.index({ money: 1 });
+schema.index({ money_num: 1 });
+schema.index({ num: 1 });
+schema.index({ type: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Order', schema, 'order');
+};

+ 25 - 0
app/model/shop.js

@@ -0,0 +1,25 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 店铺表
+const shop = {
+  name: { type: String, required: false, zh: '店铺名称' }, //
+  notice: { type: String, required: false, zh: '公告内容' }, //
+  money: { type: Number, required: false, zh: '餐位费' }, //
+  logo: { type: Array, zh: '首页图片' }, // 附件
+};
+const schema = new Schema(shop, {
+  toJSON: { getters: true, virtuals: true },
+});
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ name: 1 });
+schema.index({ notice: 1 });
+schema.index({ money: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Shop', schema, 'shop');
+};

+ 26 - 0
app/model/table.js

@@ -0,0 +1,26 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 桌台表
+const table = {
+  name: { type: String, required: false, zh: '桌台类型' }, //
+  remark: { type: String, required: false, zh: '备注' }, //
+  type: { type: String, required: false, zh: '备注' }, //
+  is_use: { type: String, required: false, zh: '是否启用', default: '0' }, //
+};
+const schema = new Schema(table, {
+  toJSON: { getters: true, virtuals: true },
+});
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ name: 1 });
+schema.index({ remark: 1 });
+schema.index({ type: 1 });
+schema.index({ is_use: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Table', schema, 'table');
+};

+ 7 - 3
app/router.js

@@ -6,8 +6,12 @@
 module.exports = app => {
   const { router, controller } = app;
   router.get('/', controller.home.index);
-  require('./z_router/admin')(app); // 管理
+  require('./z_router/admin')(app); // 管理
   require('./z_router/program')(app); // 节目表
-  // 增加数据
-  router.post('/projectadmin/api/shop', controller.shop.Shop);
+  require('./z_router/shop')(app); // 店铺表
+  require('./z_router/table')(app); // 桌台表
+  require('./z_router/goodstags')(app); // 标签表
+  require('./z_router/goods')(app); // 商品表
+  require('./z_router/order')(app); // 订单表
+  require('./z_router/cart')(app); // 购物表
 };

+ 1 - 1
app/service/admin.js

@@ -28,7 +28,7 @@ class AdminService extends CrudService {
     if (!user) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
     const { password: upwd } = user;
     // if (status !== '1') throw new BusinessError(ErrorCode.USER_NOT_BIND, '该账号处于禁止使用状态');
-    if (password !== upwd.secret) throw new BusinessError(ErrorCode.BAD_PASSWORD);
+    if (password !== upwd.secret) { throw new BusinessError(ErrorCode.BAD_PASSWORD); }
     user = JSON.parse(JSON.stringify(user));
     delete user.meta;
     delete user.__v;

+ 12 - 0
app/service/cart.js

@@ -0,0 +1,12 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+
+// 购物表
+class CartService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'cart');
+    this.model = this.ctx.model.Cart;
+  }
+}
+
+module.exports = CartService;

+ 12 - 0
app/service/goods.js

@@ -0,0 +1,12 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+
+// 标签表
+class GoodsService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'goods');
+    this.model = this.ctx.model.Goods;
+  }
+}
+
+module.exports = GoodsService;

+ 12 - 0
app/service/goodsTags.js

@@ -0,0 +1,12 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+
+// 标签表
+class GoodsTagsService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'goodsTags');
+    this.model = this.ctx.model.GoodsTags;
+  }
+}
+
+module.exports = GoodsTagsService;

+ 21 - 0
app/service/order.js

@@ -0,0 +1,21 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const _ = require('lodash');
+
+// 订单表
+class OrderService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'order');
+    this.model = this.ctx.model.Order;
+    this.tableModel = this.ctx.model.Table;
+  }
+  async getOrder({ id }) {
+    const table_id = _.get(this.ctx, 'table');
+    const order = await this.model.fetch(id);
+    const table_num = await this.tableModel.fetch(table_id);
+    const obj = { ...order, ...table_num };
+    return obj;
+  }
+}
+
+module.exports = OrderService;

+ 12 - 0
app/service/shop.js

@@ -0,0 +1,12 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+// 店铺表
+class ShopService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'shop');
+    this.model = this.ctx.model.Shop;
+    this.AdminModel = this.ctx.model.Admin;
+  }
+}
+
+module.exports = ShopService;

+ 0 - 21
app/service/shopService.js

@@ -1,21 +0,0 @@
-'use strict';
-const Service = require('egg').Service;
-class ShopService extends Service {
-  async Shop(obj) {
-    const { ctx } = this;
-    // 存储数据
-    // 留神!!!!ctx.model.xxx中xxx指的是model的文件名首字母大写
-    const ShopList = new ctx.model.ShopModel({
-      name: obj.name,
-      // 姓名
-      notice: obj.notice,
-      // 护照号
-      logo: obj.logo || {},
-    });
-    // 数据保留到数据库
-    ShopList.save();
-    return '增加胜利';
-  }
-
-}
-module.exports = ShopService;

+ 12 - 0
app/service/table.js

@@ -0,0 +1,12 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+
+// 桌台表
+class TableService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'table');
+    this.model = this.ctx.model.Table;
+  }
+}
+
+module.exports = TableService;

+ 58 - 0
app/z_router/cart.js

@@ -0,0 +1,58 @@
+'use strict';
+// 测试接口
+const rKey = 'cart'; // routerKey,路由前缀变量
+const cKey = 'cart'; // controllerKey,controller名
+const zhKey = '购物表';
+const routes = [
+  {
+    method: 'get',
+    path: `/${rKey}`,
+    controller: `${cKey}.index`,
+    name: `${cKey}Query`,
+    zh: `${zhKey}列表查询`,
+  },
+  {
+    method: 'get',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.show`,
+    name: `${cKey}Show`,
+    zh: `${zhKey}查询`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}`,
+    controller: `${cKey}.create`,
+    name: `${cKey}Create`,
+    zh: `创建${zhKey}`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.update`,
+    name: `${cKey}Update`,
+    zh: `修改${zhKey}`,
+  },
+  {
+    method: 'delete',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.destroy`,
+    name: `${cKey}Delete`,
+    zh: `删除${zhKey}`,
+  },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};

+ 58 - 0
app/z_router/goods.js

@@ -0,0 +1,58 @@
+'use strict';
+// 测试接口
+const rKey = 'goods'; // routerKey,路由前缀变量
+const cKey = 'goods'; // controllerKey,controller名
+const zhKey = '商品表';
+const routes = [
+  {
+    method: 'get',
+    path: `/${rKey}`,
+    controller: `${cKey}.index`,
+    name: `${cKey}Query`,
+    zh: `${zhKey}列表查询`,
+  },
+  {
+    method: 'get',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.show`,
+    name: `${cKey}Show`,
+    zh: `${zhKey}查询`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}`,
+    controller: `${cKey}.create`,
+    name: `${cKey}Create`,
+    zh: `创建${zhKey}`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.update`,
+    name: `${cKey}Update`,
+    zh: `修改${zhKey}`,
+  },
+  {
+    method: 'delete',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.destroy`,
+    name: `${cKey}Delete`,
+    zh: `删除${zhKey}`,
+  },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};

+ 58 - 0
app/z_router/goodsTags.js

@@ -0,0 +1,58 @@
+'use strict';
+// 测试接口
+const rKey = 'goodsTags'; // routerKey,路由前缀变量
+const cKey = 'goodsTags'; // controllerKey,controller名
+const zhKey = '标签表';
+const routes = [
+  {
+    method: 'get',
+    path: `/${rKey}`,
+    controller: `${cKey}.index`,
+    name: `${cKey}Query`,
+    zh: `${zhKey}列表查询`,
+  },
+  {
+    method: 'get',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.show`,
+    name: `${cKey}Show`,
+    zh: `${zhKey}查询`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}`,
+    controller: `${cKey}.create`,
+    name: `${cKey}Create`,
+    zh: `创建${zhKey}`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.update`,
+    name: `${cKey}Update`,
+    zh: `修改${zhKey}`,
+  },
+  {
+    method: 'delete',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.destroy`,
+    name: `${cKey}Delete`,
+    zh: `删除${zhKey}`,
+  },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};

+ 58 - 0
app/z_router/order.js

@@ -0,0 +1,58 @@
+'use strict';
+// 测试接口
+const rKey = 'order'; // routerKey,路由前缀变量
+const cKey = 'order'; // controllerKey,controller名
+const zhKey = '订单表';
+const routes = [
+  {
+    method: 'get',
+    path: `/${rKey}`,
+    controller: `${cKey}.index`,
+    name: `${cKey}Query`,
+    zh: `${zhKey}列表查询`,
+  },
+  {
+    method: 'get',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.show`,
+    name: `${cKey}Show`,
+    zh: `${zhKey}查询`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}`,
+    controller: `${cKey}.create`,
+    name: `${cKey}Create`,
+    zh: `创建${zhKey}`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.update`,
+    name: `${cKey}Update`,
+    zh: `修改${zhKey}`,
+  },
+  {
+    method: 'delete',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.destroy`,
+    name: `${cKey}Delete`,
+    zh: `删除${zhKey}`,
+  },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};

+ 58 - 0
app/z_router/shop.js

@@ -0,0 +1,58 @@
+'use strict';
+// 测试接口
+const rKey = 'shop'; // routerKey,路由前缀变量
+const cKey = 'shop'; // controllerKey,controller名
+const zhKey = '店铺表';
+const routes = [
+  {
+    method: 'get',
+    path: `/${rKey}`,
+    controller: `${cKey}.index`,
+    name: `${cKey}Query`,
+    zh: `${zhKey}列表查询`,
+  },
+  {
+    method: 'get',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.show`,
+    name: `${cKey}Show`,
+    zh: `${zhKey}查询`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}`,
+    controller: `${cKey}.create`,
+    name: `${cKey}Create`,
+    zh: `创建${zhKey}`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.update`,
+    name: `${cKey}Update`,
+    zh: `修改${zhKey}`,
+  },
+  {
+    method: 'delete',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.destroy`,
+    name: `${cKey}Delete`,
+    zh: `删除${zhKey}`,
+  },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};

+ 58 - 0
app/z_router/table.js

@@ -0,0 +1,58 @@
+'use strict';
+// 测试接口
+const rKey = 'table'; // routerKey,路由前缀变量
+const cKey = 'table'; // controllerKey,controller名
+const zhKey = '桌台表';
+const routes = [
+  {
+    method: 'get',
+    path: `/${rKey}`,
+    controller: `${cKey}.index`,
+    name: `${cKey}Query`,
+    zh: `${zhKey}列表查询`,
+  },
+  {
+    method: 'get',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.show`,
+    name: `${cKey}Show`,
+    zh: `${zhKey}查询`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}`,
+    controller: `${cKey}.create`,
+    name: `${cKey}Create`,
+    zh: `创建${zhKey}`,
+  },
+  {
+    method: 'post',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.update`,
+    name: `${cKey}Update`,
+    zh: `修改${zhKey}`,
+  },
+  {
+    method: 'delete',
+    path: `/${rKey}/:id`,
+    controller: `${cKey}.destroy`,
+    name: `${cKey}Delete`,
+    zh: `删除${zhKey}`,
+  },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};