lrf 2 years ago
parent
commit
56c81f97df

+ 39 - 0
app/controller/user/config/.notice.js

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

+ 13 - 0
app/controller/user/notice.js

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

+ 23 - 0
app/model/user/notice.js

@@ -0,0 +1,23 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+// 系统通知表
+const notice = {
+  customer: { type: String, required: true, zh: '用户', ref: 'User.User' }, //
+  time: { type: String, required: false, zh: '发送时间' }, //
+  content: { type: String, required: false, zh: '内容' }, //
+  status: { type: String, required: false, zh: '状态' }, // 字典:notice_status
+};
+const schema = new Schema(notice, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ customer: 1 });
+schema.index({ status: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Notice', schema, 'notice');
+};

+ 15 - 0
app/service/user/notice.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 NoticeService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'notice');
+    this.model = this.ctx.model.User.Notice;
+  }
+}
+
+module.exports = NoticeService;

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

@@ -11,4 +11,5 @@ module.exports = app => {
   require('./storeGoods')(app); // 收藏商品
   require('./cashBack')(app); // 返现
   require('./cashOut')(app); // 提现
+  require('./notice')(app); // 系统消息
 };

+ 19 - 0
app/z_router/user/notice.js

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