Floor.php 958 字节
<?php
namespace app\school\model\project_appointment;

use think\Db;
use think\Model;
use traits\model\SoftDelete;

class Floor extends Model
{
    use SoftDelete;
    // 数据表名称
    protected $name = 'project_floor';

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    protected $append = [
        'building_name'
    ];

    public function getBuildingNameAttr($value,$data){
        return isset($data['building_id']) ? Db::name('project_building')->where(['id' => $data['building_id']])->value('building_name') : '';
    }

    /**
     * 根据楼宇ID 获取楼层
     * @param $buildingId 楼宇ID
     */
    public function getListByBuildingId($buildingId)
    {
        return $this->where(['building_id' => $buildingId])->select();

    }
}