|
@@ -111,6 +111,7 @@ class Purchin extends BaseController
|
|
|
if($cgdinfo['status']==0){
|
|
|
return error_show(1005,"采购单未发货");
|
|
|
}
|
|
|
+
|
|
|
$wsm_in_code = makeNo("IC");
|
|
|
// $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
|
|
|
// if($wsm_code==""){
|
|
@@ -144,6 +145,15 @@ class Purchin extends BaseController
|
|
|
if($send_num>$cgdinfo['wsend_num']){
|
|
|
return error_show(1004,"采购单剩余未发货数量不足");
|
|
|
}
|
|
|
+ if($cgdinfo['order_type']==1||$cgdinfo['order_type']==2 ){
|
|
|
+ $goodinfo = Db::name("good")->where(["spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
|
|
|
+ if($goodinfo==false){
|
|
|
+ return error_show(1004,"商品数据未找到");
|
|
|
+ }
|
|
|
+ if($goodinfo['is_stock']==0){
|
|
|
+ $status=4;
|
|
|
+ }
|
|
|
+ }
|
|
|
$orin = [
|
|
|
"wsm_in_code"=>$wsm_in_code,
|
|
|
"cgdNo"=>$cgdNo,
|
|
@@ -182,48 +192,53 @@ class Purchin extends BaseController
|
|
|
$cgdinfo['updatetime']=date("Y-m-d H:i:s");
|
|
|
$up=Db::name("purchease_order")->save($cgdinfo);
|
|
|
if($up){
|
|
|
-// $good = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'],"spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
|
|
|
-// if(empty($good)) {
|
|
|
-// $good=[
|
|
|
-// "spuCode"=>$cgdinfo['skpuCode'],
|
|
|
-// "wsm_code"=>$cgdinfo['wsm_code'],
|
|
|
-// "usable_stock"=>0,
|
|
|
-// "wait_out_stock"=>0,
|
|
|
-// "wait_in_stock"=>0,
|
|
|
-// "total_stock"=>0,
|
|
|
-// "addtime"=>date("Y-m-d H:i:s"),
|
|
|
-// "updatetime"=>date("Y-m-d H:i:s"),
|
|
|
-// ];
|
|
|
-// $order = ["order_code"=>$good['good_type_code'],"status"=>1,"action_remark"=>'',
|
|
|
-// "action_type"=>"create"];
|
|
|
-//
|
|
|
-// }else{
|
|
|
-// $order = ["order_code"=>$good['good_type_code'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
|
|
|
-// }
|
|
|
-// $good['wait_in_stock']+=$send_num;
|
|
|
-// $good['updatetime'] = date("Y-m-d H:i:s");
|
|
|
-// $upd= Db::name("good_stock")->save($good);
|
|
|
-// $good_data[]=["stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,
|
|
|
-// 'stock'=>$send_num,"stock_name"=>"wait_in_stock"];
|
|
|
-// if($upd){
|
|
|
-// GoodLog::LogAdd($this->post['token'],$good_data,'入库单');
|
|
|
-// ActionLog::logAdd($this->post['token'],$order,"仓库库存", 1,$good );
|
|
|
$process=["order_code"=>$cgdNo,"order_id"=>$cgdinfo['id'],"order_status"=>$cgdinfo['status'],"order_type"=>'CGD'];
|
|
|
ProcessOrder::AddProcess($this->post['token'],$process);
|
|
|
Db::commit();
|
|
|
return app_show(0,'新建成功',["wsm_in_code"=>$wsm_in_code]);
|
|
|
-// }else{
|
|
|
-// Db::rollback();
|
|
|
-// return error_show(1002,"商品入库失败");
|
|
|
-// }
|
|
|
-
|
|
|
-// Db::commit();
|
|
|
-// return app_show(0,'新建成功',["wsm_in_code"=>$wsm_in_code]);
|
|
|
}else{
|
|
|
Db::rollback();
|
|
|
return error_show(1004,"新建失败");
|
|
|
}
|
|
|
}
|
|
|
+ if($status==4){
|
|
|
+ $good = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'],
|
|
|
+ "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
|
|
|
+
|
|
|
+ if(empty($good)) {
|
|
|
+ $good=[
|
|
|
+ "spuCode"=>$cgdinfo['spuCode'],
|
|
|
+ "wsm_code"=>$cgdinfo['wsm_code'],
|
|
|
+ "usable_stock"=>0,
|
|
|
+ "wait_out_stock"=>0,
|
|
|
+ "wait_in_stock"=>0,
|
|
|
+ "total_stock"=>0,
|
|
|
+ "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['usable_stock']+=$send_num;
|
|
|
+ $good['wait_in_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);
|
|
|
+ $good_data[]=["stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,
|
|
|
+ 'stock'=>$send_num,"stock_name"=>"usable_stock"];
|
|
|
+ if($upd){
|
|
|
+ GoodLog::LogAdd($this->post['token'],$good_data,'入库单');
|
|
|
+ ActionLog::logAdd($this->post['token'],$order,"仓库库存", 1,$good );
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,'商品入库成功',["wsm_in_code"=>$wsm_in_code]);
|
|
|
+ }else{
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"商品入库失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
Db::commit();
|
|
|
return app_show(0,'新建成功',["wsm_in_code"=>$wsm_in_code]);
|
|
|
}
|
|
@@ -301,12 +316,6 @@ class Purchin extends BaseController
|
|
|
return error_show(1004,"参数 order_num 不为空");
|
|
|
}
|
|
|
$error_list = isset($this->post['error_list']) && $this->post['error_list']!==''?$this->post['error_list']:"";
|
|
|
-
|
|
|
-// $wait_num = isset($this->post['wait_num']) && $this->post['wait_num']!==''?intval($this->post['wait_num'])
|
|
|
-// :"";
|
|
|
-// if($wait_num===''){
|
|
|
-// return error_show(1004,"参数 wait_num 不为空");
|
|
|
-// }
|
|
|
$result = GetUserInfo($this->post['token']);
|
|
|
if((!empty($result) && $result['code']!=0) ||empty($result) ){
|
|
|
return error_show($result['code'],$result['message']);
|
|
@@ -342,7 +351,6 @@ class Purchin extends BaseController
|
|
|
$data[]=$temp;
|
|
|
}
|
|
|
$derr= Db::name("purchease_info")->insertAll($data);
|
|
|
- // echo Db::name("purchease_info")->getLastSql();
|
|
|
if($derr){
|
|
|
Db::commit();
|
|
|
return app_show(0,"验货完成");
|