Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
Project
Project
Details
Activity
Releases
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
黄奎
mall.oytour.com
Commits
b6a6624a
Commit
b6a6624a
authored
Oct 22, 2020
by
吴春
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sdzq-ld' of
http://gitlab.oytour.com/Kui2/mall.oytour.com
into sdzq
parents
ddeb81df
e26d0cac
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
0 deletions
+108
-0
RedisHelper.cs
Mall.CacheManager/Base/RedisHelper.cs
+108
-0
No files found.
Mall.CacheManager/Base/RedisHelper.cs
View file @
b6a6624a
...
...
@@ -278,6 +278,114 @@ namespace Mall.CacheManager.Base
#
endregion
String
#
region
bitmap
/// <summary>
/// 设置
/// </summary>
/// <param name="uid"></param>
/// <param name="date"></param>
/// <returns></returns>
public
bool
SetSignBit
(
int
uid
,
DateTime
date
)
{
var
database
=
_conn
.
GetDatabase
(
DbNum
);
int
offset
=
date
.
Day
-
1
;
return
database
.
StringSetBit
(
buildSignKey
(
uid
,
date
),
offset
,
true
);
}
/// <summary>
/// 获取是否已经存在
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public
bool
GetSignBit
(
int
uid
,
DateTime
date
)
{
var
database
=
_conn
.
GetDatabase
(
DbNum
);
int
offset
=
date
.
Day
-
1
;
return
database
.
StringGetBit
(
buildSignKey
(
uid
,
date
),
offset
);
}
public
string
GetBitStr
(
int
uid
,
DateTime
date
)
{
var
database
=
_conn
.
GetDatabase
(
DbNum
);
return
database
.
StringGet
(
buildSignKey
(
uid
,
date
));
}
public
bool
GetSignBit
(
int
uid
,
DateTime
date
,
IDatabase
database
)
{
int
offset
=
date
.
Day
-
1
;
return
database
.
StringGetBit
(
buildSignKey
(
uid
,
date
),
offset
);
}
/// <summary>
/// 获取签到数量
/// </summary>
/// <param name="uid"></param>
/// <param name="date"></param>
/// <returns></returns>
public
long
GetSignCount
(
int
uid
,
DateTime
date
)
{
var
database
=
_conn
.
GetDatabase
(
DbNum
);
return
database
.
StringBitCount
(
buildSignKey
(
uid
,
date
));
}
/// <summary>
/// 获取当月第一次签到日期
/// </summary>
/// <param name="uid"></param>
/// <param name="date"></param>
/// <returns></returns>
public
string
getFirstSignDate
(
int
uid
,
DateTime
date
)
{
var
database
=
_conn
.
GetDatabase
(
DbNum
);
long
pos
=
database
.
StringBitPosition
(
buildSignKey
(
uid
,
date
),
true
);
return
pos
<
0
?
""
:
date
.
ToString
(
"yyyy-MM"
)
+
"-"
+
(
pos
+
1
);
}
/// <summary>
/// 当月连续签到
/// </summary>
/// <param name="uid"></param>
/// <param name="Month"></param>
/// <returns></returns>
public
long
getContinuousSignCount
(
int
uid
,
DateTime
date
)
{
int
signCount
=
0
;
var
database
=
_conn
.
GetDatabase
(
DbNum
);
DateTime
StartTime
=
Convert
.
ToDateTime
(
date
.
ToString
(
"yyyy-MM"
)
+
"-01"
);
DateTime
EndTime
=
Convert
.
ToDateTime
(
date
.
ToString
(
"yyyy-MM-dd"
));
//遍历
while
(
StartTime
<=
EndTime
)
{
if
(
GetSignBit
(
uid
,
EndTime
,
database
))
{
signCount
++;
}
else
{
if
(
EndTime
.
ToString
(
"yyyy-MM-dd"
)
!=
date
.
ToString
(
"yyyy-MM-dd"
))
{
break
;
}
}
EndTime
=
EndTime
.
AddDays
(-
1
);
}
return
signCount
;
}
private
static
String
buildSignKey
(
int
uid
,
DateTime
date
)
{
return
String
.
Format
(
"u:sign:{0}:{1}"
,
uid
,
formatDate
(
date
));
}
private
static
String
formatDate
(
DateTime
date
)
{
return
date
.
ToString
(
"yyyyMM"
);
}
#
endregion
#
region
Hash
#
region
同步方法
...
...
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