|
@@ -156,7 +156,7 @@ class Purchin extends BaseController
|
|
|
return error_show(1005,"采购单未发货");
|
|
|
}
|
|
|
|
|
|
- $wsm_in_code = makeNo("DF");
|
|
|
+ $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 不能为空");
|
|
@@ -242,6 +242,32 @@ 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['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['wait_in_stock']+=$send_num;
|
|
|
+ $good['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $upd= Db::name("good_stock")->save($good);
|
|
|
+ if($upd==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"新建失败");
|
|
|
+ }
|
|
|
+ $good_data[]=['good_log_code'=>$cgdNo,"stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$send_num,"stock_name"=>"usable_stock"];
|
|
|
+ GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
|
|
|
+ ActionLog::logAdd($this->post['token'],$order,"RKD", 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();
|
|
@@ -266,8 +292,7 @@ class Purchin extends BaseController
|
|
|
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'];
|
|
|
ProcessOrder::AddProcess($this->post['token'],$process);
|
|
|
- $good = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'],
|
|
|
- "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
|
|
|
+ $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'],
|
|
@@ -279,14 +304,11 @@ class Purchin extends BaseController
|
|
|
"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['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);
|
|
@@ -295,6 +317,45 @@ class Purchin extends BaseController
|
|
|
if($upd){
|
|
|
GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
|
|
|
ActionLog::logAdd($this->post['token'],$order,"RKD", 1,$good );
|
|
|
+ if($cgdinfo['send_status']==3){
|
|
|
+ $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();
|
|
|
+ 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')]);
|
|
|
+ if($up==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"出库单出库失败");
|
|
|
+ }
|
|
|
+ $good1 = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
|
|
|
+ if($good1==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"未找到对应商品库存");
|
|
|
+ }
|
|
|
+ $out_num = intval(array_sum(array_column($out,"send_num")));
|
|
|
+ if($out_num>$good1['usable_stock']){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"库存数量不足发货");
|
|
|
+ }
|
|
|
+ $good1['usable_stock']-=$out_num;
|
|
|
+ $good1['wait_out_stock']+=$out_num;
|
|
|
+ $good1['total_stock']=$good1['usable_stock']+$good1['wait_out_stock'];
|
|
|
+ $good1['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+ $upd= Db::name("good_stock")->save($good1);
|
|
|
+ if($upd==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"库存数量更新失败");
|
|
|
+ }
|
|
|
+ $sendp=Db::name("order_send")->where(["cgdNo"=>$cgdNo,"outCode"=>$send,"status"=>1])->save (["status"=>2]);
|
|
|
+ if($sendp==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,"库存发货失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
Db::commit();
|
|
|
return app_show(0,'商品入库成功',["wsm_in_code"=>$wsm_in_code]);
|
|
|
}else{
|
|
@@ -554,6 +615,45 @@ class Purchin extends BaseController
|
|
|
if($upd){
|
|
|
GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
|
|
|
ActionLog::logAdd($this->post['token'],$order,"RKD", 1,$good );
|
|
|
+// if($cgdinfo['send_status']==3){
|
|
|
+// $send=Db::name("order_send")->where(["cgdNo"=>$info['cgdNo'],"status"=>1])->column("outCode");
|
|
|
+// if(!empty($send)){
|
|
|
+// $out =Db::name("order_out")->where(["outCode"=>$send,"status"=>0,"is_del"=>0])->select()
|
|
|
+// ->toArray();
|
|
|
+// if(!empty($out)){
|
|
|
+// $up =Db::name("order_out")->where(["outCode"=>$send,"status"=>0,"is_del"=>0])->update
|
|
|
+// (["status"=>1,"updatetime"=>date('Y-m-d H:i:s')]);
|
|
|
+// if($up==false){
|
|
|
+// Db::rollback();
|
|
|
+// return error_show(1004,"出库单出库失败");
|
|
|
+// }
|
|
|
+// $good1 = Db::name("good_stock")->where(["wsm_code"=>$cgdinfo['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
|
|
|
+// if($good1==false){
|
|
|
+// Db::rollback();
|
|
|
+// return error_show(1004,"未找到对应商品库存");
|
|
|
+// }
|
|
|
+// $out_num = intval(array_sum(array_column($out,"send_num")));
|
|
|
+// if($out_num>$good1['usable_stock']){
|
|
|
+// Db::rollback();
|
|
|
+// return error_show(1004,"库存数量不足发货");
|
|
|
+// }
|
|
|
+// $good1['usable_stock']-=$out_num;
|
|
|
+// $good1['wait_out_stock']+=$out_num;
|
|
|
+// $good1['total_stock']=$good1['usable_stock']+$good1['wait_out_stock'];
|
|
|
+// $good1['updatetime'] = date("Y-m-d H:i:s");
|
|
|
+// $upd= Db::name("good_stock")->save($good1);
|
|
|
+// if($upd==false){
|
|
|
+// Db::rollback();
|
|
|
+// return error_show(1004,"库存数量更新失败");
|
|
|
+// }
|
|
|
+// $sendp=Db::name("order_send")->where(["cgdNo"=>$info['cgdNo'],"outCode"=>$out,"status"=>1])->save (["status"=>2]);
|
|
|
+// if($sendp==false){
|
|
|
+// Db::rollback();
|
|
|
+// return error_show(1004,"库存发货失败");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
Db::commit();
|
|
|
return app_show(0,'商品入库成功');
|
|
|
}else{
|
|
@@ -617,43 +717,79 @@ class Purchin extends BaseController
|
|
|
Db::startTrans();
|
|
|
try{
|
|
|
|
|
|
- $info['status'] =5;
|
|
|
+ $info['status'] =$info['wsm_num']==$wsm_num ? 4 :5;
|
|
|
$info['is_th'] =$return_num>0 ?1:0;
|
|
|
$info['updatetime'] = date("Y-m-d H:i:s");
|
|
|
$up= Db::name("purchease_in")->save($info);
|
|
|
if($up){
|
|
|
- $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD'];
|
|
|
- ProcessOrder::AddProcess($this->post['token'],$process);
|
|
|
- $data=[
|
|
|
- "wsm_in_code"=>$incode,
|
|
|
- "wsm_num"=>$wsm_num,
|
|
|
- "reissue_num"=>$reissue_num,
|
|
|
- "return_num"=>$return_num,
|
|
|
- "return_contactor"=>$contactor,
|
|
|
- "return_addr"=>$addr,
|
|
|
- "return_mobile"=>$mobile,
|
|
|
- "error_remark"=>$error_remark,
|
|
|
- "post_code"=>"",
|
|
|
- "post_company"=>"",
|
|
|
- "remark"=>$remark ,
|
|
|
- "apply_id"=>$userinfo['id'],
|
|
|
- "apply_name"=>$userinfo['nickname'],
|
|
|
- "status"=>0,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- $res = Db::name("purchease_return")->insert($data,true);
|
|
|
- if($res){
|
|
|
- $sto = ["order_code"=>$incode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
|
|
|
- ActionLog::logAdd($this->post['token'],$sto,"RKTHD",0,$sto);
|
|
|
- $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$res,"order_status"=>0,"order_type"=>'RKTHD'];
|
|
|
- ProcessOrder::AddProcess($this->post['token'],$process);
|
|
|
- Db::commit();
|
|
|
- return app_show(0,"验货审核完成");
|
|
|
+ $cgdinfo=Db::name("purchease_order")->where(['cgdNo'=>$info['cgdNo'],"is_del"=>0])->find();
|
|
|
+ if(empty($cgdinfo)){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"未找到采购单数据");
|
|
|
+ }
|
|
|
+ $good = Db::name("good_stock")->where(["wsm_code"=>$info['wsm_code'], "spuCode"=>$cgdinfo['spuCode'],"is_del"=>0])->find();
|
|
|
+
|
|
|
+ if(empty($good)) {
|
|
|
+ $good=[
|
|
|
+ "spuCode"=>$cgdinfo['spuCode'],
|
|
|
+ "wsm_code"=>$info['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']+=$wsm_num;
|
|
|
+ $good['wait_in_stock']-=$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);
|
|
|
+ if($upd==false){
|
|
|
Db::rollback();
|
|
|
- return error_show(1002,"验货审核失败");
|
|
|
+ return error_show(1002,"库存更新失败");
|
|
|
}
|
|
|
+ $good_data[]=["stock_id"=>isset($good['id'])? $good['id']:Db::name("good_stock")->getLastInsID(),"type"=>1, 'stock'=>$info['wsm_num'],"stock_name"=>"usable_stock"];
|
|
|
+ GoodLog::LogAdd($this->post['token'],$good_data,'RKD');
|
|
|
+ $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'RKD'];
|
|
|
+ ProcessOrder::AddProcess($this->post['token'],$process);
|
|
|
+ if($info['status']==5){
|
|
|
+ $data=[
|
|
|
+ "wsm_in_code"=>$incode,
|
|
|
+ "wsm_num"=>$wsm_num,
|
|
|
+ "reissue_num"=>$reissue_num,
|
|
|
+ "return_num"=>$return_num,
|
|
|
+ "return_contactor"=>$contactor,
|
|
|
+ "return_addr"=>$addr,
|
|
|
+ "return_mobile"=>$mobile,
|
|
|
+ "error_remark"=>$error_remark,
|
|
|
+ "post_code"=>"",
|
|
|
+ "post_company"=>"",
|
|
|
+ "remark"=>$remark ,
|
|
|
+ "apply_id"=>$userinfo['id'],
|
|
|
+ "apply_name"=>$userinfo['nickname'],
|
|
|
+ "status"=>0,
|
|
|
+ "addtime"=>date("Y-m-d H:i:s"),
|
|
|
+ "updatetime"=>date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $res = Db::name("purchease_return")->insert($data,true);
|
|
|
+ if($res==false){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1002,"验货审核失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $sto = ["order_code"=>$incode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
|
|
|
+ ActionLog::logAdd($this->post['token'],$sto,"RKTHD",0,$sto);
|
|
|
+ $process=["order_code"=>$info['wsm_in_code'],"order_id"=>$res,"order_status"=>0,"order_type"=>'RKTHD'];
|
|
|
+ ProcessOrder::AddProcess($this->post['token'],$process);
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"验货审核完成");
|
|
|
}
|
|
|
}catch (\Exception $e){
|
|
|
Db::rollback();
|