load->library('session'); $this->load->_model('Model_employee','employee'); } public function _remap($arg,$arg_array) { if($arg == 'sign')//添加 { $this->sign(); }elseif ($arg == 'add') { $this->_add(); }elseif ($arg == 'edit') { $this->_edit($arg_array); } else { $this->_index(); } } //管理 public function _index() { $post = $this->input->post(NULL, TRUE); if(isset($post['page'])) { $page = $this->input->post('page',true); $id = $this->input->post('id',true); $name = $this->input->post('name',true); $number = $this->input->post('number',true); $where = "1=1 "; if($id) { $where .= " and id = '$id'"; } if($name) { $where .= " and name = '$name'"; } if($number) { $where .= " and number = '$number'"; } //数据排序 $order_str = "id asc"; //取得信息列表 $info_list = $this->employee->find_all($where,'id,number,name,sex,sign_at,created_at',$order_str); foreach ($info_list as $key=>$value) { if($value['sex'] == 1) { $info_list[$key]['sex'] = "男"; } else { $info_list[$key]['sex'] = "女"; } $info_list[$key]['sign_at'] =$info_list[$key]['sign_at'] ? date('Y-m-d',$value['sign_at']):"未打卡"; $info_list[$key]['created_at'] = date('Y-m-d',$value['created_at']); } $rows = array('rows'=>($info_list)); echo json_encode($rows);exit; } $this->_Template('employee',$this->data); } //添加 public function _add() { $post = $this->input->post(NULL, TRUE); if(isset($post['number'])) { $post['number'] = $this->input->post('number',true); $post['name'] = $this->input->post('name',true); $post['sex'] = $this->input->post('sex',true); $post['created_at'] = time(); if($this->employee->insert($post)) { echo json_encode(array('msg'=>'添加成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit; } } $this->_Template('employee_add',$this->data); } public function _edit($arg_array) { $post = $this->input->post(NULL, TRUE); if(isset($post['id'])) { $id = $this->input->post('id',true); $post['number'] = $this->input->post('number',true); $post['name'] = $this->input->post('name',true); $post['sex'] = $this->input->post('sex',true); if($this->employee->save($post,$id)) { echo json_encode(array('msg'=>'修改成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit; } } $arg_array = $arg_array[0]; $employee = $this->employee->read($arg_array); $this->data['employee'] = $employee; $this->_Template('employee_edit',$this->data); } public function sign(){ $post = $this->input->post(NULL, TRUE); $employee_ids=$post['ids']; $employee_ids=explode(',',trim($employee_ids,',')); if(!isset($employee_ids)||empty($employee_ids)){ return false; } $res1=$this->db->set('sign_at',time())->where_in('id',$employee_ids)->update('employee'); // $res2=$this->db->set('sign_at',NULL)->where_not_in('id',$employee_ids)->update('employee'); if($res1){ echo json_encode(array('msg'=>'打卡成功','success'=>true));exit; }else{ echo json_encode(array('msg'=>'打卡失败,请重试','success'=>false));exit; } return ; } }