0
0

AssetRepair.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace app\admin\controller;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. class AssetRepair extends Auth
  6. {
  7. public function index(){
  8. if(request()->isAjax()){
  9. //分页参数
  10. $length = input('rows',10,'intval'); //每页条数
  11. $page = input('page',1,'intval'); //第几页
  12. $start = ($page - 1) * $length; //分页开始位置
  13. //排序
  14. $sortRow = input('sidx','id','trim'); //排序列
  15. $sort = input('sort','desc','trim'); //排序方式
  16. $order = $sortRow.' '.$sort;
  17. $title = input('title','','trim');
  18. if($title != ''){
  19. $map[] = ['u.real_name','like','%'.$title.'%'];
  20. }
  21. $stime = input('start','');
  22. if($stime !=''){
  23. $map[] = ['ar.create_time','>=',date('Y-m-d H:i:s',strtotime($stime))];
  24. }
  25. $etime = input('end','');
  26. if($etime !=''){
  27. $map[] = ['ar.create_time','<=',date('Y-m-d H:i:s',strtotime($etime))];
  28. }
  29. $map[] = ['ar.org_id','=',cur_org_id()];
  30. $map= empty($map) ? true: $map;
  31. //数据查询
  32. $lists = Db::name('asset_repair')
  33. ->alias('ar')
  34. ->field('ar.*,u.real_name as user_name')
  35. ->join('user u','u.id = ar.agent_user_id')
  36. ->where($map)
  37. ->limit($start,$length)
  38. ->order('ar.id desc')
  39. ->select();
  40. foreach ($lists as $k=>$v){
  41. $lists[$k]['agent_dep_name'] = Db::name('dep')->where('id',$v['agent_dep_id'])->value('title');
  42. }
  43. //数据返回
  44. $totalCount = Db::name('asset_repair')
  45. ->alias('ar')
  46. ->join('user u','u.id = ar.agent_user_id')
  47. ->where($map)
  48. ->count();
  49. $totalPage = ceil($totalCount/$length);
  50. $result['page'] = $page;
  51. $result['total'] = $totalPage;
  52. $result['records'] = $totalCount;
  53. $result['rows'] = $lists;
  54. return json($result);
  55. }else{
  56. return $this->fetch();
  57. }
  58. }
  59. /**
  60. * 新增/编辑
  61. */
  62. public function add($id=0){
  63. if(request()->isPost()){
  64. $res = model('AssetRepair')->updates();
  65. if($res){
  66. $this->success('操作成功',url('index'));
  67. }else{
  68. $this->error(model('AssetRepair')->getError());
  69. }
  70. }else{
  71. if($id){
  72. $info = db('asset_repair')->where('id',$id)->find();
  73. $this->assign('info',$info);
  74. }
  75. $userList = model('WorkTypeMode')->getWorkerUser(cur_org_id());
  76. $this->assign('userList',$userList);
  77. return $this->fetch();
  78. }
  79. }
  80. public function selectGoods($cateId=0){
  81. $title = input('title','','trim');
  82. if($title){
  83. $map[] = ['title|sn','like','%'.$title.'%'];
  84. }
  85. $classId = input('class_id','');
  86. if($classId !=''){
  87. $map[] = ['class_id','=',$classId];
  88. }
  89. $addId = input('add_id','');
  90. if($addId !=''){
  91. $map[] = ['add_id','=',$addId];
  92. }
  93. if($cateId > 0){
  94. $map[] = ['cate_id','=',$cateId];
  95. }
  96. $map[] = ['org_id','=',cur_org_id()];
  97. $map[] = ['del','=',0];
  98. $map[] = ['enable','in','1,2'];
  99. if(request()->isAjax()){
  100. //分页参数
  101. $length = input('rows',10,'intval'); //每页条数
  102. $page = input('page',1,'intval'); //第几页
  103. $start = ($page - 1) * $length; //分页开始位置
  104. //排序
  105. $sortRow = input('sidx','id','trim'); //排序列
  106. $sort = input('sord','desc','trim'); //排序方式
  107. $order = $sortRow.' '.$sort;
  108. $map= empty($map) ? true: $map;
  109. //数据查询
  110. $lists = Db::name('asset_items')->where($map)->limit($start,$length)->order('id desc')->select();
  111. foreach ($lists as $k=>$v){
  112. $lists[$k]['statusTxt'] = model('asset_items')->statusTxt[$v['enable']];
  113. $lists[$k]['cateName'] = Db::name('asset_cate')->where('id',$v['cate_id'])->value('title');
  114. $lists[$k]['className'] = Db::name('asset_class')->where('id',$v['class_id'])->value('title');
  115. $lists[$k]['addName'] = Db::name('asset_add')->where('id',$v['add_id'])->value('title');
  116. $lists[$k]['unitName'] = Db::name('asset_unit')->where('id',$v['unit_id'])->value('title');
  117. $lists[$k]['print'] = $v['print'] == 1 ?'是':'否';
  118. }
  119. //数据返回
  120. $totalCount = Db::name('asset_items')->where($map)->count();
  121. $totalPage = ceil($totalCount/$length);
  122. $result['page'] = $page;
  123. $result['total'] = $totalPage;
  124. $result['records'] = $totalCount;
  125. $result['rows'] = $lists;
  126. return json($result);
  127. }else{
  128. $class = model('AssetClass')->getList($this->orgId);
  129. $this->assign('class',$class);
  130. $add = model('AssetAdd')->getList($this->orgId);
  131. $this->assign('add',$add);
  132. $tree = model('AssetCate')->showAllTree();
  133. $this->assign('tree',$tree);
  134. $this->assign('cateId',$cateId);
  135. $cateTitle = Db::name('asset_cate')->where('id',$cateId)->value('title');
  136. $this->assign('cateTitle',$cateTitle);
  137. $countPrice = Db::name('asset_items')->where($map)->sum('price');
  138. $this->assign('countPrice',$countPrice);
  139. return $this->fetch();
  140. }
  141. }
  142. // 完成维修
  143. public function finish(){
  144. $ret = model('AssetRepair')->finish();
  145. if(!$ret){
  146. $this->error(model('AssetRepair')->getError());
  147. }
  148. $this->success('操作成功');
  149. }
  150. public function report($id=0){
  151. $info = model('AssetRepair')->info($id);
  152. $this->assign('info',$info);
  153. return $this->fetch();
  154. }
  155. public function detail($id=0){
  156. $info = model('AssetRepair')->info($id);
  157. $this->assign('info',$info);
  158. return $this->fetch();
  159. }
  160. }