Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
taxh5
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data_server
taxh5
Commits
899828bd
Commit
899828bd
authored
May 06, 2019
by
何娜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
taxH5 修改获取城市配置接口+通知优化
parent
36e0828b
Pipeline
#6989
passed with stage
in 2 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
175 additions
and
135 deletions
+175
-135
script.js
app/controller/script.js
+37
-0
context.js
app/extend/context.js
+1
-1
router.js
app/router.js
+2
-1
partner.js
app/service/partner.js
+135
-133
No files found.
app/controller/script.js
View file @
899828bd
...
...
@@ -3,6 +3,13 @@
const
Controller
=
require
(
'egg'
).
Controller
;
class
ScriptController
extends
Controller
{
constructor
(
ctx
)
{
super
(
ctx
);
this
.
cityListRule
=
{
appKey
:
'string'
,
};
}
async
fetchScripts
()
{
const
{
ctx
,
service
}
=
this
;
const
{
appKey
}
=
ctx
.
query
;
...
...
@@ -71,6 +78,36 @@ class ScriptController extends Controller {
const
data
=
await
service
.
scripts
.
fetchHubSeripts
(
hubId
);
ctx
.
success
(
data
);
}
async
partnerScripts
()
{
const
{
ctx
,
service
}
=
this
;
try
{
ctx
.
validate
(
this
.
cityListRule
,
ctx
.
query
);
const
{
appKey
}
=
ctx
.
query
;
let
limitScriptsList
=
false
;
const
ret
=
await
service
.
partner
.
fetchInfo
(
appKey
);
if
(
ret
)
{
limitScriptsList
=
ret
.
itExcludeScripts
;
}
else
{
ctx
.
error
({
message
:
'无效的appKey'
});
return
;
}
let
data
=
await
service
.
scripts
.
fetchScripts
();
if
(
limitScriptsList
)
{
data
=
data
.
filter
(
item
=>
{
if
(
item
.
state
===
'offline'
||
item
.
state
===
'online'
)
{
return
!
(
limitScriptsList
.
includes
(
item
.
id
));
}
});
}
ctx
.
body
=
{
code
:
0
,
data
,
};
}
catch
(
err
)
{
ctx
.
error
(
err
);
}
}
}
module
.
exports
=
ScriptController
;
app/extend/context.js
View file @
899828bd
...
...
@@ -32,7 +32,7 @@ module.exports = {
this
.
body
=
{
code
:
-
1
,
msg
:
'请求参数有误'
};
return
;
}
if
(
!
/token/
.
test
(
err
.
message
))
{
if
(
!
/token
|appKey
/
.
test
(
err
.
message
))
{
if
(
/
[
a-zA-Z
]
+/
.
test
(
err
.
message
))
{
this
.
body
=
{
code
:
err
.
code
||
-
1
,
msg
:
'系统错误, 请稍后再试'
};
return
;
...
...
app/router.js
View file @
899828bd
...
...
@@ -36,7 +36,8 @@ module.exports = app => {
itRouter
.
post
(
'/getToken'
,
controller
.
token
.
partnerToken
);
// 合作方获取token
itRouter
.
post
(
'/getorderSn'
,
controller
.
order
.
partnerOrder
);
// 合作方获取orderSn
itRouter
.
post
(
'/getCityConfig'
,
controller
.
task
.
cityConfigs
);
// 获取城市配置
itRouter
.
post
(
'/getCityConfig'
,
controller
.
task
.
cityConfigs
);
// 获取城市配置 老接口备用
itRouter
.
get
(
'/getCityList'
,
controller
.
script
.
partnerScripts
);
//合作方获取城市配置
itRouter
.
post
(
'/getData'
,
controller
.
order
.
partnerData
);
// 合作方拉数据
itRouter
.
get
(
'/orderData/:appKey/:orderId'
,
controller
.
order
.
orderShow
);
//获取展示页面数据
...
...
app/service/partner.js
View file @
899828bd
...
...
@@ -3,157 +3,159 @@
const
Service
=
require
(
'egg'
).
Service
;
class
PartnerService
extends
Service
{
constructor
(
ctx
)
{
super
(
ctx
);
const
{
config
:
{
partnerAPI
}
}
=
this
;
this
.
partnerAPI
=
partnerAPI
;
}
constructor
(
ctx
)
{
super
(
ctx
);
const
{
config
:
{
partnerAPI
}
}
=
this
;
this
.
partnerAPI
=
partnerAPI
;
}
async
fetchTheme
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
fetchTheme
,
host
,
redisThemePrefix
}
}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisThemePrefix
+
appKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
redisThemePrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisThemePrefix
+
appKey
);
async
fetchTheme
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
fetchTheme
,
host
,
redisThemePrefix
}}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisThemePrefix
+
appKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Scripts】fetchParams'
,
redisThemePrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisThemePrefix
+
appKey
);
}
}
}
}
}
const
ret
=
await
ctx
.
curl
(
`
${
host
+
fetchTheme
}
`
,
{
charset
:
'utf-8
'
,
timeout
:
[
'30s'
,
'30s'
]
,
dataType
:
'json'
,
method
:
'GET'
,
data
:
{
appKey
,
subject
:
'it'
}
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchTheme
}
/
${
appKey
}
`
,
ret
.
data
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
length
>
0
&&
ret
.
data
[
0
].
appKey
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisThemePrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
[
0
]),
'EX'
,
300
)
;
const
ret
=
await
ctx
.
curl
(
`
${
host
+
fetchTheme
}
`
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json
'
,
method
:
'GET'
,
data
:
{
appKey
,
subject
:
'it'
}
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchTheme
}
/
${
appKey
}
`
,
ret
.
data
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
length
>
0
&&
ret
.
data
[
0
].
appKey
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisThemePrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
[
0
]),
'EX'
,
300
);
}
return
ret
.
data
[
0
]
;
}
return
ret
.
data
[
0
];
}
async
fetchInfo
(
appKey
){
const
{
ctx
,
partnerAPI
:
{
fetchInfo
,
host
,
redisInfoPrefix
}
}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisInfoPrefix
+
appKey
);
ctx
.
logger
.
info
(
'【Scripts】fetchInfo redis data'
,
redisInfoPrefix
+
appKey
,
'result:'
,
data
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
info
(
'【Scripts】fetchInfo redis err'
,
redisInfoPrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisInfoPrefix
+
appKey
);
async
fetchInfo
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
fetchInfo
,
host
,
redisInfoPrefix
}}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisInfoPrefix
+
appKey
);
ctx
.
logger
.
info
(
'【Scripts】fetchInfo redis data'
,
redisInfoPrefix
+
appKey
,
'result:'
,
data
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
info
(
'【Scripts】fetchInfo redis err'
,
redisInfoPrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisInfoPrefix
+
appKey
);
}
}
}
}
}
const
ret
=
await
ctx
.
curl
(
`
${
host
+
fetchInfo
}
`
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
method
:
'GET'
,
data
:
{
appKey
}
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchInfo
}
?appKey=
${
appKey
}
`
,
ret
.
data
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
length
>
0
&&
ret
.
data
[
0
].
appKey
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisInfoPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
[
0
]),
'EX'
,
300
);
const
ret
=
await
ctx
.
curl
(
`
${
host
+
fetchInfo
}
`
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
method
:
'GET'
,
data
:
{
appKey
}
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchInfo
}
?appKey=
${
appKey
}
`
,
ret
.
data
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
length
>
0
&&
ret
.
data
[
0
].
appKey
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisInfoPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
[
0
]),
'EX'
,
300
);
}
return
ret
.
data
[
0
];
}
return
ret
.
data
[
0
];
}
async
fetchScripts
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
fetchScripts
,
host
,
redisScriptsPrefix
}
}
=
this
;
async
fetchScripts
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
fetchScripts
,
host
,
redisScriptsPrefix
}
}
=
this
;
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisScriptsPrefix
+
appKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Partner】 fetchScripts'
,
redisScriptsPrefix
+
appKey
,
'result:'
,
JSON
.
stringify
(
data
),
err
);
await
this
.
app
.
redis
.
del
(
redisScriptsPrefix
+
appKey
);
if
(
appKey
)
{
const
data
=
await
this
.
app
.
redis
.
get
(
redisScriptsPrefix
+
appKey
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Partner】 fetchScripts'
,
redisScriptsPrefix
+
appKey
,
'result:'
,
JSON
.
stringify
(
data
),
err
);
await
this
.
app
.
redis
.
del
(
redisScriptsPrefix
+
appKey
);
}
}
}
}
}
const
url
=
`
${
host
+
fetchScripts
}
/
${
appKey
}
`
;
const
ret
=
await
ctx
.
curl
(
url
,
{
charset
:
'utf-8
'
,
timeout
:
[
'30s'
,
'30s'
]
,
dataType
:
'json'
,
method
:
'GET'
,
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
url
}
`
,
JSON
.
stringify
(
ret
.
data
)
);
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
id
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisScriptsPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
),
'EX'
,
300
)
;
const
url
=
`
${
host
+
fetchScripts
}
/
${
appKey
}
`
;
const
ret
=
await
ctx
.
curl
(
url
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json
'
,
method
:
'GET'
,
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
url
}
`
,
JSON
.
stringify
(
ret
.
data
));
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
id
===
appKey
)
{
await
this
.
app
.
redis
.
set
(
redisScriptsPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
),
'EX'
,
300
);
}
return
ret
.
data
;
}
return
ret
.
data
;
}
async
fetchAgreements
(
id
)
{
const
{
ctx
,
partnerAPI
:
{
fetchAgreements
,
host
,
redisAgreementsPrefix
}
}
=
this
;
const
data
=
await
this
.
app
.
redis
.
get
(
redisAgreementsPrefix
+
id
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Partner】 fetchAgreements'
,
redisAgreementsPrefix
+
id
,
'result:'
,
JSON
.
stringify
(
data
),
err
);
await
this
.
app
.
redis
.
del
(
redisAgreementsPrefix
+
id
);
}
}
const
url
=
`
${
host
+
fetchAgreements
}
/
${
id
}
`
;
const
ret
=
await
ctx
.
curl
(
url
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
method
:
'GET'
,
});
ctx
.
logger
.
info
(
`【Partner】 fetchAgreements
${
url
}
`
,
JSON
.
stringify
(
ret
.
data
));
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
id
===
id
)
{
await
this
.
app
.
redis
.
set
(
redisScriptsPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
),
300
);
async
fetchAgreements
(
id
)
{
const
{
ctx
,
partnerAPI
:
{
fetchAgreements
,
host
,
redisAgreementsPrefix
}}
=
this
;
const
data
=
await
this
.
app
.
redis
.
get
(
redisAgreementsPrefix
+
id
);
if
(
data
)
{
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【Partner】 fetchAgreements'
,
redisAgreementsPrefix
+
id
,
'result:'
,
JSON
.
stringify
(
data
),
err
);
await
this
.
app
.
redis
.
del
(
redisAgreementsPrefix
+
id
);
}
}
const
url
=
`
${
host
+
fetchAgreements
}
/
${
id
}
`
;
const
ret
=
await
ctx
.
curl
(
url
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
method
:
'GET'
,
});
ctx
.
logger
.
info
(
`【Partner】 fetchAgreements
${
url
}
`
,
JSON
.
stringify
(
ret
.
data
));
if
(
ret
.
status
===
200
&&
ret
.
data
&&
ret
.
data
.
id
===
id
)
{
await
this
.
app
.
redis
.
set
(
redisScriptsPrefix
+
appKey
,
JSON
.
stringify
(
ret
.
data
),
300
);
}
return
ret
.
data
;
}
return
ret
.
data
;
}
async
notice
(
order
)
{
const
{
ctx
}
=
this
;
ctx
.
logger
.
info
(
`【Partner】 notice into`
);
const
{
orderId
,
notifyUrl
,
userId
}
=
order
;
if
(
notifyUrl
)
{
try
{
const
ret
=
await
ctx
.
curl
(
notifyUrl
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
contentType
:
'json'
,
method
:
'POST'
,
data
:
{
orderId
,
userId
,
status
:
'success'
},
async
notice
(
order
)
{
const
{
ctx
}
=
this
;
const
{
orderId
,
notifyUrl
,
userId
}
=
order
;
const
dbRes
=
await
service
.
order
.
getOneByOrderId
({
orderId
,
notice
:
1
});
if
(
!
dbRes
&&
notifyUrl
)
{
try
{
const
ret
=
await
ctx
.
curl
(
notifyUrl
,
{
charset
:
'utf-8'
,
timeout
:
[
'30s'
,
'30s'
],
contentType
:
'json'
,
method
:
'POST'
,
data
:
{
orderSn
:
orderId
,
userId
:
userId
||
''
,
status
:
'success'
},
}
);
ctx
.
logger
.
info
(
`【Partner】 notice
${
notifyUrl
}
`
,
'orderId:'
,
orderId
,
'result:'
,
ret
.
status
,
JSON
.
stringify
(
ret
.
data
));
if
(
ret
.
status
==
200
)
{
await
order
.
update
({
notice
:
1
});
}
else
{
await
order
.
update
({
notice
:
ret
.
status
});
}
);
ctx
.
logger
.
info
(
`【Partner】 notice
${
notifyUrl
}
`
,
'orderId:'
,
orderId
,
'result:'
,
ret
.
status
,
JSON
.
stringify
(
ret
.
data
));
if
(
ret
.
status
==
200
)
{
await
order
.
update
({
notice
:
1
});
}
else
{
await
order
.
update
({
notice
:
ret
.
status
});
}
catch
(
e
)
{
ctx
.
logger
.
info
(
`【Partner】 notice err
${
e
}
`
)
}
finally
{
return
}
}
catch
(
e
)
{
ctx
.
logger
.
info
(
`【Partner】 notice err
${
e
}
`
)
}
finally
{
return
}
else
{
ctx
.
logger
.
info
(
'【Partner】 notice no send'
,
'orderId:'
,
orderId
);
}
}
}
}
module
.
exports
=
PartnerService
;
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