lrf 2 years ago
parent
commit
53fe1e6838

+ 39 - 0
app/controller/system/config/.platformAct.js

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

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

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

+ 29 - 0
app/model/system/platformAct.js

@@ -0,0 +1,29 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+// content同下
+const act_time = {
+  value: { type: String, zh: '对应的值' },
+  is_use: { type: String, zh: '是否使用' }, // 字典:is_use
+};
+// 平台活动
+const platform_act = {
+  title: { type: String, required: false, zh: '活动标题' }, //
+  share: { type: Array, required: false, zh: '分享图片' }, //
+  cover: { type: Array, required: false, zh: '封面图片' }, //
+  act_time: { type: Object, required: false, zh: '活动时间' }, //  value:值;is_use:字典(is_use)是否启用
+  content: { type: Object, required: false, zh: '活动说明' }, // 富文本;value:值;is_use:字典(is_use)是否启用
+  is_use: { type: String, required: false, default: '1', zh: '是否开启' }, // 字典:is_use,默认不开启
+};
+const schema = new Schema(platform_act, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ title: 1 });
+schema.index({ is_use: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Platform_Act', schema, 'platform_act');
+};

+ 15 - 0
app/service/system/platformAct.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 PlatformActService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'platformact');
+    this.model = this.ctx.model.System.PlatformAct;
+  }
+}
+
+module.exports = PlatformActService;

+ 1 - 0
app/z_router/system/index.js

@@ -8,4 +8,5 @@ module.exports = app => {
   require('./goodsTags')(app); // 商品标签
   require('./actTags')(app); // 活动标签
   require('./config')(app); // 系统设置
+  require('./platformAct')(app); // 平台活动
 };

+ 19 - 0
app/z_router/system/platformAct.js

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