Commit 68a3862e by 王昆

Merge branch 'xggsve-uc' of gitlab.gongsibao.com:jiangyong/zhichan into xggsve-uc

parents af0c15cf e0685875
...@@ -120,123 +120,131 @@ class UserService extends ServiceBase { ...@@ -120,123 +120,131 @@ class UserService extends ServiceBase {
} }
async add(obj) { async add(obj) {
var roles = obj.roles || []; try {
var org = obj.org || {}; var roles = obj.roles || [];
var saas_id = Number(obj.saas_id || 0); var org = obj.org || {};
var ucid = this.trim(obj.ucid); var saas_id = Number(obj.saas_id || 0);
var ucname = this.trim(obj.ucname); var ucid = this.trim(obj.ucid);
var password = this.trim(obj.password); var ucname = this.trim(obj.ucname);
var uctype = Number(obj.uctype || 1); var password = this.trim(obj.password);
var uctypeId = this.trim(obj.uctypeId); var uctype = Number(obj.uctype || 1);
var mobile = this.trim(obj.mobile); var uctypeId = this.trim(obj.uctypeId);
var realName = this.trim(obj.realName); var mobile = this.trim(obj.mobile);
var isMain = obj.isMain || 0; var realName = this.trim(obj.realName);
var isMain = obj.isMain || 0;
if (!saas_id) {
return system.getResult(null, "saas_id不存在"); if (!saas_id) {
} return system.getResult(null, "saas_id不存在");
}
var exist = await this.findOne({ var exist = await this.findOne({
ucname: ucname ucname: ucname
}); });
if (exist) { if (exist) {
return system.getResult(null, `用户名【${ucname}】已存在`); return system.getResult(null, `用户名【${ucname}】已存在`);
} }
var user = { var user = {
saas_id: saas_id, saas_id: saas_id,
ucid: ucid, ucid: ucid,
ucname: ucname, ucname: ucname,
password: await this.getEncryptStr(password), password: await this.getEncryptStr(password),
uctype: uctype, uctype: uctype,
uctypeId: uctypeId, uctypeId: uctypeId,
org_id: org.id || 0, org_id: org.id || 0,
isMain: isMain, isMain: isMain,
orgpath: "", orgpath: "",
isEnabled: 1, isEnabled: 1,
} }
var orgpath = org.path || ""; var orgpath = org.path || "";
var info = { var info = {
mobile: mobile, mobile: mobile,
realName: realName, realName: realName,
} }
var self = this; var self = this;
user = await self.db.transaction(async function (t) { user = await self.db.transaction(async function (t) {
// 创建商户 // 创建商户
user = await self.dao.create(user, t); user = await self.dao.create(user, t);
info.id = user.id; info.id = user.id;
info = await self.userinfoDao.create(info, t); info = await self.userinfoDao.create(info, t);
if (roles && roles.length > 0) { if (roles && roles.length > 0) {
for (var r of roles) { for (var r of roles) {
r.user_id = user.id; r.user_id = user.id;
}
await self.userroleDao.bulkCreate(roles, t);
} }
await self.userroleDao.bulkCreate(roles, t);
}
if (user.uctype === 1) { if (user.uctype === 1) {
orgpath = (isMain ? orgpath : orgpath + "/" + user.id) + "/"; orgpath = (isMain ? orgpath : orgpath + "/" + user.id) + "/";
await self.dao.update({ await self.dao.update({
id: user.id, id: user.id,
orgpath: orgpath orgpath: orgpath
}, t); }, t);
} }
user.orgpath = orgpath; user.orgpath = orgpath;
return user; return user;
}); });
return system.getResultSuccess(user); return system.getResultSuccess(user);
} catch (error) {
return system.getResult(-1,`系统错误 错误信息${error}`);
}
} }
async upd(obj) { async upd(obj) {
var id = obj.id; try {
var roles = obj.roles || []; var id = obj.id;
var org = obj.org || {}; var roles = obj.roles || [];
var uctype = this.trim(obj.uctype); var org = obj.org || {};
var uctypeId = this.trim(obj.uctypeId); var uctype = this.trim(obj.uctype);
var mobile = this.trim(obj.mobile); var uctypeId = this.trim(obj.uctypeId);
var realName = this.trim(obj.realName); var mobile = this.trim(obj.mobile);
var isMain = obj.isMain || 0; var realName = this.trim(obj.realName);
var isMain = obj.isMain || 0;
var user = {
id: id, var user = {
uctype: uctype, id: id,
uctypeId: uctypeId, uctype: uctype,
org_id: org.id || "", uctypeId: uctypeId,
orgpath: "", org_id: org.id || null,
isMain: obj.isMain || 0, orgpath: "",
} isMain: obj.isMain || 0,
if (Number(this.trim(user.uctype)) === 1) {
user.orgpath = (isMain ? org.path : org.path + "/" + id) + "/";
}
var info = {
id: id,
mobile: mobile,
realName: realName,
}
var self = this;
user = await self.db.transaction(async function (t) {
// 创建商户
await self.dao.update(user, t);
await self.userinfoDao.update(info, t);
await self.userroleDao.delByUserId(id, t);
if (roles && roles.length > 0) {
for (var r of roles) {
r.user_id = id;
}
await self.userroleDao.bulkCreate(roles, t);
} }
return user;
}); if (Number(this.trim(user.uctype)) === 1) {
return system.getResultSuccess(user); user.orgpath = (isMain ? org.path : org.path + "/" + id) + "/";
}
var info = {
id: id,
mobile: mobile,
realName: realName,
}
var self = this;
user = await self.db.transaction(async function (t) {
// 创建商户
await self.dao.update(user, t);
await self.userinfoDao.update(info, t);
await self.userroleDao.delByUserId(id, t);
if (roles && roles.length > 0) {
for (var r of roles) {
r.user_id = id;
}
await self.userroleDao.bulkCreate(roles, t);
}
return user;
});
return system.getResultSuccess(user);
} catch (error) {
return system.getResult(-1,`系统错误 错误信息 ${error}`);
}
} }
async info(params) { async info(params) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment