Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-arena-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ygopro-arena-api
Commits
a2734daf
Commit
a2734daf
authored
Dec 10, 2017
by
ganjingcun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
投票统计
parent
ffe402e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
31 deletions
+79
-31
.gitignore
.gitignore
+1
-0
routes/api.js
routes/api.js
+78
-31
No files found.
.gitignore
View file @
a2734daf
...
...
@@ -11,3 +11,4 @@ db.sql
upload/
plan.md
query.sql
test*
\ No newline at end of file
routes/api.js
View file @
a2734daf
...
...
@@ -236,17 +236,17 @@ router.post('/score', function (req, res) {
let
expResult
=
utils
.
getExpScore
(
userA
.
exp
,
userB
.
exp
,
userscoreA
,
userscoreB
)
// 3分钟以内结束的决斗,胜者不加DP,负者照常扣DP。 平局不扣DP不加DP : 把开始时间+3分钟,如果加完比结束时间靠后,说明比赛时间不足三分钟
var
isLess3Min
=
moment
(
start
).
add
(
3
,
'
m
'
).
isAfter
(
moment
(
end
));
if
(
isLess3Min
)
{
if
(
winner
===
usernameA
)
{
ptResult
.
ptA
=
userA
.
pt
console
.
log
(
usernameA
,
'
当局有人存在早退,胜利不加分
'
,
moment
(
start
).
format
(
'
YYYY-MM-DD HH:mm
'
))
}
if
(
winner
===
usernameB
)
{
ptResult
.
ptB
=
userB
.
pt
console
.
log
(
usernameB
,
'
当局有人存在早退,胜利不加分
'
,
moment
(
start
).
format
(
'
YYYY-MM-DD HH:mm
'
))
}
}
//
var isLess3Min = moment(start).add(3, 'm').isAfter(moment(end));
//
if (isLess3Min) {
//
if (winner === usernameA) {
//
ptResult.ptA = userA.pt
//
console.log(usernameA, '当局有人存在早退,胜利不加分', moment(start).format('YYYY-MM-DD HH:mm'))
//
}
//
if (winner === usernameB) {
//
ptResult.ptB = userB.pt
//
console.log(usernameB, '当局有人存在早退,胜利不加分', moment(start).format('YYYY-MM-DD HH:mm'))
//
}
//
}
if
(
firstWin
)
{
if
(
winner
===
usernameA
)
{
...
...
@@ -894,6 +894,14 @@ router.post('/submitVote', function (req, res) {
let
user
=
req
.
body
.
user
;
let
username
=
req
.
body
.
username
;
if
(
!
user
||
!
username
||
user
==
"
undefined
"
||
username
==
"
undefined
"
)
{
var
response
=
{};
response
.
code
=
500
;
res
.
json
(
response
);
return
}
let
voteid
=
req
.
body
.
voteid
;
let
opid
=
req
.
body
.
opid
;
...
...
@@ -937,7 +945,6 @@ router.post('/submitVote', function (req, res) {
id =
${
user
}
where username = '
${
username
}
'`
;
console
.
log
(
sql2
);
async
.
waterfall
([
function
(
callback
)
{
...
...
@@ -947,11 +954,12 @@ router.post('/submitVote', function (req, res) {
callback2
(
err
);
});
},
function
(
err
)
{
callback
()
callback
(
err
)
});
},
function
(
callback
)
{
console
.
log
(
sql2
);
client
.
query
(
sql2
,
function
(
err
,
result
)
{
done
()
callback
(
err
)
...
...
@@ -971,7 +979,6 @@ router.post('/submitVote', function (req, res) {
});
});
});
...
...
@@ -1035,36 +1042,75 @@ router.get('/votes', function (req, res) {
}
var
optionCountMap
=
{}
var
voteCountMap
=
{}
var
vates
=
result
.
rows
;
async
.
each
(
vates
,
function
(
vote
,
callback
)
{
var
vateid
=
vote
.
id
var
options
=
JSON
.
parse
(
vote
.
options
)
async
.
each
(
options
,
function
(
option
,
callback2
)
{
var
queryVoteOptionCount
=
`SELECT count(*) from vote_result where vote_id='
${
vateid
}
' and option_id ='
${
option
.
key
}
'`
// console.log(queryVoteOptionCount)
client
.
query
(
queryVoteOptionCount
,
function
(
err
,
result
)
{
//call `done()` to release the client back to the pool
done
()
if
(
err
)
{
console
.
error
(
'
error running query
'
,
err
)
}
optionCountMap
[
option
.
key
]
=
result
.
rows
[
0
].
count
callback2
();
});
var
option_ids
=
[]
async
.
waterfall
([
function
(
callback3
)
{
async
.
each
(
options
,
function
(
option
,
callback2
)
{
var
queryVoteOptionCount
=
`SELECT count(*) from vote_result where vote_id='
${
vateid
}
' and option_id ='
${
option
.
key
}
' `
option_ids
.
push
(
String
(
option
.
key
))
// console.log(queryVoteOptionCount)
client
.
query
(
queryVoteOptionCount
,
function
(
err
,
result
)
{
//call `done()` to release the client back to the pool
done
()
if
(
err
)
{
console
.
error
(
'
error running query
'
,
err
)
}
optionCountMap
[
option
.
key
]
=
result
.
rows
[
0
].
count
callback2
();
});
},
function
(
err
)
{
if
(
err
)
{
console
.
error
(
"
get votes error :
"
,
err
);
}
callback3
()
});
},
function
(
callback3
)
{
var
id_str
=
"
(
"
_
.
each
(
option_ids
,
function
(
id
)
{
id_str
=
id_str
+
"
'
"
+
id
+
"
'
"
+
"
,
"
})
id_str
=
id_str
.
slice
(
0
,
-
1
)
id_str
=
id_str
+
"
)
"
var
queryVoteCount
=
`SELECT count(DISTINCT userid) from vote_result where vote_id = '
${
vateid
}
' and option_id in
${
id_str
}
`
console
.
log
(
queryVoteCount
)
client
.
query
(
queryVoteCount
,
function
(
err
,
result
)
{
//call `done()` to release the client back to the pool
done
()
if
(
err
)
{
console
.
error
(
'
error running query
'
,
err
)
}
voteCountMap
[
vateid
]
=
result
.
rows
[
0
].
count
callback3
();
});
},
function
(
err
)
{
if
(
err
)
{
console
.
error
(
"
get votes error :
"
,
err
);
}
],
function
(
err
)
{
callback
()
});
},
function
(
err
)
{
if
(
err
)
{
...
...
@@ -1074,6 +1120,7 @@ router.get('/votes', function (req, res) {
res
.
json
({
total
:
total
-
0
,
data
:
result
.
rows
,
voteCountMap
:
voteCountMap
,
optionCountMap
:
optionCountMap
});
});
...
...
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