Commit abbc8392 by 王昆

gsb

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