Commit e66a731d by 王昆

gsb

parent 46b00a80
var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class ActionAPI extends APIBase {
constructor() {
super();
this.saasSve = system.getObject("service.saas.saasSve");
this.orgSve = system.getObject("service.org.orgSve");
this.userSve = system.getObject("service.user.userSve");
this.roleSve = system.getObject("service.role.roleSve");
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");
}
constructor() {
super();
this.saasSve = system.getObject("service.saas.saasSve");
this.orgSve = system.getObject("service.org.orgSve");
this.userSve = system.getObject("service.user.userSve");
this.roleSve = system.getObject("service.role.roleSve");
this.authSve = system.getObject("service.auth.authSve");
/**
* 接口跳转
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async springboard(pobj, qobj, req) {
var result;
if (!pobj.action_process) {
return system.getResult(null, "action_process参数不能为空");
}
if (!pobj.action_type) {
return system.getResult(null, "action_type参数不能为空");
}
console.log(pobj.action_process, pobj.action_type, pobj.action_body, "---------------- this is order micro sve --------------------");
try {
result = await this.handleRequest(pobj.action_process, pobj.action_type, pobj.action_body);
} catch (error) {
console.log(error);
}
return result;
}
this.saasplatformuserSve = system.getObject("service.user.saasplatformuserSve");
this.saasmerchantuserSve = system.getObject("service.user.saasmerchantuserSve");
this.saasmerchantappletuserSve = system.getObject("service.user.saasmerchantappletuserSve");
}
async handleRequest(action_process, action_type, action_body) {
var opResult = null;
switch (action_type) {
// saas
case "addSaas":
opResult = await this.saasSve.apiAddSaas(action_body);
break;
case "updSaas":
opResult = await this.saasSve.apiUpdSaas(action_body);
break;
case "delSaas":
opResult = await this.userSve.apiFindUserBySaasId(action_body);
if (opResult.status == 0 && opResult.data.length == 0) {
opResult = await this.saasSve.apiDelSaas(action_body);
} else {
opResult = system.getResult(-1, `当前SAAS不能删除`);
}
break;
case "listSaas":
opResult = await this.saasSve.apiListSaas(action_body);
break;
case "saasQueryById":
opResult = await this.saasSve.apiQueryById(action_body);
break;
// 组织机构
case "saveOrg":
opResult = await this.orgSve.saveOrg(action_body);
break;
case "delOrg":
opResult = await this.orgSve.apiDelOrg(action_body);
break;
case "listOrg":
opResult = await this.orgSve.apiListOrg(action_body);
break;
case "findById":
opResult = await this.orgSve.apiFindById(action_body);
break;
case "orgByPid":
opResult = await this.orgSve.apiByPid(action_body);
break;
case "orgTree":
opResult = await this.orgSve.apiTree(action_body);
break;
// 菜单权限
case "addAuth":
opResult = this.authSve.add(action_body);
break;
case "updAuth":
opResult = this.authSve.upd(action_body);
break;
case "authTree":
opResult = this.authSve.tree(action_body);
break;
case "authInfo":
opResult = this.authSve.info(action_body);
break;
case "authByPid":
opResult = this.authSve.byPid(action_body);
break;
case "delAuth":
// TODO 验证是否有角色关联
opResult = this.authSve.del(action_body);
break;
// 角色
case "addRole":
opResult = await this.roleSve.apiAddRole(action_body);
break;
case "updRole":
opResult = await this.roleSve.apiUpdRole(action_body);
break;
case "delRole":
opResult = await this.roleSve.apiDelRole(action_body);
break;
case "listRole":
opResult = await this.roleSve.apiListRole(action_body);
break;
case "roleQueryById":
opResult = await this.roleSve.apiQueryById(action_body);
break;
case "setAuth":
opResult = await this.roleSve.setAuth(action_body);
break;
case "saveUser":
opResult = await this.userSve.saveUser(action_body);
break;
case "userInfo":
opResult = await this.userSve.info(action_body);
break;
case "enabled":
opResult = await this.userSve.enabled(action_body);
break;
case "delUser":
opResult = await this.userSve.delUser(action_body);
break;
case "userPage":
opResult = await this.userSve.pageByCondition(action_body);
break;
case "updPassword":
opResult = await this.userSve.updPassword(action_body);
break;
case "login":
opResult = await this.userSve.login(action_body);
break;
case "loginByUcid":
opResult = await this.userSve.loginByUcid(action_body);
break;
case "mapUserByIds":
opResult = await this.userSve.mapByIds(action_body);
break;
case "findUsers":
opResult = await this.userSve.findUsers(action_body);
break;
// -------------------------------- saas 用户接口 --------------------------------------
case "platformLogin":
opResult = await this.saasplatformuserSve.login(action_body);
break;
case "platformRegisterInner":
opResult = await this.saasplatformuserSve.registerInner(action_body);
break;
case "platformResetPasswordInner":
opResult = await this.saasplatformuserSve.resetPasswordInner(action_body);
break;
case "platformInfo":
opResult = await this.saasplatformuserSve.info(action_body);
break;
case "platformEnabled":
opResult = await this.saasplatformuserSve.enabled(action_body);
break;
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;
/**
* 接口跳转
* action_process 执行的流程
* action_type 执行的类型
* action_body 执行的参数
*/
async springboard(pobj, qobj, req) {
var result;
if (!pobj.action_process) {
return system.getResult(null, "action_process参数不能为空");
}
exam() {
return `<pre><pre/>`;
if (!pobj.action_type) {
return system.getResult(null, "action_type参数不能为空");
}
classDesc() {
return {
groupName: "op",
groupDesc: "元数据服务包",
name: "ActionAPI",
desc: "此类是对外提供接口服务",
exam: "",
};
console.log(pobj.action_process, pobj.action_type, pobj.action_body, "---------------- this is order micro sve --------------------");
try {
result = await this.handleRequest(pobj.action_process, pobj.action_type, pobj.action_body);
} catch (error) {
console.log(error);
}
methodDescs() {
return [{
methodDesc: `<pre><pre/>`,
methodName: "springboard",
paramdescs: [{
paramDesc: "请求的行为,传递如:sjb",
paramName: "action_process",
paramType: "string",
defaultValue: null,
},
{
paramDesc: "业务操作类型,详情见方法中的描述",
paramName: "action_type",
paramType: "string",
defaultValue: null,
},
{
paramDesc: "业务操作类型的参数,action_body必须传递的参数有,times_tamp(时间戳,类型int)、sign(签名,类型string),其余的为业务需要的参数",
paramName: "action_body",
paramType: "json",
defaultValue: null,
}
],
rtnTypeDesc: `<pre><pre/>`,
rtnType: `<pre><pre/>`
}];
return result;
}
async handleRequest(action_process, action_type, action_body) {
var opResult = null;
switch (action_type) {
// saas
case "addSaas":
opResult = await this.saasSve.apiAddSaas(action_body);
break;
case "updSaas":
opResult = await this.saasSve.apiUpdSaas(action_body);
break;
case "delSaas":
opResult = await this.userSve.apiFindUserBySaasId(action_body);
if (opResult.status == 0 && opResult.data.length == 0) {
opResult = await this.saasSve.apiDelSaas(action_body);
} else {
opResult = system.getResult(-1, `当前SAAS不能删除`);
}
break;
case "listSaas":
opResult = await this.saasSve.apiListSaas(action_body);
break;
case "saasQueryById":
opResult = await this.saasSve.apiQueryById(action_body);
break;
// 组织机构
case "saveOrg":
opResult = await this.orgSve.saveOrg(action_body);
break;
case "delOrg":
opResult = await this.orgSve.apiDelOrg(action_body);
break;
case "listOrg":
opResult = await this.orgSve.apiListOrg(action_body);
break;
case "findById":
opResult = await this.orgSve.apiFindById(action_body);
break;
case "orgByPid":
opResult = await this.orgSve.apiByPid(action_body);
break;
case "orgTree":
opResult = await this.orgSve.apiTree(action_body);
break;
// 菜单权限
case "addAuth":
opResult = this.authSve.add(action_body);
break;
case "updAuth":
opResult = this.authSve.upd(action_body);
break;
case "authTree":
opResult = this.authSve.tree(action_body);
break;
case "authInfo":
opResult = this.authSve.info(action_body);
break;
case "authByPid":
opResult = this.authSve.byPid(action_body);
break;
case "delAuth":
// TODO 验证是否有角色关联
opResult = this.authSve.del(action_body);
break;
// 角色
case "addRole":
opResult = await this.roleSve.apiAddRole(action_body);
break;
case "updRole":
opResult = await this.roleSve.apiUpdRole(action_body);
break;
case "delRole":
opResult = await this.roleSve.apiDelRole(action_body);
break;
case "listRole":
opResult = await this.roleSve.apiListRole(action_body);
break;
case "roleQueryById":
opResult = await this.roleSve.apiQueryById(action_body);
break;
case "setAuth":
opResult = await this.roleSve.setAuth(action_body);
break;
case "saveUser":
opResult = await this.userSve.saveUser(action_body);
break;
case "userInfo":
opResult = await this.userSve.info(action_body);
break;
case "enabled":
opResult = await this.userSve.enabled(action_body);
break;
case "delUser":
opResult = await this.userSve.delUser(action_body);
break;
case "userPage":
opResult = await this.userSve.pageByCondition(action_body);
break;
case "updPassword":
opResult = await this.userSve.updPassword(action_body);
break;
case "login":
opResult = await this.userSve.login(action_body);
break;
case "loginByUcid":
opResult = await this.userSve.loginByUcid(action_body);
break;
case "mapUserByIds":
opResult = await this.userSve.mapByIds(action_body);
break;
case "findUsers":
opResult = await this.userSve.findUsers(action_body);
break;
// -------------------------------- saas 用户接口 --------------------------------------
case "platformLogin":
opResult = await this.saasplatformuserSve.login(action_body);
break;
case "platformRegisterInner":
opResult = await this.saasplatformuserSve.registerInner(action_body);
break;
case "platformResetPasswordInner":
opResult = await this.saasplatformuserSve.resetPasswordInner(action_body);
break;
case "platformInfo":
opResult = await this.saasplatformuserSve.info(action_body);
break;
case "platformEnabled":
opResult = await this.saasplatformuserSve.enabled(action_body);
break;
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;
// 商户小程序
case "appletLogin":
opResult = await this.saasmerchantappletuserSve.appletLogin(action_body);
break;
case "appletUserInfo":
opResult = await this.saasmerchantappletuserSve.info(action_body);
break;
}
return opResult;
}
exam() {
return `<pre><pre/>`;
}
classDesc() {
return {
groupName: "op",
groupDesc: "元数据服务包",
name: "ActionAPI",
desc: "此类是对外提供接口服务",
exam: "",
};
}
methodDescs() {
return [{
methodDesc: `<pre><pre/>`,
methodName: "springboard",
paramdescs: [{
paramDesc: "请求的行为,传递如:sjb",
paramName: "action_process",
paramType: "string",
defaultValue: null,
},
{
paramDesc: "业务操作类型,详情见方法中的描述",
paramName: "action_type",
paramType: "string",
defaultValue: null,
},
{
paramDesc: "业务操作类型的参数,action_body必须传递的参数有,times_tamp(时间戳,类型int)、sign(签名,类型string),其余的为业务需要的参数",
paramName: "action_body",
paramType: "json",
defaultValue: null,
}
],
rtnTypeDesc: `<pre><pre/>`,
rtnType: `<pre><pre/>`
}];
}
}
module.exports = ActionAPI;
\ No newline at end of file
const system = require("../../../system");
const Dao = require("../../dao.base");
class SaasMerchantAppUserDao extends Dao {
class SaasMerchantAppletUserDao extends Dao {
constructor() {
super(Dao.getModelName(SaasMerchantAppUserDao));
super(Dao.getModelName(SaasMerchantAppletUserDao));
}
async byOpenId(openid, saasMerchantId) {
var sql = "SELECT * FROM uc_user WHERE openid = :openid AND saas_merchant_id = :saasMerchantId AND deleted_at IS NULL";
var sql = `SELECT * FROM ${this.model.tableName} WHERE openid = :openid AND saas_merchant_id = :saasMerchantId AND deleted_at IS NULL`;
var list = await this.customQuery(sql, {
openid: openid,
saasMerchantId: saasMerchantId,
......@@ -18,4 +18,4 @@ class SaasMerchantAppUserDao extends Dao {
}
}
module.exports = SaasMerchantAppUserDao;
\ No newline at end of file
module.exports = SaasMerchantAppletUserDao;
\ No newline at end of file
......@@ -2,16 +2,13 @@ const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("saasmerchantuser", {
return db.define("saasmerchantappletuser", {
openid: DataTypes.STRING,
ucname: DataTypes.STRING,
mobile: DataTypes.STRING,
realName: DataTypes.STRING,
nickName: DataTypes.STRING,
avatarUrl: DataTypes.STRING,
password: DataTypes.STRING,
isMain: {
type: DataTypes.BOOLEAN,
defaultValue: true
},
isEnabled: {
type: DataTypes.BOOLEAN,
defaultValue: true
......@@ -25,7 +22,7 @@ module.exports = (db, DataTypes) => {
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'saas_platform_user',
tableName: 'saas_merchant_applet_user',
validate: {
},
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class SaasMerchantAppletUserService extends ServiceBase {
constructor() {
super("user", ServiceBase.getDaoName(SaasMerchantAppletUserService));
}
async appletLogin(obj) {
let saas_merchant_id = obj.saas_merchant_id;
let saas_id = obj.saas_id;
let openid = obj.openid;
let nickName = this.trim(obj.nickName);
let avatarUrl = this.trim(obj.avatarUrl);
if (!saas_merchant_id) {
return system.getResult(null, "登录失败,商户信息错误");
}
if (!openid) {
return system.getResult(null, "登录信息获取失败");
}
let user = await this.dao.byOpenId(openid, saas_merchant_id);
if (!user) {
user = {
openid: openid,
nickName: nickName,
avatarUrl: avatarUrl,
saas_merchant_id: saas_merchant_id,
saas_id: saas_id,
mobile: "",
ucname: "",
password: "",
isEnabled: true,
};
user = await this.dao.model.create(user);
} else {
if(avatarUrl) {
user.avatarUrl = avatarUrl;
await this.dao.update({
id: user.id,
avatarUrl: avatarUrl,
});
}
if(nickName) {
this.dao.update({
id: user.id,
nickName: nickName
});
}
}
return system.getResultSuccess(user);
}
async info(params) {
let user = await this.dao.byOpenId(params.openid, params.merchant_id);
return system.getResultSuccess(user);
}
async mapByIds(params) {
let rs = await this.dao.findMapByIds(params.ids);
return system.getResultSuccess(rs);
}
}
module.exports = SaasMerchantAppletUserService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class SaasMerchantAppUserService extends ServiceBase {
constructor() {
super("user", ServiceBase.getDaoName(SaasMerchantAppUserService));
}
async login(obj) {
var uctype = Number(obj.uctype || 0);
var user = await this.dao.getByUcname(obj.ucname);
// 验证登录合法
if (!user) {
return system.getResult(null, "用户名或密码错误");
}
if (!user.isEnabled) {
return system.getResult(null, "用户已禁用");
}
if (uctype && uctype != user.uctype) {
return system.getResult(null, "用户类型错误");
}
var loginPwd = await this.getEncryptStr(obj.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 = {};
if (id) {
let u = await this.findById(id);
if (u) {
user.id = u.id;
}
}
let exist = await this.findOne({
ucname: obj.ucname
});
if (user.id) {
if (exist && exist.id != user.id) {
return system.getResult(null, `用户名【${ucname}】已存在`);
}
} else {
if (exist) {
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);
}
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);
}
user.orgpath = org.path + "/" + user.id + "/";
await self.dao.update({
id: user.id,
orgpath: user.orgpath
}, t);
return user;
});
return system.getResultSuccess(user);
} catch (error) {
console.log(error);
if (error.name == 'SequelizeValidationError') {
return system.getResult(-1, `用户名重复`);
}
return system.getResult(-1, `系统错误 错误信息${error}`);
}
}
async info(params) {
var id = Number(params.id || 0);
var user = await this.dao.getById(id);
if (!user) {
return system.getResult(null, "用户不存在");
}
this.handleDate(user, ["created_at"], null, -8);
return system.getResultSuccess(user);
}
async enabled(params) {
var user = await this.dao.findById(params.id);
if (!user) {
return system.getResult(null, "用户不存在");
}
user.isEnabled = Number(params.enabled || 0) == 0 ? false : true;
await user.save();
return system.getResultSuccess();
}
async pageByCondition(params) {
var result = {
count: 0,
rows: []
};
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 system.getResultSuccess(result);
}
result.count = total;
params.startRow = (currentPage - 1) * pageSize;
result.rows = await this.dao.listByCondition(params) || [];
if (result.rows) {
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) {
return system.getResult(null, "用户不存在");
}
user.password = await this.getEncryptStr(params.password);
await user.save();
return system.getResultSuccess();
}
async mapByIds(params) {
let rs = await this.dao.findMapByIds(params.ids);
return system.getResultSuccess(rs);
}
}
module.exports = SaasMerchantAppUserService;
\ No newline at end of file
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