Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjh5
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
gjjh5
Commits
0f7f0cc3
Commit
0f7f0cc3
authored
May 07, 2019
by
姜登
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gjj
parent
1185ad77
Pipeline
#7108
passed with stage
in 3 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
0 deletions
+119
-0
order.js
app/controller/order.js
+2
-0
nodeLimit.js
app/model/nodeLimit.js
+70
-0
partner.js
app/service/partner.js
+45
-0
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 @
0f7f0cc3
...
...
@@ -96,6 +96,7 @@ class OrderController extends Controller {
await
service
.
signature
.
signatureCheck
(
ctx
.
request
.
body
);
const
data
=
await
service
.
order
.
getOneByOrderId
({
orderId
,
status
:
'success'
});
if
(
data
)
{
await
service
.
partner
.
appKeyLimit
(
appKey
);
const
result
=
await
service
.
storage
.
read
(
orderId
,
appKey
);
ctx
.
body
=
{
code
:
0
,
...
...
@@ -122,6 +123,7 @@ class OrderController extends Controller {
}
const
data
=
await
service
.
order
.
getOneByOrderId
({
orderId
,
status
:
'success'
});
if
(
data
)
{
await
service
.
partner
.
appKeyLimit
(
appKey
);
if
(
data
.
status
===
'success'
&&
(
data
.
appKey
===
appKey
))
{
const
result
=
await
service
.
storage
.
read
(
orderId
,
appKey
);
const
ret
=
service
.
washData
.
dealData
(
result
);
...
...
app/model/nodeLimit.js
0 → 100644
View file @
0f7f0cc3
'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 @
0f7f0cc3
...
...
@@ -119,6 +119,51 @@ 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
:
'gjj'
,
},
});
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
);
}
await
ctx
.
model
.
query
(
'UPDATE node_limit set currentCount = currentCount + 1 where appKey = ?'
,
{
type
:
'UPDATE'
,
replacements
:
[
appKey
],
});
}
}
}
module
.
exports
=
PartnerService
;
config/config.local.js
View file @
0f7f0cc3
...
...
@@ -37,6 +37,7 @@ module.exports = () => {
redisAgreementsPrefix
:
'URANUS.HF.PARNTERS.Agreements'
,
fetchInfo
:
'/chaos/partner'
,
redisInfoPrefix
:
'URANUS.HF.PARNTERS.Info'
,
redisappKeyLimitPrefix
:
'URANUS.HF.PARNTERS.Limit'
,
};
config
.
scriptsAPI
=
{
...
...
config/config.prod.js
View file @
0f7f0cc3
...
...
@@ -79,6 +79,7 @@ module.exports = () => {
redisAgreementsPrefix
:
'URANUS.HF.PARNTERS.Agreements'
,
fetchInfo
:
'/chaos/partner'
,
redisInfoPrefix
:
'URANUS.HF.PARNTERS.Info'
,
redisappKeyLimitPrefix
:
'URANUS.HF.PARNTERS.Limit'
,
};
config
.
lockKeys
=
{
...
...
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