Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
825db4f9
Commit
825db4f9
authored
Jun 16, 2020
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
d
parent
0b795957
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
239 additions
and
53 deletions
+239
-53
center-manage/app/base/api/impl/auth/accessAuth.js
+8
-0
center-manage/app/base/controller/impl/auth/userCtl.js
+1
-0
center-manage/app/base/db/cache/clientBindBizUserCache.js
+22
-0
center-manage/app/base/db/impl/common/connection.js
+4
-1
center-manage/app/base/service/impl/auth/userSve.js
+204
-52
No files found.
center-manage/app/base/api/impl/auth/accessAuth.js
View file @
825db4f9
...
...
@@ -25,6 +25,14 @@ class AccessAuthAPI extends APIBase {
let
appkey
=
req
.
xctx
.
appkey
;
}
async
getBizUserForBizChance
(
p
,
q
,
req
){
let
s
=
await
this
.
userSve
.
getBizUserForBizChance
(
p
.
clientMobile
,
p
.
spName
,
p
.
productCatName
)
return
system
.
getResult
(
s
)
}
async
getBizUserForDelivery
(
p
,
q
,
req
){
let
s
=
await
this
.
userSve
.
getBizUserForDelivery
(
p
.
clientMobile
,
p
.
spName
,
p
.
productCatName
,
p
.
skucode
)
return
system
.
getResult
(
s
)
}
classDesc
()
{
return
{
groupName
:
"auth"
,
...
...
center-manage/app/base/controller/impl/auth/userCtl.js
View file @
825db4f9
...
...
@@ -123,5 +123,6 @@ class UserCtl extends CtlBase {
let
rtn
=
await
this
.
service
.
sendVCode
(
pobj
,
qobj
);
return
system
.
getResult
(
rtn
);
}
}
module
.
exports
=
UserCtl
;
center-manage/app/base/db/cache/clientBindBizUserCache.js
0 → 100644
View file @
825db4f9
const
CacheBase
=
require
(
"../cache.base"
);
const
system
=
require
(
"../../system"
);
const
settings
=
require
(
"../../../config/settings"
);
class
ClientBindBizUserCache
extends
CacheBase
{
constructor
(){
super
();
}
isdebug
(){
return
settings
.
env
==
"dev"
;
}
desc
(){
return
"缓存本地应用对象"
;
}
prefix
(){
return
"g_client2bizuser_"
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
return
JSON
.
stringify
(
val
);
}
}
module
.
exports
=
ClientBindBizUserCache
;
\ No newline at end of file
center-manage/app/base/db/impl/common/connection.js
View file @
825db4f9
...
...
@@ -56,6 +56,9 @@ class DbFactory{
this
.
db
.
models
.
user
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
this
.
db
.
models
.
company
.
hasMany
(
this
.
db
.
models
.
user
,{
as
:
'us'
,
constraints
:
false
,});
this
.
db
.
models
.
role
.
belongsTo
(
this
.
db
.
models
.
company
,
{
constraints
:
false
,});
// this.db.models.org.belongsTo(this.db.models.company,{constraints: false,});
...
...
@@ -77,7 +80,7 @@ class DbFactory{
this
.
db
.
models
.
productprice
.
belongsTo
(
this
.
db
.
models
.
company
,{
constraints
:
false
,});
//成本项目属于productprice
this
.
db
.
models
.
productcost
.
belongsTo
(
this
.
db
.
models
.
productprice
,{
constraints
:
false
,});
this
.
db
.
models
.
productprice
.
hasMany
(
this
.
db
.
models
.
productcost
,{
as
:
"costs"
,
constraints
:
false
,});
}
//async getCon(){,用于使用替换table模型内字段数据使用
getCon
(){
...
...
center-manage/app/base/service/impl/auth/userSve.js
View file @
825db4f9
...
...
@@ -7,31 +7,31 @@ class UserService extends ServiceBase {
super
(
"auth"
,
ServiceBase
.
getDaoName
(
UserService
));
this
.
companyDao
=
system
.
getObject
(
"db.common.companyDao"
);
this
.
roleDao
=
system
.
getObject
(
"db.auth.roleDao"
);
this
.
authS
=
system
.
getObject
(
"service.auth.authSve"
);
this
.
authS
=
system
.
getObject
(
"service.auth.authSve"
);
}
async
pmgetUserByCode
(
code
){
let
ux
=
await
this
.
cacheManager
[
"CodeCache"
].
getCache
(
code
);
return
ux
;
async
pmgetUserByCode
(
code
)
{
let
ux
=
await
this
.
cacheManager
[
"CodeCache"
].
getCache
(
code
);
return
ux
;
}
async
loginApp
(
appkey
,
uname
)
{
let
rtn
=
{}
let
app
=
await
this
.
cacheManager
[
"AppCache"
].
cache
(
appkey
);
let
userLogined
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
uname
);
rtn
.
user
=
userLogined
async
loginApp
(
appkey
,
uname
)
{
let
rtn
=
{}
let
app
=
await
this
.
cacheManager
[
"AppCache"
].
cache
(
appkey
);
let
userLogined
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
uname
);
rtn
.
user
=
userLogined
if
(
userLogined
)
{
let
token
=
await
this
.
cmakejwt
(
userLogined
.
jwtkey
,
userLogined
.
jwtsecret
,
null
);
rtn
.
token
=
token
;
}
let
roleids
=
userLogined
.
Roles
.
map
(
item
=>
{
let
roleids
=
userLogined
.
Roles
.
map
(
item
=>
{
return
item
.
id
})
let
auths
=
await
this
.
authS
.
findAuthsByRole
(
roleids
)
rtn
.
user
.
access
=
auths
let
code
=
this
.
getUUID
()
this
.
cacheManager
[
"CodeCache"
].
cache
(
code
,
rtn
,
60000
);
// let url=app.homePage+"?code="+code
return
{
code
,
homePage
:
app
.
homePage
};
let
auths
=
await
this
.
authS
.
findAuthsByRole
(
roleids
)
rtn
.
user
.
access
=
auths
let
code
=
this
.
getUUID
()
this
.
cacheManager
[
"CodeCache"
].
cache
(
code
,
rtn
,
60000
);
// let url=app.homePage+"?code="+code
return
{
code
,
homePage
:
app
.
homePage
};
}
//登录后的租户创建属于租户的用户
//需要在控制器里取出公司ID
...
...
@@ -40,8 +40,8 @@ class UserService extends ServiceBase {
//控制器端检查用户名和密码非空
async
registerByTantent
(
p
,
q
)
{
// 需要默认添加访客角色,为了控制单点从平台登录时看到的菜单和功能
if
(
p
.
roles
&&
p
.
roles
.
length
>
0
)
{
if
(
p
.
roles
.
indexOf
(
settings
.
pmroleid
[
"pr"
])
<
0
)
{
if
(
p
.
roles
&&
p
.
roles
.
length
>
0
)
{
if
(
p
.
roles
.
indexOf
(
settings
.
pmroleid
[
"pr"
])
<
0
)
{
p
.
roles
.
push
(
settings
.
pmroleid
[
"pr"
])
}
}
...
...
@@ -88,18 +88,18 @@ class UserService extends ServiceBase {
//设置默认角色,租户
//设置默认普通角色,由于有了租户概念,所以注册时,需要知道当前租户和应用的id 才可以设置默认角色 todo
//如果是非租户,那么按照当前应用ID是找不到指定的角色,所以是空的
if
(
p
.
isAdmin
)
{
var
roles
=
await
self
.
roleDao
.
model
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
rolecodes
},
app_id
:
roleappid
,
company_id
:
settings
.
pmcompanyid
},
transaction
:
t
});
if
(
p
.
isAdmin
)
{
var
roles
=
await
self
.
roleDao
.
model
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
rolecodes
},
app_id
:
roleappid
,
company_id
:
settings
.
pmcompanyid
},
transaction
:
t
});
if
(
roles
&&
roles
.
length
>
0
)
{
await
u
.
setRoles
(
roles
,
{
transaction
:
t
});
}
}
else
{
var
roles
=
await
self
.
roleDao
.
model
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
rolecodes
},
app_id
:
roleappid
,
company_id
:
p
.
company_id
},
transaction
:
t
});
}
else
{
var
roles
=
await
self
.
roleDao
.
model
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
rolecodes
},
app_id
:
roleappid
,
company_id
:
p
.
company_id
},
transaction
:
t
});
if
(
roles
&&
roles
.
length
>
0
)
{
await
u
.
setRoles
(
roles
,
{
transaction
:
t
});
}
}
//创建统一账号 to add extra fields
let
cred
=
await
self
.
cregister
(
u
.
userName
,
p
.
company_id
,
p
.
password
,
u
.
id
+
""
)
console
.
log
(
"......................................"
);
...
...
@@ -153,11 +153,11 @@ class UserService extends ServiceBase {
let
token
=
await
self
.
cmakejwt
(
userfind
.
jwtkey
,
userfind
.
jwtsecret
,
null
);
rtn
.
token
=
token
;
let
roleids
=
userfind
.
Roles
.
map
(
item
=>
{
let
roleids
=
userfind
.
Roles
.
map
(
item
=>
{
return
item
.
id
})
let
auths
=
await
self
.
authS
.
findAuthsByRole
(
roleids
)
userfind
[
"access"
]
=
auths
let
auths
=
await
self
.
authS
.
findAuthsByRole
(
roleids
)
userfind
[
"access"
]
=
auths
delete
userfind
[
"jwtkey"
]
delete
userfind
[
"jwtsecret"
]
...
...
@@ -176,11 +176,11 @@ class UserService extends ServiceBase {
// });
let
userfind
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
uname
)
//添加当前用户的权限信息
let
roleids
=
userfind
.
Roles
.
map
(
item
=>
{
return
item
.
id
})
let
auths
=
await
this
.
authS
.
findAuthsByRole
(
roleids
)
userfind
[
"access"
]
=
auths
let
roleids
=
userfind
.
Roles
.
map
(
item
=>
{
return
item
.
id
})
let
auths
=
await
this
.
authS
.
findAuthsByRole
(
roleids
)
userfind
[
"access"
]
=
auths
delete
userfind
[
"jwtkey"
]
delete
userfind
[
"jwtsecret"
]
...
...
@@ -211,11 +211,11 @@ class UserService extends ServiceBase {
//appkey--company_id---需要控制器基类里设置到p对象里
let
user
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
mobile
)
if
(
user
)
{
let
roleids
=
user
.
Roles
.
map
(
item
=>
{
let
roleids
=
user
.
Roles
.
map
(
item
=>
{
return
item
.
id
})
let
auths
=
await
this
.
authS
.
findAuthsByRole
(
roleids
)
user
[
"access"
]
=
auths
let
auths
=
await
this
.
authS
.
findAuthsByRole
(
roleids
)
user
[
"access"
]
=
auths
//生成token
let
token
=
await
this
.
cmakejwt
(
user
.
jwtkey
,
user
.
jwtsecret
,
null
);
...
...
@@ -229,13 +229,13 @@ class UserService extends ServiceBase {
// rtn.token = token;
// rtn.user = u;
let
userfind
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
mobile
)
let
roleids
=
userfind
.
Roles
.
map
(
item
=>
{
let
userfind
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
mobile
)
let
roleids
=
userfind
.
Roles
.
map
(
item
=>
{
return
item
.
id
})
let
auths
=
await
this
.
authS
.
findAuthsByRole
(
roleids
)
userfind
[
"access"
]
=
auths
regrtn
.
user
=
userfind
let
auths
=
await
this
.
authS
.
findAuthsByRole
(
roleids
)
userfind
[
"access"
]
=
auths
regrtn
.
user
=
userfind
regrtn
.
token
=
token
return
regrtn
;
}
...
...
@@ -361,17 +361,169 @@ class UserService extends ServiceBase {
});
}
}
//选择业务员为商机
//按照客户电话,建立和业务员的映射关系
//如果已经分配过,那么优先分配
/**
*
* @param {*} clientMobile 客户电话
* @param {*} spName 服务商名称
* @param {*} productCatName 产品类型名称
*/
async
getBizUserForBizChance
(
clientMobile
,
spName
,
productCatName
)
{
var
self
=
this
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
return
this
.
db
.
transaction
(
async
function
(
t
)
{
//先检查缓存是否存在bizuser
var
resultcache
=
await
self
.
cacheManager
[
"ClientBindBizUserCache"
].
getCache
(
clientMobile
)
let
isGoExec
=
false
if
(
!
resultcache
)
{
isGoExec
=
true
}
else
{
let
uname
=
resultcache
.
userName
let
ucache
=
await
self
.
cacheManager
[
"UserCache"
].
cache
(
uname
)
if
(
!
ucache
.
isAllocated
)
{
//解决修改为不接单
isGoExec
=
true
await
self
.
cacheManager
[
"ClientBindBizUserCache"
].
invalidate
(
clientMobile
)
}
}
if
(
isGoExec
)
{
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'
],
raw
:
true
}
],
excludes
:
[
'orgJson'
],
transaction
:
t
});
console
.
log
(
companyFind
)
let
users
=
companyFind
.
us
let
cansels
=
users
.
filter
(
u
=>
{
if
(
u
.
isAllocated
&&
u
.
skilltags
.
indexOf
(
productCatName
)
>=
0
)
{
return
true
}
else
{
return
false
}
})
let
lngth
=
cansels
.
length
if
(
lngth
>
0
)
{
let
randindex
=
Math
.
floor
(
Math
.
random
()
*
lngth
)
let
selresult
=
cansels
[
randindex
]
//添加到缓存,按照客户电话key--缓存到业务员的对象
let
tmp
=
{
userId
:
selresult
.
id
,
userName
:
selresult
.
userName
,
mobile
:
selresult
.
mobile
,
opath
:
selresult
.
opath
}
await
self
.
cacheManager
[
"ClientBindBizUserCache"
].
cache
(
clientMobile
,
tmp
)
return
tmp
}
else
{
return
null
}
}
else
{
if
(
resultcache
)
{
//不继续,直接返回缓存
return
resultcache
}
else
{
return
null
}
}
})
}
/**
*
* @param {*} clientMobile 客户电话
* @param {*} spName 服务商名称
* @param {*} productCatName 产品类型名称
* @param {*} skucode 最小销售货品编码,来自渠道上架的码
*/
async
getBizUserForDelivery
(
xclientMobile
,
spName
,
productCatName
,
skucode
)
{
let
clientMobile
=
'fordeliver'
+
xclientMobile
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'
]}
],
transaction
:
t
}
)
let
serviceCost
=
productpricetmp
.
costs
.
filter
(
c
=>
{
if
(
c
.
expensetype
==
"service"
)
{
return
true
}
})
let
costAmount
=
0
//获取服务费成本
if
(
serviceCost
.
length
>
0
)
{
costAmount
=
serviceCost
[
0
].
costamount
}
//先检查缓存是否存在bizuser todo key再加个字母d
var
resultcache
=
await
self
.
cacheManager
[
"ClientBindBizUserCache"
].
getCache
(
clientMobile
)
let
isGoExec
=
false
if
(
!
resultcache
)
{
isGoExec
=
true
}
else
{
let
uname
=
resultcache
.
userName
let
ucache
=
await
self
.
cacheManager
[
"UserCache"
].
cache
(
uname
)
if
(
!
ucache
.
isAllocated
)
{
//解决修改为不接单
isGoExec
=
true
await
self
.
cacheManager
[
"ClientBindBizUserCache"
].
invalidate
(
clientMobile
)
}
}
if
(
isGoExec
)
{
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'
],
raw
:
true
}
],
excludes
:
[
'orgJson'
],
transaction
:
t
});
let
users
=
companyFind
.
us
let
cansels
=
users
.
filter
(
u
=>
{
if
(
u
.
isAllocated
&&
u
.
skilltags
.
indexOf
(
productCatName
)
>=
0
)
{
return
true
}
else
{
return
false
}
})
let
lngth
=
cansels
.
length
if
(
lngth
>
0
)
{
let
randindex
=
Math
.
floor
(
Math
.
random
()
*
lngth
)
let
selresult
=
cansels
[
randindex
]
//添加到缓存,按照客户电话key--缓存到业务员的对象
let
tmp
=
{
userId
:
selresult
.
id
,
userName
:
selresult
.
userName
,
mobile
:
selresult
.
mobile
,
opath
:
selresult
.
opath
,
cost
:
costAmount
}
await
self
.
cacheManager
[
"ClientBindBizUserCache"
].
cache
(
clientMobile
,
tmp
)
return
tmp
}
else
{
return
null
}
}
else
{
if
(
resultcache
)
{
//不继续,直接返回缓存
resultcache
[
"cost"
]
=
costAmount
return
resultcache
}
else
{
return
null
}
}
})
}
}
module
.
exports
=
UserService
;
// // (async ()=>{
// let u=new UserService();
// // // let x=await u.cregister("jiangong")
// // // console.log(x)
// // // let x=await u.cunregister("jiangong")
// // // console.log(x)
// // // let t=await u.cmakejwt()
// // // console.log(t)
// let ux=u.register({userName:"jiangyong3",password:"123"})
// console.log(ux);
// // })()
\ No newline at end of file
// let userS=new UserService()
// userS.getBizUserForBizChance("13381139519",'好生日','工商注册').then(rtn=>{
// console.log(rtn)
// })
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment