0
0

AssetUnit.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class AssetUnit extends Auth
  5. {
  6. public function index(){
  7. if(request()->isAjax()){
  8. //分页参数
  9. $length = input('rows',10,'intval'); //每页条数
  10. $page = input('page',1,'intval'); //第几页
  11. $start = ($page - 1) * $length; //分页开始位置
  12. //排序
  13. $sortRow = input('sidx','id','trim'); //排序列
  14. $sort = input('sort','desc','trim'); //排序方式
  15. $order = $sortRow.' '.$sort;
  16. $map[] = ['org_id','=',cur_org_id()];
  17. $map= empty($map) ? true: $map;
  18. //数据查询
  19. $lists = Db::name('asset_unit')->where($map)->limit($start,$length)->order('id desc')->select();
  20. //数据返回
  21. $totalCount = Db::name('asset_unit')->where($map)->count();
  22. $totalPage = ceil($totalCount/$length);
  23. $result['page'] = $page;
  24. $result['total'] = $totalPage;
  25. $result['records'] = $totalCount;
  26. $result['rows'] = $lists;
  27. return json($result);
  28. }else{
  29. return $this->fetch();
  30. }
  31. }
  32. /**
  33. * 新增/编辑
  34. */
  35. public function add($id=0){
  36. if(request()->isPost()){
  37. $res = model('AssetUnit')->updates();
  38. if($res){
  39. $this->success('操作成功',url('index'));
  40. }else{
  41. $this->error(model('AssetUnit')->getError());
  42. }
  43. }else{
  44. if($id){
  45. $info = db('asset_unit')->where('id',$id)->find();
  46. $this->assign('info',$info);
  47. }
  48. return $this->fetch();
  49. }
  50. }
  51. /**
  52. * 删除记录
  53. * @param int $id
  54. */
  55. public function del($id=0){
  56. if(!$id){
  57. $this->error('参数错误');
  58. }
  59. $res = Db::name('asset_unit')->where('id',$id)->delete();
  60. if($res){
  61. $this->success('删除成功');
  62. }else{
  63. $this->error('删除失败');
  64. }
  65. }
  66. }