如何解决codeigniter中的日历任务问题?

时间:2017-07-25 06:14:45

标签: php mysql codeigniter datetime

在这里,我使用计划明智和额外的时间安排来设置治疗师的工作时间。 治疗师 nancy fernadez 时间表是:

  1. 31-05-2017的额外(额外)工作时间为10:00:00至14:00:00,即12小时为上午10:00至下午2:00
  2. 为她安排工作时间31-05-2017是14:00:00到19:00:00,即12小时是下午2:00到晚上7:00

    Nancy fernadez 全天开放,即上午10:00至下午7:00。

    问题: 我预订时间为13:25至14:25,即01:25 pm至02:25 pm。它会给我一些错误,就像当时没有的治疗师一样......实际上按照时间表 nancy 可用了......

  3. 此处是任务分配日历的图像

    enter image description here

    在这里,低于我的mysql查询,为她增加工作时间

    SELECT SQL_CALC_FOUND_ROWS *
    FROM `extra_day`
    INNER JOIN `therapist` ON `thrp_id` = `exd_thrp_id`
    WHERE `exd_thrp_id` = '3'
    AND `exd_date` = '2017-05-31'
    AND `exd_from` <= '13:25:00'
    AND `exd_to` >= '14:25:00'
    

    在这里,我的mysql查询低于她的

    的日程安排工作时间
    SELECT SQL_CALC_FOUND_ROWS s.*, CONCAT(th.thrp_fname, " ", th.thrp_surname) AS thrp_name
    FROM `schedule` `s`
    INNER JOIN `therapist` `th` ON `s`.`schd_thrp_id` = `th`.`thrp_id`
    WHERE `schd_thrp_id` = '3'
    AND `schd_day` = '3'
    AND `schd_from` <= '13:25:00'
    

    我使用以下控制器检查治疗师的可用性

    // check if therapist comes on this day (regular schedule or extra day) 
                $this->load->model('schedule_model');
                $schedule = $this->schedule_model->Get(NULL, array('schd_thrp_id' => $data['bk_thrp_id'],
                    'schd_day' => date('N', strtotime($data['bk_start'])),
                    'schd_from' => date('H:i:s', strtotime($data['bk_start']))
                ));
    
                $this->load->model('additional_work_model');
                $additional_work = $this->additional_work_model->Get(NULL, array('exd_thrp_id' => $data['bk_thrp_id'],
                    'exd_date' => date('Y-m-d', strtotime($data['bk_start'])),
                    'exd_from' => date('H:i:s', strtotime($data['bk_start'])),
                    'exd_to' => date('H:i:s', strtotime($data['bk_end']))
                ));
                if ($schedule['countFiltered'] == 0 && $additional_work['countFiltered'] == 0) {
                    $response['status'] = 'failure';
                    $response['errormsg'] = 'Therapist not available.';
                    return $response;
                }
    

    请问我,如果有任何与问题相关的查询

    感谢您的帮助......

1 个答案:

答案 0 :(得分:0)

您需要更改查询。由于extra_day exd_from条件有效,但exd_to条件不起作用,因为时间仅为14:00:00。并且第二个查询将无法获取,因为开始时间为14:00:00,但您获得13:25:00。您需要连接两个表才能获得结果。或者您需要提供一些条件,例如员工是否正在工作extra_day行数

<强>更新

我更改您的查询我的假设您可以更改它并加入查询也可以更改您想要的表:

SELECT SQL_CALC_FOUND_ROWS *, exd_date, exd_from, exd_to
FROM `extra_day`
INNER JOIN `therapist` ON `thrp_id` = `exd_thrp_id`
WHERE `exd_thrp_id` = '3'
AND `exd_date` = '2017-05-31'
AND `exd_from` <= '13:25:00'
AND `exd_to` >= '14:25:00'

SELECT SQL_CALC_FOUND_ROWS s.*, CONCAT(th.thrp_fname, " ", th.thrp_surname) AS thrp_name, schd_from
FROM `schedule` `s`
INNER JOIN `therapist` `th` ON `s`.`schd_thrp_id` = `th`.`thrp_id`
WHERE `schd_thrp_id` = '3'
AND `schd_day` = '3'
AND `schd_from` <= '13:25:00'

$this->load->model('schedule_model');
$schedule = $this->schedule_model->Get(NULL, array('schd_thrp_id' => $data['bk_thrp_id'],
    'schd_day' => date('N', strtotime($data['bk_start'])),
    'schd_from' => date('H:i:s', strtotime($data['bk_start']))
));

$this->load->model('additional_work_model');
$additional_work = $this->additional_work_model->Get(NULL, array('exd_thrp_id' => $data['bk_thrp_id'],
    'exd_date' => date('Y-m-d', strtotime($data['bk_start'])),
    'exd_from' => date('H:i:s', strtotime($data['bk_start'])),
    'schd_to' => date('H:i:s', strtotime($data['bk_end']))
));
if($additional_work['exd_from'] <= date('H:i:s', strtotime($data['bk_start'])) && $schedule['schd_from'] >= date('H:i:s', strtotime($data['bk_start']))){
    $get_now_with_anymodel = $this->your_model->Get(NULL, array('exd_thrp_id' => $data['bk_thrp_id'],
    'exd_date' => date('Y-m-d', strtotime($data['bk_start'])),
    'exd_from' => date('H:i:s', strtotime($data['bk_start'])),
    'exd_to' => date('H:i:s', strtotime($data['bk_end']))
    /*
    Your Model query:
    SELECT SQL_CALC_FOUND_ROWS *, exd_date, exd_from, exd_to
    FROM `extra_day` AS A
    INNER JOIN `therapist` AS B ON B.`thrp_id` = A.`exd_thrp_id`
    INNER JOIN `schedule` AS C ON C.`schd_thrp_id` = A.`exd_thrp_id`
    WHERE `exd_thrp_id` = '3'
    AND `exd_date` = '2017-05-31'
    AND A.`exd_from` <= '13:25:00'
    AND C.`schd_to` >= '14:25:00'
    */
));
}

$ additional_work ['exd_from']是您的模型的返回结果更改它就像您返回数据一样