123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- namespace app\admin\controller;
- use app\hander\HelpHander;
- use think\Db;
- class AssetCheck extends Auth
- {
- public function index(){
- 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;
- $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());
- }
- }
- }
|