codeigniter 这个功能有什么问题?它不检测是否已经进入时间

envsm3lx  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(99)

它始终保存新记录,即使该ID上已存在time in。如果time in已在数据库中,如何添加超时。
请帮忙,谢谢......在我的控制器里......

public function save() {
        $v_id = $this->input->post('v_id');     
        $date = date('Y-m-d');
        $time = date('h:i:s A');
        //check if record exist
        $this->form_validation->set_rules('v_id','Plate Number','trim|callback_get_record');
        //if record not found
        if($this->form_validation->run()==FALSE){
            //show error
            $this->session->set_flashdata('error', 'Cannot find QRCode number '.$v_id);
            redirect('attendance/create');
        }
        else{
            //check if already timein in        
            $signin = $this->attendance_model->checktimein($v_id);
                  //if timein found  
            if($signin==TRUE){ 
                $this->attendance_model->update(array('V_ID'=>$v_id,'TIMEOUT' => $time,'STATUS' => 1));
                $this->session->set_flashdata('success', 'Successfully Time OUT '.$v_id);
                redirect('attendance/create');
            }
            else{
                    $this->attendance_model->save(array('V_ID'=>$v_id,'TIMEIN' => $time,'LOGDATE' => $date,'STATUS' => 0));
                    $this->session->set_flashdata('success', 'Successfully Time IN '.$v_id);
                    redirect('attendance/create');
            }  
            
        }
    }

public function get_record($v_id){ 
        $row = $this->db->where('v_id',$v_id)                   
                    ->get('vehicle_info')
                    ->num_rows(); 
        if($row == 1){  
            return TRUE;
        }else{ 
            return FALSE;           
        } 
    }

它始终保存新记录,即使该ID上已存在time in。如果time in已在数据库中,如何添加超时。
请帮忙,谢谢......
在模型中...

public function checktimein($v_id){ 
        $row = $this->db->where('V_ID',$v_id)
                        ->where('LOGDATE',$date)
                        ->where('STATUS',0)
                        ->get('attendance')
                        ->num_rows(); 
        if($row > 0){  
            return TRUE;            
        }else{ 
            return FALSE;            
        } 
    }   

public function save($data){
            $this->db->where('V_ID',$data['v_id']);
            $this->db->insert('attendance',$data);      
    }

    public function update($data){ 
        return  $this->db->where('V_ID',$data['v_id'])
                    ->update('attendance',$data);
    }
qgzx9mmu

qgzx9mmu1#

兄弟,你错过了$日期

$signin = $this->attendance_model->checktimein($v_id);

如果在查询中使用$date表示LOGDATE,则必须将日期作为参数传递

$signin = $this->attendance_model->checktimein($v_id,$date);
public function checktimein($v_id,$date){

相关问题