123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
- namespace app\admin\controller;
- use app\hander\HelpHander;
- use think\Db;
- class AssetRepair 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;
- $title = input('title','','trim');
- if($title != ''){
- $map[] = ['u.real_name','like','%'.$title.'%'];
- }
- $stime = input('start','');
- if($stime !=''){
- $map[] = ['ar.create_time','>=',date('Y-m-d H:i:s',strtotime($stime))];
- }
- $etime = input('end','');
- if($etime !=''){
- $map[] = ['ar.create_time','<=',date('Y-m-d H:i:s',strtotime($etime))];
- }
- $map[] = ['ar.org_id','=',cur_org_id()];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name('asset_repair')
- ->alias('ar')
- ->field('ar.*,u.real_name as user_name')
- ->join('user u','u.id = ar.agent_user_id')
- ->where($map)
- ->limit($start,$length)
- ->order('ar.id desc')
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['agent_dep_name'] = Db::name('dep')->where('id',$v['agent_dep_id'])->value('title');
- }
- //数据返回
- $totalCount = Db::name('asset_repair')
- ->alias('ar')
- ->join('user u','u.id = ar.agent_user_id')
- ->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('AssetRepair')->updates();
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error(model('AssetRepair')->getError());
- }
- }else{
- if($id){
- $info = db('asset_repair')->where('id',$id)->find();
- $this->assign('info',$info);
- }
- $userList = model('WorkTypeMode')->getWorkerUser(cur_org_id());
- $this->assign('userList',$userList);
- 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','in','1,2'];
- 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(){
- $ret = model('AssetRepair')->finish();
- if(!$ret){
- $this->error(model('AssetRepair')->getError());
- }
- $this->success('操作成功');
- }
- public function report($id=0){
- $info = model('AssetRepair')->info($id);
- $this->assign('info',$info);
- return $this->fetch();
- }
- public function detail($id=0){
- $info = model('AssetRepair')->info($id);
- $this->assign('info',$info);
- return $this->fetch();
- }
- }
|