|
@@ -9,6 +9,8 @@ use app\BaseController;
|
|
use think\App;
|
|
use think\App;
|
|
use think\facade\Db;
|
|
use think\facade\Db;
|
|
|
|
|
|
|
|
+//调拨 allot_info(从表)和allot_stock(主表)
|
|
|
|
+//调拨之后,修改库存,采购单的仓库编号是否也需要修改
|
|
class Allot extends BaseController
|
|
class Allot extends BaseController
|
|
{
|
|
{
|
|
public $post= "";
|
|
public $post= "";
|
|
@@ -113,6 +115,7 @@ class Allot extends BaseController
|
|
return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
|
|
return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
|
|
}
|
|
}
|
|
public function create(){
|
|
public function create(){
|
|
|
|
+
|
|
$token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
|
|
$token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
|
|
$wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"";
|
|
$wsm_out = isset($this->post['wsm_out']) && $this->post['wsm_out'] !=="" ? trim($this->post['wsm_out']) :"";
|
|
if($wsm_out==""){
|
|
if($wsm_out==""){
|
|
@@ -122,22 +125,29 @@ class Allot extends BaseController
|
|
if($wsm_in==""){
|
|
if($wsm_in==""){
|
|
return error_show(1002,"入库仓库不能为空");
|
|
return error_show(1002,"入库仓库不能为空");
|
|
}
|
|
}
|
|
- $in_companyNo = isset($this->post['in_companyNo']) && $this->post['in_companyNo'] !=="" ? trim($this->post['in_companyNo']) :"";
|
|
|
|
- if($in_companyNo==""){
|
|
|
|
- return error_show(1002,"in_companyNo不能为空");
|
|
|
|
- }
|
|
|
|
- $out_companyNo = isset($this->post['out_companyNo']) && $this->post['out_companyNo'] !=="" ? trim($this->post['out_companyNo']) :"";
|
|
|
|
- if($out_companyNo==""){
|
|
|
|
- return error_show(1002,"out_companyNo不能为空");
|
|
|
|
- }
|
|
|
|
- $company =Db::name("business")->where(['companyNo'=>$in_companyNo,"is_del"=>0])->find();
|
|
|
|
- if($company==false){
|
|
|
|
- return error_show(1002,"未找到入库业务公司");
|
|
|
|
- }
|
|
|
|
- $company =Db::name("business")->where(['companyNo'=>$out_companyNo,"is_del"=>0])->find();
|
|
|
|
- if($company==false){
|
|
|
|
- return error_show(1002,"未找到出库业务公司");
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ //根据出入库的仓库编码,查出对应的公司、业务公司
|
|
|
|
+ $warehouse_temp_info = Db::name('warehouse_info')
|
|
|
|
+ ->where(['is_del' => 0, 'status' => 1])
|
|
|
|
+ ->whereIn('wsm_code', [$wsm_out, $wsm_in])
|
|
|
|
+ ->column('supplierNo,companyNo', 'wsm_code');//supplierNo所属供货商,companyNo业务企业
|
|
|
|
+
|
|
|
|
+// $in_companyNo = isset($this->post['in_companyNo']) && $this->post['in_companyNo'] !=="" ? trim($this->post['in_companyNo']) :"";
|
|
|
|
+// if($in_companyNo==""){
|
|
|
|
+// return error_show(1002,"in_companyNo不能为空");
|
|
|
|
+// }
|
|
|
|
+// $out_companyNo = isset($this->post['out_companyNo']) && $this->post['out_companyNo'] !=="" ? trim($this->post['out_companyNo']) :"";
|
|
|
|
+// if($out_companyNo==""){
|
|
|
|
+// return error_show(1002,"out_companyNo不能为空");
|
|
|
|
+// }
|
|
|
|
+// $company =Db::name("business")->where(['companyNo'=>$in_companyNo,"is_del"=>0])->find();
|
|
|
|
+// if($company==false){
|
|
|
|
+// return error_show(1002,"未找到入库业务公司");
|
|
|
|
+// }
|
|
|
|
+// $company =Db::name("business")->where(['companyNo'=>$out_companyNo,"is_del"=>0])->find();
|
|
|
|
+// if($company==false){
|
|
|
|
+// return error_show(1002,"未找到出库业务公司");
|
|
|
|
+// }
|
|
// $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !=="" ? trim($this->post['good_type_code']) :"";
|
|
// $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !=="" ? trim($this->post['good_type_code']) :"";
|
|
// if($good_type_code==""){
|
|
// if($good_type_code==""){
|
|
// return error_show(1002,"商品属性不能为空");
|
|
// return error_show(1002,"商品属性不能为空");
|
|
@@ -171,8 +181,8 @@ class Allot extends BaseController
|
|
"allot_code"=>$allot_code,
|
|
"allot_code"=>$allot_code,
|
|
"wsm_out"=>$wsm_out,
|
|
"wsm_out"=>$wsm_out,
|
|
"wsm_in"=>$wsm_in,
|
|
"wsm_in"=>$wsm_in,
|
|
- "out_companyNo"=>$out_companyNo,
|
|
|
|
- "in_companyNo"=>$in_companyNo,
|
|
|
|
|
|
+ "out_companyNo"=>$warehouse_temp_info[$wsm_out]['companyNo'],
|
|
|
|
+ "in_companyNo"=>$warehouse_temp_info[$wsm_in]['companyNo'],
|
|
"apply_name"=>$ri,
|
|
"apply_name"=>$ri,
|
|
"apply_id"=>$rm,
|
|
"apply_id"=>$rm,
|
|
"post_name"=>$post_name,
|
|
"post_name"=>$post_name,
|
|
@@ -194,8 +204,9 @@ class Allot extends BaseController
|
|
->join("good_stock c", "c.spuCode = b.spuCode", "left")
|
|
->join("good_stock c", "c.spuCode = b.spuCode", "left")
|
|
->join("warehouse_info v","v.wsm_code=c.wsm_code","left")
|
|
->join("warehouse_info v","v.wsm_code=c.wsm_code","left")
|
|
->join("supplier n","n.code=v.supplierNo","left")
|
|
->join("supplier n","n.code=v.supplierNo","left")
|
|
- ->where(['c.wsm_code' => $wsm_out,"v.wsm_type"=>1, 'b.spuCode' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
|
|
|
|
- ->field("b.spuCode,b.good_name,b.unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock,n.name")->find();
|
|
|
|
|
|
+ ->where(['c.wsm_code' => $wsm_out,"v.wsm_type"=>1, 'b.spuCode' => $value['spuCode'], 'b.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
|
|
|
|
+ ->field("b.spuCode,b.good_name,b.good_unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock,n.name")->find();
|
|
|
|
+
|
|
if (empty($st)) {
|
|
if (empty($st)) {
|
|
Db::rollback();
|
|
Db::rollback();
|
|
return error_show(1003, "商品不能为空");
|
|
return error_show(1003, "商品不能为空");
|
|
@@ -206,7 +217,7 @@ class Allot extends BaseController
|
|
$temp = [];
|
|
$temp = [];
|
|
$temp['good_name'] = $st['good_name'];
|
|
$temp['good_name'] = $st['good_name'];
|
|
$temp['allot_code'] =$allot_code;
|
|
$temp['allot_code'] =$allot_code;
|
|
- $temp['good_type_code'] = $value['good_code'];
|
|
|
|
|
|
+ $temp['good_type_code'] = $value['spuCode'];
|
|
$temp['allot_num'] = $value['allot_num'];
|
|
$temp['allot_num'] = $value['allot_num'];
|
|
$temp['usable_num'] = 0;
|
|
$temp['usable_num'] = 0;
|
|
$temp['error_num'] = 0;
|
|
$temp['error_num'] = 0;
|
|
@@ -274,7 +285,7 @@ class Allot extends BaseController
|
|
|
|
|
|
$data=[];
|
|
$data=[];
|
|
foreach ($vmp as $k=>$value){
|
|
foreach ($vmp as $k=>$value){
|
|
- $s =Db::name('good_stock')->where(['spuCode'=>$value['spuCode'],'wsm_code'=>$str['wsm_out']])
|
|
|
|
|
|
+ $s =Db::name('good_stock')->where(['spuCode'=>$value['good_type_code'],'wsm_code'=>$str['wsm_out']])
|
|
->find();
|
|
->find();
|
|
if($str['status']<=1) {
|
|
if($str['status']<=1) {
|
|
$value['usable_num'] = $s['usable_stock'];
|
|
$value['usable_num'] = $s['usable_stock'];
|
|
@@ -349,8 +360,8 @@ class Allot extends BaseController
|
|
->join("good_stock c", "c.spuCode = b.spuCode", "left")
|
|
->join("good_stock c", "c.spuCode = b.spuCode", "left")
|
|
->join("warehouse_info v","v.wsm_code=c.wsm_code","left")
|
|
->join("warehouse_info v","v.wsm_code=c.wsm_code","left")
|
|
->join("supplier n","n.code=v.supplierNo","left")
|
|
->join("supplier n","n.code=v.supplierNo","left")
|
|
- ->where(['c.wsm_code' => $wsm_out,"v.wsm_type"=>1, 'b.spuCode' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
|
|
|
|
- ->field("b.spuCode,b.good_name,b.unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock,n.name")->find();
|
|
|
|
|
|
+ ->where(['c.wsm_code' => $wsm_out,"v.wsm_type"=>1, 'b.spuCode' => $value['spuCode'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
|
|
|
|
+ ->field("b.spuCode,b.good_name,b.good_unit,c.wsm_code,c.usable_stock,c.good_type_code,c.wait_out_stock,c.wait_in_stock,n.name")->find();
|
|
if (empty($st)) {
|
|
if (empty($st)) {
|
|
Db::rollback();
|
|
Db::rollback();
|
|
return error_show(1003, "商品不能为空");
|
|
return error_show(1003, "商品不能为空");
|
|
@@ -370,7 +381,7 @@ class Allot extends BaseController
|
|
$temp = [];
|
|
$temp = [];
|
|
isset($value['id'])&&$value['id']!=="" ? $temp['id'] = $value['id']:'';
|
|
isset($value['id'])&&$value['id']!=="" ? $temp['id'] = $value['id']:'';
|
|
$temp['good_name'] = $st['good_name'];
|
|
$temp['good_name'] = $st['good_name'];
|
|
- $temp['good_type_code'] = $value['good_code'];
|
|
|
|
|
|
+ $temp['good_type_code'] = $value['spuCode'];
|
|
$temp['allot_num'] = $value['allot_num'];
|
|
$temp['allot_num'] = $value['allot_num'];
|
|
$temp['usable_num'] = 0;
|
|
$temp['usable_num'] = 0;
|
|
$temp['error_num'] = 0;
|
|
$temp['error_num'] = 0;
|
|
@@ -579,13 +590,13 @@ class Allot extends BaseController
|
|
$good_data=[];
|
|
$good_data=[];
|
|
foreach ($dain as $value) {
|
|
foreach ($dain as $value) {
|
|
$st = Db::name("good")->alias("b")
|
|
$st = Db::name("good")->alias("b")
|
|
- ->join("good_stock c", "c.spuCode = b.spuCode", "left")->where(['wsm_code' => $al['wsm_out'], 'b.spuCode' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
|
|
|
|
|
|
+ ->join("good_stock c", "c.spuCode = b.spuCode", "left")->where(['wsm_code' => $al['wsm_out'], 'b.spuCode' => $value['spuCode'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
|
|
->field("b.spuCode,b.good_name,c.wsm_code,c.usable_stock")->find();
|
|
->field("b.spuCode,b.good_name,c.wsm_code,c.usable_stock")->find();
|
|
if (empty($st)) {
|
|
if (empty($st)) {
|
|
Db::rollback();
|
|
Db::rollback();
|
|
return error_show(1003, "未找到商品");
|
|
return error_show(1003, "未找到商品");
|
|
}
|
|
}
|
|
- $n = Db::name('allot_info')->where(['good_type_code'=>$value['good_code'],'allot_code'=> $al['allot_code'],'is_del'=>0])->find();
|
|
|
|
|
|
+ $n = Db::name('allot_info')->where(['good_type_code'=>$value['spuCode'],'allot_code'=> $al['allot_code'],'is_del'=>0])->find();
|
|
if(empty($n)){
|
|
if(empty($n)){
|
|
Db::rollback();
|
|
Db::rollback();
|
|
return error_show(10032, "未找到数据");
|
|
return error_show(10032, "未找到数据");
|
|
@@ -601,13 +612,13 @@ class Allot extends BaseController
|
|
$temp['error_remark'] = $value['error_remark'];
|
|
$temp['error_remark'] = $value['error_remark'];
|
|
$temp['stock_num']=$n['allot_num'];
|
|
$temp['stock_num']=$n['allot_num'];
|
|
$temp['updatetime'] = date("Y-m-d H:i:s");
|
|
$temp['updatetime'] = date("Y-m-d H:i:s");
|
|
- $np = Db::name('allot_info')->where(['good_type_code'=>$value['good_code'],'allot_code'=> $al['allot_code'],'is_del'=>0])->save($temp);
|
|
|
|
|
|
+ $np = Db::name('allot_info')->where(['good_type_code'=>$value['spuCode'],'allot_code'=> $al['allot_code'],'is_del'=>0])->save($temp);
|
|
if($np==false){
|
|
if($np==false){
|
|
Db::rollback();
|
|
Db::rollback();
|
|
return error_show(1001,"数据更新失败");
|
|
return error_show(1001,"数据更新失败");
|
|
}
|
|
}
|
|
|
|
|
|
- $stock = Db::name("good_stock")->where(["spuCode"=>$value['good_code'],"wsm_code"=>$al['wsm_out'],
|
|
|
|
|
|
+ $stock = Db::name("good_stock")->where(["spuCode"=>$value['spuCode'],"wsm_code"=>$al['wsm_out'],
|
|
"is_del"=>0])->find();
|
|
"is_del"=>0])->find();
|
|
if($stock['intra_stock']<$n['allot_num']){
|
|
if($stock['intra_stock']<$n['allot_num']){
|
|
Db::rollback();
|
|
Db::rollback();
|
|
@@ -621,10 +632,10 @@ class Allot extends BaseController
|
|
return error_show(1002,"数据更新失败");
|
|
return error_show(1002,"数据更新失败");
|
|
}
|
|
}
|
|
$good_data[]=["stock_id"=>$stock['id'],"type"=>2,'stock'=>$n['allot_num'],"stock_name"=>"intra_stock"];
|
|
$good_data[]=["stock_id"=>$stock['id'],"type"=>2,'stock'=>$n['allot_num'],"stock_name"=>"intra_stock"];
|
|
- $instock = Db::name("good_stock")->where(["spuCode"=>$value['good_code'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->find();
|
|
|
|
|
|
+ $instock = Db::name("good_stock")->where(["spuCode"=>$value['spuCode'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->find();
|
|
if($instock==false){
|
|
if($instock==false){
|
|
$instock =[];
|
|
$instock =[];
|
|
- $instock['spuCode']=$value['good_code'];
|
|
|
|
|
|
+ $instock['spuCode']=$value['spuCode'];
|
|
$instock['wsm_code']=$al['wsm_in'];
|
|
$instock['wsm_code']=$al['wsm_in'];
|
|
$instock['wait_in_stock']=0;
|
|
$instock['wait_in_stock']=0;
|
|
$instock['wait_out_stock']=0;
|
|
$instock['wait_out_stock']=0;
|
|
@@ -687,7 +698,7 @@ public function vesio(){
|
|
ActionLog::logAdd($this->post['token'],$order,"DBD",5,$this->post);
|
|
ActionLog::logAdd($this->post['token'],$order,"DBD",5,$this->post);
|
|
foreach ($dain as $value) {
|
|
foreach ($dain as $value) {
|
|
$st = Db::name("good")->alias("b")
|
|
$st = Db::name("good")->alias("b")
|
|
- ->join("good_stock c", "c.spuCode = b.spuCode", "left")->where(['wsm_code' => $al['wsm_in'], 'b.spuCode' => $value['good_code'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
|
|
|
|
|
|
+ ->join("good_stock c", "c.spuCode = b.spuCode", "left")->where(['wsm_code' => $al['wsm_in'], 'b.spuCode' => $value['spuCode'], 'b.is_del' => 0, 'a.is_del' => 0])->where("c.is_del=0 or c.is_del is null")
|
|
->field("b.spuCode,b.good_name,c.wsm_code,c.usable_stock")->find();
|
|
->field("b.spuCode,b.good_name,c.wsm_code,c.usable_stock")->find();
|
|
if (empty($st)) {
|
|
if (empty($st)) {
|
|
Db::rollback();
|
|
Db::rollback();
|
|
@@ -700,17 +711,17 @@ public function vesio(){
|
|
$temp['stock_num'] = $value['stock_num'];
|
|
$temp['stock_num'] = $value['stock_num'];
|
|
$temp['error_remark'] = $value['error_remark'];
|
|
$temp['error_remark'] = $value['error_remark'];
|
|
$temp['updatetime'] = date("Y-m-d H:i:s");
|
|
$temp['updatetime'] = date("Y-m-d H:i:s");
|
|
- $np = Db::name('allot_info')->where(['good_type_code'=>$value['good_code'],'allot_code'=> $al['allot_code']])->save($temp);
|
|
|
|
|
|
+ $np = Db::name('allot_info')->where(['good_type_code'=>$value['spuCode'],'allot_code'=> $al['allot_code']])->save($temp);
|
|
if($np==false){
|
|
if($np==false){
|
|
Db::rollback();
|
|
Db::rollback();
|
|
return error_show(1001,"数据更新失败");
|
|
return error_show(1001,"数据更新失败");
|
|
}
|
|
}
|
|
- $p = Db::name('allot_info')->where(['good_type_code'=>$value['good_code'],'allot_code'=>$al['allot_code'],"is_del"=>0])->find();
|
|
|
|
|
|
+ $p = Db::name('allot_info')->where(['good_type_code'=>$value['spuCode'],'allot_code'=>$al['allot_code'],"is_del"=>0])->find();
|
|
if($p==false){
|
|
if($p==false){
|
|
Db::rollback();
|
|
Db::rollback();
|
|
return error_show(1002,"未找到数据");
|
|
return error_show(1002,"未找到数据");
|
|
}
|
|
}
|
|
- $stock = Db::name("good_stock")->where(["spuCode"=>$value['good_code'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->find();
|
|
|
|
|
|
+ $stock = Db::name("good_stock")->where(["spuCode"=>$value['spuCode'],"wsm_code"=>$al['wsm_in'],"is_del"=>0])->find();
|
|
if($stock['wait_in_stock']<$p['stock_num']){
|
|
if($stock['wait_in_stock']<$p['stock_num']){
|
|
Db::rollback();
|
|
Db::rollback();
|
|
return error_show(2000,"超出待入库存数量");
|
|
return error_show(2000,"超出待入库存数量");
|