RoomController.php
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace console\controllers;
use Yii;
use yii\console\Controller;
use common\models\Room;
/**
* Site controller
*/
class RoomController extends Controller
{
/**
* 重置房间状态
*/
public function actionStat(){
while(true){
//获取未开始的房间
$result = Room::find()
->where(['living'=>[0,2]])
->orderBy(['starting_time'=>SORT_ASC])
->all();
if($result){
foreach($result as $row){
//状态为未开始 && 当前时间大于预告时间->标记成已结束
if(($row->living == 0) && (time() > $row->starting_time)){
$room_id = $row->room_id;
$row->setAttributes([
'living'=>2,
'update_time'=>time()
]);
if($row->save()){
echo "room ".$room_id."has been reset to 2. \n";
}else{
echo "room ".$room_id."reset failed. \n";
}
}
//状态为已结束 && 当前时间小于预告时间->标记成未开始
if(($row->living == 2) && (time() < $row->starting_time)){
$room_id = $row->room_id;
$row->setAttributes([
'living'=>0,
'update_time'=>time()
]);
if($row->save()){
echo "room ".$room_id."has been reset to 0. \n";
}else{
echo "room ".$room_id."reset failed. \n";
}
}
}
}
sleep(10);
}
}
}