guhongwei 4 年之前
父節點
當前提交
d846dfdaf7

+ 40 - 0
app/controller/.dept.js

@@ -0,0 +1,40 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!name',
+      '!pid'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'name',
+      'pid'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        name:'name',
+        pid:'pid'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 42 - 0
app/controller/.role.js

@@ -0,0 +1,42 @@
+module.exports = {
+  create: {
+    requestBody: [
+      'code',
+      '!role_name',
+      'url'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'code',
+      '!role_name',
+      'url'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        role_name:'%role_name%',
+        url:'code'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 0 - 37
app/controller/.test.js

@@ -1,37 +0,0 @@
-module.exports = {
-  create: {
-    requestBody: ["!name", "mobile", "qqwx", "email", "address"],
-  },
-  destroy: {
-    params: ["!id"],
-    service: "delete",
-  },
-  update: {
-    params: ["!id"],
-    requestBody: ["!name", "mobile", "qqwx", "email", "address"],
-  },
-  show: {
-    parameters: {
-      params: ["!id"],
-    },
-    service: "fetch",
-  },
-  index: {
-    parameters: {
-      query: {
-        name: "name",
-        mobile: "mobile",
-        qqwx: "qqwx",
-        email: "email",
-        address: "address",
-      },
-    },
-    service: "query",
-    options: {
-      query: ["skip", "limit"],
-      sort: ["meta.createdAt"],
-      desc: true,
-      count: true,
-    },
-  },
-};

+ 69 - 0
app/controller/.user.js

@@ -0,0 +1,69 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!name",
+      "!phone",
+      "!passwd",
+      "openid",
+      "role",
+      "menus",
+      "uid",
+      "deptid",
+      "deptname",
+      "pid",
+      "code",
+      "remark",
+      "isdel",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "name",
+      "phone",
+      "passwd",
+      "openid",
+      "uid",
+      "role",
+      "menus",
+      "deptid",
+      "deptname",
+      "pid",
+      "code",
+      "remark",
+      "isdel",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "%name%",
+        uid: "uid",
+        phone: "phone",
+        deptid: "deptid",
+        deptname: "deptname",
+        pid: "pid",
+        code: "code",
+        role: "role",
+        isdel: "isdel",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 18 - 0
app/controller/dept.js

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

+ 12 - 0
app/controller/home.js

@@ -0,0 +1,12 @@
+'use strict';
+
+const Controller = require('egg').Controller;
+
+class HomeController extends Controller {
+  async index() {
+    const { ctx } = this;
+    ctx.body = 'hi, egg';
+  }
+}
+
+module.exports = HomeController;

+ 35 - 0
app/controller/login.js

@@ -0,0 +1,35 @@
+'use strict';
+
+const _ = require('lodash');
+const Controller = require('egg').Controller;
+
+// 登录管理
+class LoginController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.login;
+  }
+
+  async login() {
+    const res = await this.service.login(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+
+  async token() {
+    const res = await this.service.token(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+
+  async destroy() {
+    const res = await this.service.destroy(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+
+  async wxlogin() {
+    const res = await this.service.wxlogin(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+}
+
+module.exports = LoginController;

+ 18 - 0
app/controller/role.js

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

+ 0 - 16
app/controller/test.js

@@ -1,16 +0,0 @@
-'use strict';
-
-// const _ = require('lodash');
-const meta = require('./.test.js');
-const Controller = require('egg').Controller;
-const { CrudController } = require('naf-framework-mongoose/lib/controller');
-
-// 测试表
-class TestController extends Controller {
-  constructor(ctx) {
-    super(ctx);
-    this.service = this.ctx.service.test;
-  }
-}
-
-module.exports = CrudController(TestController, meta);

+ 48 - 0
app/controller/user.js

@@ -0,0 +1,48 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.user.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 管理
+class UserController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.user;
+  }
+
+  async uppasswd() {
+    const res = await this.service.uppasswd(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+
+  async querymenus() {
+    const res = await this.service.querymenus(this.ctx.query);
+    this.ctx.ok({ data: res });
+  }
+
+  async updatebyuid() {
+    const res = await this.service.updatebyuid(
+      this.ctx.params,
+      this.ctx.request.body
+    );
+    this.ctx.ok({ data: res });
+  }
+
+  async bind() {
+    const res = await this.service.bind(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+
+  async finduserlist() {
+    const res = await this.service.finduserlist(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
+  async businessuser() {
+    const res = await this.service.businessuser(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
+}
+
+module.exports = CrudController(UserController, meta);

+ 20 - 0
app/model/dept.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 机构表
+const DeptSchema = {
+  name: { type: String, required: false, maxLength: 200 }, // 机构名称
+  pid: { type: String, required: false, maxLength: 200 }, // 父ID
+};
+
+
+const schema = new Schema(DeptSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ pid: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Dept', schema, 'dept');
+};

+ 21 - 0
app/model/role.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 权限表
+const RoleSchema = {
+  code: { type: String, required: false, maxLength: 200 }, // 权限CODE
+  role_name: { type: String, required: true, maxLength: 64 }, // 权限名称
+  url: { type: String, required: false }, // 权限路由
+};
+
+
+const schema = new Schema(RoleSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ code: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Role', schema, 'role');
+};

+ 0 - 20
app/model/test.js

@@ -1,20 +0,0 @@
-'use strict';
-const Schema = require('mongoose').Schema;
-const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
-// 测试接口
-const TestSchema = {
-  name: { type: String, required: true, maxLength: 200 }, // 姓名
-  mobile: { type: String, required: true, maxLength: 200 }, // 电话
-  qqwx: { type: String, required: true, maxLength: 200 }, // qq/微信
-  email: { type: String, required: true, maxLength: 200 }, // 电子邮箱
-  address: { type: String, required: true, maxLength: 200 }, // 联系地址
-};
-
-const schema = new Schema(TestSchema, { toJSON: { virtuals: true } });
-schema.index({ id: 1 });
-schema.plugin(metaPlugin);
-
-module.exports = app => {
-  const { mongoose } = app;
-  return mongoose.model('Test', schema, 'test');
-};

+ 31 - 0
app/model/user.js

@@ -0,0 +1,31 @@
+'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 UserSchema = {
+  name: { type: String, required: false, maxLength: 200 }, // 名称
+  phone: { type: String, required: true, maxLength: 64 }, // 手机
+  passwd: { type: Secret, select: false }, // 注册密码
+  openid: { type: String, required: false }, // 微信openid
+  uid: { type: String, required: false }, // 用户信息id
+  role: { type: String, required: false }, // 1-管理员,2-个人,3-企业管理员,4-子管理员,6、专家 7、临时用户
+  menus: { type: [ String ], required: false }, // 菜单权限
+  pid: { type: String, required: false }, // 父id
+  deptname: { type: String, required: false }, // 机构名称
+  remark: { type: String, required: false }, // 备注
+  code: { type: String, required: false }, // 邀请码
+  isdel: { type: String, required: false, default: '0' }, // 0=>未删除;1=>已删除
+};
+
+
+const schema = new Schema(UserSchema, { toJSON: { virtuals: true } });
+schema.index({ openid: 1 });
+schema.index({ mobile: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('User', schema, 'user');
+};

+ 27 - 3
app/router.js

@@ -5,7 +5,31 @@
  */
 module.exports = app => {
   const { router, controller } = app;
-  // 測試
-  router.resources('test', '/api/userjurisform/test', controller.test); // index、create、show、destroy
-  router.post('test', '/api/userjurisform/test/update/:id', controller.test.update);
+  // 取得用户权限列表
+  router.get('/api/userjurisform/user/menus', controller.user.querymenus);
+  router.get('/api/userjurisform/user/finduserlist', controller.user.finduserlist);
+  // 权限表设置路由
+  router.resources('role', '/api/userjurisform/role', controller.role); // index、create、show、destroy
+  router.post('role', '/api/userjurisform/role/update/:id', controller.role.update);
+
+  // 用户表设置路由
+  router.resources('user', '/api/userjurisform/user', controller.user); // index、create、show、destroy
+  router.post('user', '/api/userjurisform/user/update/:id', controller.user.update);
+  router.post('user', '/api/userjurisform/user/uppasswd', controller.user.uppasswd);
+  router.post('/api/userjurisform/user/updatebyuid/:id', controller.user.updatebyuid);
+  router.post('/api/userjurisform/user/bind', controller.user.bind);
+  // 查询业务管理员
+  router.get('/api/userjurisform/businessuser', controller.user.businessuser);
+
+  // 机构表设置路由
+  router.resources('dept', '/api/userjurisform/dept', controller.dept); // index、create、show、destroy
+  router.post('dept', '/api/userjurisform/dept/update/:id', controller.dept.update);
+
+  // 用户登录
+  router.post('/api/userjurisform/login', controller.login.login);
+  // 根据token取得用户信息
+  router.post('/api/userjurisform/token', controller.login.token);
+  // 用户退出登录
+  router.post('/api/userjurisform/logout', controller.login.destroy);
+
 };

+ 17 - 0
app/service/dept.js

@@ -0,0 +1,17 @@
+'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 DeptService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'role');
+    this.model = this.ctx.model.Dept;
+  }
+}
+
+module.exports = DeptService;

+ 141 - 0
app/service/login.js

@@ -0,0 +1,141 @@
+'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');
+const uuid = require('uuid');
+
+class LoginService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'login');
+    this.model = this.ctx.model.User;
+    this.rmodel = this.ctx.model.Role;
+  }
+
+  // 用户登录
+  async login(data) {
+    const { phone, passwd, role } = data;
+    // 根据用户输入的手机号查询其他用户表中是否存在相应数据
+    let user = await this.model.findOne({ phone, role, isdel: '0' });
+    // 增设使用code模式登陆的判断变量
+    let is_code = false;
+    if (!user) {
+      // 添加code作为登录的方式
+      user = await this.model.findOne({ code: phone, role, isdel: '0' });
+      // 如果用户不存在抛出异常
+      if (!user) { throw new BusinessError(ErrorCode.USER_NOT_EXIST); } else is_code = true;
+    }
+    const pdata = {};
+    if (is_code) pdata.code = phone;
+    else pdata.phone = phone;
+    const _user = await this.model.findOne(pdata, '+passwd');
+    // 将用户输入的密码进行加密并与查询到的用户数据密码相比对
+    const pas = await this.createJwtPwd(passwd);
+    // 如果两个密码不一致抛出异常
+    if (pas !== _user.passwd.secret) {
+      throw new BusinessError(ErrorCode.BAD_PASSWORD);
+    }
+    if (_user.role === '4' || _user.role === '5') {
+      const url = 'http://127.0.0.1:9004/api/market/user/' + _user.uid;
+      const marketuser = await this.ctx.curl(url, {
+        method: 'get',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+      });
+      if (marketuser.data.data.status !== '1') {
+        throw new BusinessError(ErrorCode.ACCESS_DENIED);
+      }
+    } else if (_user.role === '6') {
+      const url = 'http://127.0.0.1:9004/api/market/expertsuser/' + _user.uid;
+      const expertsuser = await this.ctx.curl(url, {
+        method: 'get',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+      });
+      if (expertsuser.data.data.status !== '1') {
+        throw new BusinessError(ErrorCode.ACCESS_DENIED);
+      }
+    }
+    // 取出用户的类型,根据用户类型返回相应信息
+    const state = uuid();
+    const key = `free:auth:state:${state}`;
+    const _menus = [];
+    for (const elm of user.menus) {
+      const _menu = await this.rmodel.findById({ _id: ObjectId(elm) });
+      if (_menu) {
+        _menus.push({ id: elm, role_name: _menu.role_name, url: _menu.url });
+      }
+    }
+    user.menus = JSON.stringify(_menus);
+    const token = await this.createJwt(user);
+    await this.app.redis.set(key, token, 'EX', 60 * 60 * 24);
+    return { key };
+  }
+
+  // 创建登录Token
+  async createJwtPwd(password) {
+    const { secret, expiresIn, issuer } = this.config.jwt;
+    const token = await jwt.sign(password, secret);
+    return token;
+  }
+
+  // 创建登录Token
+  async createJwt({
+    id,
+    name,
+    uid,
+    phone,
+    role,
+    menus,
+    remark,
+    openid,
+    deptid,
+    deptname,
+    pid,
+    code,
+  }) {
+    const { secret, expiresIn = '1d', issuer = role } = this.config.jwt;
+    const subject = phone;
+    const res = {
+      uid: id,
+      userid: uid,
+      name,
+      phone,
+      role,
+      menus,
+      openid,
+      remark,
+      deptid,
+      deptname,
+      pid,
+      code,
+    };
+    const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
+    return token;
+  }
+
+  // 取得redis内token信息
+  async token({ key }) {
+    assert(key, 'key不能为空');
+    const token = await this.app.redis.get(key);
+    if (!token) {
+      throw new BusinessError(ErrorCode.SERVICE_FAULT, 'token已经过期');
+    }
+    return { token };
+  }
+
+  // 删除操作
+  async destroy({ key }) {
+    const res = await this.app.redis.del(key);
+    console.log(res);
+    return res;
+  }
+}
+module.exports = LoginService;

+ 6 - 5
app/service/test.js

@@ -1,16 +1,17 @@
 'use strict';
 
+
 const assert = require('assert');
 const _ = require('lodash');
 const { ObjectId } = require('mongoose').Types;
 const { CrudService } = require('naf-framework-mongoose/lib/service');
-const { TestError, ErrorCode } = require('naf-core').Error;
+const { BusinessError, ErrorCode } = require('naf-core').Error;
 
-class TestService extends CrudService {
+class RoleService extends CrudService {
   constructor(ctx) {
-    super(ctx, 'test');
-    this.model = this.ctx.model.Test;
+    super(ctx, 'role');
+    this.model = this.ctx.model.Role;
   }
 }
 
-module.exports = TestService;
+module.exports = RoleService;

+ 206 - 0
app/service/user.js

@@ -0,0 +1,206 @@
+'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, 'user');
+    this.model = this.ctx.model.User;
+    this.rmodel = this.ctx.model.Role;
+  }
+
+  // 重写创建方法
+  async create(data) {
+    const { name, phone, passwd, role } = data;
+    console.log(data);
+    assert(name && phone && passwd, '缺少部分信息项');
+    // if (`${role}` !== '5') { assert(/^\d{11}$/i.test(phone), 'phone无效'); }
+    // const user = await this.model.findOne({ phone });
+    // if (user) {
+    //   throw new BusinessError(ErrorCode.DATA_EXISTED);
+    // }
+    const newdata = data;
+    const pas = await this.createJwtPwd(passwd);
+    newdata.passwd = { secret: pas };
+    const res = await this.model.create(newdata);
+    return res;
+  }
+
+  // 创建登录Token
+  async createJwtPwd(password) {
+    const { secret, expiresIn, issuer } = this.config.jwt;
+    const token = await jwt.sign(password, secret);
+    return token;
+  }
+
+  // 重写修改方法
+  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;
+    }
+    await user.save();
+  }
+
+  // 用户修改密码
+  async uppasswd(data) {
+    const { id, oldpasswd, newpasswd } = data;
+    assert(id && oldpasswd && newpasswd, '缺少部分信息项');
+    // 根据用户id查询其他用户表中是否存在相应数据
+    const user = await this.model.findById(id, '+passwd');
+    // 如果用户不存在抛出异常
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    // 将用户输入的密码进行加密并与查询到的用户数据密码相比对
+    const _oldpasswd = await this.createJwtPwd(oldpasswd);
+    // 如果两个密码不一致抛出异常
+    if (_oldpasswd !== user.passwd.secret) {
+      throw new BusinessError(ErrorCode.BAD_PASSWORD);
+    }
+    const _newpasswd = await this.createJwtPwd(newpasswd);
+    user.passwd = { secret: _newpasswd };
+    await user.save();
+  }
+
+  async querymenus({ id }) {
+    const user = await this.model.findById(id);
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    const _menus = [];
+    for (const elm of user.menus) {
+      const _menu = await this.rmodel.findById({ _id: ObjectId(elm) });
+      if (_menu) {
+        _menus.push({ id: elm, role_name: _menu.role_name, url: _menu.url });
+      }
+    }
+    return { id, menus: _menus };
+  }
+
+  // 按条件更新方法
+  async updatebyuid({ id }, data) {
+    const user = await this.model.findOne({ uid: id });
+    if (user) {
+      user.name = data.name;
+      user.deptname = data.deptname;
+    }
+    await user.save();
+  }
+
+  // 按条件更新方法
+  async bind(data) {
+    const user = await this.model.findById(data.uid);
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    user.openid = data.openid;
+    return await user.save();
+  }
+
+  async findByOpenid(openid) {
+    const user = await this.model.findOne({ openid });
+    return user;
+  }
+
+  async finduserlist({ skip, limit, ...info }) {
+    const query = {
+      ...info,
+      $or: [{ role: '4' }, { role: '5' }, { role: '6' }],
+    };
+    const total = await this.model.count(query);
+    const data = await this.model
+      .find(query)
+      .skip(Number(skip))
+      .limit(Number(limit));
+    return { data, total };
+  }
+  async businessuser({ pid, skip, limit }) {
+    const query = { code: { $regex: /^.{9}$/ } };
+    pid ? (query.pid = pid) : '';
+    const total = await this.model.count(query);
+    const data = await this.model
+      .find(query)
+      .skip(Number(skip))
+      .limit(Number(limit));
+    return { data, total };
+  }
+  // 重写删除方法
+  /**
+   * 根据id删除=>修改isdel为1
+   * @param {Object} {id} 只接收id,不过需要解构,因为是object形式过来的
+   */
+  async delete({ id }) {
+    const res = await this.model.update({ _id: ObjectId(id) }, { isdel: '1' });
+    if (res) {
+      const { config } = this.app;
+      if (!config) throw new BusinessError(ErrorCode.SERVICE_FAULT, '系统错误,需要检查系统项目设置');
+      const { project } = config;
+      if (!project) throw new BusinessError(ErrorCode.SERVICE_FAULT, '系统错误,需要检查系统中各项目的设置');
+      const { market } = project;
+      if (!market) throw new BusinessError(ErrorCode.SERVICE_FAULT, '系统错误,需要检查系统项目中项目设置的各项目配置');
+      const url = `${market}/product/userdelete`;
+      const r = await this.ctx.curl(url, {
+        method: 'post',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+        data: { id },
+      });
+      console.log(r);
+    }
+    return res;
+  }
+}
+
+module.exports = UserService;

+ 15 - 6
config/config.default.js

@@ -6,11 +6,11 @@ const { jwt } = require('./config.secret');
  * @param {Egg.EggAppInfo} appInfo app info
  */
 module.exports = appInfo => {
-/**
- * built-in config
- * @type {Egg.EggAppConfig}
- **/
-  const config = exports = {};
+  /**
+   * built-in config
+   * @type {Egg.EggAppConfig}
+   **/
+  const config = (exports = {});
 
   // use for cookie sign key, should change to your own and keep security
   config.keys = appInfo.name + '_1579225760252_7743';
@@ -20,7 +20,7 @@ module.exports = appInfo => {
 
   // add your user config here
   const userConfig = {
-  // myAppName: 'egg',
+    // myAppName: 'egg',
   };
 
   // add your config here
@@ -45,6 +45,15 @@ module.exports = appInfo => {
     expiresIn: '1d',
     issuer: 'userjurisform',
   };
+  // redis config
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '127.0.0.1', // Redis host
+      password: 123456,
+      db: 0,
+    },
+  };
 
   // config.amqp = {
   //   client: {

+ 3 - 3
config/config.prod.js

@@ -1,11 +1,11 @@
 'use strict';
 
 module.exports = () => {
-  const config = exports = {};
+  const config = (exports = {});
 
   config.logger = {
-  // level: 'DEBUG',
-  // consoleLevel: 'DEBUG',
+    // level: 'DEBUG',
+    // consoleLevel: 'DEBUG',
   };
 
   // mongoose config