0
0

AssetCheck.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. namespace app\admin\controller;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. class AssetCheck 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. $status = input('status','','trim');
  18. if($status !=''){
  19. $map[] = ['status','=',$status];
  20. }
  21. $map[] = ['org_id','=',cur_org_id()];
  22. $map[] = ['del','=',0];
  23. $map= empty($map) ? true: $map;
  24. //数据查询
  25. $lists = Db::name('asset_check')
  26. ->where($map)
  27. ->limit($start,$length)
  28. ->order('id desc')
  29. ->select();
  30. foreach ($lists as $k=>$v){
  31. $lists[$k]['user_name'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  32. }
  33. //数据返回
  34. $totalCount = Db::name('asset_check')
  35. ->where($map)
  36. ->count();
  37. $totalPage = ceil($totalCount/$length);
  38. $result['page'] = $page;
  39. $result['total'] = $totalPage;
  40. $result['records'] = $totalCount;
  41. $result['rows'] = $lists;
  42. return json($result);
  43. }else{
  44. return $this->fetch();
  45. }
  46. }
  47. /**
  48. * 新增/编辑
  49. */
  50. public function add($id=0){
  51. if(request()->isPost()){
  52. $res = model('AssetCheck')->updates();
  53. if($res){
  54. $this->success('操作成功',url('index'));
  55. }else{
  56. $this->error(model('AssetCheck')->getError());
  57. }
  58. }else{
  59. if($id){
  60. $info = db('asset_check')->where('id',$id)->find();
  61. $this->assign('info',$info);
  62. }
  63. return $this->fetch();
  64. }
  65. }
  66. public function selectGoods($cateId=0){
  67. $title = input('title','','trim');
  68. if($title){
  69. $map[] = ['title|sn','like','%'.$title.'%'];
  70. }
  71. $classId = input('class_id','');
  72. if($classId !=''){
  73. $map[] = ['class_id','=',$classId];
  74. }
  75. $addId = input('add_id','');
  76. if($addId !=''){
  77. $map[] = ['add_id','=',$addId];
  78. }
  79. if($cateId > 0){
  80. $map[] = ['cate_id','=',$cateId];
  81. }
  82. $map[] = ['org_id','=',cur_org_id()];
  83. $map[] = ['del','=',0];
  84. $map[] = ['enable','=','1'];
  85. if(request()->isAjax()){
  86. //分页参数
  87. $length = input('rows',10,'intval'); //每页条数
  88. $page = input('page',1,'intval'); //第几页
  89. $start = ($page - 1) * $length; //分页开始位置
  90. //排序
  91. $sortRow = input('sidx','id','trim'); //排序列
  92. $sort = input('sord','desc','trim'); //排序方式
  93. $order = $sortRow.' '.$sort;
  94. $map= empty($map) ? true: $map;
  95. //数据查询
  96. $lists = Db::name('asset_items')->where($map)->limit($start,$length)->order('id desc')->select();
  97. foreach ($lists as $k=>$v){
  98. $lists[$k]['statusTxt'] = model('asset_items')->statusTxt[$v['enable']];
  99. $lists[$k]['cateName'] = Db::name('asset_cate')->where('id',$v['cate_id'])->value('title');
  100. $lists[$k]['className'] = Db::name('asset_class')->where('id',$v['class_id'])->value('title');
  101. $lists[$k]['addName'] = Db::name('asset_add')->where('id',$v['add_id'])->value('title');
  102. $lists[$k]['unitName'] = Db::name('asset_unit')->where('id',$v['unit_id'])->value('title');
  103. $lists[$k]['print'] = $v['print'] == 1 ?'是':'否';
  104. }
  105. //数据返回
  106. $totalCount = Db::name('asset_items')->where($map)->count();
  107. $totalPage = ceil($totalCount/$length);
  108. $result['page'] = $page;
  109. $result['total'] = $totalPage;
  110. $result['records'] = $totalCount;
  111. $result['rows'] = $lists;
  112. return json($result);
  113. }else{
  114. $class = model('AssetClass')->getList($this->orgId);
  115. $this->assign('class',$class);
  116. $add = model('AssetAdd')->getList($this->orgId);
  117. $this->assign('add',$add);
  118. $tree = model('AssetCate')->showAllTree();
  119. $this->assign('tree',$tree);
  120. $this->assign('cateId',$cateId);
  121. $cateTitle = Db::name('asset_cate')->where('id',$cateId)->value('title');
  122. $this->assign('cateTitle',$cateTitle);
  123. $countPrice = Db::name('asset_items')->where($map)->sum('price');
  124. $this->assign('countPrice',$countPrice);
  125. return $this->fetch();
  126. }
  127. }
  128. // 完成
  129. public function finish($id=0){
  130. $ret = model('AssetCheck')->finish($id);
  131. if(!$ret){
  132. $this->error(model('AssetCheck')->getError());
  133. }
  134. $this->success('操作成功');
  135. }
  136. //删除
  137. public function del($id=0){
  138. $del = Db::name('asset_check')->where('id',$id)->setField('del',1);
  139. if(!$del){
  140. $this->error('操作失败');
  141. }
  142. $this->success('操作成功');
  143. }
  144. public function report($id=0){
  145. $ret = model('AssetCheck')->allItems($id);
  146. $this->assign('list',$ret['list']);
  147. $this->assign('info',$ret['check']);
  148. return $this->fetch();
  149. }
  150. public function detail($id=0){
  151. if(request()->isAjax()){
  152. //分页参数
  153. $length = input('rows',10,'intval'); //每页条数
  154. $page = input('page',1,'intval'); //第几页
  155. $start = ($page - 1) * $length; //分页开始位置
  156. //排序
  157. $sortRow = input('sidx','id','trim'); //排序列
  158. $sort = input('sort','desc','trim'); //排序方式
  159. $order = $sortRow.' '.$sort;
  160. $title = input('title','','trim');
  161. if($title){
  162. $map[] = ['sn|title','like','%'.$title.'%'];
  163. }
  164. $status = input('status','','trim');
  165. if($status !=''){
  166. $map[] = ['status','=',$status];
  167. }
  168. $map[] = ['check_id','=',$id];
  169. $map[] = ['del','=',0];
  170. $map= empty($map) ? true: $map;
  171. //数据查询
  172. $lists = Db::name('asset_check_items')
  173. ->where($map)
  174. ->limit($start,$length)
  175. ->order('id asc')
  176. ->select();
  177. foreach ($lists as $k=>$v){
  178. $lists[$k]['depName'] = '';
  179. $lists[$k]['userName'] = '';
  180. if($v['dep_id']){
  181. $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  182. $lists[$k]['userName'] = Db::name('user')->where('user',$v['user_id'])->value('real_name');
  183. }
  184. $lists[$k]['diffNums'] = $v['check_nums'] - $v['nums'];
  185. }
  186. //数据返回
  187. $totalCount = Db::name('asset_check_items')->where($map)->count();
  188. $totalPage = ceil($totalCount/$length);
  189. $result['page'] = $page;
  190. $result['total'] = $totalPage;
  191. $result['records'] = $totalCount;
  192. $result['rows'] = $lists;
  193. $result['info'] = model('AssetCheck')->info($id);
  194. return json($result);
  195. }else{
  196. $info = model('AssetCheck')->info($id);
  197. $this->assign('info',$info);
  198. $this->assign('id',$id);
  199. return $this->fetch();
  200. }
  201. }
  202. // 收到盘点
  203. public function finishItems(){
  204. $id = input('id/d',0);
  205. $save = model('AssetCheck')->finishItems($id);
  206. if($save){
  207. $this->success('操作成功');
  208. }else{
  209. $this->error(model('AssetCheck')->getError());
  210. }
  211. }
  212. // 删除资产
  213. public function delItems(){
  214. $id = input('id/d',0);
  215. $del = model('AssetCheck')->delItems($id);
  216. if($del){
  217. $this->success('操作成功');
  218. }else{
  219. $this->error(model('AssetCheck')->getError());
  220. }
  221. }
  222. }