MateCheck.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\MateGoodsLog;
  4. use think\App;
  5. use think\Db;
  6. use think\Exception;
  7. class MateCheck extends Auth
  8. {
  9. public function __construct(App $app = null) {
  10. parent::__construct($app);
  11. $this->model = new \app\common\model\MateCheck();
  12. $this->table = $this->model->table;
  13. }
  14. public function index(){
  15. if(request()->isAjax()){
  16. //分页参数
  17. $length = input('rows',10,'intval'); //每页条数
  18. $page = input('page',1,'intval'); //第几页
  19. $start = ($page - 1) * $length; //分页开始位置
  20. //排序
  21. $sortRow = input('sidx','id','trim'); //排序列
  22. $sort = input('sord','desc','trim'); //排序方式
  23. $order = $sortRow.' '.$sort;
  24. $enable = input('enable','','trim');
  25. if($enable != ''){
  26. $map[] = ['status','=',$enable];
  27. }
  28. $map[] = ['del','=',0];
  29. $map[] = ['org_id','=',$this->orgId];
  30. $map= empty($map) ? true: $map;
  31. //数据查询
  32. $lists =db($this->table)
  33. ->where($map)->limit($start,$length)
  34. ->order($order)->select();
  35. $lists = $lists?$lists:[];
  36. foreach ($lists as $k=>$v){
  37. $lists[$k]['userName'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  38. }
  39. //数据返回
  40. $totalCount = db($this->table)->where($map)->count();
  41. $totalPage = ceil($totalCount/$length);
  42. $result['page'] = $page;
  43. $result['total'] = $totalPage;
  44. $result['records'] = $totalCount;
  45. $result['rows'] = $lists;
  46. return json($result);
  47. }else{
  48. $this->assign('meta_title','盘库列表');
  49. return $this->fetch();
  50. }
  51. }
  52. /**
  53. * 新增/编辑
  54. */
  55. public function add(){
  56. if(request()->isPost()){
  57. $res = $this->model->updates($this->userId);
  58. if($res){
  59. $this->success('操作成功',url('index'));
  60. }else{
  61. $this->error($this->model->getError());
  62. }
  63. }else{
  64. $meta_title = '新增盘库';
  65. $this->assign('meta_title',$meta_title);
  66. return $this->fetch();
  67. }
  68. }
  69. //详情
  70. public function info($id){
  71. $info = $this->model->getInfo($id);
  72. if(!$info) $this->error('记录不存在');
  73. $this->assign('info',$info);
  74. return $this->fetch();
  75. }
  76. public function check($id=0){
  77. if(request()->isPost()){
  78. $res = $this->model->checkGoods($this->userId);
  79. if($res){
  80. $this->success('操作成功',url('index'));
  81. }else{
  82. $this->error($this->model->getError());
  83. }
  84. }else{
  85. $this->assign('id',$id);
  86. return $this->fetch();
  87. }
  88. }
  89. public function delGoods($id=0){
  90. $info = Db::name('mate_check_goods')->where('id',$id)->where('del',0)->find();
  91. if(!$info){
  92. $this->error('记录不存在');
  93. }
  94. $ret = Db::name('mate_check_goods')->where('id',$id)->update(['user_id'=>$this->userId,'del'=>1]);
  95. if($ret){
  96. $this->success('操作成功');
  97. }else{
  98. $this->error('操作失败');
  99. }
  100. }
  101. public function del($id=0){
  102. $info = Db::name('mate_check')->where('id',$id)->where('del',0)->find();
  103. if(!$info){
  104. $this->error('记录不存在');
  105. }
  106. Db::startTrans();
  107. try{
  108. $ret = Db::name('mate_check')->where('id',$id)->update(['del_user'=>$this->userId,'del'=>1,'del_time'=>date('Y-m-d H:i:s')]);
  109. if(!$ret){
  110. \exception('操作成功');
  111. }
  112. Db::name('mate_check_goods')->where('check_id',$id)->update(['user_id'=>$this->userId,'del'=>1]);
  113. Db::commit();
  114. }catch (Exception $e){
  115. Db::rollback();
  116. $this->error('操作失败');
  117. }
  118. $this->success('操作成功');
  119. }
  120. public function finish($id=0){
  121. $info = Db::name('mate_check')->where('id',$id)->where('del',0)->find();
  122. if(!$info){
  123. $this->error('记录不存在');
  124. }
  125. if($info['status'] != 0){
  126. $this->error('盘库已完成');
  127. }
  128. $ginfo = Db::name('mate_check_goods')->where('check_id',$id)->where('status',0)->where('del',0)->find();
  129. if($ginfo){
  130. $this->error('还有物品未盘库');
  131. }
  132. $ret = Db::name('mate_check')->where('id',$id)->update(['status'=>1,'finish_time'=>date('Y-m-d H:i:s')]);
  133. if(!$ret){
  134. $this->error('操作失败');
  135. }
  136. $this->success('操作成功');
  137. }
  138. }