当前位置:网站首页>Bitmap sign in
Bitmap sign in
2022-07-18 03:41:00 【Chenqing Nuo language】
/**
* User sign in interface
* @return false|string
*/
public function sign()
{
$uid = \request()->get('uid');
if (!is_numeric($uid) || $uid !=(int)$uid || $uid <= 0){
return json_encode(['code' => 500,'msg' => 'uid Parameter error ','']);
}
// Get the current time
$now = date('Ym');
$day = date('d'); //04
// Splicing bitmap Of key
$key = $uid.':'.$now; //"1:202207"
// Check whether you have checked in
$date = Redis::getbit($key,$day);
if($date){
return json_encode(['code' => 200,'msg' =>' I signed in today ','data' => '']);
}
// Get yesterday's time
$lastDay = date("d", strtotime("-1 day")); //"02"
// Check whether you checked in yesterday
$lastDate = Redis::getbit($key,$lastDay);
$user = Users::where('uid',$uid)->first()->toarray();
// Redis::setbit($key,0,1);
// Sign in yesterday ( Countersignature )
if($lastDate){
// Integral superposition bitmap Deposit has been signed in
$integral = $user['integral'] + 10 + ($user['sign_num']*5);
// Check in times
$num = $user['sign_num'] + 1;
$data['integral'] = $integral;
$data['sign_num'] = $num;
$result = Users::where('uid',$uid)->update($data);
if (!$result){
return json_encode(['code' => 500,'msg' =>' Check in failed ','data' => '']);
}
Redis::setbit($key,$day,1);
// Sign in record
$sign = \App\Models\SignIn::where('uid',$uid)->orderby('balance','desc')->first();
// Accumulated points
$integralFen = $sign['balance'] + 10 + ($user['sign_num']*5);
$signData['uid'] = $uid;
$signData['title'] = " User No $num Check in times ";
$signData['number'] = 10 + ($user['sign_num']*5);
$signData['balance'] = $integralFen;
$signData['add_time'] = time();
$signRes = \App\Models\SignIn::insert($signData);
if (!$signRes){
return json_encode(['code' => 500,'msg' =>' Check in failed ','data' => '']);
}
return json_encode(['code' => 200,'msg' => " You have checked in continuously $num God , Earned points $integral branch ",'data' => '']);
}
// I didn't sign in yesterday ( Severance )
$data['sign_num'] = 1;
$data['integral'] = $user['integral'] + 10;
$result = Users::where('uid',$uid)->update($data);
if (!$result){
return json_encode(['code' => 500,'msg' =>' Check in failed ','data' => '']);
}
Redis::setbit($key,$day,1);
$signData['uid'] = $uid;
$signData['title'] = ' The first time the user checks in ';
$signData['number'] = 10;
$signData['balance'] = 10;
$signData['add_time'] = time();
$signRes = \App\Models\SignIn::insert($signData);
if (!$signRes){
return json_encode(['code' => 500,'msg' =>' Check in failed ','data' => '']);
}
return json_encode(['code' => 200,'msg' =>' Sign in successfully ','data' => '']);
}
/**
* Make up and recalculate the continuous check-in
* @return false|string
*
*/
public static function retroactive()
{
$uid = \request()->get('uid');
$date = \request()->get('date');
// Get the present time
$now = date('Ymd');
if ($date >= $now) {
return json_encode(['code' => 500,'msg' =>' The date of re signing cannot be later than or equal to today ','data' => '']);
}
// Get the time to re sign
$day = substr($date, 6, 2);
$month = substr($date, 0, 6);
$key = $uid . ':' . $month;
$sign = Redis::getbit($key, $day); //0
if ($sign == 1) {
return json_encode(['code' => 200,'msg' =>' You've already signed in. You don't need to sign in ','data' => '']);
}
Redis::setbit($key, $day, 1);
$month = date('Ym');
$day = date('d') - 1;
$signKey = $uid . ':' . $month;
$sign = Redis::getbit($signKey, $day); //
$i = 1;
if ($sign == 1) {
dd(1123);
$min = self::getNum($uid, $month, $day,$i);
Users::where('uid',$uid)->update(['sign_num' => $min]);
}
// Query user sign in information
$user = Users::where('uid',$uid)->first()->toarray();
$integral = $user['integral'];
$signData['uid'] = $uid;
$signData['title'] = ' User's supplementary signature ';
$signData['number'] = 10;
$signData['balance'] = $integral;
$signData['add_time'] = time();
$signRes = \App\Models\SignIn::insert($signData);
if (!$signRes){
return json_encode(['code' => 500,'msg' =>' Check in failed ','data' => '']);
}
return json_encode(['code' => 200,'msg' => " You have successfully re signed , Get integral $integral branch ,",'data' => '']);
}
/**
* Get the number of consecutive check-in days of users
* @param $uid
* @param $date
* @param $day
* @param $i
*/
public static function getNum($uid, $date, $day,&$i)
{
try {
$key = $uid . ':' . $date;
$sign = Redis::getbit($key, $day);
if ($sign == 1) {
$i ++;
if ($day - 1 > 0) {
self::getNum($uid, $date, $day - 1,$i);
}else{
$time = strtotime($date . '0' . $day) - 86400;
$mytime = date('Ymd', $time);
$day = substr($mytime, 6, 2);
$month = substr($mytime, 0, 6);
self::getNum($uid, $month, $day,$i);
}
}
return $i;
}catch (\Exception $e){
return json_encode(500,$e->getMessage());
}
}
边栏推荐
- AI简报-模型集成 SAM 和SWA
- win11虚拟机里面mysql的ibd文件在哪里
- 浅谈 Slack Channel 支持的一些提高工作效率的特性
- APUE学习笔记-15章进程间通信
- bitmap签到
- [development tutorial 17] AI voice face recognition (Conference recorder / face punch) -ai face registration, authentication and recognition
- Google Earth engine (GEE) -- abnormal value of S2 image
- leetcode:558. Quadtree intersection [quadtree DFS]
- After 00, he graduated from Nanjing University and planned to be a special associate researcher. Netizens quarreled after picking out their papers
- Four sides Ali offer grading p82022 latest and most practical Ali 68 advanced interview questions to help you succeed in your interview!!
猜你喜欢

"The faster the code is written, the slower the program runs"

朱松纯团队最新研究:机器人可与人类“推心置腹”!还说下一步要造“AI大白”...

The software supply chain security risk that makes enterprise digitalization and it executives bear the brunt of the cauldron points to the north

盖茨再捐200亿美元,谷歌云转投ARM,推特员工因马斯克遭CEO警告,今日更多大新闻在此...

Will the expired data of redis be deleted immediately? Great mystery

BufferedInputStream字节缓存输入流和缓存流的效率测试_复制文件

DEVKIT-mpc5744p配置rtos

让企业数字化砸锅和IT主管背锅的软件供应链安全风险指北

The colleague next to me was suddenly promoted to meituan P7 because he secretly learned this JVM note?

世界首款抗量子攻击商用密码芯片 | 沐创
随机推荐
活动预告|Apache Doris x Apache SeaTunnel 联合 Meetup 开启报名!
是时候升级你的Junit了,Junit5超详细实战
Slow SQL analysis and optimization
Issue 99: flutter learning (2)
51nod 1102 rectangle with the largest area
普通二本毕业五年,备战两个月,四面阿里巴巴定级P7
曾经,我对着AI客服喷了两分钟,它只回复了我的第一句话
H5 implementation generates urlscheme and jumps from H5 to applet
The latest research of Zhu Songchun's team: robots can "confide" with humans! Also said that the next step is to create "Ai white"
真的牛b!京东T3-2都还在学的微服务+MySQL+Kafka+boot2.x+虚拟机PDF
Evaluation of 5 internal systems to build a low code platform
Index in MySQL
5 款内部系统搭建低代码平台评测
00后博士毕业拟任南大特任副研究员,网友扒出论文后吵翻了
Google Earth engine (GEE) - random forest classification has mapped the detailed code of mangrove app in Guyana in 2000, 2010 and 2020
麦肯锡:未来十年,十大顶尖技术趋势将影响投资和研究方向
Talking about some features of improving work efficiency supported by slack channel
Two years of crud, two ordinary graduates, three months of challenge interview Ali, successfully won the offer grading P7! Annual salary 50W
第105期:一次失败的浏览器插件开发
TiKV & TiFlash 加速复杂业务查询