ThStock.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\admin\model\PurcheaseOrder;use think\App;use think\facade\Validate;use think\Request;
  5. class ThStock extends Base
  6. {
  7. protected $model=null;
  8. public function __construct(App $app) {
  9. parent::__construct($app);
  10. $this->model=new \app\admin\model\ThStock();
  11. }
  12. public function List(){
  13. $param=$this->request->param(['start'=>"","end"=>'',"orderCode"=>'',"thCode"=>'',"good_code"=>'',"companyNo"=>'',"status"=>'',
  14. "page"=>1,"size"=>15],"post","trim");
  15. $where=[];
  16. if($param['start']!='' && $param['end']!=""){
  17. $where[]=["addtime","between",[date("Y-m-d 00:00:00",strtotime($param['start'])),date('Y-m-d 23:59:59',strtotime($param['end']))]];
  18. }
  19. $param['orderCode']==""?:$where[]=["orderCode","like","%{$param["orderCode"]}%"];
  20. $param['thCode']==""?:$where[]=["thCode","like","%{$param["thCode"]}%"];
  21. $param['good_code']==""?:$where[]=["good_code","like","%{$param["good_code"]}%"];
  22. $param['companyNo']==""?:$where[]=["companyNo","=",$param["companyNo"]];
  23. $param['status']==""?:$where[]=["status","=",$param["status"]];
  24. $list=$this->model->with(["purcheaseOrder"])->where($where)->order("id desc")->paginate(["list_rows"=>$param['size'],
  25. "page"=>$param["page"]]);
  26. return app_show(0,"获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  27. }
  28. public function status(){
  29. $param=$this->request->param(['id'=>"","rela_cgdNo"=>"","status"=>""],'post','trim');
  30. $valid=Validate::rule([
  31. "id|主键ID"=>"require|number|gt:0",
  32. "rela_cgdNo|关联采购单编号"=>"requireIf:status,2|max:255|unique:th_stock",
  33. "status|状态"=>"require|number|in:1,2,3"
  34. ]);
  35. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  36. $info =$this->model->findOrEmpty($param['id']);
  37. if($info->isEmpty())return error_show(1004,'未找到数据');
  38. if($param['status']==2){
  39. $cgd = (new PurcheaseOrder())->where(["cgdNo"=>$param['rela_cgdNo']])->findOrEmpty();
  40. if($cgd->isEmpty())return error_show(1004,'未找到采购单数据');
  41. if($info->supplierNo!=$cgd->supplierNo) return error_show(1004,'供应商信息不一致');
  42. if($info->companyNo!=$cgd->companyNo) return error_show(1004,'业务公司信息不一致');
  43. if($info->th_num!=$cgd->good_num) return error_show(1004,'商品数量不一致');
  44. if($info->th_cgd_price!=$cgd->good_price) return error_show(1004,'商品采购价不一致');
  45. }
  46. $info->status=$param['status'];
  47. $info->rela_cgdNo=$param['status']==3?"":$param['rela_cgdNo'];
  48. $up =$info->save();
  49. return $up?app_show(0,"数据更新成功"):error_show(1004,"数据更新失败");
  50. }
  51. }