Room.php
2.0 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace app\school\model\project_appointment;
use think\Db;
use think\Model;
use traits\model\SoftDelete;
use app\school\model\project_appointment\BuildingEnter;
use app\school\model\project_appointment\Floor;
use app\school\model\project_appointment\Building;
class Room extends Model
{
const ROOM_STATUS_N = 0; //不开放
const ROOM_STATUS_Y = 1; //已开放
const IS_USE_N = 1; //未分配
const IS_USE_Y = 2; //已分配
public static $room_type = [
1 => '会议室',
2 => '办公室',
3 => '路演大厅',
4 => '公共办公区',
5 => '实验室',
6 => '多媒体教室',
];
use SoftDelete;
// 数据表名称
protected $name = 'project_room';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
protected $append = [
'room_type_text',
'room_status_text',
'build_text',
'floor_text',
];
public function getRoomTypeTextAttr($value,$data)
{
return isset($data['room_type']) ? self::$room_type[$data['room_type']] : '';
}
public function getRoomStatusTextAttr($value,$data)
{
return isset($data['room_status']) ? ($data['room_status'] == 1 ? '开放' : '不开放') : '';
}
public function getBuildTextAttr($value,$data)
{
return (new Building())->where(['id' => $data['building_id']])->value('building_name');
}
public function getFloorTextAttr($value,$data)
{
return (new Floor)->where(['id' => $data['floor_id']])->value('floor_name');
}
/**
* 根据where条件查询出房间
* @param $where
*/
public function getCollegeRoom($where)
{
$model = new static();
$list = $model
->where($where)
->where(['room_status' => self::ROOM_STATUS_Y])
->select();
return $list;
}
}