Employee.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Employee extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_employee','employee');
  7. }
  8. public function _remap($arg,$arg_array)
  9. {
  10. if($arg == 'sign')//添加
  11. {
  12. $this->sign();
  13. }elseif ($arg == 'add') {
  14. $this->_add();
  15. }elseif ($arg == 'edit') {
  16. $this->_edit($arg_array);
  17. }
  18. else
  19. {
  20. $this->_index();
  21. }
  22. }
  23. //管理
  24. public function _index()
  25. {
  26. $post = $this->input->post(NULL, TRUE);
  27. if(isset($post['page']))
  28. {
  29. $page = $this->input->post('page',true);
  30. $id = $this->input->post('id',true);
  31. $name = $this->input->post('name',true);
  32. $number = $this->input->post('number',true);
  33. $where = "1=1 ";
  34. if($id)
  35. {
  36. $where .= " and id = '$id'";
  37. }
  38. if($name)
  39. {
  40. $where .= " and name = '$name'";
  41. }
  42. if($number)
  43. {
  44. $where .= " and number = '$number'";
  45. }
  46. //数据排序
  47. $order_str = "id asc";
  48. //取得信息列表
  49. $info_list = $this->employee->find_all($where,'id,number,name,sex,sign_at,created_at',$order_str);
  50. foreach ($info_list as $key=>$value)
  51. {
  52. if($value['sex'] == 1)
  53. {
  54. $info_list[$key]['sex'] = "男";
  55. }
  56. else
  57. {
  58. $info_list[$key]['sex'] = "女";
  59. }
  60. $info_list[$key]['sign_at'] =$info_list[$key]['sign_at'] ? date('Y-m-d',$value['sign_at']):"未打卡";
  61. $info_list[$key]['created_at'] = date('Y-m-d',$value['created_at']);
  62. }
  63. $rows = array('rows'=>($info_list));
  64. echo json_encode($rows);exit;
  65. }
  66. $this->_Template('employee',$this->data);
  67. }
  68. //添加
  69. public function _add()
  70. {
  71. $post = $this->input->post(NULL, TRUE);
  72. if(isset($post['number']))
  73. {
  74. $post['number'] = $this->input->post('number',true);
  75. $post['name'] = $this->input->post('name',true);
  76. $post['sex'] = $this->input->post('sex',true);
  77. $post['created_at'] = time();
  78. if($this->employee->insert($post))
  79. {
  80. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  81. }
  82. else
  83. {
  84. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  85. }
  86. }
  87. $this->_Template('employee_add',$this->data);
  88. }
  89. public function _edit($arg_array)
  90. {
  91. $post = $this->input->post(NULL, TRUE);
  92. if(isset($post['id']))
  93. {
  94. $id = $this->input->post('id',true);
  95. $post['number'] = $this->input->post('number',true);
  96. $post['name'] = $this->input->post('name',true);
  97. $post['sex'] = $this->input->post('sex',true);
  98. if($this->employee->save($post,$id))
  99. {
  100. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  101. }
  102. else
  103. {
  104. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  105. }
  106. }
  107. $arg_array = $arg_array[0];
  108. $employee = $this->employee->read($arg_array);
  109. $this->data['employee'] = $employee;
  110. $this->_Template('employee_edit',$this->data);
  111. }
  112. public function sign(){
  113. $post = $this->input->post(NULL, TRUE);
  114. $employee_ids=$post['ids'];
  115. $employee_ids=explode(',',trim($employee_ids,','));
  116. if(!isset($employee_ids)||empty($employee_ids)){
  117. return false;
  118. }
  119. $res1=$this->db->set('sign_at',time())->where_in('id',$employee_ids)->update('employee');
  120. // $res2=$this->db->set('sign_at',NULL)->where_not_in('id',$employee_ids)->update('employee');
  121. if($res1){
  122. echo json_encode(array('msg'=>'打卡成功','success'=>true));exit;
  123. }else{
  124. echo json_encode(array('msg'=>'打卡失败,请重试','success'=>false));exit;
  125. }
  126. return ;
  127. }
  128. }