Staff.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Staff extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_staff','staff');
  7. $this->load->_model('Model_staffclass','staffclass');
  8. $this->load->_model('Model_stafflist','stafflist');
  9. $this->load->_model('Model_staffzw','staffzw');
  10. }
  11. //定义方法的调用规则 获取URI第二段值
  12. public function _remap($arg,$arg_array)
  13. {
  14. if($arg == 'add')//添加
  15. {
  16. $this->_add();
  17. }
  18. else if($arg == 'edit')//修改
  19. {
  20. $this->_edit($arg_array);
  21. }
  22. else if($arg == 'del')//修改
  23. {
  24. $this->_del();
  25. }
  26. else if($arg == 'listadd')//添加
  27. {
  28. $this->_listadd();
  29. }
  30. else if($arg == 'listedit')//修改
  31. {
  32. $this->_listedit($arg_array);
  33. }
  34. else if($arg == 'list')//修改
  35. {
  36. $this->_list();
  37. }
  38. else if($arg == 'rows')//修改
  39. {
  40. $this->_rows();
  41. }
  42. else
  43. {
  44. $this->_index();
  45. }
  46. }
  47. //管理
  48. public function _index()
  49. {
  50. $post = $this->input->post(NULL, TRUE);
  51. if(isset($post['page']))
  52. {
  53. $page = $this->input->post('page',true);
  54. $perpage = $this->input->post('perpage',true);
  55. $name = $this->input->post('name',true);
  56. $position = $this->input->post('position',true);
  57. $phone = $this->input->post('phone',true);
  58. $type = $this->input->post('type',true);
  59. $xztime = $this->input->post('xztime',true);
  60. $timetk = $this->input->post('timetk',true);
  61. $timetj = $this->input->post('timetj',true);
  62. $timetk = strtotime($timetk);
  63. $timetj = strtotime($timetj);
  64. $where = "1=1 ";
  65. if($timetk && $timetj && $xztime)
  66. {
  67. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  68. }
  69. if($name)
  70. {
  71. $where .= " and name = '$name'";
  72. }
  73. if($phone)
  74. {
  75. $where .= " and phone = '$phone'";
  76. }
  77. if($position)
  78. {
  79. $where .= " and position = '$position'";
  80. }
  81. if($type)
  82. {
  83. $where .= " and type = '$type'";
  84. }
  85. //数据排序
  86. $order_str = "id asc";
  87. if(empty($page))
  88. {
  89. $start = 0;
  90. $perpage = 1;
  91. }
  92. else
  93. {
  94. $start = ($page - 1)*$perpage;
  95. }
  96. //取得信息列表
  97. $info_list = $this->staff->find_all($where,'id,number,position,name,sex,birthday,phone,urgentname,urgentphone,address,entrytime,outtime',$order_str,$start,$perpage);
  98. foreach ($info_list as $key=>$value)
  99. {
  100. if($value['sex'] == 1)
  101. {
  102. $info_list[$key]['sex'] = "男";
  103. }
  104. else
  105. {
  106. $info_list[$key]['sex'] = "女";
  107. }
  108. if($value['outtime'] > 0)
  109. {
  110. $info_list[$key]['outtime'] = date('Y-m-d',$value['outtime']);
  111. }
  112. else
  113. {
  114. $info_list[$key]['outtime'] = "";
  115. }
  116. $info_list[$key]['number'] = 10000+$value['id'];
  117. $info_list[$key]['birthday'] = date('Y-m-d',$value['birthday']);
  118. $info_list[$key]['entrytime'] = date('Y-m-d',$value['entrytime']);
  119. $position = $this->staffclass->read($value['position']);
  120. $info_list[$key]['position'] = $position['name'];
  121. }
  122. $total = $this->staff->find_count($where);
  123. $pagenum = ceil($total/$perpage);
  124. $over = $total-($start+$perpage);
  125. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  126. echo json_encode($rows);exit;
  127. }
  128. $class = $this->staffclass->find_all();
  129. $this->data['class'] = $class;
  130. $zw = $this->staffzw->find_all();
  131. $this->data['zw'] = $zw;
  132. $this->_Template('staff',$this->data);
  133. }
  134. //添加
  135. public function _add()
  136. {
  137. $post = $this->input->post(NULL, TRUE);
  138. if(isset($post['type']))
  139. {
  140. $birthday = $this->input->post('birthday',true);
  141. $post['birthday'] = strtotime($birthday);
  142. $entrytime = $this->input->post('entrytime',true);
  143. $post['entrytime'] = strtotime($entrytime);
  144. $zztime = $this->input->post('zztime',true);
  145. $post['zztime'] = strtotime($zztime);
  146. $htktime = $this->input->post('htktime',true);
  147. $post['htktime'] = strtotime($htktime);
  148. $htjtime = $this->input->post('htjtime',true);
  149. $post['htjtime'] = strtotime($htjtime);
  150. $outtime = $this->input->post('outtime',true);
  151. $post['outtime'] = strtotime($outtime);
  152. $post['position'] = $this->input->post('position',true);
  153. if($post['position'] == '')
  154. {
  155. echo json_encode(array('msg'=>'必须选择职位!','success'=>false));exit;
  156. }
  157. if($this->staff->insert($post))
  158. {
  159. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  160. }
  161. else
  162. {
  163. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  164. }
  165. }
  166. $class = $this->staffclass->find_all();
  167. $this->data['class'] = $class;
  168. $zw = $this->staffzw->find_all();
  169. $this->data['zw'] = $zw;
  170. $this->_Template('staff_add',$this->data);
  171. }
  172. //修改
  173. public function _edit($arg_array)
  174. {
  175. $post = $this->input->post(NULL, TRUE);
  176. if(isset($post['id']))
  177. {
  178. $id = $this->input->post('id',true);
  179. $birthday = $this->input->post('birthday',true);
  180. $post['birthday'] = strtotime($birthday);
  181. $entrytime = $this->input->post('entrytime',true);
  182. $post['entrytime'] = strtotime($entrytime);
  183. $zztime = $this->input->post('zztime',true);
  184. $post['zztime'] = strtotime($zztime);
  185. $htktime = $this->input->post('htktime',true);
  186. $post['htktime'] = strtotime($htktime);
  187. $htjtime = $this->input->post('htjtime',true);
  188. $post['htjtime'] = strtotime($htjtime);
  189. $outtime = $this->input->post('outtime',true);
  190. $post['outtime'] = strtotime($outtime);
  191. $post['position'] = $this->input->post('position',true);
  192. if($post['position'] == '')
  193. {
  194. echo json_encode(array('msg'=>'必须选择职位!','success'=>false));exit;
  195. }
  196. if($this->staff->save($post,$id))
  197. {
  198. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  199. }
  200. else
  201. {
  202. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  203. }
  204. }
  205. $arg_array = $arg_array[0];
  206. $staff = $this->staff->read($arg_array);
  207. $this->data['staff'] = $staff;
  208. $class = $this->staffclass->find_all();
  209. $this->data['class'] = $class;
  210. $zw = $this->staffzw->find_all();
  211. $this->data['zw'] = $zw;
  212. $this->_Template('staff_edit',$this->data);
  213. }
  214. public function _list()
  215. {
  216. $post = $this->input->post(NULL, TRUE);
  217. if(isset($post['uid']))
  218. {
  219. $uid = $this->input->post('uid',true);
  220. $where = "uid='$uid'";
  221. //数据排序
  222. $order_str = "id desc";
  223. //取得信息列表
  224. $info_list = $this->stafflist->find_all($where,'id,data,time',$order_str);
  225. foreach ($info_list as $key=>$value)
  226. {
  227. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  228. }
  229. $total = $this->stafflist->find_count($where);
  230. $pagenum = 0;
  231. $over = 0;
  232. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  233. echo json_encode($rows);exit;
  234. }
  235. if(isset($post['s']))
  236. {
  237. $id_arr = $this->input->post('s');
  238. $id_arr = explode(',',$id_arr);
  239. if(!$id_arr)
  240. {
  241. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  242. }
  243. //循环删除记录
  244. foreach ($id_arr as $v)
  245. {
  246. $this->stafflist->remove($v);
  247. }
  248. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  249. }
  250. }
  251. //添加
  252. public function _listadd()
  253. {
  254. $post = $this->input->post(NULL, TRUE);
  255. if(isset($post['data']))
  256. {
  257. $post['uid'] = $this->input->post('uid',true);
  258. $post['data'] = $this->input->post('data',true);
  259. $time = $this->input->post('time',true);
  260. $post['time'] = strtotime($time);
  261. if($post['data'] == '')
  262. {
  263. echo json_encode(array('msg'=>'必须填写内容!','success'=>false));exit;
  264. }
  265. $ok = $this->stafflist->insert($post);
  266. if($ok)
  267. {
  268. echo json_encode(array('msg'=>'添加成功','data'=>$post['data'],'time'=>date('Y-m-d',$post['time']),'id'=>$ok,'success'=>true));exit;
  269. }
  270. else
  271. {
  272. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  273. }
  274. }
  275. $this->_Template('staff_listadd',$this->data);
  276. }
  277. //修改
  278. public function _listedit($arg_array)
  279. {
  280. $post = $this->input->post(NULL, TRUE);
  281. if(isset($post['id']))
  282. {
  283. $id = $this->input->post('id',true);
  284. $post['data'] = $this->input->post('data',true);
  285. $time = $this->input->post('time',true);
  286. $post['time'] = strtotime($time);
  287. if($post['data'] == '')
  288. {
  289. echo json_encode(array('msg'=>'必须填写内容!','success'=>false));exit;
  290. }
  291. if($this->stafflist->save($post,$id))
  292. {
  293. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  294. }
  295. else
  296. {
  297. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  298. }
  299. }
  300. $arg_array = $arg_array[0];
  301. $staff = $this->staff->read($arg_array);
  302. $this->data['staff'] = $staff;
  303. $this->_Template('staff_listedit',$this->data);
  304. }
  305. //删除
  306. public function _listdel()
  307. {
  308. $post = $this->input->post(NULL, TRUE);
  309. if(isset($post['s']))
  310. {
  311. $id_arr = $this->input->post('s');
  312. $id_arr = explode(',',$id_arr);
  313. if(!$id_arr)
  314. {
  315. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  316. }
  317. //循环删除记录
  318. foreach ($id_arr as $v)
  319. {
  320. $this->stafflist->remove($v);
  321. }
  322. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  323. }
  324. }
  325. public function _del()
  326. {
  327. $post = $this->input->post(NULL, TRUE);
  328. if(isset($post['s']))
  329. {
  330. $id_arr = $this->input->post('s');
  331. $id_arr = explode(',',$id_arr);
  332. if(!$id_arr)
  333. {
  334. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  335. }
  336. //循环删除记录
  337. foreach ($id_arr as $v)
  338. {
  339. $this->staff->remove($v);
  340. }
  341. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  342. }
  343. }
  344. }