Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sb_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
sb_h5
Commits
3837d238
Commit
3837d238
authored
Mar 06, 2019
by
高诸锋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
250e3412
Pipeline
#4070
passed with stage
in 51 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
11 deletions
+92
-11
app.js
app.js
+8
-0
order.js
app/controller/order.js
+7
-2
nodeLimit.js
app/middleware/nodeLimit.js
+36
-0
getNodeLimit.js
app/schedule/getNodeLimit.js
+27
-0
order.js
app/service/order.js
+3
-9
config.local.js
config/config.local.js
+11
-0
No files found.
app.js
0 → 100644
View file @
3837d238
'use strict'
;
module
.
exports
=
app
=>
{
app
.
beforeStart
(
async
()
=>
{
});
};
app/controller/order.js
View file @
3837d238
...
@@ -51,7 +51,7 @@ class OrderController extends Controller {
...
@@ -51,7 +51,7 @@ class OrderController extends Controller {
let
{
orderId
}
=
ctx
.
request
.
body
;
let
{
orderId
}
=
ctx
.
request
.
body
;
// const orderId = await service.signature.createOrderId(ctx.request.body);
// const orderId = await service.signature.createOrderId(ctx.request.body);
orderId
=
orderId
||
ctx
.
helper
.
getUuid
();
orderId
=
orderId
||
ctx
.
helper
.
getUuid
();
await
service
.
order
.
update
(
{
const
toDbObj
=
{
orderId
,
orderId
,
taskId
:
''
,
taskId
:
''
,
userId
:
userId
||
''
,
userId
:
userId
||
''
,
...
@@ -60,7 +60,12 @@ class OrderController extends Controller {
...
@@ -60,7 +60,12 @@ class OrderController extends Controller {
status
:
'init'
,
status
:
'init'
,
notifyUrl
:
notifyUrl
||
(
ctx
.
app
.
notifyMap
.
get
(
appKey
)
&&
ctx
.
app
.
notifyMap
.
get
(
appKey
).
notifyUrl
)
||
''
,
notifyUrl
:
notifyUrl
||
(
ctx
.
app
.
notifyMap
.
get
(
appKey
)
&&
ctx
.
app
.
notifyMap
.
get
(
appKey
).
notifyUrl
)
||
''
,
backUrl
,
backUrl
,
});
};
if
(
orderId
)
{
// 老的H5
await
service
.
order
.
update
(
toDbObj
);
}
else
{
await
service
.
order
.
create
(
toDbObj
);
}
ctx
.
success
({
orderId
});
ctx
.
success
({
orderId
});
}
}
...
...
app/middleware/nodeLimit.js
0 → 100644
View file @
3837d238
'use strict'
;
module
.
exports
=
(
options
,
app
)
=>
{
return
async
function
(
ctx
,
next
)
{
const
{
query
}
=
ctx
.
request
;
// 测试appKey限制
const
isLimit
=
await
judgeLimit
(
query
);
if
(
isLimit
)
{
ctx
.
body
=
{
code
:
107
,
msg
:
'测试appKey使用次数到达限制'
};
return
;
}
await
next
();
};
};
async
function
judgeLimit
(
params
)
{
const
{
ctx
,
app
}
=
this
;
const
{
appKey
}
=
params
;
// ctx.logger.info(app.devAppkeyMap.keys());
if
(
!
app
.
nodeLimitMap
.
has
(
appKey
))
{
return
false
;
}
let
{
currentCount
,
limitCount
,
env
}
=
app
.
devAppkeyMap
.
get
(
appKey
);
if
(
env
===
'dev'
&&
currentCount
>=
limitCount
)
{
return
true
;
}
currentCount
++
;
const
upObj
=
{
currentCount
,
};
await
ctx
.
model
.
NodeLimit
.
update
(
upObj
,
{
where
:
{
appKey
}
}
);
return
false
;
}
app/schedule/getNodeLimit.js
0 → 100644
View file @
3837d238
'use strict'
;
module
.
exports
=
app
=>
{
return
{
schedule
:
{
interval
:
'5m'
,
// 5分钟间隔
type
:
'all'
,
immediate
:
true
,
},
// 定时操作node_gjj.node_limit表
async
task
(
ctx
)
{
const
rows
=
await
ctx
.
nodeGjj
.
query
(
'SELECT appKey, currentCount, limitCount, text FROM node_limit WHERE type = shebao'
,
{
type
:
'SELECT'
});
const
map
=
new
Map
();
rows
.
forEach
(
item
=>
{
const
{
currentCount
,
limitCount
,
text
}
=
item
;
const
obj
=
{
currentCount
,
limitCount
,
env
:
text
,
};
map
.
set
(
item
.
appKey
,
obj
);
});
ctx
.
app
.
modeLimitMap
=
map
;
},
};
};
app/service/order.js
View file @
3837d238
...
@@ -21,14 +21,7 @@ class OrderService extends Service {
...
@@ -21,14 +21,7 @@ class OrderService extends Service {
async
create
(
params
)
{
async
create
(
params
)
{
const
{
ctx
}
=
this
;
const
{
ctx
}
=
this
;
const
order
=
await
ctx
.
model
.
TaskStatus
.
findOne
({
where
:
{
orderId
:
params
.
orderId
},
});
if
(
order
)
{
ctx
.
throw
(
400
,
{
message
:
'already have order'
});
}
await
ctx
.
model
.
TaskStatus
.
create
(
params
);
await
ctx
.
model
.
TaskStatus
.
create
(
params
);
return
order
;
}
}
async
update
(
params
)
{
async
update
(
params
)
{
...
@@ -38,8 +31,9 @@ class OrderService extends Service {
...
@@ -38,8 +31,9 @@ class OrderService extends Service {
order
:
[[
'createDate'
,
'DESC'
]],
order
:
[[
'createDate'
,
'DESC'
]],
});
});
// console.log(order);
// console.log(order);
if
(
order
.
length
===
0
)
{
//
if
(
order
.
length
===
0
)
{
// 创建订单号
await
ctx
.
model
.
TaskStatus
.
create
(
params
);
// await ctx.model.TaskStatus.create(params);
ctx
.
throw
(
400
,
{
message
:
'no orderId'
});
return
;
return
;
}
}
for
(
const
item
of
order
)
{
for
(
const
item
of
order
)
{
...
...
config/config.local.js
View file @
3837d238
...
@@ -100,6 +100,17 @@ module.exports = () => {
...
@@ -100,6 +100,17 @@ module.exports = () => {
username
:
'hexin'
,
username
:
'hexin'
,
password
:
'gYUHszn9#q'
,
password
:
'gYUHszn9#q'
,
port
:
3306
,
port
:
3306
,
},
{
// 东八时区
timezone
:
'+08:00'
,
delegate
:
'nodeGjj'
,
baseDir
:
'model'
,
dialect
:
'mysql'
,
host
:
'rm-bp1272001633qc0x9o.mysql.rds.aliyuncs.com'
,
database
:
'nodetest'
,
username
:
'hexin'
,
password
:
'gYUHszn9#q'
,
port
:
3306
,
}],
}],
};
};
...
...
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