isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 //排序 $sortRow = input('sidx','id','trim'); //排序列 $sort = input('sort','desc','trim'); //排序方式 $order = $sortRow.' '.$sort; $status = input('status','','trim'); if($status !=''){ $map[] = ['status','=',$status]; } $map[] = ['org_id','=',cur_org_id()]; $map[] = ['del','=',0]; $map= empty($map) ? true: $map; //数据查询 $lists = Db::name('asset_check') ->where($map) ->limit($start,$length) ->order('id desc') ->select(); foreach ($lists as $k=>$v){ $lists[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name'); } //数据返回 $totalCount = Db::name('asset_check') ->where($map) ->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $lists; return json($result); }else{ return $this->fetch(); } } /** * 新增/编辑 */ public function add($id=0){ if(request()->isPost()){ $res = model('AssetCheck')->updates(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('AssetCheck')->getError()); } }else{ if($id){ $info = db('asset_check')->where('id',$id)->find(); $this->assign('info',$info); } return $this->fetch(); } } public function selectGoods($cateId=0){ $title = input('title','','trim'); if($title){ $map[] = ['title|sn','like','%'.$title.'%']; } $classId = input('class_id',''); if($classId !=''){ $map[] = ['class_id','=',$classId]; } $addId = input('add_id',''); if($addId !=''){ $map[] = ['add_id','=',$addId]; } if($cateId > 0){ $map[] = ['cate_id','=',$cateId]; } $map[] = ['org_id','=',cur_org_id()]; $map[] = ['del','=',0]; $map[] = ['enable','=','1']; if(request()->isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 //排序 $sortRow = input('sidx','id','trim'); //排序列 $sort = input('sord','desc','trim'); //排序方式 $order = $sortRow.' '.$sort; $map= empty($map) ? true: $map; //数据查询 $lists = Db::name('asset_items')->where($map)->limit($start,$length)->order('id desc')->select(); foreach ($lists as $k=>$v){ $lists[$k]['statusTxt'] = model('asset_items')->statusTxt[$v['enable']]; $lists[$k]['cateName'] = Db::name('asset_cate')->where('id',$v['cate_id'])->value('title'); $lists[$k]['className'] = Db::name('asset_class')->where('id',$v['class_id'])->value('title'); $lists[$k]['addName'] = Db::name('asset_add')->where('id',$v['add_id'])->value('title'); $lists[$k]['unitName'] = Db::name('asset_unit')->where('id',$v['unit_id'])->value('title'); $lists[$k]['print'] = $v['print'] == 1 ?'是':'否'; } //数据返回 $totalCount = Db::name('asset_items')->where($map)->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $lists; return json($result); }else{ $class = model('AssetClass')->getList($this->orgId); $this->assign('class',$class); $add = model('AssetAdd')->getList($this->orgId); $this->assign('add',$add); $tree = model('AssetCate')->showAllTree(); $this->assign('tree',$tree); $this->assign('cateId',$cateId); $cateTitle = Db::name('asset_cate')->where('id',$cateId)->value('title'); $this->assign('cateTitle',$cateTitle); $countPrice = Db::name('asset_items')->where($map)->sum('price'); $this->assign('countPrice',$countPrice); return $this->fetch(); } } // 完成 public function finish($id=0){ $ret = model('AssetCheck')->finish($id); if(!$ret){ $this->error(model('AssetCheck')->getError()); } $this->success('操作成功'); } //删除 public function del($id=0){ $del = Db::name('asset_check')->where('id',$id)->setField('del',1); if(!$del){ $this->error('操作失败'); } $this->success('操作成功'); } public function report($id=0){ $ret = model('AssetCheck')->allItems($id); $this->assign('list',$ret['list']); $this->assign('info',$ret['check']); return $this->fetch(); } public function detail($id=0){ if(request()->isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 //排序 $sortRow = input('sidx','id','trim'); //排序列 $sort = input('sort','desc','trim'); //排序方式 $order = $sortRow.' '.$sort; $title = input('title','','trim'); if($title){ $map[] = ['sn|title','like','%'.$title.'%']; } $status = input('status','','trim'); if($status !=''){ $map[] = ['status','=',$status]; } $map[] = ['check_id','=',$id]; $map[] = ['del','=',0]; $map= empty($map) ? true: $map; //数据查询 $lists = Db::name('asset_check_items') ->where($map) ->limit($start,$length) ->order('id asc') ->select(); foreach ($lists as $k=>$v){ $lists[$k]['depName'] = ''; $lists[$k]['userName'] = ''; if($v['dep_id']){ $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('title'); $lists[$k]['userName'] = Db::name('user')->where('user',$v['user_id'])->value('real_name'); } $lists[$k]['diffNums'] = $v['check_nums'] - $v['nums']; } //数据返回 $totalCount = Db::name('asset_check_items')->where($map)->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $lists; $result['info'] = model('AssetCheck')->info($id); return json($result); }else{ $info = model('AssetCheck')->info($id); $this->assign('info',$info); $this->assign('id',$id); return $this->fetch(); } } // 收到盘点 public function finishItems(){ $id = input('id/d',0); $save = model('AssetCheck')->finishItems($id); if($save){ $this->success('操作成功'); }else{ $this->error(model('AssetCheck')->getError()); } } // 删除资产 public function delItems(){ $id = input('id/d',0); $del = model('AssetCheck')->delItems($id); if($del){ $this->success('操作成功'); }else{ $this->error(model('AssetCheck')->getError()); } } }