limit($num)->select(); //随机获得$num个虚拟用户昵称和头像 foreach($virtualHead as $k=>$v) { $nickname = $this->getNickName(); $head = $v->head_image; $r = rand(($time - 86400*7),$time); $users[] = [ "nickname"=>$nickname, "head_image"=>$head, "time"=>$r, "jointype" => "1", "havetype" => "".($k % 2) ]; } if(!$set){ return $users; }else{ $user_data=[]; foreach($users as $k=> $user) { $r = rand(($time - 86400*7),$time); $user_data[] = [ "nickname"=>$user["nickname"], "head_image"=>$user["head_image"], "classes_lib_id"=>$classes_lib_id, "time"=>$r, "jointype" => "1", "havetype" => $user["havetype"] ]; } (new VirtualUser)->saveAll($user_data); \app\common\model\school\classes\ClassesLib::update_classes($classes_lib_id); return $user_data; } } public static function getWeekByTime($time){ $time = $time && !is_numeric($time) ? strtotime($time) : time(); //得到当前日期所在周几 $week = date("w",$time); $week = $week == 0 ? '7' : $week; $sub = abs(7-( 7-$week)) -1; //绝对值 $start_time = $time - ($sub*86400); // var_dump( date("Y-m-d",$start_time)); $titles = ["周一","周二","周三","周四","周五","周六","周日"]; //循环7天 $week_arr = []; for($i=0;$i<7;$i++){ $week_arr[$i]['active'] = false; $week_arr[$i]['start_time'] = $start_time + ($i*86400); $week_arr[$i]['end_time'] = strtotime("+1 day",$week_arr[$i]['start_time']) -1 ; $week_arr[$i]['start_date'] = date("Y/m/d H:i:s",$week_arr[$i]['start_time']); $week_arr[$i]['end_date'] = date("Y/m/d H:i:s",$week_arr[$i]['end_time']); $week_arr[$i]['day_text'] = date("m.d",$week_arr[$i]['start_time']); $week_arr[$i]['week'] = $i+1; $week_arr[$i]['week_text'] = $titles[$i]; if($week_arr[$i]['week'] == $week){ $week_arr[$i]['active'] = true; } } return $week_arr; } }