Kaynağa Gözat

Merge remote-tracking branch 'origin/master'

chen 4 yıl önce
ebeveyn
işleme
d3f83e53e4
3 değiştirilmiş dosya ile 25 ekleme ve 0 silme
  1. 5 0
      app/controller/otheruser.js
  2. 1 0
      app/router.js
  3. 19 0
      app/service/otheruser.js

+ 5 - 0
app/controller/otheruser.js

@@ -22,6 +22,11 @@ class OtheruserController extends Controller {
     const res = await this.service.uppasswd(this.ctx.request.body);
     this.ctx.ok({ data: res });
   }
+
+  async creatcpjl() {
+    const res = await this.service.creatcpjl(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
 }
 
 module.exports = CrudController(OtheruserController, meta);

+ 1 - 0
app/router.js

@@ -12,6 +12,7 @@ module.exports = app => {
   router.post('otheruser', '/api/financial/otheruser/update/:id', controller.otheruser.update);
   router.post('otheruser', '/api/financial/otheruser/login', controller.otheruser.login);
   router.post('otheruser', '/api/financial/otheruser/uppasswd', controller.otheruser.uppasswd);
+  router.post('otheruser', '/api/financial/otheruser/creatcpjl', controller.otheruser.creatcpjl);
 
   // 企业用户表设置路由
   router.resources('companyuser', '/api/financial/companyuser', controller.companyuser); // index、create、show、destroy

+ 19 - 0
app/service/otheruser.js

@@ -35,6 +35,25 @@ class OtheruserService extends CrudService {
     return res;
   }
 
+  async creatcpjl(data) {
+    const { name, phone, passwd, type, characterid } = data;
+    console.log(data);
+    assert(name && phone && passwd && type, '缺少部分信息项');
+    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 = pas;
+    const res = await this.model.create(newdata);
+    if (type === '1') {
+      await this.imodel.create({ uid: res.id, name });
+    }
+    return res;
+  }
+
   // 重写修改方法
   async update({ id }, data) {
     const { name, phone, passwd, type, characterid } = data;