<?php

class meeting_keyClassModel extends Model
{

    /**
     *	判断会议室是否重复申请了
     */
    public function isapplymsg($startdt, $enddt, $hyname, $id=0)
    {
        $msg 		= '';
        $sql        = `select id, meeting_room, start_time, end_time from xinhu_meeting  where id <> {$id} and meet_state in (0, 1)
                       union ALL
                       select id, meeting_room, start_time, end_time from xinhu_meeting_key where id <> {$id} and meet_state in (0, 1)`;
        $rows 		= $this->db->getall($sql);

        foreach($rows as $k=>$rs){
            if($rs['meeting_room'] != $hyname)continue;
            $sdt = $rs['start_time'];
            $edt = $rs['end_time'];
            if(
                ($sdt<=$startdt && $edt>$startdt)
                || ($sdt<$enddt && $edt>=$enddt)
                || ($sdt>$startdt && $edt<$enddt)
                || ($sdt==$startdt && $edt==$enddt)
            )$msg = '该会议室的时间段已被申请过了，主题“'.$rs['title'].'”';
        }
        return $msg;
    }

    public function firstMeetingTopicStart($meeting_id) {

        $topic = m('meeting_topics')->getone("mid={$meeting_id}", "id", 'sort');
        if (isset($topic['id'])) {
            m('meeting_topics')->update(['topic_state'=>'2'], 'id='.$topic['id']);
        }
    }
}