123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace app\cxinv\controller;
- use app\cxinv\model\DataChange;
- use think\App;
- use think\facade\Validate;
- class Change extends Base{
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model = new DataChange();
- }
- public function list(){
- $param = $this->request->param(["code"=>"","companyNo"=>"","goodNo"=>"","good_type"=>"","page"=>1,"size"=>15],"post","trim");
- $where=[];
- if ($param['code']!="") $where[]=['code','like','%'.$param['code'].'%'];
- if ($param['companyNo']!="") $where[]=['data_change.companyNo','like','%'.$param['companyNo'].'%'];
- if ($param['goodNo']!="") $where[]=['goodNo','like','%'.$param['goodNo'].'%'];
- if ($param['good_type']!=""){
- switch ($param['good_type']){
- case 1:
- $where[]=['isZx','=',1];
- break;
- case 2:
- $where[]=['is_stock','=',1];
- break;
- case 3:
- $where[]=['is_stock','=',0];
- $where[]=['isZx','=',0];
- break;
- }
- }
- $list = $this->model->with(["Business"])
- ->withJoin(["good"],"left")
- ->where($where)
- ->order('id desc')->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
- return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
- }
- public function create(){
- $param=$this->request->param(["code"=>"","remark"=>"","type"=>1,"order_type"=>"","content"=>[]],"post","trim");
- $valid = Validate::rule([
- "code|单据编号"=>"require|max:255",
- "type|修改类型"=>"require|number|in:1",
- "order_type|单据类型"=>"require|number|in:1,2",
- "remark|备注"=>"max:255",
- "content|修改内容"=>"require|array",
- ]);
- if(!$valid->check($param)) return error($valid->getError());
- $model = $param['order_type']==1 ? new \app\cxinv\model\QrdInfo() : new \app\cxinv\model\CgdInfo();
- $info = $model->where("sequenceNo",$param['code'])->findOrEmpty();
- if($info->isEmpty()) return error("单据不存在");
- $before = DataChange::GetBefore($param['code'],$param['type'],$param['order_type']);
- DataChange::diffContent($before,$param['content'],$param['type']);
- $data = [
- "code"=>$param['code'],
- "type"=>$param['type'],
- "order_type"=>$param['order_type'],
- "companyNo"=>$info['companyNo'],
- "goodNo"=>$info['goodNo'],
- "before"=>$before,
- "after"=>$param['content'],
- "remark"=>$param['remark'],
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- ];
- $save= $this->model->save($data);
- if($save) return success("提交成功");
- return error("提交失败");
- }
- public function info(){
- $param=$this->request->param(["id"=>0],"get","trim");
- $valid = Validate::rule([
- "id|id"=>"require|number",
- ]);
- if(!$valid->check($param)) return error($valid->getError());
- $info = $this->model->with(["Business"])->where("id",$param['id'])->findOrEmpty();
- if($info->isEmpty()) return error("单据不存在");
- $info['goodList'] = DataChange::GetBefore($info['code'],$info['type'],$info['order_type']);
- return success("获取成功",$info);
- }
- }
|