AssetDisposal.php 6.3 KB

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