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
db1217a4
Commit
db1217a4
authored
Dec 14, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
🎸
sign模块
parent
8773c72d
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
177 additions
and
4 deletions
+177
-4
sign.controller.ts
v2.0/src/controller/sign.controller.ts
+29
-0
db.ts
v2.0/src/db.ts
+2
-0
index.ts
v2.0/src/service/common/index.ts
+5
-2
sign.service.ts
v2.0/src/service/common/sign.service.ts
+53
-0
sign.d.ts
v2.0/src/typings/sign.d.ts
+19
-0
checkSign.ts
v2.0/src/utils/common/check/checkSign.ts
+25
-0
index.ts
v2.0/src/utils/common/check/index.ts
+5
-2
sign.ts
v2.0/src/utils/common/sign.ts
+39
-0
No files found.
v2.0/src/controller/sign.controller.ts
0 → 100644
View file @
db1217a4
/** @format */
import
{
services
,
preCheck
,
registeInfos
,
preUpdate
,
checkParams
}
from
'../decorator/common/'
import
{
resultsModel
}
from
'../sdk'
import
{
CommonSignService
}
from
'../service/common'
import
{
STAT_TYPE
}
from
'../constants'
import
{
checkActivityTime
,
checkInviteId
,
checkHelpRecord
,
checkNewVip
,
checkSign
}
from
'../utils/common/check'
import
{
updateHelpRecord
,
updateVip
}
from
'../utils/common/update/'
export
default
class
SignController
{
/**
* 签到
*/
@
checkParams
([
'activityId'
,
'subscribeSignDay?'
])
@
services
([
CommonSignService
])
@
preCheck
([
checkSign
])
async
doSign
(
context
:
IContext
<
{
activityId
:
string
subscribeSignDay
?:
string
}
>
,
{
userInfo
}:
IControllerInfos
,
[
signService
]:
[
CommonSignService
]
)
{
const
{
activityId
,
subscribeSignDay
}
=
context
.
data
const
result
=
await
signService
.
doSign
(
userInfo
,
activityId
,
subscribeSignDay
)
return
resultsModel
.
success
(
result
)
}
}
v2.0/src/db.ts
View file @
db1217a4
...
@@ -8,6 +8,8 @@ export const AWARDS_DB_NAME = 'c_awards_info'
...
@@ -8,6 +8,8 @@ export const AWARDS_DB_NAME = 'c_awards_info'
export
const
JOIN_DB_NAME
=
'c_user_join'
export
const
JOIN_DB_NAME
=
'c_user_join'
export
const
SIGN_DB_NAME
=
'c_user_sign'
export
const
STAT_DB_NAME
=
'c_stats'
export
const
STAT_DB_NAME
=
'c_stats'
export
const
ERROR_LOG_DB_NAME
=
'error_log'
export
const
ERROR_LOG_DB_NAME
=
'error_log'
...
...
v2.0/src/service/common/index.ts
View file @
db1217a4
...
@@ -7,6 +7,7 @@ import CommonAwardsService from './awards.service'
...
@@ -7,6 +7,7 @@ import CommonAwardsService from './awards.service'
import
CommonTaskService
from
'./task.service'
import
CommonTaskService
from
'./task.service'
import
CommonStatService
from
'./stat.service'
import
CommonStatService
from
'./stat.service'
import
CommonGameService
from
'./game.service'
import
CommonGameService
from
'./game.service'
import
CommonSignService
from
'./sign.service'
const
common
=
{
const
common
=
{
CommonAccessService
,
CommonAccessService
,
...
@@ -15,7 +16,8 @@ const common = {
...
@@ -15,7 +16,8 @@ const common = {
CommonAwardsService
,
CommonAwardsService
,
CommonTaskService
,
CommonTaskService
,
CommonStatService
,
CommonStatService
,
CommonGameService
CommonGameService
,
CommonSignService
}
}
export
default
common
export
default
common
...
@@ -27,5 +29,6 @@ export {
...
@@ -27,5 +29,6 @@ export {
CommonAwardsService
,
CommonAwardsService
,
CommonTaskService
,
CommonTaskService
,
CommonStatService
,
CommonStatService
,
CommonGameService
CommonGameService
,
CommonSignService
}
}
v2.0/src/service/common/sign.service.ts
0 → 100644
View file @
db1217a4
/**
* 基本信息
*
* @format
*/
import
{
BaseDao
,
TBAPIS
}
from
'../../sdk'
import
{
SIGN_DB_NAME
}
from
'../../db'
import
{
ACTIVITY_STATUS
}
from
'../../constants'
import
UserService
from
'./user.service'
import
{
getToday
}
from
'../../utils'
import
{
CODE_TYPES
}
from
'../../errorCode'
export
default
class
SignService
extends
UserService
{
context
:
IContext
<
any
>
signdao
:
IBaseDao
constructor
(
context
:
IContext
<
any
>
)
{
super
(
context
)
this
.
signdao
=
new
BaseDao
(
context
,
SIGN_DB_NAME
)
}
async
doSign
(
userInfo
:
IUserInfo
,
activityId
:
string
,
subscribeSignDay
=
''
)
{
const
{
openId
}
=
this
.
context
const
{
userNick
}
=
userInfo
const
today
=
getToday
()
const
signResult
=
await
this
.
signdao
.
insertOne
<
IUserSign
>
({
activityId
,
openId
,
userNick
,
isSignLater
:
!!
subscribeSignDay
,
createDay
:
today
,
signTime
:
subscribeSignDay
?
new
Date
(
subscribeSignDay
)
:
new
Date
(),
signDay
:
subscribeSignDay
||
today
,
createTime
:
new
Date
()
})
if
(
!
signResult
)
return
CODE_TYPES
.
SYSTEM_ERROR
return
{
signId
:
signResult
}
}
async
getSignList
(
activityId
:
string
)
{
const
{
openId
}
=
this
.
context
const
signInfoList
:
ISignInfoAggregate
[]
=
await
this
.
signdao
.
aggregate
(
{
$match
:
{
activityId
,
openId
}
},
{
$project
:
{
d
:
{
$dayOfYear
:
'$signTime'
},
y
:
{
$year
:
'$signTime'
},
signTime
:
'$signTime'
}
}
)
return
signInfoList
}
}
v2.0/src/typings/sign.d.ts
0 → 100644
View file @
db1217a4
/** @format */
interface
IUserSign
{
activityId
:
string
openId
:
string
userNick
:
string
createTime
:
Date
createDay
:
string
signTime
:
Date
signDay
:
string
isSignLater
?:
boolean
// 是否补签
}
interface
ISignInfoAggregate
{
_id
?:
string
d
:
number
y
:
number
signTime
:
Date
}
v2.0/src/utils/common/check/checkSign.ts
0 → 100644
View file @
db1217a4
/** @format */
import
{
resultsModel
}
from
'../../../sdk'
import
{
CODE_TYPES
}
from
'../../../errorCode'
import
{
dbCount
}
from
'../mongodb'
import
{
SIGN_DB_NAME
}
from
'../../../db'
import
{
getToday
}
from
'../getToday'
export
default
async
function
checkSign
(
context
:
IContext
<
{
activityId
:
string
subscribeSignDay
?:
string
}
>
,
{
userInfo
}:
IControllerInfos
)
{
const
{
activityId
,
subscribeSignDay
}
=
context
.
data
const
{
openId
}
=
context
const
todaySigned
=
await
dbCount
(
context
,
SIGN_DB_NAME
,
{
activityId
,
openId
,
signDay
:
subscribeSignDay
||
getToday
()
})
if
(
todaySigned
)
return
resultsModel
.
error
(
CODE_TYPES
.
PARAMS_ERROR
,
'今日已签到~'
)
}
v2.0/src/utils/common/check/index.ts
View file @
db1217a4
...
@@ -12,6 +12,7 @@ import checkVip from './checkVip'
...
@@ -12,6 +12,7 @@ import checkVip from './checkVip'
import
checkUserInfo
,
{
checkGameTimes
}
from
'./checkUserInfo'
import
checkUserInfo
,
{
checkGameTimes
}
from
'./checkUserInfo'
import
checkJoinId
from
'./checkJoinId'
import
checkJoinId
from
'./checkJoinId'
import
checkOpenPrizeStatus
from
'./checkOpenPrizeStatus'
import
checkOpenPrizeStatus
from
'./checkOpenPrizeStatus'
import
checkSign
from
'./checkSign'
const
check
=
{
const
check
=
{
checkActivityTime
,
checkActivityTime
,
...
@@ -29,7 +30,8 @@ const check = {
...
@@ -29,7 +30,8 @@ const check = {
checkUserInfo
,
checkUserInfo
,
checkJoinId
,
checkJoinId
,
checkGameTimes
,
checkGameTimes
,
checkOpenPrizeStatus
checkOpenPrizeStatus
,
checkSign
}
}
export
default
check
export
default
check
...
@@ -50,5 +52,6 @@ export {
...
@@ -50,5 +52,6 @@ export {
checkUserInfo
,
checkUserInfo
,
checkJoinId
,
checkJoinId
,
checkGameTimes
,
checkGameTimes
,
checkOpenPrizeStatus
checkOpenPrizeStatus
,
checkSign
}
}
v2.0/src/utils/common/sign.ts
0 → 100644
View file @
db1217a4
/** @format */
import
*
as
dayjs
from
'dayjs'
import
{
uniq
}
from
'lodash'
import
{
getToday
}
from
'./getToday'
const
isLeapYear
=
(
year
:
number
)
=>
(
year
%
4
===
0
&&
year
%
100
!==
0
)
||
year
%
400
===
0
// 获取最大连续签到天数
export
const
getMaxContinusSignDays
=
(
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
for
(
let
i
=
0
;
i
<
m
.
length
;
i
++
)
{
let
idx
=
0
while
(
m
[
i
+
1
]
-
m
[
i
]
===
1
)
{
idx
++
i
++
max
=
Math
.
max
(
idx
,
max
)
}
}
return
max
+
1
}
// 获取某天是否签到
export
const
getSignedByDay
=
(
signInfoList
:
ISignInfoAggregate
[],
day
=
getToday
()):
boolean
=>
{
return
signInfoList
.
some
(
v
=>
dayjs
(
v
.
signTime
).
format
(
'yyyy/MM/dd'
)
===
day
)
}
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