0
0

CompanyDispatch.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 CompanyDispatch extends Auth
  8. {
  9. public function __construct(App $app = null) {
  10. parent::__construct($app);
  11. $this->model = new \app\common\model\MateApply();
  12. $this->table = $this->model->table;
  13. }
  14. /**
  15. * 公司仓库入库记录
  16. *
  17. * @author wst
  18. * @date 2021/9/10 8:37
  19. */
  20. public function show(){
  21. if(request()->isAjax()){
  22. //分页参数
  23. $length = input('rows',10,'intval'); //每页条数
  24. $page = input('page',1,'intval'); //第几页
  25. $start = ($page - 1) * $length; //分页开始位置
  26. //排序
  27. $sortRow = input('sidx','id','trim'); //排序列
  28. $sort = input('sord','desc','trim'); //排序方式
  29. $order = $sortRow.' '.$sort;
  30. $title = input('title','','trim');
  31. if($title){
  32. $map[] = ['sn','like','%'.$title.'%'];
  33. }
  34. $enable = input('enable','','trim');
  35. if($enable != ''){
  36. $map[] = ['enable','=',$enable];
  37. }
  38. $map[] = ['org_id','=',$this->orgId];
  39. $map[] = ['type','=',1];
  40. $map= empty($map) ? true: $map;
  41. //数据查询
  42. $lists =db($this->table)
  43. ->where($map)->limit($start,$length)
  44. ->order($order)->select();
  45. foreach ($lists as $k=>$v){
  46. $lists[$k]['userName'] = db('user')
  47. ->where('id',$v['user_id'])
  48. ->value('real_name');
  49. }
  50. //数据返回
  51. $totalCount = db($this->table)->where($map)->count();
  52. $totalPage = ceil($totalCount/$length);
  53. $result['page'] = $page;
  54. $result['total'] = $totalPage;
  55. $result['records'] = $totalCount;
  56. $result['rows'] = $lists;
  57. return json($result);
  58. }else{
  59. $this->assign('meta_title','入库记录');
  60. return $this->fetch();
  61. }
  62. }
  63. /**
  64. * 新增入库
  65. */
  66. public function add(){
  67. if(request()->isPost()){
  68. $res = $this->model->updates($this->userId);
  69. if($res){
  70. $this->success('操作成功',url('show'));
  71. }else{
  72. $this->error($this->model->getError());
  73. }
  74. }else{
  75. $meta_title = '新增入库';
  76. $this->assign('meta_title',$meta_title);
  77. return $this->fetch();
  78. }
  79. }
  80. //详情
  81. public function info($id){
  82. $info = $this->model->getInfo($id);
  83. if(!$info) $this->error('记录不存在');
  84. $this->assign('info',$info);
  85. return $this->fetch();
  86. }
  87. }