'调拨发货', "allotin"=>'调拨入库', "allotincheck"=>'调拨验货', 'CGD'=>'采购单', 'BHD'=>'备库单', 'FKD'=>'备库反馈单', 'RKD'=>'入库单', 'ZXQRD'=>'咨询单', 'XSQRD'=>'销售单', 'PDD'=>'盘点单', 'DBD'=>'调拨单', 'CKD'=>'出库单', 'CGTHD'=>'采购退货单', 'XSTHD'=>'销售退货单', 'CGGCD'=>'采购工差单', 'ZXGCD'=>'咨询工差单' ]; public function __construct(App $app) { parent::__construct($app); $this->post = $this->request->post(); $token = isset($this->post['token']) ? trim($this->post['token']) : ""; if($token==""){ return error_show(101,'token不能为空'); } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0){ return error_show($effetc['code'],$effetc['message']); } } public function list(){ $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1; $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10; $condtion=[['a.is_del',"=",0],['b.is_del',"=",0]]; $wsmcode =isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):""; if($wsmcode!=""){ $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code"); $condtion[]=["b.type_code",'in',$typecode]; } $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):""; if($good_code!=""){ //$condtion['b.type_code'] = $good_code; $condtion[]=["b.type_code",'=',$good_code]; } $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code']) :""; if($goodcode!=""){ //$condtion['a.good_code'] = Db::raw("like '%{$goodcode}%'"); $condtion[]=["a.good_code",'like',"%{$goodcode}%"]; } $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name']) :""; if($good_name!=""){ // $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'"); $condtion[]=["a.good_name",'like',"%{$good_name}%"]; } $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):""; if($supplierNo!=""){ $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find(); if(empty($supplier)){ return error_show(1004,"未找到供应商信息"); } $condtion[]=["a.gys_code",'=',$supplierNo]; } $count = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left") ->where($condtion)->count(); $page>=ceil($count/$size) ? $page=ceil($count/$size) :""; $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left") ->where($condtion)->field("b.id,a.good_code,a.good_name,a.good_desc,a.brand,a.original_price,a.cg_saler,a.good_type,a.market_fee,a.gys_code,a.unit, a.sort_f,a.sort_s,a.sort_t,b.color,b.material,b.specs,b.is_main,b.type_code,b.attribute,b.status as bstatus,a.addtime,a.updatetime,a.cat_id") ->page($page,$size)->select(); $data=[]; foreach ($list as $key=>$value){ $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock"); $value['usable_stock']=$stock; $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find(); $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :""; $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[]; $data[]=$value; } return app_show(0,"获取成功",["list"=>$data,"count"=>$count]); } public function SetWarn(){ $condition=["is_del"=>0]; $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):""; if($wsm_code!=""){ $condition["wsm_code"] = $wsm_code; }else{ return error_show(1004,"参数wsm_code 不能为空"); } $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):""; if($type_code!=""){ $condition["good_type_code"] = $type_code; }else{ return error_show(1004,"参数type_code 不能为空"); } $good= Db::name("good_stock")->where($condition)->find(); if(empty($good)){ return error_show(1005,"未找到数据"); } $warn_stock = isset($this->post['warn_stock']) &&$this->post['warn_stock'] !=="" ? intval($this->post['warn_stock']):""; if($warn_stock===""){ return error_show(1005,"参数warn_stock 不能为空"); } $good['warn_stock'] = $warn_stock; $good['updatetime'] = date("Y-m-d H:i:s"); $up= Db::name("good_stock")->save($good); if($up){ $data=["stock_id"=>$good['id'],"type"=>1,'stock'=>$warn_stock,"stock_name"=>"warn_stock"]; GoodLog::LogAdd($this->post['token'],$data,'setwarn'); return app_show(0,"预警库存更新成功"); }else{ return error_show(1005,"预警库存更新失败"); } } public function SetStatus(){ $id = isset($this->post['id']) &&$this->post['id'] !=="" ? intval($this->post['id']):""; if($id===""){ return error_show(1005,"参数id 不能为空"); } $good= Db::name("good_type")->where(["id"=>$id,"is_del"=>0])->find(); if(empty($good)){ return error_show(1005,"未找到数据"); } $good['status'] = $good['status']==1?0 :1; $good['updatetime'] = date("Y-m-d H:i:s"); $msg = $good['status']==1?"下架" :"上架"; $up= Db::name("good_type")->save($good); return $up ? app_show(0,"商品{$msg}成功"): error_show(1005,"商品{$msg}失败"); } public function GetStock(){ $condition = [["a.is_del","=",0]]; $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):""; if($type_code!==""){ $condition[]=["a.good_type_code","=",$type_code]; } $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']) :""; if($wsm_code!==""){ //$condition["a.wsm_code"]=$wsm_code; $condition[]=["a.wsm_code","=",$type_code]; } $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :""; if($suplierNo!==""){ $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code"); $condition[]=["a.wsm_code","in",$wsmcode]; } $list = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")->join("supplier c","b.supplierNo=c.code","left") ->where($condition)->field("a.id,b.name as wsm_name,c.code,c.name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.status,a.warn_stock")->select(); if(empty($list)){ return error_show(1004,"未找到数据"); } return app_show(0,"获取成功",$list); } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function GetStockBet(){ $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1; $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10; $condition = [["is_del","=",0]]; $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):""; if($type_code!==""){ $condition[]=["good_type_code","like","%{$type_code}%"]; } $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']) :""; if($wsm_code!==""){ $condition[]=["wsm_code","=",$wsm_code]; } $suplierNo = isset($this->post['suplierNo']) &&$this->post['suplierNo'] !=="" ? trim($this->post['suplierNo']) :""; if($suplierNo!==""){ $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code"); $condition[]=["wsm_code","in",$wsmcode]; } $start = isset($this->post['start']) &&$this->post['start'] !=="" ? $this->post['start']:""; $end = isset($this->post['end']) &&$this->post['end'] !=="" ? $this->post['end']:""; if($start!=""){ $condition[]=["addtime",">=",$start]; } if($end!=""){ $condition[]=["addtime","<=",$end]; } $count = Db::name("good_stock")->where($condition)->count(); $page>=ceil($count/$size) ? $page=ceil($count/$size) :""; $list = Db::name("good_stock")->where($condition)->page($page,$size)->order("addtime desc")->select(); $data=[]; foreach ($list as $key=>$value){ $temp=[]; if($value['wsm_code']!=""){ $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name") ->find(); } $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:""; $temp['wsm_code']=$value['wsm_code']; $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:""; $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:""; if($value['good_type_code']!=""){ $good=Db::name("good_type")->alias("a")->join("good b","a.good_code=b.good_code","left")->where(["a.type_code"=>$value['good_type_code'],"a.is_del"=>0,"b.is_del"=>0]) ->field("a.good_code,a.type_code,b.good_name,b.unit,a.attribute,b.sort_f")->find(); } $temp['good_code']=isset($good['good_code'])?$good['good_code']:""; $temp['type_code']=isset($good['type_code'])?$good['type_code']:""; $temp['good_name']=isset($good['good_name'])?$good['good_name']:""; $temp['unit']=isset($good['unit'])?$good['unit']:""; $temp['attribute']=isset($good['attribute'])?$good['attribute']:""; $temp['sort_f']=isset($good['sort_f'])?$good['sort_f']:""; $temp['usable_stock'] = $value['usable_stock']; $temp['wait_in_stock'] = $value['wait_in_stock']; $temp['wait_out_stock'] = $value['wait_out_stock']; $temp['intra_stock'] = $value['intra_stock']; $temp['total_stock'] = $value['total_stock']; $temp['warn_stock'] = $value['warn_stock']; $temp['id'] = $value['id']; $temp['out_total'] =0; $temp['in_total'] = 0; $temp['addtime'] = $value['addtime']; $data[]=$temp; } return app_show(0,"获取成功",["list"=>$data,"count"=>$count]); } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function GetStockWsm(){ $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1; $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10; $condition = [["is_del","=",0]]; $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']) :""; if($wsm_code!==""){ $condition[]=["wsm_code","=",$wsm_code]; } $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :""; if($suplierNo!==""){ $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code"); $condition[]=["wsm_code","in",$wsmcode]; } $build= Db::name("good_stock")->where($condition)->group("wsm_code")->field("wsm_code")->buildSql(); $count = Db::table($build." a")->count(); $page>=ceil($count/$size) ? $page=ceil($count/$size) :""; $list = Db::name("good_stock")->where($condition)->page($page,$size)->group("wsm_code") ->field("wsm_code,sum(wait_in_stock) wait_in_stock,sum(wait_out_stock) wait_out_stock,sum(usable_stock) usable_stock, sum(intra_stock) intra_stock,sum(warn_stock) warn_stock,sum(total_stock) total_stock")->select(); $data=[]; foreach ($list as $key=>$value){ $temp=[]; if($value['wsm_code']!=""){ $wsm = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where (['a.wsm_code'=>$value['wsm_code'],"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name") ->find(); $good = Db::name("good_stock")->alias("a")->join("good_type b","a.good_type_code=b.type_code","left") ->join("good c","c.good_code=b.good_code","left")->where(["a.wsm_code"=>$value['wsm_code'],"a.is_del"=>0,"b.is_del"=>0,"c.is_del"=>0]) ->field("c.good_code,a.good_type_code,c.good_name,b.attribute,c.sort_f,c.unit,a.usable_stock,a.wait_in_stock,a.wait_out_stock,a.intra_stock,a.total_stock,a.warn_stock") ->select(); } $temp['wsm_name'] = isset($wsm['wsm_name'])?$wsm['wsm_name']:""; $temp['wsm_code']=$value['wsm_code']; $temp['supplier_code']=isset($wsm['code'])?$wsm['code']:""; $temp['supplier_name']=isset($wsm['name'])?$wsm['name']:""; $temp['usable_stock'] = $value['usable_stock']; $temp['wait_in_stock'] = $value['wait_in_stock']; $temp['wait_out_stock'] = $value['wait_out_stock']; $temp['intra_stock'] = $value['intra_stock']; $temp['total_stock'] = $value['total_stock']; // $temp['warn_stock'] = $value['warn_stock']; $temp['child']=isset($good)&&!empty($good) ? $good:[]; $data[]=$temp; } return app_show(0,"获取成功",["list"=>$data,"count"=>$count]); } public function GetStockGod(){ $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1; $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10; $condition = [["a.is_del","=",0],["b.is_del","=",0],["c.usable_stock",">",0]]; $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']) :""; if($type_code!==""){ $condition[]=["b.type_code","like","%{$type_code}%"]; } $count = Db::name("good_type")->alias("b") ->join("good a","a.good_code = b.good_code","left") ->join("good_stock c","c.good_type_code = b.type_code","left") ->where($condition)->group("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime")->count(); $page>=ceil($count/$size) ? $page=ceil($count/$size) :""; $list = Db::name("good_type")->alias("b") ->join("good a","a.good_code = b.good_code","left") ->join("good_stock c","c.good_type_code = b.type_code","left") ->where($condition)->field("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime,sum(c.wait_in_stock) wait_in_stock, sum(c.wait_out_stock) wait_out_stock,sum(c.usable_stock) usable_stock,sum(c.intra_stock) intra_stock,sum(c.warn_stock) warn_stock,sum(c.total_stock) total_stock") ->page($page,$size)->order("a.addtime desc")->group("a.good_code,a.good_name,a.unit,a.sort_f,b.type_code,b.attribute,a.addtime")->select(); // echo Db::name("good_type")->getLastSql(); $data=[]; foreach ($list as $key=>$value){ $temp=[]; if($value['type_code']!=""){ $child = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left") ->where(['a.good_type_code'=>$value['type_code'],"b.wsm_type"=>1,"a.is_del"=>0])->field("a.wsm_code,b.name wsm_name,a.wait_in_stock,a.wait_out_stock,a.usable_stock,a.intra_stock,a.total_stock,a.warn_stock")->select(); } $temp['good_name'] = $value['good_name']; $temp['good_code'] = $value['good_code']; $temp['type_code'] = $value['type_code']; $temp['unit'] = $value['unit']; $temp['sort_f']=$value['sort_f']; $temp['attribute']=$value['attribute']; $temp['addtime']=$value['addtime']; $temp['usable_stock'] = isset($value['usable_stock'])? $value['usable_stock']:""; $temp['wait_in_stock'] = isset($value['wait_in_stock'])? $value['wait_in_stock']:""; $temp['wait_out_stock'] = isset($value['wait_out_stock'])? $value['wait_out_stock']:""; $temp['intra_stock'] = isset($value['intra_stock'])? $value['intra_stock']:""; $temp['total_stock'] = isset($value['total_stock'])? $value['total_stock']:""; // $temp['warn_stock'] = isset($value['warn_stock'])? $value['warn_stock']:""; $temp['child']=isset($child)&&!empty($child) ? $child:[]; $data[]=$temp; } return app_show(0,"获取成功",["list"=>$data,"count"=>$count]); } /** * @return \think\response\Json|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function Stat(){ $condition =[["is_del","=",0]]; $wsm_code = isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):""; if($wsm_code!=""){ //$condition["wsm_code"] = $wsm_code; $condition[]=["wsm_code","=",$wsm_code]; } $suplierNo = isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :""; if($suplierNo!==""){ $wsmcode = Db::name("warehouse_info")->where(['supplierNo'=>$suplierNo,"wsm_type"=>1,"is_del"=>0])->column("wsm_code"); $condition[]=["wsm_code","in",$wsmcode]; } $type_code = isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):""; if($type_code!=""){ $condition[] = ["good_type_code","=",$type_code]; } $statlist = Db::name("good_stock")->where($condition)->field("sum(wait_in_stock) as wait_in_stock,sum(wait_out_stock) as wait_out_stock ,sum(usable_stock) as usable_stock,sum(intra_stock) as intra_stock,sum(total_stock) as total_stock,sum(warn_stock) as warn_stock")->find(); return app_show(0,"获取成功",$statlist); } public function all(){ $condtion=["a.is_del"=>0,"b.is_del"=>0]; $wsmcode =isset($this->post['wsmcode']) &&$this->post['wsmcode'] !=="" ? trim($this->post['wsmcode']):""; if($wsmcode!=""){ $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code"); $condtion["b.type_code"] = $typecode; } $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):""; if($good_code!=""){ $condtion['b.type_code'] = $good_code; } $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code']) :""; if($goodcode!=""){ $condtion['a.good_code'] = $goodcode; } $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name']) :""; if($good_name!=""){ $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'"); } $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):""; if($supplierNo!=""){ $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find(); if(empty($supplier)){ return error_show(1004,"未找到供应商信息"); } $condtion["a.gys_code"] = $supplierNo; } $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left") ->where($condtion)->field("b.id,a.good_code,a.good_name,a.good_desc,a.brand,a.original_price,a.cg_saler,a.good_type,a.market_fee,a.gys_code,a.unit, a.sort_f,a.sort_s,a.sort_t,b.color,b.material,b.specs,b.is_main,b.type_code,b.attribute,b.status as bstatus,a.addtime,a.updatetime") ->select(); $data=[]; foreach ($list as $key=>$value){ $stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock"); $value['usable_stock']=$stock; $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find(); $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :""; $data[]=$value; } return app_show(0,"获取成功",$data); } public function loglist(){ $page = isset($this->post['page']) && $this->post['page']!==""? intval($this->post['page']) :"1"; $size = isset($this->post['size']) && $this->post['size']!==""? intval($this->post['size']) :"10"; $where=[]; $wsm_code= isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):""; if($wsm_code!=""){ $where[]=['b.wsm_code',"like","%$wsm_code%"]; } $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):""; if($supplierNo!=""){ $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find(); if(empty($supplier)){ return error_show(1004,"未找到供应商信息"); } $wsmcode = Db::name("warehouse_info")->where([ "is_del"=>0,"wsm_type"=>1,"supplierNo"=>$supplierNo])->column("wsm_code"); $where[]=['b.wsm_code',"in",$wsmcode]; } $count = Db::name("good_log")->alias('a') ->join("good_stock b","b.id=a.id","left")->where($where) ->join("good_type c","c.type_code=b.good_type_code","left") ->join("good v","v.good_code=c.good_code","left")->count(); $total = ceil($count/$size); $page = $total>=$page ? $page :$total; $list = Db::name("good_log")->alias('a') ->join("good_stock b","b.id=a.stock_id","left") ->join("good_type c","c.type_code=b.good_type_code","left") ->join("good v","v.good_code=c.good_code","left") ->where($where)->page($page,$size)->order("a.addtime desc") ->field("a.action_name,a.type,a.stock_name,a.stock,a.action_type, a.addtime,a.action_uid,b.wsm_code,v.good_code,v.good_name,v.cat_id")->select(); $data=[]; foreach ($list as $value){ $db = Db::name("depart_user")->where(['uid'=>$value['action_uid']])->column("itemid"); $item = Db::name("company_item")->where(['id'=>$db])->column("id,name"); $wsm = Db::name("warehouse_info")->alias("a")->Join("supplier b","a.supplierNo=b.code","left")->where (['a.wsm_code'=>$value['wsm_code'],"a.wsm_type"=>1,"a.is_del"=>0])->field("a.name as wsm_name,wsm_code,b.code,b.name")->find(); $int = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : []; $value['wsm_name'] =$wsm['wsm_name']; $value['wsm_code'] =$wsm['wsm_code']; $value['code'] =$wsm['code']; $value['name'] =$wsm['name']; $value['action_type_cn'] =$this->acton[$value['action_type']]; $value['item'] =$item; $value['can'] =$int; $data[]=$value; } return app_show(0,"获取成功",['list'=>$data,'count'=>$count]); } }