lrf 2 年之前
父節點
當前提交
6188f20ff7

+ 43 - 0
app/controller/shop/config/.goodsSet.js

@@ -0,0 +1,43 @@
+module.exports = {
+  create: {
+    requestBody: ['name', 'set', 'shop', 'goods', 'spec', 'is_use', 'sell_money', 'single_stock', 'stock'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['name', 'set', 'shop', 'goods', 'spec', 'is_use', 'sell_money', 'single_stock', 'stock'],
+  },
+  show: {
+    parameters: {
+      params: ['!id'],
+    },
+    service: 'fetch',
+  },
+  index: {
+    parameters: {
+      query: {
+        'meta.createdAt@start': 'meta.createdAt@start',
+        'meta.createdAt@end': 'meta.createdAt@end',
+        name: '%name%',
+        shop: 'shop',
+        goods: 'goods',
+        spec: 'spec',
+        is_use: 'is_use',
+        single_stock: 'single_stock',
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/shop/goodsSet.js

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

+ 32 - 0
app/model/shop/goodsSet.js

@@ -0,0 +1,32 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 套装表
+const goodsSet = {
+  name: { type: String, required: false, zh: '套装名称' }, //
+  set: { type: Array, required: false, zh: '商品规格组合' }, //
+  shop: { type: Array, required: false, zh: '参与组合的店铺id集合' }, // 由set来
+  goods: { type: Array, required: false, zh: '参与组合的商品id集合' }, // 由set来
+  spec: { type: Array, required: false, zh: '参与组合的规格id集合' }, // 由set来
+  is_use: { type: String, required: false, default: '0', zh: '是否使用' }, // 字典:is_use
+  sell_money: { type: Number, required: false, zh: '套装销售金额' }, // 由set中的set_money之后而来
+  single_stock: { type: String, required: false, default: '1', zh: '单独设置库存' }, // 字典:is_use
+  stock: { type: Number, required: false, default: '0', zh: '库存数量' }, //
+};
+const schema = new Schema(goodsSet, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ name: 1 });
+schema.index({ shop: 1 });
+schema.index({ goods: 1 });
+schema.index({ spec: 1 });
+schema.index({ is_use: 1 });
+schema.index({ single_stock: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('GoodsSet', schema, 'goodsSet');
+};

+ 15 - 0
app/service/shop/goodsSet.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 GoodsSetService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'goodsset');
+    this.model = this.ctx.model.Shop.GoodsSet;
+  }
+}
+
+module.exports = GoodsSetService;

+ 19 - 0
app/z_router/shop/goodsSet.js

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'goodsSet';
+const ckey = 'shop.goodsSet';
+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 - 0
app/z_router/shop/index.js

@@ -11,4 +11,5 @@ module.exports = app => {
   require('./shopInBill')(app); // 店铺流水
   require('./shopCashOut')(app); // 店铺申请提现
   require('./shopNotice')(app); // 店铺系统消息
+  require('./goodsSet')(app); // 商品套装
 };