123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\admin\model\PurcheaseOrder;use think\App;use think\facade\Validate;use think\Request;
- class ThStock extends Base
- {
- protected $model=null;
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model=new \app\admin\model\ThStock();
- }
-
- public function List(){
- $param=$this->request->param(['start'=>"","end"=>'',"orderCode"=>'',"thCode"=>'',"good_code"=>'',"companyNo"=>'',"status"=>'',
- "page"=>1,"size"=>15],"post","trim");
- $where=[];
- if($param['start']!='' && $param['end']!=""){
- $where[]=["addtime","between",[date("Y-m-d 00:00:00",strtotime($param['start'])),date('Y-m-d 23:59:59',strtotime($param['end']))]];
- }
- $param['orderCode']==""?:$where[]=["orderCode","like","%{$param["orderCode"]}%"];
- $param['thCode']==""?:$where[]=["thCode","like","%{$param["thCode"]}%"];
- $param['good_code']==""?:$where[]=["good_code","like","%{$param["good_code"]}%"];
- $param['companyNo']==""?:$where[]=["companyNo","=",$param["companyNo"]];
- $param['status']==""?:$where[]=["status","=",$param["status"]];
- $list=$this->model->with(["purcheaseOrder"])->where($where)->order("id desc")->paginate(["list_rows"=>$param['size'],
- "page"=>$param["page"]]);
- return app_show(0,"获取成功",["list"=>$list->items(),"count"=>$list->total()]);
- }
-
-
- public function status(){
- $param=$this->request->param(['id'=>"","rela_cgdNo"=>"","status"=>""],'post','trim');
- $valid=Validate::rule([
- "id|主键ID"=>"require|number|gt:0",
- "rela_cgdNo|关联采购单编号"=>"requireIf:status,2|max:255|unique:th_stock",
- "status|状态"=>"require|number|in:1,2,3"
- ]);
- if($valid->check($param)==false) return error_show(1004,$valid->getError());
- $info =$this->model->findOrEmpty($param['id']);
- if($info->isEmpty())return error_show(1004,'未找到数据');
- if($param['status']==2){
- $cgd = (new PurcheaseOrder())->where(["cgdNo"=>$param['rela_cgdNo']])->findOrEmpty();
- if($cgd->isEmpty())return error_show(1004,'未找到采购单数据');
- if($info->supplierNo!=$cgd->supplierNo) return error_show(1004,'供应商信息不一致');
- if($info->companyNo!=$cgd->companyNo) return error_show(1004,'业务公司信息不一致');
- if($info->th_num!=$cgd->good_num) return error_show(1004,'商品数量不一致');
- if($info->th_cgd_price!=$cgd->good_price) return error_show(1004,'商品采购价不一致');
- }
- $info->status=$param['status'];
- $info->rela_cgdNo=$param['status']==3?"":$param['rela_cgdNo'];
- $up =$info->save();
- return $up?app_show(0,"数据更新成功"):error_show(1004,"数据更新失败");
- }
- }
|