AssetReceive.php 6.0 KB

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