123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class Employee extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->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 ;
- }
-
- }
|