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
9a300ff1
Commit
9a300ff1
authored
Jul 28, 2020
by
王勇飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pp
parent
ccee0aa1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
151 additions
and
41 deletions
+151
-41
center-manage/app/base/service/impl/auth/userSve.js
+102
-0
center-manage/app/base/service/impl/common/channelhandlers/ali.js
+15
-15
center-manage/app/config/routes/api.js
+34
-26
No files found.
center-manage/app/base/service/impl/auth/userSve.js
View file @
9a300ff1
...
...
@@ -561,6 +561,108 @@ class UserService extends ServiceBase {
}
})
}
/**
* 阿里交付单分配规则(交付单处理业务员和交付员不是一个同一人)
* @param {*} xclientMobile 客户电话
* @param {*} spName 服务商名称
* @param {*} productCatName 产品类型名称
* @param {*} skucode 最小销售货品编码,来自渠道上架的码
* @param {*} regionName 区域
*/
async
getBizUserForAliDelivery
(
xclientMobile
,
spName
,
productCatName
,
skucode
,
regionName
)
{
let
clientMobile
=
'fordeliver'
+
xclientMobile
+
"_"
+
spName
+
"_"
+
regionName
let
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
let
resultcache
=
await
self
.
cacheManager
[
"DeliveryBizUserCache"
].
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
[
"DeliveryBizUserCache"
].
invalidate
(
clientMobile
)
}
}
//TODO 查询数据库user表来获取交付员信息 需要根据是否是"交付员"字段筛选(派单规则是将交付单派给交付员)
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
(
regionName
&&
regionName
!=
""
&&
u
.
regiontags
)
{
if
(
u
.
isAllocated
&&
u
.
skilltags
.
indexOf
(
productCatName
)
>=
0
&&
u
.
regiontags
.
indexOf
(
regionName
)
>=
0
)
{
return
true
}
else
{
return
false
}
}
else
{
if
(
u
.
isAllocated
&&
u
.
skilltags
.
indexOf
(
productCatName
)
>=
0
)
{
return
true
}
else
{
return
false
}
}
})
let
lngth
=
cansels
.
length
//TODO 分配规则,需要改成循环分配
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
,
compId
:
companyFind
.
id
}
await
self
.
cacheManager
[
"DeliveryBizUserCache"
].
cache
(
clientMobile
,
tmp
)
return
tmp
}
else
{
return
null
}
}
else
{
if
(
resultcache
)
{
//不继续,直接返回缓存
resultcache
[
"cost"
]
=
costAmount
return
resultcache
}
else
{
return
null
}
}
})
}
}
module
.
exports
=
UserService
;
...
...
center-manage/app/base/service/impl/common/channelhandlers/ali.js
View file @
9a300ff1
var
system
=
require
(
"../../../../system"
);
const
sha235
=
require
(
"sha256"
);
var
settings
=
require
(
"../../../../../config/settings"
);
class
Tx
Handler
{
class
Ali
Handler
{
constructor
()
{
this
.
icUrl
=
settings
.
icUrl
()
+
"/web/bizchance"
;
this
.
userService
=
system
.
getObject
(
"service.auth.userSve"
);
...
...
@@ -18,7 +18,7 @@ class TxHandler {
console
.
log
(
"put in queue"
,
datajson
);
try
{
var
cachestr
=
sha235
(
JSON
.
stringify
(
datajson
));
var
cacheInfo
=
await
this
.
cacheManager
[
"
Tx
Cache"
].
getCache
(
cachestr
);
var
cacheInfo
=
await
this
.
cacheManager
[
"
Ali
Cache"
].
getCache
(
cachestr
);
if
(
cacheInfo
&&
cacheInfo
!=
'undefined'
)
{
return
{
"status"
:
1
,
//1代表成功,否则失败
...
...
@@ -64,7 +64,7 @@ class TxHandler {
var
j
=
JSON
.
parse
(
rtn
.
stdout
);
console
.
log
(
JSON
.
stringify
(
j
),
"RRRRRRRRRRRRRRR"
);
if
(
j
.
status
==
1
)
{
await
this
.
cacheManager
[
"
Tx
Cache"
].
cache
(
cachestr
,
null
,
1200000
);
//插入redis缓存
await
this
.
cacheManager
[
"
Ali
Cache"
].
cache
(
cachestr
,
null
,
1200000
);
//插入redis缓存
//给业务员发信息
var
msg
=
{
"title"
:
"你有新的商机,请尽快处理"
,
...
...
@@ -100,7 +100,7 @@ class TxHandler {
console
.
log
(
"put in queue"
+
JSON
.
stringify
(
datajson
)
+
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
);
try
{
var
cachestr
=
sha235
(
JSON
.
stringify
(
datajson
));
var
cacheInfo
=
await
this
.
cacheManager
[
"
Tx
Cache"
].
getCache
(
cachestr
);
var
cacheInfo
=
await
this
.
cacheManager
[
"
Ali
Cache"
].
getCache
(
cachestr
);
if
(
cacheInfo
&&
cacheInfo
!=
'undefined'
)
{
return
{
"status"
:
1
,
//1代表成功,否则失败
...
...
@@ -123,7 +123,7 @@ class TxHandler {
var
rtn
=
await
rc
.
execPost3
(
params
,
requrl
);
var
j
=
JSON
.
parse
(
rtn
.
stdout
);
if
(
j
.
status
==
0
)
{
await
this
.
cacheManager
[
"
Tx
Cache"
].
cache
(
cachestr
,
null
,
1200000
);
//插入缓存
await
this
.
cacheManager
[
"
Ali
Cache"
].
cache
(
cachestr
,
null
,
1200000
);
//插入缓存
//给业务员发信息
var
selUrl
=
this
.
icUrl
+
"/schemeCtl/findInfoByDemandCode"
;
...
...
@@ -179,7 +179,7 @@ class TxHandler {
console
.
log
(
"put in queue-----------------------------------------------------------------------------------------------------"
,
datajson
);
try
{
var
cachestr
=
sha235
(
JSON
.
stringify
(
datajson
));
var
cacheInfo
=
await
this
.
cacheManager
[
"
Tx
Cache"
].
getCache
(
cachestr
);
var
cacheInfo
=
await
this
.
cacheManager
[
"
Ali
Cache"
].
getCache
(
cachestr
);
if
(
cacheInfo
&&
cacheInfo
!=
'undefined'
)
{
return
{
"status"
:
1
,
//1代表成功,否则失败
...
...
@@ -210,7 +210,7 @@ class TxHandler {
ConsultTypeName
=
datajson
.
actionBody
.
productTypeName
.
split
(
"/"
)[
2
];
}
console
.
log
(
"ConsultTypeName-----------------------------"
+
ConsultTypeName
);
var
salesmanInfo
=
await
this
.
userService
.
getBizUserForDelivery
(
datajson
.
actionBody
.
orderSnapshot
.
contactsPhone
,
datajson
.
actionBody
.
servicerName
,
ConsultTypeName
,
datajson
.
actionBody
.
tx
PriceCode
,
datajson
.
actionBody
.
regionName
);
var
salesmanInfo
=
await
this
.
userService
.
getBizUserForDelivery
(
datajson
.
actionBody
.
orderSnapshot
.
contactsPhone
,
datajson
.
actionBody
.
servicerName
,
ConsultTypeName
,
datajson
.
actionBody
.
ali
PriceCode
,
datajson
.
actionBody
.
regionName
);
requrl
=
this
.
icUrl
+
"/deliverybillCtl/insertInfo"
;
var
bizurl
=
this
.
icUrl
+
"/bizoptCtl/updateStatusByDemandCode"
;
var
params
=
{
...
...
@@ -220,10 +220,10 @@ class TxHandler {
"serviceName"
:
datajson
.
actionBody
.
regionName
,
"businessType"
:
datajson
.
actionBody
.
productType
,
"businessName"
:
ConsultTypeName
,
"skuCode"
:
datajson
.
actionBody
.
tx
PriceCode
,
"
txOrderNum"
:
datajson
.
actionBody
.
tx
OrderNum
,
"skuCode"
:
datajson
.
actionBody
.
ali
PriceCode
,
"
aliOrderNum"
:
datajson
.
actionBody
.
ali
OrderNum
,
"baseInfo"
:
{
"
txOrderNum"
:
datajson
.
actionBody
.
tx
OrderNum
,
"
aliOrderNum"
:
datajson
.
actionBody
.
ali
OrderNum
,
"isAdviser"
:
"已分配"
,
//是否分配顾问
"contactsName"
:
datajson
.
actionBody
.
orderSnapshot
.
contactsName
,
"contactsPhone"
:
datajson
.
actionBody
.
orderSnapshot
.
contactsPhone
,
...
...
@@ -400,7 +400,7 @@ class TxHandler {
var
j1
=
JSON
.
parse
(
rtn
.
stdout
);
console
.
log
(
"j1---------------------------------"
+
rtn
.
stdout
);
if
(
j
.
status
==
0
&&
j1
.
status
==
0
)
{
await
this
.
cacheManager
[
"
Tx
Cache"
].
cache
(
cachestr
,
null
,
1200000
);
await
this
.
cacheManager
[
"
Ali
Cache"
].
cache
(
cachestr
,
null
,
1200000
);
//给业务员发信息
var
msg
=
{
"title"
:
"你有新的交付单,请尽快处理"
,
...
...
@@ -443,7 +443,7 @@ class TxHandler {
console
.
log
(
"put in queue"
,
datajson
);
try
{
var
cachestr
=
sha235
(
JSON
.
stringify
(
datajson
));
var
cacheInfo
=
await
this
.
cacheManager
[
"
Tx
Cache"
].
getCache
(
cachestr
);
var
cacheInfo
=
await
this
.
cacheManager
[
"
Ali
Cache"
].
getCache
(
cachestr
);
if
(
cacheInfo
&&
cacheInfo
!=
'undefined'
)
{
return
{
"status"
:
1
,
//1代表成功,否则失败
...
...
@@ -465,7 +465,7 @@ class TxHandler {
var
rtn
=
await
rc
.
execPost3
(
params
,
requrl
);
var
j
=
JSON
.
parse
(
rtn
.
stdout
);
if
(
j
.
status
==
0
)
{
await
this
.
cacheManager
[
"
Tx
Cache"
].
cache
(
cachestr
,
null
,
1200000
);
//插入缓存
await
this
.
cacheManager
[
"
Ali
Cache"
].
cache
(
cachestr
,
null
,
1200000
);
//插入缓存
//给业务员发信息
var
selUrl
=
this
.
icUrl
+
"/deliverybillCtl/findInfoByDeliverCode"
;
...
...
@@ -516,10 +516,10 @@ class TxHandler {
}
}
module
.
exports
=
new
Tx
Handler
();
module
.
exports
=
new
Ali
Handler
();
// (async ()=>{
// var task = new
Tx
Handler();
// var task = new
Ali
Handler();
// var d = await task.userService.getBizUserForDelivery("16512345678","公司宝","公司注册","sv_business_registration_category_limited1","北京");
// console.log("ddddddddddddd");
// console.log(JSON.stringify(d));
...
...
center-manage/app/config/routes/api.js
View file @
9a300ff1
var
url
=
require
(
"url"
);
var
System
=
require
(
"../../base/system"
);
const
chnelapi
=
System
.
getObject
(
"api.common.channels"
)
const
chnelapi
=
System
.
getObject
(
"api.common.channels"
)
let
channelCache
=
{};
module
.
exports
=
function
(
app
)
{
app
.
all
(
"*"
,
async
function
(
req
,
res
,
next
){
try
{
let
channel
=
await
chnelapi
.
getChannels
(
req
.
headers
[
"x-forwarded-host"
])
if
(
!
channel
){
app
.
all
(
"*"
,
async
function
(
req
,
res
,
next
)
{
try
{
let
channel
;
let
sourceHost
=
req
.
headers
[
"x-forwarded-host"
];
if
(
sourceHost
in
channelCache
)
{
channel
=
channelCache
[
sourceHost
];
}
else
{
channel
=
await
chnelapi
.
getChannels
(
sourceHost
);
channelCache
[
sourceHost
]
=
channel
;
}
if
(
!
channel
)
{
next
()
}
else
{
let
rtn
=
await
chnelapi
.
channelHandle
(
channel
,
req
.
path
+
"/"
+
req
.
body
.
actionType
,
req
.
body
)
if
(
rtn
!=
null
)
{
}
else
{
let
rtn
=
await
chnelapi
.
channelHandle
(
channel
,
req
.
path
+
"/"
+
req
.
body
.
actionType
,
req
.
body
)
if
(
rtn
!=
null
)
{
res
.
end
(
JSON
.
stringify
(
rtn
));
}
else
{
res
.
end
(
JSON
.
stringify
({
status
:
-
1
,
message
:
"fail"
}));
}
else
{
res
.
end
(
JSON
.
stringify
({
status
:
-
1
,
message
:
"fail"
}));
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
)
res
.
end
(
JSON
.
stringify
({
status
:
-
1
,
message
:
e
}));
res
.
end
(
JSON
.
stringify
({
status
:
-
1
,
message
:
e
}));
}
})
app
.
get
(
'/api/:gname/:qname/:method'
,
function
(
req
,
res
)
{
// var classPath = req.params["qname"];
var
methodName
=
req
.
params
[
"method"
];
var
gname
=
req
.
params
[
"gname"
];
classPath
=
gname
+
"."
+
classPath
;
var
methodName
=
req
.
params
[
"method"
];
var
gname
=
req
.
params
[
"gname"
];
classPath
=
gname
+
"."
+
classPath
;
var
tClientIp
=
System
.
get_client_ip
(
req
);
req
.
clientIp
=
tClientIp
;
req
.
uagent
=
req
.
headers
[
"user-agent"
];
req
.
uagent
=
req
.
headers
[
"user-agent"
];
// req.classname=classPath;
var
params
=
[];
params
.
push
(
gname
);
params
.
push
(
methodName
);
params
.
push
(
methodName
);
params
.
push
(
req
.
body
);
params
.
push
(
req
.
query
);
params
.
push
(
req
);
params
.
push
(
req
.
query
);
params
.
push
(
req
);
var
p
=
null
;
var
invokeObj
=
System
.
getObject
(
"api."
+
classPath
);
if
(
invokeObj
[
"doexec"
])
{
...
...
@@ -47,22 +55,22 @@ module.exports = function (app) {
});
app
.
post
(
'/api/:gname/:qname/:method'
,
function
(
req
,
res
)
{
var
classPath
=
req
.
params
[
"qname"
];
var
methodName
=
req
.
params
[
"method"
];
var
gname
=
req
.
params
[
"gname"
];
var
params
=
[];
classPath
=
gname
+
"."
+
classPath
;
var
methodName
=
req
.
params
[
"method"
];
var
gname
=
req
.
params
[
"gname"
];
var
params
=
[];
classPath
=
gname
+
"."
+
classPath
;
console
.
log
(
"===================="
);
console
.
log
(
classPath
);
var
tClientIp
=
System
.
get_client_ip
(
req
);
req
.
clientIp
=
tClientIp
;
req
.
uagent
=
req
.
headers
[
"user-agent"
];
req
.
uagent
=
req
.
headers
[
"user-agent"
];
// req.classname=classPath;
params
.
push
(
gname
);
params
.
push
(
methodName
);
params
.
push
(
req
.
body
);
params
.
push
(
req
.
query
);
params
.
push
(
req
);
params
.
push
(
req
.
query
);
params
.
push
(
req
);
var
p
=
null
;
var
invokeObj
=
System
.
getObject
(
"api."
+
classPath
);
if
(
invokeObj
[
"doexec"
])
{
...
...
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