Change.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\cxinv\controller;
  3. use app\cxinv\model\DataChange;
  4. use think\App;
  5. use think\facade\Validate;
  6. class Change extends Base{
  7. public function __construct(App $app) {
  8. parent::__construct($app);
  9. $this->model = new DataChange();
  10. }
  11. public function list(){
  12. $param = $this->request->param(["code"=>"","companyNo"=>"","goodNo"=>"","good_type"=>"","page"=>1,"size"=>15],"post","trim");
  13. $where=[];
  14. if ($param['code']!="") $where[]=['code','like','%'.$param['code'].'%'];
  15. if ($param['companyNo']!="") $where[]=['data_change.companyNo','like','%'.$param['companyNo'].'%'];
  16. if ($param['goodNo']!="") $where[]=['goodNo','like','%'.$param['goodNo'].'%'];
  17. if ($param['good_type']!=""){
  18. switch ($param['good_type']){
  19. case 1:
  20. $where[]=['isZx','=',1];
  21. break;
  22. case 2:
  23. $where[]=['is_stock','=',1];
  24. break;
  25. case 3:
  26. $where[]=['is_stock','=',0];
  27. $where[]=['isZx','=',0];
  28. break;
  29. }
  30. }
  31. $list = $this->model->with(["Business"])
  32. ->withJoin(["good"],"left")
  33. ->where($where)
  34. ->order('id desc')->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
  35. return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  36. }
  37. public function create(){
  38. $param=$this->request->param(["code"=>"","remark"=>"","type"=>1,"order_type"=>"","content"=>[]],"post","trim");
  39. $valid = Validate::rule([
  40. "code|单据编号"=>"require|max:255",
  41. "type|修改类型"=>"require|number|in:1",
  42. "order_type|单据类型"=>"require|number|in:1,2",
  43. "remark|备注"=>"max:255",
  44. "content|修改内容"=>"require|array",
  45. ]);
  46. if(!$valid->check($param)) return error($valid->getError());
  47. $model = $param['order_type']==1 ? new \app\cxinv\model\QrdInfo() : new \app\cxinv\model\CgdInfo();
  48. $info = $model->where("sequenceNo",$param['code'])->findOrEmpty();
  49. if($info->isEmpty()) return error("单据不存在");
  50. $before = DataChange::GetBefore($param['code'],$param['type'],$param['order_type']);
  51. DataChange::diffContent($before,$param['content'],$param['type']);
  52. $data = [
  53. "code"=>$param['code'],
  54. "type"=>$param['type'],
  55. "order_type"=>$param['order_type'],
  56. "companyNo"=>$info['companyNo'],
  57. "goodNo"=>$info['goodNo'],
  58. "before"=>$before,
  59. "after"=>$param['content'],
  60. "remark"=>$param['remark'],
  61. "apply_id"=>$this->uid,
  62. "apply_name"=>$this->uname,
  63. ];
  64. $save= $this->model->save($data);
  65. if($save) return success("提交成功");
  66. return error("提交失败");
  67. }
  68. public function info(){
  69. $param=$this->request->param(["id"=>0],"get","trim");
  70. $valid = Validate::rule([
  71. "id|id"=>"require|number",
  72. ]);
  73. if(!$valid->check($param)) return error($valid->getError());
  74. $info = $this->model->with(["Business"])->where("id",$param['id'])->findOrEmpty();
  75. if($info->isEmpty()) return error("单据不存在");
  76. $info['goodList'] = DataChange::GetBefore($info['code'],$info['type'],$info['order_type']);
  77. return success("获取成功",$info);
  78. }
  79. }