liuyu 5 lat temu
rodzic
commit
b0585a4956

+ 95 - 0
app/controller/.expertsuser.js

@@ -0,0 +1,95 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!name",
+      "!password",
+      "gender",
+      "cardnumber",
+      "phone",
+      "email",
+      "addr",
+      "img_path",
+      "birthday",
+      "level",
+      "levelname",
+      "position",
+      "school",
+      "xl",
+      "xw",
+      "major",
+      "professional",
+      "resume",
+      "project",
+      "academic",
+      "paper",
+      "remark",
+      "status",
+      "role"
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "name",
+      "password",
+      "gender",
+      "cardnumber",
+      "phone",
+      "email",
+      "addr",
+      "img_path",
+      "birthday",
+      "level",
+      "levelname",
+      "position",
+      "school",
+      "xl",
+      "xw",
+      "major",
+      "professional",
+      "resume",
+      "project",
+      "academic",
+      "paper",
+      "remark",
+      "status",
+      "role"
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        cardnumber: "cardnumber",
+        phone: "phone",
+        email: "email",
+        addr: "addr",
+        img_path: "img_path",
+        school: "school",
+        level: "level",
+        position: "position",
+        xl: "xl",
+        xw: "xw",
+        status: "status",
+        role: "role"
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 19 - 0
app/controller/expertsuser.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.expertsuser.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 专家用户管理
+class ExpertsuserController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.expertsuser;
+  }
+
+
+}
+
+module.exports = CrudController(ExpertsuserController, meta);

+ 41 - 0
app/model/expertsuser.js

@@ -0,0 +1,41 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { Secret } = require('naf-framework-mongoose/lib/model/schema');
+
+// 专家基本信息表
+const ExpertsuserSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 专家姓名
+  gender: { type: String, required: false, maxLength: 200 }, // 性别
+  password: { type: Secret, required: false, select: false }, // 登录密码
+  cardnumber: { type: String, required: false, maxLength: 500 }, // 身份证号
+  phone: { type: String, required: true, maxLength: 200 }, // 电话号码
+  email: { type: String, required: false, maxLength: 200 }, // 邮箱
+  addr: { type: String, required: false, maxLength: 500 }, // 地址
+  img_path: { 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 }, // 院校
+  xl: { type: String, required: false, maxLength: 200 }, // 学历
+  xw: { type: String, required: false, maxLength: 200 }, // 学位
+  major: { type: String, required: false, maxLength: 200 }, // 专业
+  professional: { 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 }, // 学术成就
+  paper: { type: String, required: false, maxLength: 5000 }, // 论文
+  remark: { type: String, required: false, maxLength: 5000 }, // 备注
+  role: { type: String, required: false, maxLength: 20 }, // 角色
+  status: { type: String, required: false, default: '0', maxLength: 200 }, // 审核状态,0-注册,1-通过,2-拒绝
+};
+
+const schema = new Schema(ExpertsuserSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Expertsuser', schema, 'experts_user');
+};

+ 11 - 0
app/router.js

@@ -3,14 +3,25 @@
 /**
  * @param {Egg.Application} app - egg application
  */
+const ueditor = require('egg-ueditor');
 module.exports = app => {
   const { router, controller } = app;
+  app.all('/ueditor', ueditor());
   router.get('/', controller.home.index);
 
+  router.all('/ueditor', ueditor([ 'app/public', 'public' ], {
+    imageAllowFiles: [ '.png', '.jpg', '.jpeg' ],
+    imagePathFormat: '/upload/ueditor/image/{yyyy}{mm}{dd}/{filename}', // 保存为原文件名
+  }));
+
   // 科技超市用户表设置路由
   router.resources('user', '/api/market/user', controller.user); // index、create、show、destroy
   router.post('user', '/api/market/user/:id', controller.user.update);
 
+  // 专家用户表设置路由
+  router.resources('expertsuser', '/api/market/expertsuser', controller.expertsuser); // index、create、show、destroy
+  router.post('expertsuser', '/api/market/expertsuser/:id', controller.expertsuser.update);
+
   // 产品信息表设置路由
   router.resources('product', '/api/market/product', controller.product); // index、create、show、destroy
   router.post('product', '/api/market/product/update/:id', controller.product.update);

+ 79 - 0
app/service/expertsuser.js

@@ -0,0 +1,79 @@
+'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;
+const jwt = require('jsonwebtoken');
+class ExpertuserService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'experts_user');
+    this.model = this.ctx.model.Expertsuser;
+  }
+
+  async create(data) {
+    const { name, password } = data;
+    assert(name, '用户名不能为空');
+    assert(password, '密码不能为空');
+    const { phone } = data;
+    const has_phone = await this.model.findOne({ phone });
+    if (has_phone) {
+      throw new BusinessError('此手机号已被注册,请更换手机号');
+    }
+    const newdata = data;
+    newdata.password = { secret: password };
+    const res = await this.model.create(newdata);
+    if (res) {
+      const url = this.ctx.app.config.axios.auth.baseUrl;
+      const newdata = { name, phone: data.phone, passwd: password, uid: res.id, role: data.role };
+      await this.ctx.curl(url, {
+        method: 'post',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+        data: JSON.stringify(newdata),
+      });
+    }
+    return res;
+  }
+
+  async update({ id }, data) {
+    const user = await this.model.findById(id);
+    const { phone } = data;
+    const phoneList = await this.model.find({ phone });
+    const is_has = phoneList.find(f => f.id !== id);
+    if (is_has) throw new BusinessError('此手机号已被注册,请更换手机号');
+    if (data.name) {
+      user.name = data.name;
+    }
+    if (data.password) {
+      user.password = { secret: data.password };
+    }
+    user.cardnumber = data.cardnumber;
+    user.phone = data.phone;
+    user.email = data.email;
+    user.addr = data.addr;
+    user.img_path = data.img_path;
+    user.birthday = data.birthday;
+    user.level = data.level;
+    user.levelname = data.levelname;
+    user.position = data.position;
+    user.school = data.school;
+    user.xl = data.xl;
+    user.xw = data.xw;
+    user.major = data.major;
+    user.professional = data.professional;
+    user.resume = data.resume;
+    user.project = data.project;
+    user.academic = data.academic;
+    user.paper = data.paper;
+    user.remark = data.remark;
+    user.role = data.role;
+    return await user.save();
+  }
+}
+
+module.exports = ExpertuserService;