reloaded 5 lat temu
rodzic
commit
3301162ae8

+ 34 - 0
app/controller/.comment.js

@@ -0,0 +1,34 @@
+module.exports = {
+  create: {
+    requestBody: ["!newsid", "uid", "content", "public_time"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["!newsid", "uid", "content", "public_time"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        newsid: "newsid",
+        uid: "uid",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 91 - 0
app/controller/.expert.js

@@ -0,0 +1,91 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!name",
+      "!gender",
+      "!id_number",
+      "email",
+      "address",
+      "img_url",
+      "birthday",
+      "level",
+      "levelname",
+      "position",
+      "school",
+      "education",
+      "degree",
+      "major",
+      "profession",
+      "resume",
+      "project",
+      "academic",
+      "status",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "name",
+      "gender",
+      "id_number",
+      "email",
+      "address",
+      "img_url",
+      "birthday",
+      "level",
+      "levelname",
+      "position",
+      "school",
+      "education",
+      "degree",
+      "major",
+      "profession",
+      "resume",
+      "project",
+      "academic",
+      "status",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        gender: "gender",
+        id_number: "id_number",
+        email: "email",
+        address: "address",
+        img_url: "img_url",
+        birthday: "birthday",
+        level: "level",
+        levelname: "levelname",
+        position: "position",
+        school: "school",
+        education: "education",
+        degree: "degree",
+        major: "major",
+        profession: "profession",
+        resume: "resume",
+        project: "project",
+        academic: "academic",
+        status: "status",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["is_top", "meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 4 - 1
app/controller/.news.js

@@ -14,6 +14,7 @@ module.exports = {
       "is_top",
       "view_times",
       "status",
+      "file_url",
     ],
   },
   destroy: {
@@ -36,6 +37,7 @@ module.exports = {
       "is_top",
       "view_times",
       "status",
+      "file_url",
     ],
   },
   show: {
@@ -60,12 +62,13 @@ module.exports = {
         is_top: "is_top",
         view_times: "view_times",
         status: "status",
+        file_url: "file_url",
       },
     },
     service: "query",
     options: {
       query: ["skip", "limit"],
-      sort: ["meta.createdAt"],
+      sort: ["is_top", "meta.createdAt"],
       desc: true,
       count: true,
     },

+ 20 - 3
app/controller/.user.js

@@ -1,6 +1,14 @@
 module.exports = {
   create: {
-    requestBody: ["uid", "openid", "!passwd", "role_id", "name", "phone"],
+    requestBody: [
+      "userid",
+      "openid",
+      "!passwd",
+      "role_id",
+      "name",
+      "phone",
+      "type",
+    ],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +16,15 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["uid", "openid", "passwd", "role_id", "name", "phone"],
+    requestBody: [
+      "userid",
+      "openid",
+      "passwd",
+      "role_id",
+      "name",
+      "phone",
+      "type",
+    ],
   },
   show: {
     parameters: {
@@ -19,12 +35,13 @@ module.exports = {
   index: {
     parameters: {
       query: {
-        uid: "uid",
+        userid: "userid",
         openid: "openid",
         passwd: "passwd",
         role_id: "role_id",
         name: "name",
         phone: "phone",
+        type: "type",
       },
     },
     service: "query",

+ 21 - 0
app/controller/comment.js

@@ -0,0 +1,21 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.comment.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 评论管理
+class CommentController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.comment;
+  }
+
+  async index() {
+    const res = await this.service.query(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
+}
+
+module.exports = CrudController(CommentController, meta);

+ 18 - 0
app/controller/expert.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.expert.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 部门表管理
+class ExpertController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.expert;
+  }
+
+}
+
+module.exports = CrudController(ExpertController, meta);

+ 21 - 0
app/model/comment.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 评论表
+const CommentSchema = {
+  newsid: { type: String, required: true, maxLength: 500 }, // 信息ID
+  uid: { type: String, required: true, maxLength: 500 }, // 用户ID
+  content: { type: String, required: true }, // 评论内容
+  public_time: { type: String, required: false, maxLength: 500 }, // 发布时间
+};
+
+
+const schema = new Schema(CommentSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Comment', schema, 'comment');
+};

+ 36 - 0
app/model/expert.js

@@ -0,0 +1,36 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 专家基本信息表
+const ExpertSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 专家姓名
+  gender: { type: String, required: false, maxLength: 200 }, // 性别
+  id_number: { type: String, required: false, maxLength: 500 }, // 身份证号
+  phone: { type: String, required: true, maxLength: 200 }, // 电话号码
+  email: { type: String, required: false, maxLength: 200 }, // 邮箱
+  address: { type: String, required: false, maxLength: 500 }, // 地址
+  img_url: { type: String, required: false }, // 头像图片
+  birthday: { type: String, required: false, maxLength: 20 }, // 出生日期
+  level: { type: String, required: false, maxLength: 200 }, // 职称级别
+  levelname: { type: String, required: false, maxLength: 200 }, // 职称名称
+  position: { type: String, required: false, maxLength: 200 }, // 职务
+  school: { type: String, required: false, maxLength: 200 }, // 院校
+  education: { type: String, required: false, maxLength: 200 }, // 学历
+  degree: { type: String, required: false, maxLength: 200 }, // 学位
+  major: { type: String, required: false, maxLength: 200 }, // 专业
+  profession: { type: String, required: false, maxLength: 200 }, // 从事专业
+  resume: { type: String, required: false, maxLength: 5000 }, // 工作简历
+  project: { type: String, required: false, maxLength: 5000 }, // 项目
+  academic: { type: String, required: false, maxLength: 5000 }, // 学术成就
+  status: { type: String, required: false, default: "0", maxLength: 200 }, // 审核状态,0-注册,1-通过,2-拒绝
+};
+
+const schema = new Schema(ExpertSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Expert', schema, 'expert');
+};

+ 1 - 0
app/model/news.js

@@ -17,6 +17,7 @@ const NewsSchema = {
   is_top: { type: String, required: false, maxLength: 200, default: '0' }, // 是否推荐,0-不推荐,1-推荐
   view_times: { type: String, required: false, maxLength: 200 }, // 浏览次数
   status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态,0-草稿,1-未审核,2-已审核
+  file_url: { type: String, required: false }, // 文件路径
 };
 
 

+ 2 - 1
app/model/user.js

@@ -5,12 +5,13 @@ const { Secret } = require('naf-framework-mongoose/lib/model/schema');
 
 // 用户表
 const UserSchema = {
-  uid: { type: String, required: false, maxLength: 200 }, // 用户信息表id
+  userid: { type: String, required: false, maxLength: 200 }, // 用户信息表id
   openid: { type: String, required: false, maxLength: 200 }, // 用户微信openid
   passwd: { type: { Secret }, required: true, select: false, maxLength: 200 }, // 用户密码
   role_id: { type: String, required: false, maxLength: 200 }, // 用户权限id
   name: { type: String, required: false, maxLength: 200 }, // 用户名
   phone: { type: String, required: true, maxLength: 64 }, // 手机号
+  type: { type: String, required: false, maxLength: 200 }, // 用户类型,0-超级管理员,1-管理员,2-专家,3-普通用户
 };
 
 

+ 8 - 0
app/router.js

@@ -31,4 +31,12 @@ module.exports = app => {
   // 人员表设置路由
   router.resources('staff', '/api/count/staff', controller.staff); // index、create、show、destroy
   router.post('staff', '/api/count/staff/update/:id', controller.staff.update);
+
+  // 评论表设置路由
+  router.resources('comment', '/api/live/comment', controller.comment); // index、create、show、destroy
+  router.post('comment', '/api/live/comment/update/:id', controller.comment.update);
+
+  // 专家表设置路由
+  router.resources('expert', '/api/live/expert', controller.expert); // index、create、show、destroy
+  router.post('expert', '/api/live/expert/update/:id', controller.expert.update);
 };

+ 31 - 0
app/service/comment.js

@@ -0,0 +1,31 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class CommentService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'comment');
+    this.model = this.ctx.model.Comment;
+    this.umodel = this.ctx.model.User;
+  }
+
+  async query({ skip, limit, ...info }) {
+    const total = await (await this.model.find(info)).length;
+    const comments = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
+    const newdatas = [];
+    for (const comment of comments) {
+      const user = await this.umodel.findById(comment.uid);
+      comment.uname = user.data.name;
+      newdatas.push(comment);
+    }
+    return { data: newdatas, total };
+  }
+
+}
+
+module.exports = CommentService;

+ 18 - 0
app/service/expert.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class ExpertService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'expert');
+    this.model = this.ctx.model.Expert;
+  }
+
+}
+
+module.exports = ExpertService;

+ 6 - 6
app/service/user.js

@@ -16,7 +16,7 @@ class UserService extends CrudService {
 
   // 重写创建方法
   async create(data) {
-    const { uid, openid, passwd, role_id, name, phone } = data;
+    const { userid, openid, passwd, role_id, name, phone, type } = data;
     // console.log(data);
     assert(name && phone && passwd, '缺少部分信息项');
     assert(/^\d{11}$/i.test(phone), '无效的手机号');
@@ -35,7 +35,7 @@ class UserService extends CrudService {
   async uppasswd(data) {
     const { userid, oldpasswd, newpasswd } = data;
     assert(userid && oldpasswd && newpasswd, '缺少部分信息项');
-    // 根据用户id查询其他用户表中是否存在相应数据
+    // 根据用户id查询用户表中是否存在相应数据
     const user = await this.model.findById(userid, '+passwd');
     // 如果用户不存在抛出异常
     if (!user) {
@@ -78,11 +78,11 @@ class UserService extends CrudService {
   }
 
   // 创建登录Token
-  async createJwt({ id, uid, openid, role_id, name, phone }) {
-    const { secret, expiresIn = '1d', issuer } = this.config.jwt;
+  async createJwt({ id, userid, openid, role_id, name, phone, type }) {
+    const { secret, expiresIn = '1d', issuer = type } = this.config.jwt;
     const subject = phone;
-    const _userid = id;
-    const res = { userid: _userid, uid, openid, role_id, name, phone };
+    const _uid = id;
+    const res = { userid, uid: _uid, openid, role_id, name, phone, type };
     const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
     return token;
   }