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
56f26a5f
Commit
56f26a5f
authored
Jul 30, 2020
by
王勇飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add loopDistributionUserCache
parent
9a557a21
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
195 additions
and
75 deletions
+195
-75
center-manage/app/base/db/cache/aliCache.js
+26
-0
center-manage/app/base/db/cache/loopDistributionUserCache.js
+27
-0
center-manage/app/base/service/impl/auth/userSve.js
+117
-64
center-manage/app/base/service/impl/common/channelhandlers/ali.js
+25
-11
No files found.
center-manage/app/base/db/cache/aliCache.js
0 → 100644
View file @
56f26a5f
const
CacheBase
=
require
(
"../cache.base"
);
const
system
=
require
(
"../../system"
);
const
settings
=
require
(
"../../../config/settings"
);
class
AliCache
extends
CacheBase
{
constructor
()
{
super
();
//this.userDao = system.getObject("db.auth.userDao");
}
isdebug
()
{
return
settings
.
env
==
"dev"
;
}
desc
()
{
return
"缓存缓存阿里队列信息"
;
}
prefix
()
{
return
"g_aliInfo_cm:"
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
if
(
val
)
{
return
val
;
}
return
null
;
}
}
module
.
exports
=
AliCache
;
\ No newline at end of file
center-manage/app/base/db/cache/loopDistributionUserCache.js
0 → 100644
View file @
56f26a5f
const
CacheBase
=
require
(
"../cache.base"
);
const
system
=
require
(
"../../system"
);
const
settings
=
require
(
"../../../config/settings"
);
class
LoopDistributionUserCache
extends
CacheBase
{
constructor
()
{
super
();
this
.
userDao
=
system
.
getObject
(
"db.auth.userDao"
);
this
.
channelDao
=
system
.
getObject
(
"db.common.channelDao"
);
}
isdebug
()
{
return
settings
.
env
==
"dev"
;
}
desc
()
{
return
"缓存阿里订单轮循环分配的业务员信息"
;
}
prefix
()
{
return
"g_loopDistributionUserInfo_cm:"
}
async
buildCacheVal
(
cachekey
,
inputkey
,
val
,
ex
,
...
items
)
{
if
(
val
)
{
return
val
;
}
return
null
;
}
}
module
.
exports
=
LoopDistributionUserCache
;
\ No newline at end of file
center-manage/app/base/service/impl/auth/userSve.js
View file @
56f26a5f
...
@@ -9,11 +9,11 @@ class UserService extends ServiceBase {
...
@@ -9,11 +9,11 @@ class UserService extends ServiceBase {
this
.
roleDao
=
system
.
getObject
(
"db.auth.roleDao"
);
this
.
roleDao
=
system
.
getObject
(
"db.auth.roleDao"
);
this
.
authS
=
system
.
getObject
(
"service.auth.authSve"
);
this
.
authS
=
system
.
getObject
(
"service.auth.authSve"
);
}
}
async
pmgetUserByCode
(
code
)
{
async
pmgetUserByCode
(
code
)
{
let
ux
=
await
this
.
cacheManager
[
"CodeCache"
].
getCache
(
code
);
let
ux
=
await
this
.
cacheManager
[
"CodeCache"
].
getCache
(
code
);
return
ux
;
return
ux
;
}
}
async
loginApp
(
appkey
,
uname
)
{
async
loginApp
(
appkey
,
uname
)
{
let
rtn
=
{}
let
rtn
=
{}
let
app
=
await
this
.
cacheManager
[
"AppCache"
].
cache
(
appkey
);
let
app
=
await
this
.
cacheManager
[
"AppCache"
].
cache
(
appkey
);
let
userLogined
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
uname
);
let
userLogined
=
await
this
.
cacheManager
[
"UserCache"
].
cache
(
uname
);
...
@@ -38,7 +38,7 @@ class UserService extends ServiceBase {
...
@@ -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
&&
p
.
roles
.
length
>
0
)
{
if
(
p
.
roles
.
indexOf
(
settings
.
pmroleid
[
"pr"
])
<
0
)
{
if
(
p
.
roles
.
indexOf
(
settings
.
pmroleid
[
"pr"
])
<
0
)
{
...
@@ -51,7 +51,7 @@ class UserService extends ServiceBase {
...
@@ -51,7 +51,7 @@ class UserService extends ServiceBase {
}
}
//应用的自由用户注册,无需验证,需要前端头设置公司KEY
//应用的自由用户注册,无需验证,需要前端头设置公司KEY
async
pmregisterByFreeUser
(
p
,
q
)
{
async
pmregisterByFreeUser
(
p
,
q
)
{
p
.
rolecodes
=
[
settings
.
pmroleid
[
"pr"
]];
p
.
rolecodes
=
[
settings
.
pmroleid
[
"pr"
]];
let
rtn
=
await
this
.
pmregister
(
p
,
q
)
let
rtn
=
await
this
.
pmregister
(
p
,
q
)
return
rtn
;
return
rtn
;
...
@@ -60,7 +60,7 @@ class UserService extends ServiceBase {
...
@@ -60,7 +60,7 @@ class UserService extends ServiceBase {
//平台租户注册接口方法
//平台租户注册接口方法
//控制器端检查用户名和密码非空
//控制器端检查用户名和密码非空
async
pmregister
(
p
,
q
)
{
async
pmregister
(
p
,
q
)
{
var
self
=
this
;
var
self
=
this
;
let
tmppwd
=
p
.
password
;
let
tmppwd
=
p
.
password
;
if
(
!
tmppwd
)
{
if
(
!
tmppwd
)
{
...
@@ -133,7 +133,7 @@ class UserService extends ServiceBase {
...
@@ -133,7 +133,7 @@ class UserService extends ServiceBase {
}
}
});
});
}
}
async
logout
(
pobj
)
{
async
logout
(
pobj
)
{
await
this
.
cacheManager
[
"UserCache"
].
invalidate
(
pobj
.
username
);
await
this
.
cacheManager
[
"UserCache"
].
invalidate
(
pobj
.
username
);
return
{}
return
{}
}
}
...
@@ -141,7 +141,7 @@ class UserService extends ServiceBase {
...
@@ -141,7 +141,7 @@ class UserService extends ServiceBase {
//登录接口封装kong-url
//登录接口封装kong-url
//登录路由放行
//登录路由放行
//p里面含有appkey,company_id,userName,password
//p里面含有appkey,company_id,userName,password
async
pmlogin
(
p
,
q
,
req
)
{
async
pmlogin
(
p
,
q
,
req
)
{
var
self
=
this
;
var
self
=
this
;
//先要按照用户名,在统一账户中查找存在性
//先要按照用户名,在统一账户中查找存在性
//如果不存在
//如果不存在
...
@@ -185,7 +185,7 @@ class UserService extends ServiceBase {
...
@@ -185,7 +185,7 @@ class UserService extends ServiceBase {
}
}
})
})
}
}
async
getUserInfo
(
uname
)
{
async
getUserInfo
(
uname
)
{
// let userfind = await this.dao.model.findOne({
// let userfind = await this.dao.model.findOne({
// where: { userName: uname, app_id: settings.pmappid },
// where: { userName: uname, app_id: settings.pmappid },
// attributes: ['userName', 'nickName',"headUrl",'isSuper','isAdmin'],
// attributes: ['userName', 'nickName',"headUrl",'isSuper','isAdmin'],
...
@@ -206,7 +206,7 @@ class UserService extends ServiceBase {
...
@@ -206,7 +206,7 @@ class UserService extends ServiceBase {
//自由用户的电话登录和注册
//自由用户的电话登录和注册
//需要存在公司KEY
//需要存在公司KEY
async
pmloginByVCodeForFreeUser
(
p
,
q
)
{
async
pmloginByVCodeForFreeUser
(
p
,
q
)
{
p
.
rolecodes
=
[
settings
.
pmroleid
[
"pr"
]];
p
.
rolecodes
=
[
settings
.
pmroleid
[
"pr"
]];
let
rtn
=
await
this
.
pmloginByVCode
(
p
,
q
,
req
)
let
rtn
=
await
this
.
pmloginByVCode
(
p
,
q
,
req
)
return
system
.
getResult
(
rtn
);
return
system
.
getResult
(
rtn
);
...
@@ -215,7 +215,7 @@ class UserService extends ServiceBase {
...
@@ -215,7 +215,7 @@ class UserService extends ServiceBase {
//平台租户注册与登录
//平台租户注册与登录
//用户验证码登录
//用户验证码登录
//
//
async
pmloginByVCode
(
p
,
q
,
req
)
{
async
pmloginByVCode
(
p
,
q
,
req
)
{
var
rtn
=
{}
var
rtn
=
{}
//检查传递过来的手机验证码是否与缓存的一致
//检查传递过来的手机验证码是否与缓存的一致
let
mobile
=
p
.
mobile
;
let
mobile
=
p
.
mobile
;
...
@@ -260,19 +260,19 @@ class UserService extends ServiceBase {
...
@@ -260,19 +260,19 @@ class UserService extends ServiceBase {
//不一致那么就
//不一致那么就
}
}
//发送手机验证码并缓存
//发送手机验证码并缓存
async
sendVCode
(
p
,
q
,
req
)
{
async
sendVCode
(
p
,
q
,
req
)
{
let
mobile
=
p
.
mobile
;
let
mobile
=
p
.
mobile
;
let
vcodeobj
=
await
this
.
cacheManager
[
"VCodeCache"
].
cache
(
mobile
,
null
,
60
);
let
vcodeobj
=
await
this
.
cacheManager
[
"VCodeCache"
].
cache
(
mobile
,
null
,
60
);
return
vcodeobj
.
vcode
;
return
vcodeobj
.
vcode
;
}
}
async
reSendVCode
(
p
,
q
,
req
)
{
async
reSendVCode
(
p
,
q
,
req
)
{
let
mobile
=
p
.
mobile
;
let
mobile
=
p
.
mobile
;
await
this
.
cacheManager
[
"VCodeCache"
].
invalidate
(
mobile
);
await
this
.
cacheManager
[
"VCodeCache"
].
invalidate
(
mobile
);
let
vcodeobj
=
await
this
.
cacheManager
[
"VCodeCache"
].
cache
(
mobile
,
null
,
60
);
let
vcodeobj
=
await
this
.
cacheManager
[
"VCodeCache"
].
cache
(
mobile
,
null
,
60
);
return
vcodeobj
.
vcode
;
return
vcodeobj
.
vcode
;
}
}
//修改中心密码
//修改中心密码
async
cmodifypwd
(
uname
,
newpwd
,
cmpid
)
{
async
cmodifypwd
(
uname
,
newpwd
,
cmpid
)
{
try
{
try
{
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
consumerUrl
(
uname
),
{
tags
:
[
"cmp_"
+
cmpid
,
"pass_"
+
newpwd
]
},
"PATCH"
)
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
consumerUrl
(
uname
),
{
tags
:
[
"cmp_"
+
cmpid
,
"pass_"
+
newpwd
]
},
"PATCH"
)
console
.
log
(
rtn
)
console
.
log
(
rtn
)
...
@@ -286,7 +286,7 @@ class UserService extends ServiceBase {
...
@@ -286,7 +286,7 @@ class UserService extends ServiceBase {
}
}
}
}
//创建统一账号及jwt身份
//创建统一账号及jwt身份
async
cregister
(
uname
,
cmpid
,
pass
,
uid
)
{
async
cregister
(
uname
,
cmpid
,
pass
,
uid
)
{
try
{
try
{
var
rtn2
=
null
;
var
rtn2
=
null
;
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
newConsumerUrl
(),
{
username
:
uname
,
custom_id
:
uid
,
tags
:
[
"cmp_"
+
cmpid
,
"pass_"
+
pass
]
})
let
rtn
=
await
system
.
postJsonTypeReq
(
UserService
.
newConsumerUrl
(),
{
username
:
uname
,
custom_id
:
uid
,
tags
:
[
"cmp_"
+
cmpid
,
"pass_"
+
pass
]
})
...
@@ -308,7 +308,7 @@ class UserService extends ServiceBase {
...
@@ -308,7 +308,7 @@ class UserService extends ServiceBase {
}
}
//plkey--对应消费者jwt身份的key,插件解码token后,获取iss-key,查询出身份,利用
//plkey--对应消费者jwt身份的key,插件解码token后,获取iss-key,查询出身份,利用
//身份中的secret验证签名
//身份中的secret验证签名
async
jwtsign
(
plkey
,
secretstr
,
opts
)
{
async
jwtsign
(
plkey
,
secretstr
,
opts
)
{
let
promise
=
new
Promise
(
function
(
resv
,
rej
)
{
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
)
{
if
(
err
)
{
...
@@ -321,13 +321,13 @@ class UserService extends ServiceBase {
...
@@ -321,13 +321,13 @@ class UserService extends ServiceBase {
return
promise
;
return
promise
;
}
}
//只要登录 生成新的访问jwttoken
//只要登录 生成新的访问jwttoken
async
cmakejwt
(
key
,
secret
,
opts
)
{
async
cmakejwt
(
key
,
secret
,
opts
)
{
var
token
=
await
this
.
jwtsign
(
key
,
secret
,
opts
);
var
token
=
await
this
.
jwtsign
(
key
,
secret
,
opts
);
return
token
;
return
token
;
}
}
//删除统一账号
//删除统一账号
async
cunregister
(
uname
)
{
async
cunregister
(
uname
)
{
try
{
try
{
let
rtn
=
await
system
.
delReq
(
UserService
.
consumerUrl
(
uname
))
let
rtn
=
await
system
.
delReq
(
UserService
.
consumerUrl
(
uname
))
if
(
rtn
.
statusCode
==
204
)
{
if
(
rtn
.
statusCode
==
204
)
{
...
@@ -341,15 +341,15 @@ class UserService extends ServiceBase {
...
@@ -341,15 +341,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
);
let
inpassword
=
this
.
getEncryptStr
(
pwd
);
var
self
=
this
;
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
...
@@ -367,7 +367,7 @@ class UserService extends ServiceBase {
...
@@ -367,7 +367,7 @@ class UserService extends ServiceBase {
});
});
}
}
//修改
//修改
async
update
(
qobj
,
tm
=
null
)
{
async
update
(
qobj
,
tm
=
null
)
{
var
self
=
this
;
var
self
=
this
;
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
delete
qobj
[
'company_id'
]
delete
qobj
[
'company_id'
]
...
@@ -389,7 +389,7 @@ class UserService extends ServiceBase {
...
@@ -389,7 +389,7 @@ class UserService extends ServiceBase {
* @param {*} productCatName 产品类型名称
* @param {*} productCatName 产品类型名称
* @param {*} regionName 区域
* @param {*} regionName 区域
*/
*/
async
getBizUserForBizChance
(
clientMobile
,
spName
,
productCatName
,
regionName
)
{
async
getBizUserForBizChance
(
clientMobile
,
spName
,
productCatName
,
regionName
)
{
var
self
=
this
var
self
=
this
clientMobile
=
clientMobile
+
"_"
+
spName
+
"_"
+
regionName
+
"_"
+
productCatName
clientMobile
=
clientMobile
+
"_"
+
spName
+
"_"
+
regionName
+
"_"
+
productCatName
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
...
@@ -411,7 +411,7 @@ class UserService extends ServiceBase {
...
@@ -411,7 +411,7 @@ class UserService extends ServiceBase {
let
companyFind
=
await
self
.
companyDao
.
model
.
findOne
({
let
companyFind
=
await
self
.
companyDao
.
model
.
findOne
({
where
:
{
name
:
spName
},
include
:
[
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'
,
'isAllArea'
,
'isSalesman'
,
'isDelivery'
],
raw
:
true
}
}
],
excludes
:
[
'orgJson'
],
transaction
:
t
],
excludes
:
[
'orgJson'
],
transaction
:
t
});
});
...
@@ -469,7 +469,7 @@ class UserService extends ServiceBase {
...
@@ -469,7 +469,7 @@ class UserService extends ServiceBase {
* @param {*} skucode 最小销售货品编码,来自渠道上架的码
* @param {*} skucode 最小销售货品编码,来自渠道上架的码
* @param {*} regionName 区域
* @param {*} regionName 区域
*/
*/
async
getBizUserForDelivery
(
xclientMobile
,
spName
,
productCatName
,
skucode
,
regionName
)
{
async
getBizUserForDelivery
(
xclientMobile
,
spName
,
productCatName
,
skucode
,
regionName
)
{
let
clientMobile
=
'fordeliver'
+
xclientMobile
+
"_"
+
spName
+
"_"
+
regionName
+
"_"
+
productCatName
let
clientMobile
=
'fordeliver'
+
xclientMobile
+
"_"
+
spName
+
"_"
+
regionName
+
"_"
+
productCatName
var
self
=
this
var
self
=
this
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
...
@@ -511,7 +511,7 @@ class UserService extends ServiceBase {
...
@@ -511,7 +511,7 @@ class UserService extends ServiceBase {
let
companyFind
=
await
self
.
companyDao
.
model
.
findOne
({
let
companyFind
=
await
self
.
companyDao
.
model
.
findOne
({
where
:
{
name
:
spName
},
include
:
[
where
:
{
name
:
spName
},
include
:
[
{
{
model
:
self
.
db
.
models
.
user
,
as
:
"us"
,
attributes
:
[
'id'
,
'userName'
,
'mobile'
,
'isAllocated'
,
'opath'
,
'skilltags'
],
raw
:
true
model
:
self
.
db
.
models
.
user
,
as
:
"us"
,
attributes
:
[
'id'
,
'userName'
,
'mobile'
,
'isAllocated'
,
'opath'
,
'skilltags'
,
'regiontags'
,
'isAllArea'
,
'isSalesman'
,
'isDelivery'
],
raw
:
true
}
}
],
excludes
:
[
'orgJson'
],
transaction
:
t
],
excludes
:
[
'orgJson'
],
transaction
:
t
});
});
...
@@ -562,15 +562,15 @@ class UserService extends ServiceBase {
...
@@ -562,15 +562,15 @@ class UserService extends ServiceBase {
}
}
/**
/**
* 阿里交付单分配规则(交付单处理业务员和交付员不是一个同一人)
* 阿里交付单分配规则
-轮循分配
(交付单处理业务员和交付员不是一个同一人)
* @param {*} xclientMobile 客户电话
* @param {*} xclientMobile 客户电话
* @param {*} spName 服务商名称
* @param {*} spName 服务商名称
* @param {*} productCatName 产品类型名称
* @param {*} productCatName 产品类型名称
* @param {*} skucode 最小销售货品编码,来自渠道上架的码
* @param {*} skucode 最小销售货品编码,来自渠道上架的码
* @param {*} regionName 区域
* @param {*} regionName 区域
*/
*/
async
getBizUserForAliDelivery
(
xclientMobile
,
spName
,
productCatName
,
skucode
,
regionName
)
{
async
getBizUserForAliDelivery
(
xclientMobile
,
spName
,
productCatName
,
skucode
,
regionName
)
{
let
clientMobile
=
'fordeliver'
+
xclientMobile
+
"_"
+
spName
+
"_"
+
regionName
//
let clientMobile = 'fordeliver' + xclientMobile + "_" + spName + "_" + regionName
let
self
=
this
let
self
=
this
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
//按照服务商名字查询到公司,按照公司查询出users,条件是可以接受派单任务,并且技能标签含有,产品类别名称
return
this
.
db
.
transaction
(
async
function
(
t
)
{
return
this
.
db
.
transaction
(
async
function
(
t
)
{
...
@@ -594,29 +594,64 @@ class UserService extends ServiceBase {
...
@@ -594,29 +594,64 @@ class UserService extends ServiceBase {
costAmount
=
serviceCost
[
0
].
costamount
costAmount
=
serviceCost
[
0
].
costamount
}
}
//先检查缓存是否存在bizuser
// console.log('------------1:', JSON.stringify(productpricetmp.costs));
let
resultcache
=
await
self
.
cacheManager
[
"DeliveryBizUserCache"
].
getCache
(
clientMobile
)
//检查缓存是否存在bizuser
let
isGoExec
=
false
let
resultcache
=
await
self
.
cacheManager
[
"LoopDistributionUserCache"
].
getCache
(
"LoopDistributionUserCache"
);
let
isGoExec
=
false
;
if
(
!
resultcache
)
{
if
(
!
resultcache
)
{
isGoExec
=
true
isGoExec
=
true
;
}
else
{
}
let
uname
=
resultcache
.
userName
else
{
//如果有用户数据,那么根据算法分配并返回一条业务员数据
let
ucache
=
await
self
.
cacheManager
[
"UserCache"
].
cache
(
uname
)
let
userArrCache
=
Object
.
keys
(
resultcache
);
if
(
!
ucache
.
isAllocated
)
{
//解决修改为不接单
if
(
userArrCache
==
0
)
{
//如果缓存中没有用户数据,从数据库查找
isGoExec
=
true
isGoExec
=
true
;
await
self
.
cacheManager
[
"DeliveryBizUserCache"
].
invalidate
(
clientMobile
)
}
else
{
let
userData
;
let
userInfo
,
userKey
;
let
num
=
resultcache
[
userArrCache
[
0
]].
num
;
for
(
let
key
in
resultcache
)
{
if
(
resultcache
[
key
].
num
<=
num
)
{
num
=
resultcache
[
key
].
num
;
userData
=
resultcache
[
key
];
userKey
=
key
;
}
}
userInfo
=
userData
.
userInfo
;
//查看是否接单,该用户是否接单,不接单就使缓存失效,接单就直接返回该业务员
let
uname
=
userKey
;
let
ucache
=
await
self
.
cacheManager
[
"UserCache"
].
cache
(
uname
);
if
(
!
ucache
.
isAllocated
)
{
//解决修改为不接单
isGoExec
=
true
await
self
.
cacheManager
[
"LoopDistributionUserCache"
].
invalidate
(
"LoopDistributionUserCache"
);
}
else
{
userData
.
num
+=
1
;
//该业务员数据+1,并保存到缓存中,返回用户数据
await
self
.
cacheManager
[
"LoopDistributionUserCache"
].
cache
(
"LoopDistributionUserCache"
,
JSON
.
stringify
(
resultcache
));
return
userInfo
;
}
}
}
}
}
//TODO 查询数据库user表来获取交付员信息 需要根据是否是"交付员"字段筛选(派单规则是将交付单派给交付员)
//查询数据库user表来获取交付员信息 需要根据是否是"交付员"字段筛选(派单规则是将交付单派给交付员)
if
(
isGoExec
)
{
if
(
isGoExec
)
{
let
companyFind
=
await
self
.
companyDao
.
model
.
findOne
({
let
companyFind
=
await
self
.
companyDao
.
model
.
findOne
({
where
:
{
name
:
spName
},
include
:
[
where
:
{
name
:
spName
},
include
:
[
{
{
model
:
self
.
db
.
models
.
user
,
as
:
"us"
,
attributes
:
[
'id'
,
'userName'
,
'mobile'
,
'isAllocated'
,
'opath'
,
'skilltags'
],
raw
:
true
model
:
self
.
db
.
models
.
user
,
as
:
"us"
,
attributes
:
[
'id'
,
'userName'
,
'mobile'
,
'isAllocated'
,
'opath'
,
'skilltags'
,
'regiontags'
,
'isAllArea'
,
'isSalesman'
,
'isDelivery'
],
raw
:
true
}
}
],
excludes
:
[
'orgJson'
],
transaction
:
t
],
excludes
:
[
'orgJson'
],
transaction
:
t
});
});
let
users
=
companyFind
.
us
let
users
=
companyFind
.
us
;
//按名单筛选
// let deliveryList = ["", "", "", "", ""];
// let cansels = users.filter(u => {
// if (regionName && deliveryList.indexOf(u.userName) >= 0) {
// return true;
// } else {
// return false;
// }
// });
//按条件筛选
let
cansels
=
users
.
filter
(
u
=>
{
let
cansels
=
users
.
filter
(
u
=>
{
if
(
regionName
&&
regionName
!=
""
&&
u
.
regiontags
)
{
if
(
regionName
&&
regionName
!=
""
&&
u
.
regiontags
)
{
if
(
u
.
isAllocated
&&
u
.
isDelivery
&&
u
.
skilltags
.
indexOf
(
productCatName
)
>=
0
&&
u
.
regiontags
.
indexOf
(
regionName
)
>=
0
)
{
if
(
u
.
isAllocated
&&
u
.
isDelivery
&&
u
.
skilltags
.
indexOf
(
productCatName
)
>=
0
&&
u
.
regiontags
.
indexOf
(
regionName
)
>=
0
)
{
...
@@ -632,32 +667,36 @@ class UserService extends ServiceBase {
...
@@ -632,32 +667,36 @@ class UserService extends ServiceBase {
}
}
}
}
})
})
console
.
log
(
'------------1'
,
JSON
.
stringify
(
cansels
)
);
let
lngth
=
cansels
.
length
let
lngth
=
cansels
.
length
//TODO 分配规则,需要改成循环分配
if
(
lngth
>
0
)
{
if
(
lngth
>
0
)
{
let
randindex
=
Math
.
floor
(
Math
.
random
()
*
lngth
)
let
obj
=
{};
let
selresult
=
cansels
[
randindex
]
for
(
let
i
=
0
;
i
<
lngth
;
i
++
)
{
//添加到缓存,按照客户电话key--缓存到业务员的对象
let
selresult
=
cansels
[
i
];
let
tmp
=
{
let
tmp
=
{
userId
:
selresult
.
id
,
userId
:
selresult
.
id
,
userName
:
selresult
.
userName
,
userName
:
selresult
.
userName
,
mobile
:
selresult
.
mobile
,
mobile
:
selresult
.
mobile
,
opath
:
selresult
.
opath
,
opath
:
selresult
.
opath
,
cost
:
costAmount
,
cost
:
costAmount
,
compId
:
companyFind
.
id
compId
:
companyFind
.
id
}
obj
[
selresult
.
userName
]
=
{
userInfo
:
tmp
,
num
:
0
}
}
}
await
self
.
cacheManager
[
"DeliveryBizUserCache"
].
cache
(
clientMobile
,
tmp
)
return
tmp
}
else
{
return
null
}
}
else
{
console
.
log
(
'------------2'
,
JSON
.
stringify
(
obj
)
);
if
(
resultcache
)
{
//不继续,直接返回缓存
resultcache
[
"cost"
]
=
costAmount
let
resultUserKey
=
Object
.
keys
(
obj
)[
0
];
return
resultcache
let
resultUser
=
obj
[
resultUserKey
].
userInfo
;
obj
[
resultUserKey
].
num
+=
1
;
await
self
.
cacheManager
[
"LoopDistributionUserCache"
].
cache
(
"LoopDistributionUserCache"
,
JSON
.
stringify
(
obj
));
return
resultUser
;
}
else
{
}
else
{
return
null
return
null
;
}
}
}
}
})
})
...
@@ -668,4 +707,19 @@ module.exports = UserService;
...
@@ -668,4 +707,19 @@ module.exports = UserService;
// let userS=new UserService()
// let userS=new UserService()
// userS.getBizUserForBizChance("13381139519",'好生日','工商注册').then(rtn=>{
// userS.getBizUserForBizChance("13381139519",'好生日','工商注册').then(rtn=>{
// console.log(rtn)
// console.log(rtn)
// })
// })
\ No newline at end of file
// let cacheManager = system.getObject("db.common.cacheManager");
// start();
// async function start() {
// try {
// // let result = await cacheManager["LoopDistributionUserCache"].cache("wyf", JSON.stringify({name: "test2", idx: 2}));
// let result = await cacheManager["LoopDistributionUserCache"].getCache("LoopDistributionUserCache");
// // let result = await cacheManager["LoopDistributionUserCache"].invalidate("LoopDistributionUserCache");
// console.log('----=-=-=-:' + JSON.stringify(result));
// } catch (error) {
// console.log("err:" + error);
// }
// }
center-manage/app/base/service/impl/common/channelhandlers/ali.js
View file @
56f26a5f
...
@@ -70,7 +70,7 @@ class AliHandler {
...
@@ -70,7 +70,7 @@ class AliHandler {
"title"
:
"你有新的商机,请尽快处理"
,
"title"
:
"你有新的商机,请尽快处理"
,
"content"
:
"商机编号"
+
params
.
businessMode
+
",商机类型是"
+
params
.
businessName
+
",服务地区是"
+
params
.
serviceName
,
"content"
:
"商机编号"
+
params
.
businessMode
+
",商机类型是"
+
params
.
businessName
+
",服务地区是"
+
params
.
serviceName
,
"sender"
:
"管理员"
,
"sender"
:
"管理员"
,
"sender_id"
:
0
,
"sender_id"
:
0
,
"msgType"
:
"single"
,
"msgType"
:
"single"
,
"target"
:
{
"id"
:
params
.
salesmanId
,
"name"
:
params
.
clerkName
},
"target"
:
{
"id"
:
params
.
salesmanId
,
"name"
:
params
.
clerkName
},
}
}
...
@@ -135,12 +135,12 @@ class AliHandler {
...
@@ -135,12 +135,12 @@ class AliHandler {
rtn
=
await
rc
.
execPost3
(
selpar
,
selUrl
);
rtn
=
await
rc
.
execPost3
(
selpar
,
selUrl
);
var
jj
=
JSON
.
parse
(
rtn
.
stdout
);
var
jj
=
JSON
.
parse
(
rtn
.
stdout
);
console
.
log
(
"jj------------------------------"
+
rtn
.
stdout
);
console
.
log
(
"jj------------------------------"
+
rtn
.
stdout
);
if
(
jj
.
status
==
0
&&
jj
.
data
){
if
(
jj
.
status
==
0
&&
jj
.
data
)
{
var
msg
=
{
var
msg
=
{
"title"
:
"你有退回的商机,请尽快处理"
,
"title"
:
"你有退回的商机,请尽快处理"
,
"content"
:
"商机编号"
+
jj
.
data
.
businessMode
+
",商机类型是"
+
jj
.
data
.
businessName
,
"content"
:
"商机编号"
+
jj
.
data
.
businessMode
+
",商机类型是"
+
jj
.
data
.
businessName
,
"sender"
:
"管理员"
,
"sender"
:
"管理员"
,
"sender_id"
:
0
,
"sender_id"
:
0
,
"msgType"
:
"single"
,
"msgType"
:
"single"
,
"target"
:
{
"id"
:
jj
.
data
.
clerkId
,
"name"
:
jj
.
data
.
clerkName
},
"target"
:
{
"id"
:
jj
.
data
.
clerkId
,
"name"
:
jj
.
data
.
clerkName
},
}
}
...
@@ -191,6 +191,8 @@ class AliHandler {
...
@@ -191,6 +191,8 @@ class AliHandler {
else
{
else
{
var
rc
=
system
.
getObject
(
"util.execClient"
);
var
rc
=
system
.
getObject
(
"util.execClient"
);
var
requrl
=
this
.
icUrl
+
"/deliverybillCtl/findInfoByDeliverCode"
;
var
requrl
=
this
.
icUrl
+
"/deliverybillCtl/findInfoByDeliverCode"
;
//TODO 将下面的actionBody中的所有字段都检查一遍
//TODO 确定订单编号的key, 将datajson.actionBody.orderNum替换
var
delInfo
=
await
rc
.
execPost3
({
"d"
:
{
"deliverNumber"
:
datajson
.
actionBody
.
orderNum
}
},
requrl
);
var
delInfo
=
await
rc
.
execPost3
({
"d"
:
{
"deliverNumber"
:
datajson
.
actionBody
.
orderNum
}
},
requrl
);
console
.
log
(
"jdelInfo---------------------------------------------"
+
delInfo
.
stdout
);
console
.
log
(
"jdelInfo---------------------------------------------"
+
delInfo
.
stdout
);
var
jdelInfo
=
JSON
.
parse
(
delInfo
.
stdout
);
var
jdelInfo
=
JSON
.
parse
(
delInfo
.
stdout
);
...
@@ -210,7 +212,7 @@ class AliHandler {
...
@@ -210,7 +212,7 @@ class AliHandler {
ConsultTypeName
=
datajson
.
actionBody
.
productTypeName
.
split
(
"/"
)[
2
];
ConsultTypeName
=
datajson
.
actionBody
.
productTypeName
.
split
(
"/"
)[
2
];
}
}
console
.
log
(
"ConsultTypeName-----------------------------"
+
ConsultTypeName
);
console
.
log
(
"ConsultTypeName-----------------------------"
+
ConsultTypeName
);
var
salesmanInfo
=
await
this
.
userService
.
getBizUserForDelivery
(
datajson
.
actionBody
.
orderSnapshot
.
contactsPhone
,
datajson
.
actionBody
.
servicerName
,
ConsultTypeName
,
datajson
.
actionBody
.
aliPriceCode
,
datajson
.
actionBody
.
regionName
);
var
salesmanInfo
=
await
this
.
userService
.
getBizUserFor
Ali
Delivery
(
datajson
.
actionBody
.
orderSnapshot
.
contactsPhone
,
datajson
.
actionBody
.
servicerName
,
ConsultTypeName
,
datajson
.
actionBody
.
aliPriceCode
,
datajson
.
actionBody
.
regionName
);
requrl
=
this
.
icUrl
+
"/deliverybillCtl/insertInfo"
;
requrl
=
this
.
icUrl
+
"/deliverybillCtl/insertInfo"
;
var
bizurl
=
this
.
icUrl
+
"/bizoptCtl/updateStatusByDemandCode"
;
var
bizurl
=
this
.
icUrl
+
"/bizoptCtl/updateStatusByDemandCode"
;
var
params
=
{
var
params
=
{
...
@@ -314,7 +316,7 @@ class AliHandler {
...
@@ -314,7 +316,7 @@ class AliHandler {
if
(
datajson
.
actionBody
.
orderSnapshot
.
hasOwnProperty
(
"annualReport"
))
{
//年报信息
if
(
datajson
.
actionBody
.
orderSnapshot
.
hasOwnProperty
(
"annualReport"
))
{
//年报信息
params
.
baseInfo
.
annualReport
=
datajson
.
actionBody
.
orderSnapshot
.
annualReport
;
params
.
baseInfo
.
annualReport
=
datajson
.
actionBody
.
orderSnapshot
.
annualReport
;
}
}
else
{
else
{
if
(
datajson
.
actionBody
.
orderSnapshot
.
annual_report
&&
datajson
.
actionBody
.
orderSnapshot
.
annual_report
!=
'undefined'
)
{
if
(
datajson
.
actionBody
.
orderSnapshot
.
annual_report
&&
datajson
.
actionBody
.
orderSnapshot
.
annual_report
!=
'undefined'
)
{
params
.
baseInfo
.
annualReport
=
true
;
//shifouxuyaonianbao
params
.
baseInfo
.
annualReport
=
true
;
//shifouxuyaonianbao
}
}
...
@@ -406,7 +408,7 @@ class AliHandler {
...
@@ -406,7 +408,7 @@ class AliHandler {
"title"
:
"你有新的交付单,请尽快处理"
,
"title"
:
"你有新的交付单,请尽快处理"
,
"content"
:
"交付单编号"
+
params
.
deliverNumber
+
",产品类型是"
+
params
.
businessName
+
",服务地区是"
+
params
.
serviceName
,
"content"
:
"交付单编号"
+
params
.
deliverNumber
+
",产品类型是"
+
params
.
businessName
+
",服务地区是"
+
params
.
serviceName
,
"sender"
:
"管理员"
,
"sender"
:
"管理员"
,
"sender_id"
:
0
,
"sender_id"
:
0
,
"msgType"
:
"single"
,
"msgType"
:
"single"
,
"target"
:
{
"id"
:
params
.
clerkId
,
"name"
:
params
.
clerkName
},
"target"
:
{
"id"
:
params
.
clerkId
,
"name"
:
params
.
clerkName
},
}
}
...
@@ -470,19 +472,19 @@ class AliHandler {
...
@@ -470,19 +472,19 @@ class AliHandler {
//给业务员发信息
//给业务员发信息
var
selUrl
=
this
.
icUrl
+
"/deliverybillCtl/findInfoByDeliverCode"
;
var
selUrl
=
this
.
icUrl
+
"/deliverybillCtl/findInfoByDeliverCode"
;
var
selpar
=
{
var
selpar
=
{
"d"
:{
"d"
:
{
"deliverNumber"
:
datajson
.
actionBody
.
orderNum
"deliverNumber"
:
datajson
.
actionBody
.
orderNum
}
}
}
}
rtn
=
await
rc
.
execPost3
(
selpar
,
selUrl
);
rtn
=
await
rc
.
execPost3
(
selpar
,
selUrl
);
var
jj
=
JSON
.
parse
(
rtn
.
stdout
);
var
jj
=
JSON
.
parse
(
rtn
.
stdout
);
console
.
log
(
"jj-------------------------"
+
rtn
.
stdout
);
console
.
log
(
"jj-------------------------"
+
rtn
.
stdout
);
if
(
jj
.
status
==
0
&&
jj
.
data
)
{
if
(
jj
.
status
==
0
&&
jj
.
data
)
{
var
msg
=
{
var
msg
=
{
"title"
:
"你有关闭的交付单,请尽快处理"
,
"title"
:
"你有关闭的交付单,请尽快处理"
,
"content"
:
"交付单编号"
+
jj
.
data
.
delivery_code
+
",产品类型是"
+
jj
.
data
.
product_name
,
"content"
:
"交付单编号"
+
jj
.
data
.
delivery_code
+
",产品类型是"
+
jj
.
data
.
product_name
,
"sender"
:
"管理员"
,
"sender"
:
"管理员"
,
"sender_id"
:
0
,
"sender_id"
:
0
,
"msgType"
:
"single"
,
"msgType"
:
"single"
,
"target"
:
{
"id"
:
jj
.
data
.
salesman_id
,
"name"
:
jj
.
data
.
salesman_name
},
"target"
:
{
"id"
:
jj
.
data
.
salesman_id
,
"name"
:
jj
.
data
.
salesman_name
},
}
}
...
@@ -496,7 +498,7 @@ class AliHandler {
...
@@ -496,7 +498,7 @@ class AliHandler {
}
}
await
this
.
msgService
.
create
(
msg
);
await
this
.
msgService
.
create
(
msg
);
}
}
return
{
return
{
"status"
:
1
,
//1代表成功,否则失败
"status"
:
1
,
//1代表成功,否则失败
"msg"
:
""
,
"msg"
:
""
,
...
@@ -526,3 +528,14 @@ module.exports = new AliHandler();
...
@@ -526,3 +528,14 @@ module.exports = new AliHandler();
// console.log("dddddddddddddd");
// console.log("dddddddddddddd");
// })()
// })()
// let userService = system.getObject("service.auth.userSve");
// start();
// async function start() {
// console.log('开始:')
// try {
// let result = await userService.getBizUserForAliDelivery(" ", "公司宝", "icp", "sv_vat_shareholder_domestic1015", "北京市");
// console.log('=-=-=-=-=-=:'+JSON.stringify(result));
// } catch (error) {
// console.log("getBizUserForAliDelivery err: "+ error);
// }
// }
\ 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