Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xuexin_h5
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
xuexin_h5
Commits
672106f1
Commit
672106f1
authored
May 09, 2019
by
何娜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
学信H5 增加测试上限
parent
72edc639
Pipeline
#7287
passed with stage
in 6 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
152 additions
and
22 deletions
+152
-22
order.js
app/controller/order.js
+29
-15
nodeLimit.js
app/model/nodeLimit.js
+70
-0
partner.js
app/service/partner.js
+49
-5
signature.js
app/service/signature.js
+2
-2
config.local.js
config/config.local.js
+1
-0
config.prod.js
config/config.prod.js
+1
-0
No files found.
app/controller/order.js
View file @
672106f1
...
...
@@ -46,9 +46,9 @@ class OrderController extends Controller {
}
async
create
()
{
const
{
ctx
,
service
}
=
this
;
const
{
ctx
,
service
}
=
this
;
ctx
.
validate
(
this
.
createRule
);
let
{
appKey
,
userId
,
notifyUrl
,
backUrl
,
orderId
}
=
ctx
.
request
.
body
;
let
{
appKey
,
userId
,
notifyUrl
,
redirectUrl
,
orderId
}
=
ctx
.
request
.
body
;
const
appKeyInfo
=
await
service
.
partner
.
fetchInfo
(
appKey
);
ctx
.
logger
.
info
(
appKey
,
',appKeyInfo,'
,
appKeyInfo
);
if
(
!
(
appKeyInfo
&&
appKeyInfo
.
valid
===
true
&&
appKeyInfo
.
enableIt
===
true
))
{
...
...
@@ -60,7 +60,7 @@ class OrderController extends Controller {
userId
:
userId
||
''
,
cityId
:
''
,
notifyUrl
:
notifyUrl
||
(
ctx
.
app
.
notifyMap
&&
ctx
.
app
.
notifyMap
.
get
(
appKey
)
&&
ctx
.
app
.
notifyMap
.
get
(
appKey
).
notifyUrl
)
||
''
,
backUrl
:
back
Url
||
''
,
backUrl
:
redirect
Url
||
''
,
appkey
:
appKey
,
status
:
'init'
,
};
...
...
@@ -70,7 +70,7 @@ class OrderController extends Controller {
object
.
orderId
=
ctx
.
helper
.
getUuid
();
await
service
.
order
.
create
(
object
);
}
ctx
.
success
({
orderId
:
object
.
orderId
});
ctx
.
success
({
orderId
:
object
.
orderId
});
}
async
partnerOrder
()
{
...
...
@@ -93,16 +93,30 @@ class OrderController extends Controller {
async
partnerData
()
{
const
{
ctx
,
service
}
=
this
;
ctx
.
validate
(
this
.
showRule
);
const
{
appKey
,
orderSn
}
=
ctx
.
request
.
body
.
params
;
await
service
.
signature
.
signatureCheck
(
ctx
.
request
.
body
);
const
data
=
await
service
.
order
.
getOneByOrderId
(
orderSn
);
const
{
appKey
,
orderId
}
=
ctx
.
request
.
body
.
params
;
const
appKeyInfo
=
await
service
.
partner
.
fetchInfo
(
appKey
);
if
(
!
(
appKeyInfo
&&
appKeyInfo
.
valid
===
true
&&
appKeyInfo
.
enableIt
===
true
))
{
return
ctx
.
body
=
{
code
:
-
1
,
mag
:
'未开通此服务'
}
}
const
sign
=
await
service
.
signature
.
signatureCheck
(
ctx
.
request
.
body
);
if
(
sign
.
code
!=
0
)
{
return
ctx
.
body
=
{
code
:
-
1
,
mag
:
sign
.
msg
}
}
const
data
=
await
service
.
order
.
getOneByOrderId
({
orderId
,
status
:
'success'
});
if
(
data
&&
data
.
status
===
'success'
)
{
const
result
=
await
service
.
storage
.
read
(
orderSn
,
appKey
);
ctx
.
body
=
{
code
:
0
,
data
:
result
};
return
;
await
service
.
partner
.
appKeyLimit
(
appKey
);
const
result
=
await
service
.
storage
.
read
(
orderId
,
appKey
);
ctx
.
body
=
{
code
:
0
,
data
:
result
};
return
;
}
ctx
.
body
=
{
code
:
-
1
,
...
...
@@ -111,8 +125,8 @@ class OrderController extends Controller {
}
async
orderShow
()
{
const
{
ctx
,
service
}
=
this
;
const
{
appKey
,
orderId
}
=
ctx
.
params
;
const
{
ctx
,
service
}
=
this
;
const
{
appKey
,
orderId
}
=
ctx
.
params
;
const
appKeyInfo
=
await
service
.
partner
.
fetchInfo
(
appKey
);
if
(
!
(
appKeyInfo
&&
appKeyInfo
.
valid
===
true
&&
appKeyInfo
.
enableItView
===
true
))
{
return
ctx
.
fail
(
'未开通此服务'
);
...
...
app/model/nodeLimit.js
0 → 100644
View file @
672106f1
'use strict'
;
module
.
exports
=
app
=>
{
const
{
DataTypes
}
=
app
.
Sequelize
;
const
nodeLimit
=
app
.
model
.
define
(
'nodeLimit'
,
{
id
:
{
type
:
DataTypes
.
INTEGER
,
allowNull
:
false
,
autoIncrement
:
true
,
primaryKey
:
true
,
field
:
'id'
,
},
companyName
:
{
type
:
DataTypes
.
STRING
(
255
),
allowNull
:
true
,
field
:
'companyName'
,
},
appKey
:
{
type
:
DataTypes
.
STRING
(
255
),
allowNull
:
false
,
field
:
'appKey'
,
},
type
:
{
type
:
DataTypes
.
STRING
(
255
),
allowNull
:
true
,
field
:
'type'
,
},
currentCount
:
{
type
:
DataTypes
.
INTEGER
(
20
),
allowNull
:
true
,
defaultValue
:
0
,
field
:
'currentCount'
,
},
limitCount
:
{
type
:
DataTypes
.
INTEGER
(
20
),
allowNull
:
true
,
defaultValue
:
0
,
field
:
'limitCount'
,
},
createTime
:
{
type
:
DataTypes
.
DATE
,
allowNull
:
true
,
defaultValue
:
app
.
Sequelize
.
literal
(
'CURRENT_TIMESTAMP'
),
field
:
'createTime'
,
},
updateTime
:
{
type
:
DataTypes
.
DATE
,
allowNull
:
true
,
defaultValue
:
app
.
Sequelize
.
literal
(
'CURRENT_TIMESTAMP'
),
field
:
'updateTime'
,
},
text
:
{
type
:
DataTypes
.
STRING
(
255
),
allowNull
:
true
,
field
:
'text1'
,
},
text2
:
{
type
:
DataTypes
.
STRING
(
255
),
allowNull
:
true
,
field
:
'text2'
,
},
},
{
tableName
:
'node_limit'
,
timestamps
:
false
,
});
return
nodeLimit
;
};
app/service/partner.js
View file @
672106f1
...
...
@@ -17,7 +17,7 @@ class PartnerService extends Service {
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【
Scripts】fetchParams
'
,
redisThemePrefix
+
appKey
,
'result:'
,
data
,
err
);
ctx
.
logger
.
error
(
'【
Partner】fetchTheme
'
,
redisThemePrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisThemePrefix
+
appKey
);
}
}
...
...
@@ -32,7 +32,7 @@ class PartnerService extends Service {
subject
:
'it'
}
});
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchTheme
}
/
${
appKey
}
`
,
ret
.
data
);
ctx
.
logger
.
info
(
`【Partner】 fetchTheme
${
host
+
fetchTheme
}
/
${
appKey
}
`
,
JSON
.
stringify
(
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
);
}
...
...
@@ -47,7 +47,7 @@ class PartnerService extends Service {
try
{
return
JSON
.
parse
(
data
);
}
catch
(
err
)
{
ctx
.
logger
.
error
(
'【
Scripts
】fetchInfo'
,
redisInfoPrefix
+
appKey
,
'result:'
,
data
,
err
);
ctx
.
logger
.
error
(
'【
Partner
】fetchInfo'
,
redisInfoPrefix
+
appKey
,
'result:'
,
data
,
err
);
await
this
.
app
.
redis
.
del
(
redisInfoPrefix
+
appKey
);
}
}
...
...
@@ -62,7 +62,7 @@ class PartnerService extends Service {
appKey
}
});
ctx
.
logger
.
info
(
`【Partner】 fetch
Theme
${
host
+
fetchInfo
}
?appKey=
${
appKey
}
`
,
ret
.
data
);
ctx
.
logger
.
info
(
`【Partner】 fetch
Info
${
host
+
fetchInfo
}
?appKey=
${
appKey
}
`
,
JSON
.
stringify
(
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
);
}
...
...
@@ -90,7 +90,7 @@ class PartnerService extends Service {
dataType
:
'json'
,
method
:
'GET'
,
});
ctx
.
logger
.
info
(
`【Partner】 fetch
Theme
${
url
}
`
,
JSON
.
stringify
(
ret
.
data
));
ctx
.
logger
.
info
(
`【Partner】 fetch
Scripts
${
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
);
}
...
...
@@ -147,6 +147,50 @@ class PartnerService extends Service {
}
return
}
async
appKeyLimit
(
appKey
)
{
const
{
ctx
,
partnerAPI
:
{
redisappKeyLimitPrefix
}
}
=
this
;
let
data
=
await
this
.
app
.
redis
.
get
(
redisappKeyLimitPrefix
);
data
=
JSON
.
parse
(
data
);
if
(
data
)
{
if
(
data
.
includes
(
appKey
))
{
let
limit
=
await
this
.
app
.
redis
.
get
(
redisappKeyLimitPrefix
+
appKey
);
if
(
limit
)
{
limit
=
JSON
.
parse
(
limit
);
if
(
limit
.
currentCount
>=
limit
.
limitCount
)
{
ctx
.
throw
(
422
,
{
message
:
'appKey查询数量超过限制,请联系技术人员'
});
}
else
{
// limit.currentCount++;
// await this.app.redis.set(redisappKeyLimitPrefix + appKey, JSON.stringify({ currentCount: limit.currentCount, limitCount: limit.limitCount }), 'EX', 300);
await
ctx
.
model
.
query
(
'UPDATE node_limit set currentCount = currentCount + 1 where appKey = ?'
,
{
type
:
'UPDATE'
,
replacements
:
[
appKey
],
});
}
}
}
}
else
{
const
dbRes
=
await
ctx
.
model
.
NodeLimit
.
findAll
({
attributes
:
[
'appKey'
,
'currentCount'
,
'limitCount'
],
where
:
{
type
:
'xuexin'
},
});
if
(
dbRes
)
{
const
appKeyArray
=
[];
for
(
const
item
of
dbRes
)
{
const
{
appKey
,
currentCount
,
limitCount
}
=
item
;
appKeyArray
.
push
(
appKey
);
await
this
.
app
.
redis
.
set
(
redisappKeyLimitPrefix
+
appKey
,
JSON
.
stringify
({
currentCount
,
limitCount
}),
'EX'
,
300
);
}
await
this
.
app
.
redis
.
set
(
redisappKeyLimitPrefix
,
JSON
.
stringify
(
appKeyArray
),
'EX'
,
300
);
if
(
appKeyArray
.
includes
(
appKey
))
{
await
ctx
.
model
.
query
(
'UPDATE node_limit set currentCount = currentCount + 1 where appKey = ?'
,
{
type
:
'UPDATE'
,
replacements
:
[
appKey
],
});
}
}
}
}
}
module
.
exports
=
PartnerService
;
app/service/signature.js
View file @
672106f1
...
...
@@ -96,8 +96,8 @@ class SignatureService extends Service {
contentType
:
'json'
,
});
ctx
.
logger
.
info
(
'【Signature】signatureCheck params'
,
JSON
.
stringify
({
...
params
,
type
:
signatureType
}),
'result:'
,
JSON
.
stringify
(
result
.
data
));
this
.
_checkSuccess
(
result
);
return
result
.
data
.
data
;
//
this._checkSuccess(result);
return
result
.
data
;
}
async
cityConfig
(
params
){
...
...
config/config.local.js
View file @
672106f1
...
...
@@ -33,6 +33,7 @@ module.exports = () => {
redisScriptsPrefix
:
'URANUS.XX.PARNTERS.SCRIPTS'
,
redisAgreementsPrefix
:
'URANUS.XX.PARNTERS.Agreements'
,
redisInfoPrefix
:
'URANUS.XX.PARNTERS.Info'
,
redisappKeyLimitPrefix
:
'URANUS.XX.PARNTERS.Limit'
,
};
config
.
scriptsAPI
=
{
...
...
config/config.prod.js
View file @
672106f1
...
...
@@ -36,6 +36,7 @@ module.exports = () => {
redisScriptsPrefix
:
'URANUS.XX.PARNTERS.SCRIPTS'
,
redisAgreementsPrefix
:
'URANUS.XX.PARNTERS.Agreements'
,
redisInfoPrefix
:
'URANUS.XX.PARNTERS.Info'
,
redisappKeyLimitPrefix
:
'URANUS.XX.PARNTERS.Limit'
,
};
config
.
scriptsAPI
=
{
...
...
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