Commit 961c57e8 by 蒋勇

d

parent d79cd06c
......@@ -9,11 +9,11 @@ class UserService extends ServiceBase {
this.roleDao = system.getObject("db.auth.roleDao");
this.authS = system.getObject("service.auth.authSve");
}
async pmgetUserByCode(code) {
async pmgetUserByCode (code) {
let ux = await this.cacheManager["CodeCache"].getCache(code);
return ux;
}
async loginApp(appkey, uname) {
async loginApp (appkey, uname) {
let rtn = {}
let app = await this.cacheManager["AppCache"].cache(appkey);
let userLogined = await this.cacheManager["UserCache"].cache(uname);
......@@ -38,7 +38,7 @@ class UserService extends ServiceBase {
//和租户绑定同一家公司
//按照用户名和密码进行注册
//控制器端检查用户名和密码非空
async registerByTantent(p, q) {
async registerByTantent (p, q) {
// 需要默认添加访客角色,为了控制单点从平台登录时看到的菜单和功能
if (p.roles && p.roles.length > 0) {
if (p.roles.indexOf(settings.pmroleid["pr"]) < 0) {
......@@ -51,7 +51,7 @@ class UserService extends ServiceBase {
}
//应用的自由用户注册,无需验证,需要前端头设置公司KEY
async pmregisterByFreeUser(p, q) {
async pmregisterByFreeUser (p, q) {
p.rolecodes = [settings.pmroleid["pr"]];
let rtn = await this.pmregister(p, q)
return rtn;
......@@ -60,7 +60,7 @@ class UserService extends ServiceBase {
//平台租户注册接口方法
//控制器端检查用户名和密码非空
async pmregister(p, q) {
async pmregister (p, q) {
var self = this;
let tmppwd = p.password;
if (!tmppwd) {
......@@ -71,8 +71,8 @@ class UserService extends ServiceBase {
p.nickName = p.userName;
}
//检查是否已经存在同名账号
let existOne=await this.dao.model.findOne({where:{userName:p.userName}})
if(existOne){
let existOne = await this.dao.model.findOne({ where: { userName: p.userName } })
if (existOne) {
throw new Error("平台中已存在相同的账号.");
}
......@@ -107,7 +107,7 @@ class UserService extends ServiceBase {
await u.setRoles(roles, { transaction: t });
}
}*/
var roles = await self.roleDao.model.findAll({ where: { id: { [self.db.Op.in]: rolecodes }}, transaction: t });
var roles = await self.roleDao.model.findAll({ where: { id: { [self.db.Op.in]: rolecodes } }, transaction: t });
if (roles && roles.length > 0) {
await u.setRoles(roles, { transaction: t });
}
......@@ -134,7 +134,7 @@ class UserService extends ServiceBase {
}
});
}
async logout(pobj){
async logout (pobj) {
await this.cacheManager["UserCache"].invalidate(pobj.username);
return {}
}
......@@ -142,7 +142,7 @@ class UserService extends ServiceBase {
//登录接口封装kong-url
//登录路由放行
//p里面含有appkey,company_id,userName,password
async pmlogin(p, q, req) {
async pmlogin (p, q, req) {
var self = this;
//先要按照用户名,在统一账户中查找存在性
//如果不存在
......@@ -186,7 +186,7 @@ class UserService extends ServiceBase {
}
})
}
async getUserInfo(uname) {
async getUserInfo (uname) {
// let userfind = await this.dao.model.findOne({
// where: { userName: uname, app_id: settings.pmappid },
// attributes: ['userName', 'nickName',"headUrl",'isSuper','isAdmin'],
......@@ -207,7 +207,7 @@ class UserService extends ServiceBase {
//自由用户的电话登录和注册
//需要存在公司KEY
async pmloginByVCodeForFreeUser(p, q) {
async pmloginByVCodeForFreeUser (p, q) {
p.rolecodes = [settings.pmroleid["pr"]];
let rtn = await this.pmloginByVCode(p, q, req)
return system.getResult(rtn);
......@@ -216,7 +216,7 @@ class UserService extends ServiceBase {
//平台租户注册与登录
//用户验证码登录
//
async pmloginByVCode(p, q, req) {
async pmloginByVCode (p, q, req) {
var rtn = {}
//检查传递过来的手机验证码是否与缓存的一致
let mobile = p.mobile;
......@@ -261,19 +261,19 @@ class UserService extends ServiceBase {
//不一致那么就
}
//发送手机验证码并缓存
async sendVCode(p, q, req) {
async sendVCode (p, q, req) {
let mobile = p.mobile;
let vcodeobj = await this.cacheManager["VCodeCache"].cache(mobile, null, 60);
return vcodeobj.vcode;
}
async reSendVCode(p, q, req) {
async reSendVCode (p, q, req) {
let mobile = p.mobile;
await this.cacheManager["VCodeCache"].invalidate(mobile);
let vcodeobj = await this.cacheManager["VCodeCache"].cache(mobile, null, 60);
return vcodeobj.vcode;
}
//修改中心密码
async cmodifypwd(uname, newpwd, cmpid) {
async cmodifypwd (uname, newpwd, cmpid) {
try {
let rtn = await system.postJsonTypeReq(UserService.consumerUrl(uname), { tags: ["cmp_" + cmpid, "pass_" + newpwd] }, "PATCH")
console.log(rtn)
......@@ -287,7 +287,7 @@ class UserService extends ServiceBase {
}
}
//创建统一账号及jwt身份
async cregister(uname, cmpid, pass, uid) {
async cregister (uname, cmpid, pass, uid) {
try {
var rtn2 = null;
let rtn = await system.postJsonTypeReq(UserService.newConsumerUrl(), { username: uname, custom_id: uid, tags: ["cmp_" + cmpid, "pass_" + pass] })
......@@ -309,9 +309,9 @@ class UserService extends ServiceBase {
}
//plkey--对应消费者jwt身份的key,插件解码token后,获取iss-key,查询出身份,利用
//身份中的secret验证签名
async jwtsign(plkey, secretstr, opts) {
async jwtsign (plkey, secretstr, opts) {
let promise = new Promise(function (resv, rej) {
jwt.sign({exp: Math.floor(Date.now() / 1000) + (60 * 60),iss: plkey}, secretstr, opts, function (err, rtn) {
jwt.sign({ exp: Math.floor(Date.now() / 1000) + (60 * 60), iss: plkey }, secretstr, opts, function (err, rtn) {
if (err) {
rej(err);
} else {
......@@ -322,13 +322,13 @@ class UserService extends ServiceBase {
return promise;
}
//只要登录 生成新的访问jwttoken
async cmakejwt(key, secret, opts) {
async cmakejwt (key, secret, opts) {
var token = await this.jwtsign(key, secret, opts);
return token;
}
//删除统一账号
async cunregister(uname) {
async cunregister (uname) {
try {
let rtn = await system.delReq(UserService.consumerUrl(uname))
if (rtn.statusCode == 204) {
......@@ -342,15 +342,15 @@ class UserService extends ServiceBase {
//登录统一账号
async clogin(uname) {
async clogin (uname) {
//检查是否存在重名
}
//按用户名查询统一用户
async findCUser(uname) {
async findCUser (uname) {
}
async resetPassword(uname, pwd) {
async resetPassword (uname, pwd) {
let inpassword = this.getEncryptStr(pwd);
var self = this;
return this.db.transaction(async function (t) {
......@@ -368,7 +368,7 @@ class UserService extends ServiceBase {
});
}
//修改
async update(qobj, tm = null) {
async update (qobj, tm = null) {
var self = this;
return this.db.transaction(async function (t) {
delete qobj['company_id']
......@@ -390,9 +390,9 @@ class UserService extends ServiceBase {
* @param {*} productCatName 产品类型名称
* @param {*} regionName 区域
*/
async getBizUserForBizChance(clientMobile, spName, productCatName,regionName) {
async getBizUserForBizChance (clientMobile, spName, productCatName, regionName) {
var self = this
clientMobile=clientMobile+"_"+spName
clientMobile = clientMobile + "_" + spName "_" + regionName
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
return this.db.transaction(async function (t) {
//先检查缓存是否存在bizuser
......@@ -412,27 +412,27 @@ class UserService extends ServiceBase {
let companyFind = await self.companyDao.model.findOne({
where: { name: spName }, include: [
{
model: self.db.models.user, as: "us", attributes: ['id', 'userName', 'mobile', 'isAllocated', 'opath', 'skilltags','regiontags'], raw: true
model: self.db.models.user, as: "us", attributes: ['id', 'userName', 'mobile', 'isAllocated', 'opath', 'skilltags', 'regiontags'], raw: true
}
], excludes: ['orgJson'], transaction: t
});
console.log(companyFind)
let users = companyFind.us
let cansels = users.filter(u => {
if(regionName && regionName!="" && u.regiontags){
if (u.isAllocated && u.skilltags.indexOf(productCatName) >= 0 && u.regiontags.indexOf(regionName)>=0) {
if (regionName && regionName != "" && u.regiontags) {
if (u.isAllocated && u.skilltags.indexOf(productCatName) >= 0 && u.regiontags.indexOf(regionName) >= 0) {
return true
} else {
return false
}
}else{
} else {
if (u.isAllocated && u.skilltags.indexOf(productCatName) >= 0) {
return true
} else {
return false
}
}
})
let lngth = cansels.length
if (lngth > 0) {
......@@ -444,7 +444,7 @@ class UserService extends ServiceBase {
userName: selresult.userName,
mobile: selresult.mobile,
opath: selresult.opath,
compId:companyFind.id
compId: companyFind.id
}
await self.cacheManager["ClientBindBizUserCache"].cache(clientMobile, tmp)
return tmp
......@@ -470,19 +470,19 @@ class UserService extends ServiceBase {
* @param {*} skucode 最小销售货品编码,来自渠道上架的码
* @param {*} regionName 区域
*/
async getBizUserForDelivery(xclientMobile, spName, productCatName, skucode,regionName) {
let clientMobile='fordeliver'+xclientMobile+"_"+spName
async getBizUserForDelivery (xclientMobile, spName, productCatName, skucode, regionName) {
let clientMobile = 'fordeliver' + xclientMobile + "_" + spName + "_" + regionName
var self = this
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
return this.db.transaction(async function (t) {
//按照产品简码,查询服务成本
let productpricetmp = await self.db.models.productprice.findOne({
where: { skucode: skucode },
include:[
{model: self.db.models.productcost,as:"costs",attributes:['id','expensetype','costamount']}
include: [
{ model: self.db.models.productcost, as: "costs", attributes: ['id', 'expensetype', 'costamount'] }
],
transaction: t
}
}
)
let serviceCost = productpricetmp.costs.filter(c => {
if (c.expensetype == "service") {
......@@ -491,7 +491,7 @@ class UserService extends ServiceBase {
})
let costAmount = 0
//获取服务费成本
if (serviceCost.length>0) {
if (serviceCost.length > 0) {
costAmount = serviceCost[0].costamount
}
......@@ -518,13 +518,13 @@ class UserService extends ServiceBase {
});
let users = companyFind.us
let cansels = users.filter(u => {
if(regionName && regionName!="" && u.regiontags){
if (u.isAllocated && u.skilltags.indexOf(productCatName) >= 0 && u.regiontags.indexOf(regionName)>=0) {
if (regionName && regionName != "" && u.regiontags) {
if (u.isAllocated && u.skilltags.indexOf(productCatName) >= 0 && u.regiontags.indexOf(regionName) >= 0) {
return true
} else {
return false
}
}else{
} else {
if (u.isAllocated && u.skilltags.indexOf(productCatName) >= 0) {
return true
} else {
......@@ -543,7 +543,7 @@ class UserService extends ServiceBase {
mobile: selresult.mobile,
opath: selresult.opath,
cost: costAmount,
compId:companyFind.id
compId: companyFind.id
}
await self.cacheManager["ClientBindBizUserCache"].cache(clientMobile, tmp)
return tmp
......
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