<?php namespace process; use App\Utils\API\SendCode; use app\model\UserPhone; use App\model\UserReward; use app\dao\UserRewardDao; use Workerman\Crontab\Crontab; use app\model\GetLodeLog; use app\model\User; /** * 获取今天在线时间超过6小时的用户 */ class Task3 { public function onWorkerStart() { // // 每秒钟执行一次 // new Crontab('*/1 * * * * *', function(){ // echo date('Y-m-d H:i:s')."\n"; // }); // // 每5秒执行一次 // new Crontab('*/5 * * * * *', function(){ // echo date('Y-m-d H:i:s')."\n"; // }); // // 每分钟执行一次 // new Crontab('0 */1 * * * *', function(){ // echo date('Y-m-d H:i:s')."\n"; // }); // // 每5分钟执行一次 // new Crontab('0 */5 * * * *', function(){ // echo date('Y-m-d H:i:s')."\n"; // }); // // 每分钟的第一秒执行 // new Crontab('1 * * * * *', function(){ // echo date('Y-m-d H:i:s')."\n"; // }); // // 每天的7点50执行,注意这里省略了秒位 // new Crontab('50 7 * * *', function(){ // echo date('Y-m-d H:i:s')."\n"; // }); // // 每5秒执行一次 new Crontab('0 */5 * * * *', function () { //获取在线时间超过6小时的用户 $today = date('Y-m-d'); $UserPhone = UserPhone::where('score', '>=', 120)->where('score', '<',140)->get(); //判断用户绑定Whatsapp首次登录 foreach ($UserPhone as $key => $value) { $user_id = $value->user_id; //判定有没有父级 这里父级没有默认是0 $user = User::find($user_id); if ($user->f_id==0) { continue; } //获取该用户的父级 $parent = User::find($user->f_id); //满足则加80积分 UserRewardDao::base($parent->id, 5, 80, '有效用户奖励'); //vip_id等级加1,并更新数据库 $parent->vip_id += 1; //今天邀请人数加1 $parent->today_num += 1; $parent->today_team_income+=80; $parent->save(); //判定有没有父级的父级 这里父级没有默认是0 if($parent->f_id==0){ continue; } //获取父级的父级 $ancestor = User::find($parent->f_id); //今天活跃人数加1 $ancestor->active_figures += 1; $ancestor->save(); } }); } }