Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
c42183c6
Commit
c42183c6
authored
Feb 19, 2021
by
王波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
签到相关功能拓展
parent
d37265f6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
1 deletion
+62
-1
sign.service.ts
v2.0/src/service/common/sign.service.ts
+9
-1
sign.d.ts
v2.0/src/typings/sign.d.ts
+6
-0
sign.ts
v2.0/src/utils/common/sign.ts
+47
-0
No files found.
v2.0/src/service/common/sign.service.ts
View file @
c42183c6
...
@@ -10,6 +10,7 @@ import { ACTIVITY_STATUS } from '../../constants'
...
@@ -10,6 +10,7 @@ import { ACTIVITY_STATUS } from '../../constants'
import
UserService
from
'./user.service'
import
UserService
from
'./user.service'
import
{
getToday
}
from
'../../utils'
import
{
getToday
}
from
'../../utils'
import
{
CODE_TYPES
}
from
'../../errorCode'
import
{
CODE_TYPES
}
from
'../../errorCode'
import
{
getDistanceDays
}
from
'../../utils/common/sign'
import
{
formatDate
}
from
'../../utils/common/date'
import
{
formatDate
}
from
'../../utils/common/date'
export
default
class
SignService
extends
UserService
{
export
default
class
SignService
extends
UserService
{
...
@@ -48,7 +49,14 @@ export default class SignService extends UserService {
...
@@ -48,7 +49,14 @@ export default class SignService extends UserService {
const
{
openId
}
=
this
.
context
const
{
openId
}
=
this
.
context
const
signInfoList
:
ISignInfoAggregate
[]
=
await
this
.
signdao
.
aggregate
(
const
signInfoList
:
ISignInfoAggregate
[]
=
await
this
.
signdao
.
aggregate
(
{
$match
:
{
activityId
,
openId
}
},
{
$match
:
{
activityId
,
openId
}
},
{
$project
:
{
d
:
{
$dayOfYear
:
'$signTime'
},
y
:
{
$year
:
'$signTime'
},
signTime
:
'$signTime'
}
}
{
$project
:
{
d
:
{
$dayOfYear
:
'$signTime'
},
y
:
{
$year
:
'$signTime'
},
signTime
:
'$signTime'
,
signDay
:
'$signDay'
}
}
)
)
return
signInfoList
return
signInfoList
...
...
v2.0/src/typings/sign.d.ts
View file @
c42183c6
...
@@ -15,5 +15,11 @@ interface ISignInfoAggregate {
...
@@ -15,5 +15,11 @@ interface ISignInfoAggregate {
_id
?:
string
_id
?:
string
d
:
number
d
:
number
y
:
number
y
:
number
signDay
:
string
signTime
:
Date
signTime
:
Date
}
}
interface
signDayList
{
isSing
:
boolean
signDay
:
string
}
v2.0/src/utils/common/sign.ts
View file @
c42183c6
...
@@ -3,8 +3,10 @@
...
@@ -3,8 +3,10 @@
import
*
as
dayjs
from
'dayjs'
import
*
as
dayjs
from
'dayjs'
import
{
uniq
}
from
'lodash'
import
{
uniq
}
from
'lodash'
import
{
getToday
}
from
'./getToday'
import
{
getToday
}
from
'./getToday'
import
{
formatDate
}
from
'./date'
const
isLeapYear
=
(
year
:
number
)
=>
(
year
%
4
===
0
&&
year
%
100
!==
0
)
||
year
%
400
===
0
const
isLeapYear
=
(
year
:
number
)
=>
(
year
%
4
===
0
&&
year
%
100
!==
0
)
||
year
%
400
===
0
const
oneDayTime
=
24
*
3600
*
1000
// 获取最大连续签到天数
// 获取最大连续签到天数
export
const
getMaxContinusSignDays
=
(
signInfoList
:
ISignInfoAggregate
[]):
number
=>
{
export
const
getMaxContinusSignDays
=
(
signInfoList
:
ISignInfoAggregate
[]):
number
=>
{
...
@@ -37,3 +39,48 @@ export const getMaxContinusSignDays = (signInfoList: ISignInfoAggregate[]): numb
...
@@ -37,3 +39,48 @@ export const getMaxContinusSignDays = (signInfoList: ISignInfoAggregate[]): numb
export
const
getSignedByDay
=
(
signInfoList
:
ISignInfoAggregate
[],
day
=
getToday
()):
boolean
=>
{
export
const
getSignedByDay
=
(
signInfoList
:
ISignInfoAggregate
[],
day
=
getToday
()):
boolean
=>
{
return
signInfoList
.
some
(
v
=>
dayjs
(
v
.
signTime
).
format
(
'yyyy/MM/dd'
)
===
day
)
return
signInfoList
.
some
(
v
=>
dayjs
(
v
.
signTime
).
format
(
'yyyy/MM/dd'
)
===
day
)
}
}
// 获取当前几天签到信息(包含今天)
export
const
getDistanceDays
=
(
days
:
number
,
signInfoList
:
ISignInfoAggregate
[]):
signDayList
[]
=>
{
let
signDayList
=
[]
for
(
let
index
=
0
;
index
<
days
;
index
++
)
{
let
signDay
=
formatDate
(
dayjs
().
subtract
(
index
,
'day'
).
valueOf
()).
format
()
const
signInfo
=
signInfoList
.
find
(
v
=>
v
.
signDay
===
signDay
)
signDayList
.
push
({
signDay
,
isSign
:
signInfo
?
true
:
false
})
}
return
signDayList
}
// 获取几天前至今连续签到天数(包含今天),如果昨天签到今天未签到,则也算连续签到,不算断签
export
const
getContinueDays
=
(
days
:
number
,
signInfoList
:
ISignInfoAggregate
[]):
number
=>
{
const
minYear
=
Math
.
min
.
apply
(
null
,
signInfoList
.
map
(
v
=>
+
v
.
y
)
)
const
list
:
number
[]
=
signInfoList
.
map
(
v
=>
{
const
gap
=
(
isLeapYear
?
366
:
365
)
*
(
v
.
y
-
minYear
)
return
gap
+
v
.
d
})
.
sort
((
a
,
b
)
=>
a
-
b
)
if
(
list
.
length
===
0
)
return
0
let
m
=
uniq
(
list
.
sort
((
a
,
b
)
=>
a
-
b
))
let
max
=
0
//判断当天或者昨天是否已经签到
const
isSign
=
signInfoList
.
some
(
v
=>
v
.
signDay
===
getToday
()
||
v
.
signDay
===
formatDate
(
dayjs
().
subtract
(
-
1
,
'day'
).
valueOf
()).
format
()
)
for
(
let
i
=
0
;
i
<
days
;
i
++
)
{
if
(
isSign
&&
m
[
i
+
1
]
-
m
[
i
]
===
1
)
{
//当天或者昨天已经签到,则开始计算连续签到天数
max
++
}
else
{
break
}
}
return
max
}
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