12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\index\controller;
- use think\Db;
- class Archives extends Base
- {
- public function lists(){
- $page = input('page/d',1);
- $length = input('size/d',10);
- $name = input('name','','trim');
- $start = ($page - 1) * $length;
- $map['org_id'] = $this->orgId;
- if($name){
- $map['name'] = ['like','%'.$name.'%'];
- }
- $list = Db::name('user_archives')
- ->where($map)
- ->limit($start,$length)
- ->order('id desc')
- ->select();
- $total = Db::name('user_archives')->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $list?$list:[]
- ];
- ajax_return_ok($data);
- }
- public function add(){
- $data = request()->post();
- $data['org_id'] = $this->orgId;
- if(empty($data['name'])){
- ajax_return_error('姓名不能为空');
- }
- if(empty($data['id'])){ // 新增
- unset($data['id']);
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = Db::name('user_archives')->strict(false)->insert($data);
- }else{ // 编辑
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = Db::name('user_archives')->where('id',$data['id'])->strict(false)->update($data);
- }
- if($ret){
- ajax_return_ok();
- }else{
- ajax_return_error('保存失败');
- }
- }
- public function info(){
- $id = input('id/d',0);
- $info = Db::name('user_archives')->where('id',$id)->find();
- if(!$info){
- ajax_return_error('人员档案不存在');
- }
- ajax_return_ok($info);
- }
- public function del(){
- $id = input('id/d',0);
- $info = Db::name('user_archives')->where('id',$id)->delete();
- if(!$info){
- ajax_return_error('删除失败');
- }
- ajax_return_ok('','删除成功');
- }
- }
|