lrf402788946 %!s(int64=4) %!d(string=hai) anos
pai
achega
b1755a658b

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

@@ -0,0 +1,59 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "title",
+      "origin",
+      "type",
+      "content",
+      "imgUrl",
+      "fileUrl",
+      "contact",
+      "remark",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "title",
+      "origin",
+      "renew_time",
+      "type",
+      "content",
+      "imgUrl",
+      "fileUrl",
+      "contact",
+      "remark",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        user_id: "user_id",
+        "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,
+    },
+  },
+};

+ 13 - 0
app/controller/service.js

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

+ 1 - 1
app/model/refute.js

@@ -12,7 +12,7 @@ const refute = {
   content: { type: String }, // 内容
   content: { type: String }, // 内容
   website: { type: String }, // 文字网址
   website: { type: String }, // 文字网址
   fileUrl: { type: String }, // 文章视频
   fileUrl: { type: String }, // 文章视频
-  imgUrl: { type: String }, // 图片
+  imgUrl: { type: String }, // 封面图片
   read: { type: Number, default: 0 }, // 阅读数
   read: { type: Number, default: 0 }, // 阅读数
   remark: { type: String, maxLength: 200 },
   remark: { type: String, maxLength: 200 },
   create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
   create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },

+ 29 - 0
app/model/service.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 service = {
+  user_id: { type: ObjectId },
+  title: { type: String }, // 标题
+  origin: { type: String }, // 来源
+  renew_time: { type: String }, // 更新时间
+  type: { type: String }, // 类型:0=>文字;1=>图文;2=>科普视频;3=>培训视频
+  content: { type: String }, // 内容
+  imgUrl: { type: Array }, // 图片 [{url:uri}]
+  fileUrl: { type: Array }, // 视频 [{url:uri}]
+  contact: { type: Object }, // 服务联系人:name-姓名;phone-联系电话;email-电子邮箱;address-联系地址
+  read: { type: Number, default: 0 }, // 阅读数
+  remark: { type: String, maxLength: 200 },
+  create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
+};
+const schema = new Schema(service, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Service', schema, 'service');
+};

+ 1 - 0
app/router.js

@@ -11,4 +11,5 @@ module.exports = app => {
   router.post('user', `${profix}init`, controller.user.init);
   router.post('user', `${profix}init`, controller.user.init);
   require('./router/refute')(app); // 文章/辟谣
   require('./router/refute')(app); // 文章/辟谣
   require('./router/topic')(app); // 社区话题
   require('./router/topic')(app); // 社区话题
+  require('./router/service')(app); // 咨询服务
 };
 };

+ 12 - 0
app/router/service.js

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

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