guhongwei před 4 roky
rodič
revize
a42ae14321
4 změnil soubory, kde provedl 69 přidání a 90 odebrání
  1. 31 53
      app/service/expertsuser.js
  2. 2 2
      app/service/login.js
  3. 32 33
      app/service/marketuser.js
  4. 4 2
      app/service/user.js

+ 31 - 53
app/service/expertsuser.js

@@ -47,62 +47,40 @@ class ExpertuserService extends CrudService {
   }
   }
 
 
   async update({ id }, data) {
   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 expertuser = await this.model.findById(id);
+    if (expertuser) {
+      expertuser.name = data.name;
+      expertuser.education = data.education;
+      expertuser.school = data.school;
+      expertuser.birthDate = data.birthDate;
+      expertuser.phone = data.phone;
+      expertuser.qqwx = data.qqwx;
+      expertuser.email = data.email;
+      expertuser.company = data.company;
+      expertuser.zwzc = data.zwzc;
+      expertuser.expertise = data.expertise;
+      expertuser.expertimage = data.expertimage;
+      expertuser.workexperience = data.workexperience;
+      expertuser.scientific = data.scientific;
+      expertuser.undertakingproject = data.undertakingproject;
+      expertuser.scienceaward = data.scienceaward;
+      expertuser.social = data.social;
+      expertuser.userid = data.userid;
+      expertuser.code = data.code;
+      expertuser.role = data.role;
+      expertuser.status = data.status;
+      expertuser.pid = data.pid;
+      expertuser.deptname = data.deptname;
+      expertuser.isdel = data.isdel;
+
     }
     }
-    const res = await user.save();
+    const res = await expertuser.save();
     if (res) {
     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),
-      });
+      const authuser = await this.umodel.findOne({ uid: res._id });
+      const id = authuser._id;
+      const authres = await this.ctx.service.user.update({ id }, data);
+      return authres;
     }
     }
-    return res;
   }
   }
 
 
   async upgrade({ id }, data) {
   async upgrade({ id }, data) {

+ 2 - 2
app/service/login.js

@@ -33,9 +33,9 @@ class LoginService extends CrudService {
     else pdata.phone = phone;
     else pdata.phone = phone;
     const _user = await this.model.findOne(pdata, '+passwd');
     const _user = await this.model.findOne(pdata, '+passwd');
     // 将用户输入的密码进行加密并与查询到的用户数据密码相比对
     // 将用户输入的密码进行加密并与查询到的用户数据密码相比对
-    const pas = await this.createJwtPwd(passwd);
+    // const pas = await this.createJwtPwd(passwd);
     // 如果两个密码不一致抛出异常
     // 如果两个密码不一致抛出异常
-    if (pas !== _user.passwd.secret) {
+    if (passwd !== _user.passwd.secret) {
       throw new BusinessError(ErrorCode.BAD_PASSWORD);
       throw new BusinessError(ErrorCode.BAD_PASSWORD);
     }
     }
     if (_user.role === '4' || _user.role === '5') {
     if (_user.role === '4' || _user.role === '5') {

+ 32 - 33
app/service/marketuser.js

@@ -63,39 +63,38 @@ class UserService extends CrudService {
   }
   }
 
 
   async update({ id }, data) {
   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;
-      }
+    const marketuser = await this.model.findById(id);
+    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 res = await marketuser.save();
+    if (res) {
+      const authuser = await this.modeluser.findOne({ uid: res._id });
+      const id = authuser._id;
+      const authres = await this.ctx.service.user.update({ id }, data);
+      return authres;
     }
     }
   }
   }
 
 

+ 4 - 2
app/service/user.js

@@ -25,8 +25,8 @@ class UserService extends CrudService {
     //   throw new BusinessError(ErrorCode.DATA_EXISTED);
     //   throw new BusinessError(ErrorCode.DATA_EXISTED);
     // }
     // }
     const newdata = data;
     const newdata = data;
-    const pas = await this.createJwtPwd(passwd);
-    newdata.passwd = { secret: pas };
+    // const pas = await this.createJwtPwd(passwd);
+    newdata.passwd = { secret: passwd };
     const res = await this.model.create(newdata);
     const res = await this.model.create(newdata);
     return res;
     return res;
   }
   }
@@ -40,6 +40,8 @@ class UserService extends CrudService {
 
 
   // 重写修改方法
   // 重写修改方法
   async update({ id }, data) {
   async update({ id }, data) {
+    console.log(id);
+    console.log(data);
     const user = await this.model.findById(id);
     const user = await this.model.findById(id);
     if (data.name)user.name = data.name;
     if (data.name)user.name = data.name;
     if (data.phone) user.phone = data.phone;
     if (data.phone) user.phone = data.phone;