guhongwei 4 năm trước cách đây
mục cha
commit
eed9fd652c
2 tập tin đã thay đổi với 10 bổ sung21 xóa
  1. 0 1
      app/router.js
  2. 10 20
      app/service/expertsuser.js

+ 0 - 1
app/router.js

@@ -40,7 +40,6 @@ module.exports = app => {
   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);

+ 10 - 20
app/service/expertsuser.js

@@ -15,42 +15,32 @@ class ExpertuserService extends CrudService {
   }
 
   async create(data) {
-    const { name, password, role } = data;
+    const { name, password, role, phone } = data;
     assert(name, '用户名不能为空');
     assert(password, '密码不能为空');
-    const { phone } = data;
     const has_phone = await this.model.findOne({ phone, role });
     if (has_phone) {
-      throw new BusinessError('此身份手机号已被注册,请更换手机号');
+      throw new BusinessError('此身份手机号已被注册,请更换手机号');
     }
-    const newdata = data;
-    newdata.password = { secret: password };
-    const res = await this.model.create(newdata);
+    data.password = { secret: password };
+    const res = await this.model.create(data);
     if (res) {
-      const url = this.ctx.app.config.axios.auth.baseUrl;
       const newdata = {
         name,
         phone: data.phone,
-        passwd: password,
+        passwd: data.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();
+      const auth_user = await this.umodel.findOne({ phone, role });
+      if (auth_user) {
+        throw new BusinessError('此身份手机号已被注册,请更换手机号');
       }
+      const authres = await this.umodel.create(newdata);
+      return authres;
     }
     return res;
   }