import { default as BaseController } from "../baseController";
|
import { Post } from "egg-shell-decorators";
|
import { SysUser } from "../../entity/sys/core/sysUser";
|
import { BaseConsignor } from "../../entity/basicInfo/consignor/baseConsignor";
|
|
/**
|
* 用户中心
|
*/
|
export default class UserController extends BaseController {
|
//#region 用户账号禁用
|
/**
|
* 用户账号禁用
|
*/
|
@Post()
|
public async disabledUser() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let _userInfo = await ctx.helper.userInfo();
|
|
try {
|
//#region 校验数据
|
if (!body.user_Id) {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
this.ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
|
//#region 禁用
|
let userInfo = await this.dbRead.findOne(SysUser, {
|
where: {
|
userProduct_Id: _userInfo.userProduct_Id,
|
user_Id: body.user_Id
|
}
|
});
|
|
if (userInfo) {
|
await this.dbWrite.update(SysUser, userInfo.user_Id, {
|
enable: 0
|
});
|
this.info.result = true;
|
this.info.msg = "禁用成功,已将用户转移到已禁用账号tab中";
|
} else {
|
this.info.result = false;
|
this.info.msg = "禁用失败";
|
}
|
//#endregion
|
|
ctx.body = this.info;
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 用户账号启用
|
/**
|
* 用户账号启用
|
*/
|
@Post()
|
public async enableUser() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let _userInfo = await ctx.helper.userInfo();
|
|
try {
|
//#region 校验数据
|
if (!body.user_Id) {
|
this.info.result = false;
|
this.info.msg = "数据不存在";
|
this.ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
|
//#region 禁用
|
let userInfo = await this.dbRead.findOne(SysUser, {
|
where: {
|
userProduct_Id: _userInfo.userProduct_Id,
|
user_Id: body.user_Id
|
}
|
});
|
|
if (userInfo) {
|
await this.dbWrite.update(SysUser, userInfo.user_Id, {
|
enable: 1
|
});
|
this.info.result = true;
|
this.info.msg = "启用成功,在公司员工tab中可见";
|
} else {
|
this.info.result = false;
|
this.info.msg = "启用失败";
|
}
|
//#endregion
|
|
ctx.body = this.info;
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "错误信息:" + ex.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 超级管理员后端修改密码
|
@Post()
|
public async modifyPwd() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let _userInfo = await ctx.helper.userInfo();
|
|
try {
|
//校验数据
|
if (!body.userPwd) {
|
this.info.result = false;
|
this.info.msg = "请输入密码!";
|
this.ctx.body = this.info;
|
return;
|
}
|
if (!body.repeatPassWord) {
|
this.info.result = false;
|
this.info.msg = "请确认密码!";
|
this.ctx.body = this.info;
|
return;
|
}
|
if (body.repeatPassWord != body.userPwd) {
|
this.info.result = false;
|
this.info.msg = "两次密码不一致!";
|
this.ctx.body = this.info;
|
return;
|
}
|
|
var userInfo = await this.dbRead.findOne(SysUser, {
|
where: {
|
user_Id: body.user_Id,
|
userProduct_Id: _userInfo.userProduct_Id
|
}
|
});
|
if (userInfo == null) {
|
this.info.result = false;
|
this.info.msg = "用户不存在!";
|
this.ctx.body = this.info;
|
return;
|
}
|
//修改密码
|
let userPwd = ctx.helper.md5EncodingSalt(body.userPwd);
|
await this.dbWrite.update(SysUser, userInfo.user_Id, {
|
userPwd: userPwd
|
});
|
this.info.result = true;
|
this.info.msg = "修改成功!";
|
this.ctx.body = this.info;
|
return;
|
} catch (ex) {
|
this.info.result = false;
|
this.info.msg = "修改失败," + ex.message;
|
this.ctx.body = this.info;
|
return;
|
}
|
}
|
//#endregion
|
|
//#region SaaS修改超级管理员密码
|
@Post()
|
public async saaSModifyPwd() {
|
try {
|
//#region 校验数据
|
if (!this.body.oldPwd) {
|
this.info.result = false;
|
this.info.msg = "请输入旧密码!";
|
this.ctx.body = this.info;
|
return;
|
}
|
if (!this.body.userPwd) {
|
this.info.result = false;
|
this.info.msg = "请输入密码!";
|
this.ctx.body = this.info;
|
return;
|
}
|
if (!this.body.repeatPassWord) {
|
this.info.result = false;
|
this.info.msg = "请确认密码!";
|
this.ctx.body = this.info;
|
return;
|
}
|
if (this.body.RepeatPassWord != this.body.userPwd) {
|
this.info.result = false;
|
this.info.msg = "两次密码不一致!";
|
this.ctx.body = this.info;
|
return;
|
}
|
//#endregion
|
|
var userInfo = await this.dbRead.findOne(SysUser, {
|
userProduct_Id: this.body.userProduct_Id,
|
isAdministrator: 1
|
});
|
if (userInfo != null) {
|
var newUserPwd = await this.ctx.helper.md5EncodingSalt(this.body.oldPwd);
|
if (userInfo.userPwd == newUserPwd) {
|
let userPwd = await this.ctx.helper.md5EncodingSalt(this.body.userPwd);
|
await this.dbWrite.update(SysUser, userInfo.user_Id, {
|
userPwd: userPwd
|
});
|
this.info.result = true;
|
this.info.msg = "修改成功!";
|
this.ctx.body = this.info;
|
return;
|
} else {
|
this.info.result = false;
|
this.info.msg = "旧密码不正确";
|
this.ctx.body = this.info;
|
return;
|
}
|
}
|
this.ctx.body = this.info;
|
return;
|
} catch {
|
this.info.result = false;
|
this.info.msg = "修改失败!";
|
this.ctx.body = this.info;
|
return;
|
}
|
}
|
//#endregion
|
|
//#region 修改货主密码
|
@Post()
|
public async consignorModifyPwd() {
|
let { ctx } = this;
|
// let body = ctx.request.body;
|
let _userInfo = await ctx.helper.userInfo();
|
try {
|
//#region 校验数据
|
// if (!this.body.oldPwd) {
|
// this.info.result = false;
|
// this.info.msg = "请输入旧密码!";
|
// this.ctx.body = this.info;
|
// return;
|
// }
|
if (!this.body.userPwd) {
|
this.info.result = false;
|
this.info.msg = "请输入密码!";
|
this.ctx.body = this.info;
|
return;
|
}
|
if (!this.body.repeatPassWord) {
|
this.info.result = false;
|
this.info.msg = "请确认密码!";
|
this.ctx.body = this.info;
|
return;
|
}
|
if (this.body.repeatPassWord != this.body.userPwd) {
|
this.info.result = false;
|
this.info.msg = "新密码与确认密码不一致!";
|
this.ctx.body = this.info;
|
return;
|
}
|
var userInfo = await this.dbRead.findOne(BaseConsignor, {
|
consignor_Id: this.body.consignor_Id,
|
userProduct_Id: _userInfo.userProduct_Id
|
});
|
if (!userInfo) {
|
this.info.result = false;
|
this.info.msg = "用户未注册!";
|
this.ctx.body = this.info;
|
return;
|
}
|
//#endregion 校验数据
|
if (userInfo != null) {
|
let userPwd = await this.ctx.helper.md5EncodingSalt(this.body.userPwd);
|
await this.dbWrite.update(BaseConsignor, userInfo.consignor_Id, {
|
password: userPwd
|
});
|
// await this.dbRead.update(BaseConsignor, this.body.consignor_Id, {});
|
this.info.result = true;
|
this.info.msg = "修改成功!";
|
this.ctx.body = this.info;
|
return;
|
}
|
this.ctx.body = this.info;
|
return;
|
} catch {
|
this.info.result = false;
|
this.info.msg = "修改失败!";
|
this.ctx.body = this.info;
|
return;
|
}
|
}
|
//#endregion
|
|
//#region 获取用户管理用户列表
|
/**
|
* 获取用户管理用户列表
|
*/
|
@Post()
|
public async getList() {
|
let { ctx } = this;
|
let userInfo = await ctx.helper.userInfo();
|
try {
|
var dataList = await this.dbRead.find(SysUser, {
|
select: ["userTrueName"],
|
where: { userProduct_Id: userInfo.userProduct_Id, enable: 1 }
|
});
|
this.info.result = true;
|
this.info.data = dataList;
|
} catch (e) {
|
this.info.result = false;
|
this.info.msg = e.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
|
//#region 更换头像
|
/**
|
* 更换头像
|
*/
|
@Post()
|
public async picUpdate() {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let pic = body.pic; // 获取到的图片
|
let userInfo = await this.userInfo;
|
|
try {
|
await this.dbWrite.update(SysUser, userInfo.user_Id, {
|
pic: pic
|
});
|
|
this.info.result = true;
|
this.info.msg = "保存成功";
|
|
ctx.body = this.info;
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "保存失败" + error.message;
|
}
|
ctx.body = this.info;
|
}
|
//#endregion
|
}
|