Archives.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\index\controller;
  3. use think\Db;
  4. class Archives extends Base
  5. {
  6. public function lists(){
  7. $page = input('page/d',1);
  8. $length = input('size/d',10);
  9. $name = input('name','','trim');
  10. $start = ($page - 1) * $length;
  11. $map['org_id'] = $this->orgId;
  12. if($name){
  13. $map['name'] = ['like','%'.$name.'%'];
  14. }
  15. $list = Db::name('user_archives')
  16. ->where($map)
  17. ->limit($start,$length)
  18. ->order('id desc')
  19. ->select();
  20. $total = Db::name('user_archives')->where($map)->count();
  21. $data = [
  22. 'total' => $total,
  23. 'list' => $list?$list:[]
  24. ];
  25. ajax_return_ok($data);
  26. }
  27. public function add(){
  28. $data = request()->post();
  29. $data['org_id'] = $this->orgId;
  30. if(empty($data['name'])){
  31. ajax_return_error('姓名不能为空');
  32. }
  33. if(empty($data['id'])){ // 新增
  34. unset($data['id']);
  35. $data['create_time'] = date('Y-m-d H:i:s');
  36. $ret = Db::name('user_archives')->strict(false)->insert($data);
  37. }else{ // 编辑
  38. $data['update_time'] = date('Y-m-d H:i:s');
  39. $ret = Db::name('user_archives')->where('id',$data['id'])->strict(false)->update($data);
  40. }
  41. if($ret){
  42. ajax_return_ok();
  43. }else{
  44. ajax_return_error('保存失败');
  45. }
  46. }
  47. public function info(){
  48. $id = input('id/d',0);
  49. $info = Db::name('user_archives')->where('id',$id)->find();
  50. if(!$info){
  51. ajax_return_error('人员档案不存在');
  52. }
  53. ajax_return_ok($info);
  54. }
  55. public function del(){
  56. $id = input('id/d',0);
  57. $info = Db::name('user_archives')->where('id',$id)->delete();
  58. if(!$info){
  59. ajax_return_error('删除失败');
  60. }
  61. ajax_return_ok('','删除成功');
  62. }
  63. }