guhongwei há 4 anos atrás
pai
commit
56c1d00749

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

@@ -0,0 +1,115 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!name",
+      "education",
+      "school",
+      "birthDate",
+      "phone",
+      "qqwx",
+      "email",
+      "company",
+      "zwzc",
+      "expertise",
+      "expertimage",
+      "workexperience",
+      "scientific",
+      "undertakingproject",
+      "scienceaward",
+      "social",
+      "userid",
+      "code",
+      "role",
+      "status",
+      "pid",
+      "deptname",
+      "password",
+      "isdel",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "!name",
+      "education",
+      "school",
+      "birthDate",
+      "phone",
+      "qqwx",
+      "email",
+      "company",
+      "zwzc",
+      "expertise",
+      "expertimage",
+      "workexperience",
+      "scientific",
+      "undertakingproject",
+      "scienceaward",
+      "social",
+      "userid",
+      "code",
+      "role",
+      "status",
+      "pid",
+      "deptname",
+      "password",
+      "isdel",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "%name%",
+        education: "education",
+        phone: "phone",
+        email: "email",
+        birthDate: "birthDate",
+        school: "school",
+        qqwx: "qqwx",
+        company: "company",
+        social: "social",
+        isdel: "isdel",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+  indexQuery: {
+    parameters: {
+      query: {
+        name: "%name%",
+        education: "education",
+        phone: "phone",
+        email: "email",
+        birthDate: "birthDate",
+        school: "school",
+        qqwx: "qqwx",
+        company: "company",
+        social: "social",
+        isdel: "isdel",
+      },
+    },
+    service: "indexQuery",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 147 - 0
app/controller/.marketuser.js

@@ -0,0 +1,147 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!name",
+      "!password",
+      "cardnumber",
+      "phone",
+      "email",
+      "addr",
+      "img_path",
+      "is_qy",
+      "cardfile_a",
+      "cardfile_b",
+      "img_qy",
+      "resume",
+      "major",
+      "institution_type",
+      "institution_name",
+      "institution_code",
+      "institution_nature",
+      "office_phone",
+      "profession",
+      "status",
+      "is_del",
+      "role",
+      "token",
+      "deptname",
+      "pid",
+      "code",
+      "columnid",
+      "openid",
+      "companytype",
+      "companydate",
+      "companycapital",
+      "companyperson",
+      "sndqyzsr",
+      "sndyffy",
+      "companytotal",
+      "zjzyfrs",
+      "companybrief",
+      "mainproduct",
+      "qualifications",
+      "isdel",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "name",
+      "password",
+      "cardnumber",
+      "phone",
+      "email",
+      "addr",
+      "img_path",
+      "is_qy",
+      "cardfile_a",
+      "cardfile_b",
+      "img_qy",
+      "resume",
+      "major",
+      "institution_type",
+      "institution_name",
+      "institution_code",
+      "institution_nature",
+      "office_phone",
+      "profession",
+      "status",
+      "is_del",
+      "role",
+      "token",
+      "deptname",
+      "pid",
+      "code",
+      "columnid",
+      "openid",
+      "companytype",
+      "companydate",
+      "companycapital",
+      "companyperson",
+      "sndqyzsr",
+      "sndyffy",
+      "companytotal",
+      "zjzyfrs",
+      "companybrief",
+      "mainproduct",
+      "qualifications",
+      "isdel",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        password: "password",
+        cardnumber: "cardnumber",
+        phone: "phone",
+        email: "email",
+        addr: "addr",
+        img_path: "img_path",
+        is_qy: "is_qy",
+        cardfile_a: "cardfile_a",
+        cardfile_b: "cardfile_b",
+        img_qy: "img_qy",
+        resume: "resume",
+        major: "major",
+        institution_type: "institution_type",
+        institution_name: "institution_name",
+        institution_code: "institution_code",
+        institution_nature: "institution_nature",
+        office_phone: "office_phone",
+        profession: "profession",
+        status: "status",
+        is_del: "is_del",
+        role: "role",
+        token: "token",
+        deptname: "deptname",
+        pid: "pid",
+        code: "code",
+        columnidg: "columnid",
+        openid: "openid",
+        isdel:"isdel",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+  login: {
+    requestBody: ["phone", "password", "role"],
+    service: "login",
+  },
+};

+ 26 - 0
app/controller/buff.js

@@ -0,0 +1,26 @@
+'use strict';
+
+const _ = require('lodash');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 产品审核表管理
+class BuffController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.buff;
+  }
+
+  async userlist() {
+    const res = await this.service.userlist(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
+  async userCodeList() {
+    const res = await this.service.userlist(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
+
+}
+
+module.exports = BuffController;

+ 24 - 0
app/controller/expertsuser.js

@@ -0,0 +1,24 @@
+'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;
+  }
+
+  // 个人升级成专家
+  async upgrade() {
+    const data = await this.service.upgrade(this.ctx.params, this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
+
+}
+
+module.exports = CrudController(ExpertsuserController, meta);

+ 20 - 0
app/controller/marketuser.js

@@ -0,0 +1,20 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.marketuser.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科技超市用户管理
+class marketuserController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.marketuser;
+  }
+  async uppasswd() {
+    const res = await this.service.uppasswd(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+}
+
+module.exports = CrudController(marketuserController, 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 }, // 专家姓名
+  education: { type: String, required: false, maxLength: 200 }, // 最高学历
+  school: { type: String, required: false, maxLength: 200 }, // 毕业院校
+  birthDate: { type: String, required: false, maxLength: 200 }, // 出生日期
+  phone: { type: String, required: false, maxLength: 11 }, // 联系电话
+  qqwx: { type: String, required: false, maxLength: 200 }, // qq&微信
+  email: { type: String, required: false, maxLength: 200 }, // 邮箱
+  company: { type: String, required: false, maxLength: 500 }, // 单位名称
+  zwzc: { type: String, required: false, maxLength: 200 }, // 职务职称
+  expertise: { type: String, required: false, maxLength: 200 }, // 擅长领域
+  expertimage: { type: String, required: false, maxLength: 200 }, // 商务图片
+  workexperience: { type: String, required: false, maxLength: 500 }, // 工作经历
+  scientific: { type: String, required: false, maxLength: 300 }, // 科研综述
+  undertakingproject: { type: String, required: false, maxLength: 200 }, // 承担项目
+  scienceaward: { type: String, required: false, maxLength: 200 }, // 科技奖励
+  social: { type: String, required: false, maxLength: 200 }, // 社会任职
+  userid: { type: String, required: false }, // 用户表主键id
+  code: { type: String, required: false }, // 邀请码
+  role: { type: String, required: false, maxLength: 20 }, // 角色
+  status: { type: String, required: false, default: "0", maxLength: 200 }, // 审核状态,0-注册,1-通过,2-拒绝
+  pid: { type: String, required: false }, // 父id
+  deptname: { type: String, required: false }, // 机构名称
+  password: { type: Secret, select: false }, // 密码
+  isdel: { type: String, required: false, default: "0" }, // 0=>未删除;1=>已删除
+};
+
+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');
+};

+ 50 - 0
app/model/marketuser.js

@@ -0,0 +1,50 @@
+'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 MarketuserSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 用户名
+  password: { type: Secret, required: true, select: false }, // 登录密码
+  phone: { type: String, required: false, maxLength: 200 }, // 电话号码
+  email: { type: String, required: false, maxLength: 200 }, // 邮箱
+  addr: { type: String, required: false, maxLength: 500 }, // 地址
+  img_path: { type: String, required: false }, // 头像图片
+  resume: { type: String, required: false }, // 个人简介
+  major: { type: String, required: false }, // 专业领域
+  institution_code: { type: String, required: false, maxLength: 500 }, // 机构代码
+  office_phone: { type: String, required: false, maxLength: 500 }, // 办公电话
+  profession: { type: String, required: false, maxLength: 500 }, // 所属行业
+  status: { type: String, required: false, default: '0', maxLength: 200 }, // 审核状态,0-注册,1-通过,2-拒绝
+  is_del: { type: String, required: false, maxLength: 200 }, // 是否删除,0-否,1-是
+  role: { type: String, required: false, maxLength: 200 }, // 1-管理员,2-个人,3-企业管理员,4-子管理员
+  token: { type: String, required: false, maxLength: 500 }, // 令牌
+  columnid: [ String ],
+  pid: { type: String, required: false }, // 父id
+  deptname: { type: String, required: false }, // 机构名称
+  code: { type: String, required: false }, // 邀请码
+  openid: { type: String, required: false }, // 微信openid
+  companytype: { type: String, required: false, maxLength: 300 }, // 注册类型
+  companydate: { type: String, required: false, maxLength: 300 }, // 注册时间
+  companycapital: { type: String, required: false, maxLength: 300 }, // 注册资金
+  companyperson: { type: String, required: false, maxLength: 300 }, // 企业法人
+  sndqyzsr: { type: String, required: false, maxLength: 300 }, // 上年度企业总收入
+  sndyffy: { type: String, required: false, maxLength: 300 }, // 上年度研发费用
+  companytotal: { type: String, required: false, maxLength: 300 }, // 企业总人数
+  zjzyfrs: { type: String, required: false, maxLength: 300 }, // 专&兼职研发人数
+  companybrief: { type: String, required: false }, // 企业简介
+  mainproduct: { type: String, required: false, maxLength: 300 }, // 主要产品
+  qualifications: { type: String, required: false, maxLength: 300 }, // 企业资质&荣誉
+  isdel: { type: String, required: false, default: '0' }, // 0=>未删除;1=>已删除
+};
+
+
+const schema = new Schema(MarketuserSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Marketuser', schema, 'marketuser');
+};

+ 12 - 0
app/router.js

@@ -32,4 +32,16 @@ module.exports = app => {
   // 用户退出登录
   router.post('/api/userjurisform/logout', controller.login.destroy);
 
+
+  router.get('/api/userjurisform/marketuser/hwsxg', controller.buff.userCodeList);
+  // 科技超市用户表设置路由
+  router.post('marketuser', '/api/userjurisform/marketuser/uppasswd', controller.marketuser.uppasswd);
+  router.resources('marketuser', '/api/userjurisform/marketuser', controller.marketuser); // index、create、show、destroy
+  router.post('marketuser', '/api/userjurisform/marketuser/:id', controller.marketuser.update);
+
+  router.get('expertsuser', '/api/userjurisform/expertsuser/indexquery', controller.expertsuser.indexQuery);
+
+  router.resources('expertsuser', '/api/userjurisform/expertsuser', controller.expertsuser); // index、create、show、destroy
+  router.post('expertsuser', '/api/userjurisform/expertsuser/update/:id', controller.expertsuser.update);
+  router.post('expertsuser', '/api/userjurisform/expertsuser/upgrade/:id', controller.expertsuser.upgrade);
 };

+ 183 - 0
app/service/expertsuser.js

@@ -0,0 +1,183 @@
+'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;
+    this.umodel = this.ctx.model.User;
+  }
+
+  async create(data) {
+    const { name, password, role } = data;
+    assert(name, '用户名不能为空');
+    assert(password, '密码不能为空');
+    const { phone } = data;
+    const has_phone = await this.model.findOne({ phone, role });
+    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,
+        pid: data.pid,
+        deptname: data.deptname,
+        code: data.code,
+      };
+      const user = await this.ctx.curl(url, {
+        method: 'post',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+        data: JSON.stringify(newdata),
+      });
+      if (user.data.errcode === 0) {
+        const result = await this.model.findById(res.id);
+        result.userid = user.data.data.id;
+        result.save();
+      }
+    }
+    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 };
+    }
+    const model = [
+      'name',
+      'education',
+      'school',
+      'birthDate',
+      'phone',
+      'qqwx',
+      'email',
+      'company',
+      'zwzc',
+      'expertise',
+      'expertimage',
+      'workexperience',
+      'scientific',
+      'undertakingproject',
+      'scienceaward',
+      'social',
+      'userid',
+      'code',
+      'role',
+      'status',
+      'pid',
+      'deptname',
+      'password',
+    ];
+    for (const key of model) {
+      if (data[key]) {
+        user[key] = data[key];
+      }
+    }
+    const res = await user.save();
+    if (res) {
+      const url =
+        this.ctx.app.config.axios.auth.baseUrl + '/updatebyuid/' + res.id;
+      const newdata = { name: data.name, deptname: data.deptname };
+      await this.ctx.curl(url, {
+        method: 'post',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+        data: JSON.stringify(newdata),
+      });
+    }
+    return res;
+  }
+
+  async upgrade({ id }, data) {
+    await this.umodel.deleteOne({ _id: ObjectId(id) });
+    const { phone, uid } = data;
+    const phoneList = await this.model.find({ phone });
+    const is_has = phoneList.find(f => f.id !== id);
+    if (is_has) throw new BusinessError('此手机号已被注册,请更换手机号');
+    const user = {};
+    if (data.name) {
+      user.name = data.name;
+    }
+    if (data.password) {
+      user.password = { secret: data.password };
+    }
+    user.phone = data.phone;
+    user.code = data.code;
+    user.role = data.role;
+    user.status = data.status;
+    user.company = data.company;
+    user.school = data.school;
+    user.birthDate = data.birthDate;
+    user.qqwx = data.qqwx;
+    user.email = data.email;
+    user.expertimage = data.expertimage;
+    user.workexperience = data.workexperience;
+    user.scientific = data.scientific;
+    user.undertakingproject = data.undertakingproject;
+    user.scienceaward = data.scienceaward;
+    user.expertise = data.expertise;
+    user.education = data.education;
+    user.zwzc = data.zwzc;
+    user.social = data.social;
+    const res = await this.model.create(user);
+    if (res) {
+      const url = this.ctx.app.config.axios.auth.baseUrl + '/update/' + uid;
+      const newdata = { uid: res.id, role: data.role, name: data.name };
+      await this.ctx.curl(url, {
+        method: 'post',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+        data: JSON.stringify(newdata),
+      });
+    }
+    return res;
+  }
+
+  // 首页查询
+  async indexQuery(data, { limit }) {
+    const res = await this.model.aggregate([
+      { $match: data },
+      { $sample: { size: parseInt(limit) } },
+    ]);
+    return res;
+  }
+  // 重写删除方法
+  /**
+   * 根据id删除=>修改isdel为1
+   * @param {Object} {id} 只接收id,不过需要解构,因为是object形式过来的
+   */
+  async delete({ id }) {
+    const res = await this.model.update({ _id: ObjectId(id) }, { isdel: '1' });
+    return res;
+  }
+}
+
+module.exports = ExpertuserService;

+ 169 - 0
app/service/marketuser.js

@@ -0,0 +1,169 @@
+'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 UserService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'marketuser');
+    this.model = this.ctx.model.Marketuser;
+    this.modeluser = this.ctx.model.User;
+  }
+
+  async create(data) {
+    const { name, password, role, phone } = data;
+    assert(name, '用户名不能为空');
+    assert(password, '密码不能为空');
+    const has_phone = await this.model.findOne({ phone, role });
+    if (has_phone) {
+      throw new BusinessError('此身份手机号已被注册,请更换手机号');
+    }
+    data.password = { secret: password };
+    const res = await this.model.create(data);
+    if (res) {
+      const newdata = {
+        name,
+        phone: data.phone,
+        passwd: data.password,
+        uid: res.id,
+        role: data.role,
+        pid: data.pid,
+        deptname: data.deptname,
+        code: data.code,
+      };
+      if (role === '5') {
+        newdata.phone = data.institution_code;
+      }
+      const auth_user = await this.modeluser.findOne({ phone, role });
+      if (auth_user) {
+        throw new BusinessError('此身份手机号已被注册,请更换手机号');
+      }
+      const authres = await this.modeluser.create(newdata);
+      return authres;
+    }
+    return res;
+  }
+
+  // 用户修改密码
+  async uppasswd(data) {
+    const { uid, newpasswd } = data;
+    assert(uid && newpasswd, '缺少部分信息项');
+    // 根据用户id查询其他用户表中是否存在相应数据
+    const user = await this.model.findById(uid, '+password');
+    // 如果用户不存在抛出异常
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    user.password = { secret: data.newpasswd };
+    await user.save();
+  }
+
+  async update({ id }, data) {
+    const user = await this.modeluser.findById(id);
+    if (user) {
+      const res = await this.ctx.service.user.update({ id }, data);
+      if (res) {
+        const marketuser = await this.model.findById(user.uid);
+        if (marketuser) {
+          marketuser.name = data.name;
+          marketuser.phone = data.phone;
+          marketuser.addr = data.addr;
+          marketuser.img_path = data.img_path;
+          marketuser.institution_code = data.phone;
+          marketuser.office_phone = data.office_phone;
+          marketuser.profession = data.profession;
+          marketuser.status = data.status;
+          marketuser.role = data.role;
+          marketuser.pid = data.pid;
+          marketuser.deptname = data.deptname;
+          marketuser.code = data.code;
+          marketuser.companytype = data.companytype;
+          marketuser.companydate = data.companydate;
+          marketuser.companycapital = data.companycapital;
+          marketuser.companyperson = data.companyperson;
+          marketuser.sndqyzsr = data.sndqyzsr;
+          marketuser.sndyffy = data.sndyffy;
+          marketuser.companytotal = data.companytotal;
+          marketuser.zjzyfrs = data.zjzyfrs;
+          marketuser.companybrief = data.companybrief;
+          marketuser.mainproduct = data.mainproduct;
+          marketuser.qualifications = data.qualifications;
+        }
+        const marketres = await marketuser.save();
+        return marketres;
+      }
+    }
+  }
+
+  async login({ phone, password, role }) {
+    assert(phone, '手机号不能为空');
+    assert(password, '密码不能为空');
+    assert(role, '需要选择用户类型');
+    const user = await this.model.findOne({ phone, role }, '+password');
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    if (user.password.secret !== password) {
+      throw new BusinessError(ErrorCode.BAD_PASSWORD);
+    }
+    if (user.status === '0') {
+      throw new BusinessError('用户未审核,请等待审核后再登陆');
+    } else if (user.status === '2') {
+      throw new BusinessError('用户申请被拒绝,请联系平台管理员');
+    }
+    return await this.createJwt(user);
+  }
+
+  // 创建登录Token
+  async createJwt({
+    id,
+    name,
+    phone,
+    is_qy,
+    img_path,
+    email,
+    resume,
+    major,
+    office_phone,
+    profession,
+    role,
+    status,
+    columnid,
+  }) {
+    const { secret, expiresIn = '1d', issuer } = this.config.jwt;
+    const subject = phone;
+    // const _userid = id;
+    const res = {
+      name,
+      phone,
+      is_qy,
+      id,
+      img_path,
+      email,
+      resume,
+      major,
+      office_phone,
+      profession,
+      role,
+      status,
+      columnid,
+    };
+    const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
+    return token;
+  }
+  // 重写删除方法
+  /**
+   * 根据id删除=>修改isdel为1
+   * @param {Object} {id} 只接收id,不过需要解构,因为是object形式过来的
+   */
+  async delete({ id }) {
+    const res = await this.model.update({ _id: ObjectId(id) }, { isdel: '1' });
+    return res;
+  }
+}
+
+module.exports = UserService;

+ 11 - 48
app/service/user.js

@@ -40,54 +40,17 @@ class UserService extends CrudService {
 
   // 重写修改方法
   async update({ id }, data) {
-    const {
-      name,
-      phone,
-      passwd,
-      openid,
-      role,
-      menus,
-      remark,
-      uid,
-      deptid,
-      deptname,
-      pid,
-    } = data;
-    const user = await this.model.findById(id, '+passwd');
-    if (name) {
-      user.name = name;
-    }
-    if (phone) {
-      user.phone = phone;
-    }
-    if (passwd) {
-      const newpasswd = await this.createJwtPwd(passwd);
-      user.passwd = { secret: newpasswd };
-    }
-    if (openid) {
-      user.openid = openid;
-    }
-    if (role) {
-      user.role = role;
-    }
-    if (menus) {
-      user.menus = menus;
-    }
-    if (uid) {
-      user.uid = uid;
-    }
-    if (deptid) {
-      user.deptid = deptid;
-    }
-    if (deptname) {
-      user.deptname = deptname;
-    }
-    if (pid) {
-      user.pid = pid;
-    }
-    if (remark) {
-      user.remark = remark;
-    }
+    const user = await this.model.findById(id);
+    if (data.name)user.name = data.name;
+    if (data.phone) user.phone = data.phone;
+    if (data.uid) user.uid = data.uid;
+    if (data.role) user.role = data.role;
+    if (data.menus) user.menus = data.menus;
+    if (data.pid) user.pid = data.pid;
+    if (data.deptname) user.deptname = data.deptname;
+    if (data.remark) user.remark = data.remark;
+    if (data.code) user.code = data.code;
+    if (data.isdel) user.isdel = data.isdel;
     await user.save();
   }