Commit abbc8392 by 王昆

gsb

parent 7093d07f
...@@ -11,6 +11,8 @@ class ActionAPI extends APIBase { ...@@ -11,6 +11,8 @@ class ActionAPI extends APIBase {
this.authSve = system.getObject("service.auth.authSve"); this.authSve = system.getObject("service.auth.authSve");
this.saasplatformuserSve = system.getObject("service.user.saasplatformuserSve"); this.saasplatformuserSve = system.getObject("service.user.saasplatformuserSve");
this.saasmerchantuserSve = system.getObject("service.user.saasmerchantuserSve");
this.saasmerchantappuserSve = system.getObject("service.user.saasmerchantappuserSve");
} }
/** /**
...@@ -175,7 +177,29 @@ class ActionAPI extends APIBase { ...@@ -175,7 +177,29 @@ class ActionAPI extends APIBase {
case "platforMapByIds": case "platforMapByIds":
opResult = await this.saasplatformuserSve.mapByIds(action_body); opResult = await this.saasplatformuserSve.mapByIds(action_body);
break; break;
// saas商户
case "merchantLogin":
opResult = await this.saasmerchantuserSve.login(action_body);
break;
case "merchantSave":
opResult = await this.saasmerchantuserSve.save(action_body);
break;
case "merchantInfo":
opResult = await this.saasmerchantuserSve.info(action_body);
break;
case "merchantEnabled":
opResult = await this.saasmerchantuserSve.enabled(action_body);
break;
case "merchantPage":
opResult = await this.saasmerchantuserSve.pageByCondition(action_body);
break;
case "merchantPassword":
opResult = await this.saasmerchantuserSve.updPassword(action_body);
break;
case "merchantMapByIds":
opResult = await this.saasmerchantuserSve.mapByIds(action_body);
break;
} }
return opResult; return opResult;
} }
......
...@@ -29,11 +29,11 @@ class SaasMerchantUserDao extends Dao { ...@@ -29,11 +29,11 @@ class SaasMerchantUserDao extends Dao {
return await this.customQuery(sql.join(" "), params); return await this.customQuery(sql.join(" "), params);
} }
async getByUcname(saasId, ucname) { async byUcname(ucname, merchantId) {
var sql = "SELECT * FROM uc_user WHERE ucname = :ucname AND saas_id = :saasId AND deleted_at IS NULL"; var sql = "SELECT * FROM uc_user WHERE ucname = :ucname AND saas_merchant_id = :merchantId AND deleted_at IS NULL";
var list = await this.customQuery(sql, { var list = await this.customQuery(sql, {
ucname: ucname, ucname: ucname,
saasId: saasId, merchantId: merchantId,
}); });
if (!list || list.length == 0) { if (!list || list.length == 0) {
return null; return null;
...@@ -112,7 +112,7 @@ class SaasMerchantUserDao extends Dao { ...@@ -112,7 +112,7 @@ class SaasMerchantUserDao extends Dao {
} }
} }
async findMapByIds(ids, attrs) { async mapByIds(ids, attrs) {
let result = {}; let result = {};
if (!ids || ids.length == 0) { if (!ids || ids.length == 0) {
......
...@@ -149,7 +149,7 @@ class SaasMerchantAppUserService extends ServiceBase { ...@@ -149,7 +149,7 @@ class SaasMerchantAppUserService extends ServiceBase {
var total = await this.dao.countByCondition(params); var total = await this.dao.countByCondition(params);
if (total == 0) { if (total == 0) {
return result; return system.getResultSuccess(result);
} }
result.count = total; result.count = total;
......
...@@ -7,10 +7,8 @@ class SaasMerchantUserService extends ServiceBase { ...@@ -7,10 +7,8 @@ class SaasMerchantUserService extends ServiceBase {
super("user", ServiceBase.getDaoName(SaasMerchantUserService)); super("user", ServiceBase.getDaoName(SaasMerchantUserService));
} }
async login(obj) { async login(params) {
var uctype = Number(obj.uctype || 0); let user = await this.dao.byUcname(params.ucname, params.saas_merchant_id);
var user = await this.dao.getByUcname(obj.ucname);
// 验证登录合法 // 验证登录合法
if (!user) { if (!user) {
return system.getResult(null, "用户名或密码错误"); return system.getResult(null, "用户名或密码错误");
...@@ -19,99 +17,77 @@ class SaasMerchantUserService extends ServiceBase { ...@@ -19,99 +17,77 @@ class SaasMerchantUserService extends ServiceBase {
return system.getResult(null, "用户已禁用"); return system.getResult(null, "用户已禁用");
} }
if (uctype && uctype != user.uctype) { let loginPwd = await this.getEncryptStr(params.password);
return system.getResult(null, "用户类型错误");
}
var loginPwd = await this.getEncryptStr(obj.password);
if (loginPwd != user.password) { if (loginPwd != user.password) {
return system.getResult(null, "用户名或密码错误"); return system.getResult(null, "用户名或密码错误");
} }
await this.setLoginUser(user);
return system.getResultSuccess(user); return system.getResultSuccess(user);
} }
async saveUser(obj) { async save(params) {
try { let id = Number(params.id || 0);
var id = obj.id; let saas_merchant_id = this.trim(params.saas_merchant_id);
var roleIds = obj.roles || []; let saas_id = this.trim(params.saas_id);
var org_id = this.trim(obj.org_id); let ucname = this.trim(params.ucname);
let mobile = this.trim(params.mobile);
let roles = []; let realName = this.trim(params.realName);
for (let roleId of roleIds) { let password = this.trim(params.password);
roles.push({role_id: roleId}); let isEnabled = Number(params.isEnabled || 0);
} if (!realName) {
return system.getResult(null, "请输入用户姓名");
if (!obj.saas_id) { }
return system.getResult(null, "saas_id不存在"); if (!mobile) {
} return system.getResult(null, "请输入联系手机");
let user = {}; }
if (!ucname) {
return system.getResult(null, "请输入账号");
}
try {
let exists = await this.dao.findOne({
saas_merchant_id: saas_merchant_id,
ucname: ucname
});
let user;
if (id) { if (id) {
let u = await this.findById(id); if (exists && exists.id != id) {
if (u) { return system.getResult(null, `账号名称[${ucname}]已存在`);
user.id = u.id;
} }
} user = await this.dao.findById(id);
user.realName = realName;
let exist = await this.findOne({ user.ucname = ucname;
ucname: obj.ucname user.isEnabled = isEnabled;
}); if (password && password != user.password) {
if (user.id) { user.password = await this.getEncryptStr(password);
if (exist && exist.id != user.id) {
return system.getResult(null, `用户名【${ucname}】已存在`);
} }
await user.save();
} else { } else {
if (exist) { if (exists) {
return system.getResult(null, `用户名【${ucname}已存在`); return system.getResult(null, `账号名称[${ucname}]已存在`);
} }
user.password = await this.getEncryptStr(obj.password); if (!saas_merchant_id) {
} return system.getResult(null, "请选择商户");
let org = await this.orgDao.findById(org_id);
if (!org) {
return system.getResult(null, `组织机构不存在`);
}
user.ucid = this.trim(obj.ucid);
user.ucname = this.trim(obj.ucname);
user.uctype = 1;
user.uctypeId = "";
user.mobile = this.trim(obj.mobile);
user.realName = this.trim(obj.realName);
user.org_id = org_id;
user.saas_id = this.trim(obj.saas_id);
var self = this;
user = await self.db.transaction(async function (t) {
if (user.id) {
await self.dao.update(user, t);
} else {
// 创建商户
user = await self.dao.create(user, t);
} }
await self.userroleDao.delByUserId(user.id, t); if (!password) {
return system.getResult(null, "请输入密码");
if (roles && roles.length > 0) {
for (var r of roles) {
r.user_id = user.id;
}
await self.userroleDao.bulkCreate(roles, t);
} }
user.orgpath = org.path + "/" + user.id + "/"; user = {
await self.dao.update({ saas_id: saas_id,
id: user.id, saas_merchant_id: saas_merchant_id,
orgpath: user.orgpath password: await this.getEncryptStr(password),
}, t); realName: realName,
return user; ucname: ucname,
}); mobile: mobile,
isEnabled: isEnabled,
};
user = await this.dao.model.create(user);
}
return system.getResultSuccess(user); return system.getResultSuccess(user);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
if (error.name == 'SequelizeValidationError') { if (error.name == 'SequelizeValidationError') {
return system.getResult(-1, `用户名重复`); return system.getResult(null, `账号名称[${ucname}]已存在`);
} }
return system.getResult(-1, `系统错误 错误信息${error}`); return system.getResult(-1, `系统错误 错误信息${error}`);
} }
} }
...@@ -143,13 +119,9 @@ class SaasMerchantUserService extends ServiceBase { ...@@ -143,13 +119,9 @@ class SaasMerchantUserService extends ServiceBase {
}; };
var currentPage = Number(params.currentPage || 1); var currentPage = Number(params.currentPage || 1);
var pageSize = Number(params.pageSize || 10); var pageSize = Number(params.pageSize || 10);
if (params.orgpath) {
params.orgpath = params.orgpath + "%";
}
var total = await this.dao.countByCondition(params); var total = await this.dao.countByCondition(params);
if (total == 0) { if (total == 0) {
return result; return system.getResultSuccess(result);
} }
result.count = total; result.count = total;
...@@ -159,13 +131,10 @@ class SaasMerchantUserService extends ServiceBase { ...@@ -159,13 +131,10 @@ class SaasMerchantUserService extends ServiceBase {
for (let item of result.rows) { for (let item of result.rows) {
this.handleDate(item, ["created_at"], null, -8); this.handleDate(item, ["created_at"], null, -8);
} }
await this.setRoles(result.rows);
await this.setOrg(result.rows);
} }
return system.getResultSuccess(result); return system.getResultSuccess(result);
} }
async updPassword(params) { async updPassword(params) {
var user = await this.findById(params.id); var user = await this.findById(params.id);
if (!user) { if (!user) {
...@@ -178,7 +147,7 @@ class SaasMerchantUserService extends ServiceBase { ...@@ -178,7 +147,7 @@ class SaasMerchantUserService extends ServiceBase {
} }
async mapByIds(params) { async mapByIds(params) {
let rs = await this.dao.findMapByIds(params.ids); let rs = await this.dao.mapByIds(params.ids, params.attrs);
return system.getResultSuccess(rs); return system.getResultSuccess(rs);
} }
} }
......
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