|
@@ -3,7 +3,7 @@ namespace app\admin\controller;
|
|
|
|
|
|
use app\admin\model\ActionLog;
|
|
|
use app\admin\model\GoodLog;
|
|
|
-use app\admin\model\ProcessOrder;
|
|
|
+use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
|
|
|
use app\BaseController;
|
|
|
use think\facade\Db;
|
|
|
use think\App;
|
|
@@ -173,11 +173,8 @@ class Purchin extends Base
|
|
|
return error_show(1005,"采购单未发货");
|
|
|
}
|
|
|
|
|
|
- $wsm_in_code = makeNo("CF");
|
|
|
-// $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
|
|
|
-// if($wsm_code==""){
|
|
|
-// return error_show(1004,"参数 wsm_code 不能为空");
|
|
|
-// }
|
|
|
+ $wsm_in_code = makeNo("CF");
|
|
|
+ $bn_code = makeNo("BN");
|
|
|
$wsminfo = Db::name("warehouse_info")->where(["wsm_code"=>$cgdinfo['wsm_code'],"is_del"=>0])->find();
|
|
|
if(empty($wsminfo)){
|
|
|
return error_show(1004,"未找到仓库信息");
|
|
@@ -208,24 +205,13 @@ class Purchin extends Base
|
|
|
if($send_num>$cgdinfo['wsend_num']-$wsmin_num){
|
|
|
return error_show(1009,"采购单剩余未发货数量不足");
|
|
|
}
|
|
|
-// if($cgdinfo['order_type']==1||$cgdinfo['order_type']==2 ){
|
|
|
-// $goodinfo = Db::name("good_basic")->where(["spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
|
|
|
-// if($goodinfo==false){
|
|
|
-// return error_show(1004,"商品数据未找到");
|
|
|
-// }
|
|
|
-// if($goodinfo['is_stock']==0){
|
|
|
-// $status=4;
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// $send_way = Db::name("good_zixun")->where(["spuCode" => $cgdinfo['spuCode'], "is_del" => 0])->value('send_way');
|
|
|
-// if ($send_way) $status = 4;
|
|
|
-// }
|
|
|
if($sendtype==2 || $cgdinfo['order_type']!=1){
|
|
|
$status=4;
|
|
|
}
|
|
|
$orin = [
|
|
|
"wsm_in_code"=>$wsm_in_code,
|
|
|
"cgdNo"=>$cgdNo,
|
|
|
+ "bnCode"=>$bn_code,
|
|
|
"wsm_code"=>$cgdinfo['wsm_code'],
|
|
|
"wsm_reaper"=>isset($recep)&& $recep['wsm_name']!=''? $recep['wsm_name']:"",
|
|
|
"send_num"=>$send_num,
|
|
@@ -282,34 +268,23 @@ class Purchin extends Base
|
|
|
"addtime"=>date("Y-m-d H:i:s"),
|
|
|
"updatetime"=>date("Y-m-d H:i:s"),
|
|
|
];
|
|
|
- // $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'',
|
|
|
- // "action_type"=>"create"];
|
|
|
- }else{
|
|
|
- // $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'',
|
|
|
- // "action_type"=>"edit"];
|
|
|
}
|
|
|
$good['wait_in_stock']-=$send_num;
|
|
|
-// if($good['presale_stock']>0){
|
|
|
-// if($good['presale_stock']>=$send_num){
|
|
|
-// $good['presale_stock']-=$send_num;
|
|
|
-// $good['wait_out_stock']+=$send_num;
|
|
|
-// }else{
|
|
|
-// $good['presale_stock']=0;
|
|
|
-// $good['usable_stock']+=$send_num-$good['presale_stock'];
|
|
|
-// $good['wait_out_stock']+=$good['presale_stock'];
|
|
|
-// }
|
|
|
-// }else{
|
|
|
- $good['usable_stock']+=$send_num;
|
|
|
- // }
|
|
|
-
|
|
|
+ $good['usable_stock']+=$send_num;
|
|
|
$good['total_stock']=$good['usable_stock']+$good['wait_out_stock'];
|
|
|
$good['updatetime'] = date("Y-m-d H:i:s");
|
|
|
$upd= Db::name("good_stock")->save($good);
|
|
|
+ $stockid=$good['id']?? Db::name("good_stock")->getLastInsID();
|
|
|
//商品变动日志表,good_log_code字段存储采购单单号
|
|
|
- $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$send_num,"stock_name"=>"usable_stock"];
|
|
|
- $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_in_stock"];
|
|
|
+ $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>1,'stock'=>$send_num,"stock_name"=>"usable_stock"];
|
|
|
+ $good_data[]=['good_log_code'=>$wsm_in_code,"stock_id"=>$stockid,"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_in_stock"];
|
|
|
if($upd){
|
|
|
- GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
|
|
|
+ $bnin=GoodStockInfo::AddBn($stockid,$bn_code,$send_num,$cgdinfo['good_price']);
|
|
|
+ if($bnin==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"库存bn数据新增失败");
|
|
|
+ }
|
|
|
+ GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
|
|
|
//todo:: 新增bn编号库存数据修改
|
|
|
if($cgdinfo['order_type']==1){
|
|
|
$bk =Db::name("order_bk")->where(['cgdNo'=>$cgdinfo['cgdNo']])->find();
|
|
@@ -343,8 +318,7 @@ class Purchin extends Base
|
|
|
if($cgdinfo['send_status']==3 && $cgdinfo['order_type']!=1){
|
|
|
$send=Db::name("order_send")->where(["cgdNo"=>$cgdNo,"status"=>1])->column("outCode");
|
|
|
if(!empty($send)){
|
|
|
- $out =Db::name("order_out")->where(["outCode"=>$send,"status"=>0])->select()
|
|
|
- ->toArray();
|
|
|
+ $out =Db::name("order_out")->where(["outCode"=>$send,"status"=>0])->select()->toArray();
|
|
|
if(!empty($out)){
|
|
|
$up =Db::name("order_out")->where(["outCode"=>$send,"status"=>0])->update
|
|
|
(["status"=>1,'wsm_code'=>$cgdinfo['wsm_code'],"updatetime"=>date('Y-m-d H:i:s')]);
|
|
@@ -353,7 +327,6 @@ class Purchin extends Base
|
|
|
return error_show(1004,"出库单出库失败");
|
|
|
}else{
|
|
|
foreach ($out as $k => $v_outCode) {
|
|
|
- //修改状态,添加待办
|
|
|
ActionLog::logAdd($this->post['token'], [
|
|
|
"order_code" => $v_outCode['outCode'],//出库单号
|
|
|
"status" => 0,//这里的status是之前的值
|
|
@@ -398,6 +371,17 @@ class Purchin extends Base
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ $orderdata =Db::name("order_num")->where(["cgdNo"=>$cgdNo])->find();
|
|
|
+ if($orderdata==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"关联订单未找到");
|
|
|
+ }
|
|
|
+ $OrderBn = GoodStockInfo::OrderBn($orderdata['orderCode'],$stockid,
|
|
|
+ $cgdinfo['good_num']-$cgdinfo['th_num']);
|
|
|
+ if($OrderBn==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"Bn库存数关联订单失败");
|
|
|
+ }
|
|
|
}
|
|
|
ActionLog::logAdd($this->post['token'],$order,"CGD", $cgdinfo['status'],$cgdinfo);
|
|
|
$process=["order_code"=>$cgdNo,"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD',"before_status"=>$order['status']];
|
|
@@ -678,29 +662,22 @@ class Purchin extends Base
|
|
|
}else{
|
|
|
$order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
|
|
|
}
|
|
|
-// $good['usable_stock']+=$info['wsm_num'];
|
|
|
$good['wait_in_stock']-=$info['wsm_num'];
|
|
|
-// if($good['presale_stock']>0){
|
|
|
-// if($good['presale_stock']>=$info['wsm_num']){
|
|
|
-// $good['presale_stock']-=$info['wsm_num'];
|
|
|
-// $good['wait_out_stock']+$info['wsm_num'];
|
|
|
-// }else{
|
|
|
-// $good['presale_stock']=0;
|
|
|
-// $good['usable_stock']+=$info['wsm_num']-$good['presale_stock'];
|
|
|
-// $good['wait_out_stock']+=$good['presale_stock'];
|
|
|
-// }
|
|
|
-// }else{
|
|
|
- $good['usable_stock']+=$info['wsm_num'];
|
|
|
- // }
|
|
|
-
|
|
|
+ $good['usable_stock']+=$info['wsm_num'];
|
|
|
$good['total_stock']=$good['usable_stock']+$good['wait_out_stock'];
|
|
|
$good['updatetime'] = date("Y-m-d H:i:s");
|
|
|
$upd= Db::name("good_stock")->save($good);
|
|
|
+ $stockid=$good['id']?? Db::name("good_stock")->getLastInsID();
|
|
|
//商品变动日志表,good_log_code字段存储入库单编号
|
|
|
$good_data[] = ['good_log_code' => $incode, "stock_id" => isset($good['id']) ? $good['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $info['wsm_num'], "stock_name" => "usable_stock"];
|
|
|
$good_data[] = ['good_log_code' => $incode, "stock_id" => isset($good['id']) ? $good['id'] :
|
|
|
Db::name("good_stock")->getLastInsID(), "type" => 2, 'stock' => $info['wsm_num'], "stock_name" => "wait_in_stock"];
|
|
|
if($upd){
|
|
|
+ $bnin=GoodStockInfo::AddBn($stockid,$info['bnCode'],$info['wsm_num'],$cgdinfo['good_price']);
|
|
|
+ if($bnin==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"库存bn数据新增失败");
|
|
|
+ }
|
|
|
GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
|
|
|
Db::commit();
|
|
|
return app_show(0,'商品入库成功');
|
|
@@ -984,27 +961,12 @@ class Purchin extends Base
|
|
|
"addtime"=>date("Y-m-d H:i:s"),
|
|
|
"updatetime"=>date("Y-m-d H:i:s"),
|
|
|
];
|
|
|
- $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'',
|
|
|
- "action_type"=>"create"];
|
|
|
-
|
|
|
+ $order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'',"action_type"=>"create"];
|
|
|
}else{
|
|
|
$order = ["order_code"=>$good['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
|
|
|
}
|
|
|
- $good['wait_in_stock']-=$return['wsm_num']+$return['return_num']-$return['reissue_num'];
|
|
|
-// if($good['presale_stock']>0){
|
|
|
-// if($good['presale_stock']>=$return['wsm_num']){
|
|
|
-// $good['presale_stock']-=$return['wsm_num'];
|
|
|
-// $good['wait_out_stock']+=$return['wsm_num'];
|
|
|
-// }else{
|
|
|
-// $good['presale_stock']=0;
|
|
|
-// $good['usable_stock']+=$return['wsm_num']-$good['presale_stock'];
|
|
|
-// $good['wait_out_stock']+=$good['presale_stock'];
|
|
|
-// }
|
|
|
-// }else{
|
|
|
- $good['usable_stock']+=$return['wsm_num'];
|
|
|
-// }
|
|
|
-// $good['usable_stock']+=$return['wsm_num'];
|
|
|
-// $good['wait_in_stock']-=$return['wsm_num']+$return['return_num']-$return['reissue_num'];
|
|
|
+ $good['wait_in_stock']-=$return['wsm_num']+$return['return_num']-$return['reissue_num'];
|
|
|
+ $good['usable_stock']+=$return['wsm_num'];
|
|
|
$good['total_stock']=$good['usable_stock']+$good['wait_out_stock'];
|
|
|
$good['updatetime'] = date("Y-m-d H:i:s");
|
|
|
$upd= Db::name("good_stock")->save($good);
|
|
@@ -1012,8 +974,14 @@ class Purchin extends Base
|
|
|
Db::rollback();
|
|
|
return error_show(1002,"库存更新失败");
|
|
|
}
|
|
|
- $good_data[]=['good_log_code' => $incode,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1, 'stock'=>$info['wsm_num'],"stock_name"=>"usable_stock"];
|
|
|
- $good_data[]=['good_log_code' => $incode,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>2, 'stock'=>$good['wait_in_stock'],"stock_name"=>"wait_in_stock"];
|
|
|
+ $stockid=$good['id']?? Db::name("good_stock")->getLastInsID();
|
|
|
+ $bnin=GoodStockInfo::AddBn($stockid,$info['bnCode'],$return['wsm_num'],$cgdinfo['good_price']);
|
|
|
+ if($bnin==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"库存bn数据新增失败");
|
|
|
+ }
|
|
|
+ $good_data[]=['good_log_code' => $incode,"stock_id"=>$stockid,"type"=>1, 'stock'=>$info['wsm_num'],"stock_name"=>"usable_stock"];
|
|
|
+ $good_data[]=['good_log_code' => $incode,"stock_id"=>$stockid,"type"=>2, 'stock'=>$good['wait_in_stock'],"stock_name"=>"wait_in_stock"];
|
|
|
GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
|
|
|
|
|
|
$order = ["order_code"=>$cgdinfo['cgdNo'],"status"=>$cgdinfo['status'],"action_remark"=>'',"action_type"=>"edit"];
|
|
@@ -1032,7 +1000,6 @@ class Purchin extends Base
|
|
|
Db::rollback();
|
|
|
return error_show(1004,"采购单数量更新失败");
|
|
|
}
|
|
|
-
|
|
|
$bk =Db::name("order_bk")->where(['cgdNo'=>$cgdinfo['cgdNo']])->lock(true)->find();
|
|
|
if($bk==false){
|
|
|
$bk=[
|