|
@@ -758,5 +758,100 @@ class OrderOutChild extends Base
|
|
|
|
|
|
return json_show(0, '获取成功', $list);
|
|
|
}
|
|
|
+ //退货旧数据生成发货工单
|
|
|
+ public function makeOutChild(){
|
|
|
+ $param = $this->request->only(['outCode'], 'post', 'trim');
|
|
|
+ $val = Validate::rule(['outCode' => 'require']);
|
|
|
+ if($val->check($param)==false) return error_show(1004,$val->getError());
|
|
|
+ $out=Db::name("order_out")->where(["outCode"=>$param['outCode'],"is_del"=>0])->findOrEmpty();
|
|
|
+ if(empty($out))return error_show(1004,'发货单不存在');
|
|
|
+ if(!in_array($out['status'],[2,3]))return error_show(1004,'发货单状态不满足条件');
|
|
|
+ $sale=Db::name("sale")->where(["orderCode"=>$out['orderCode'],"is_del"=>0])->findOrEmpty();
|
|
|
+ if(empty($sale))return error_show(1004,'订单不存在');
|
|
|
+ if(!in_array($sale['status'],[1,2]))return error_show(1004,'订单状态不满足条件');
|
|
|
+ $bninfo =Db::name("sale_info")->where([["orderCode","=",$out['orderCode']],["is_change_outbn","in",[1,2]]])
|
|
|
+ ->select()->toArray();
|
|
|
+ if(empty($bninfo)) return error_show(1004,'订单状态bn数据未找到');
|
|
|
+ $isT= Db::name("order_out_child")->where(["outCode"=>$param['outCode'],"is_del"=>0])->findOrEmpty();
|
|
|
+ if(!empty($isT))return error_show(1004,'发货单已存在工单');
|
|
|
+ if($out['wsm_code']==''){
|
|
|
+ if($sale["order_type"]==1) $cod =["b.supplierNo"=>$sale['supNo']];
|
|
|
+ else $cod =["b.companyNo"=>$sale['supplierNo']];
|
|
|
+ $wsmcode =Db::name("good_stock")->alias("a")
|
|
|
+ ->leftJoin("warehouse_info b","a.wsm_code = b.wsm_code ")
|
|
|
+ ->where("a.spuCode",$sale['good_code'])
|
|
|
+ ->where("b.wsm_type","in",[2,5])
|
|
|
+ ->where($cod)
|
|
|
+ ->value("a.wsm_code",'');
|
|
|
+ }else $wsmcode =$out['wsm_code'];
|
|
|
+ $outchild=[
|
|
|
+ "outChildCode"=>"",str_replace("DF","TCD",$param['outCode']),
|
|
|
+ "orderCode"=>$out['orderCode'],
|
|
|
+ "outCode"=>$out['outCode'],
|
|
|
+ "companyNo"=>$sale['supplierNo'],
|
|
|
+ "companyName"=>$sale['supplierName'],
|
|
|
+ "customer_code"=>$sale['customer_code'],
|
|
|
+ "customer_name"=>$sale['customerName'],
|
|
|
+ "supplierNo"=>$sale['supNo'],
|
|
|
+ "supplierName"=>$sale['supName'],
|
|
|
+ "spuCode"=>$sale['good_code'],
|
|
|
+ "skuCode"=>$sale['skuCode'],
|
|
|
+ "good_name"=>$sale['good_name'],
|
|
|
+ "order_type"=>$sale['order_type'],
|
|
|
+ "order_source"=>$sale['order_source'],
|
|
|
+ "num"=>$out['send_num'],
|
|
|
+ "wsm_code"=>$wsmcode,
|
|
|
+ "apply_id"=>$out['apply_id'],
|
|
|
+ "apply_name"=>$out['apply_name'],
|
|
|
+ "addrid"=>$out['addrid'],
|
|
|
+ "post_name"=>$out['post_name'],
|
|
|
+ "post_code"=>$out['post_code'],
|
|
|
+ "post_fee"=>$out['post_fee'],
|
|
|
+ "status"=>"2",
|
|
|
+ "sendtime"=>$out['sendtime'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ $bnin=[];
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+ $sendnum =$out['send_num'];
|
|
|
+ foreach ($bninfo as $item) {
|
|
|
+ if($item['num']>=$sendnum){
|
|
|
+ $temp=$sendnum;
|
|
|
+ $item['num']-=$sendnum;
|
|
|
+ $sendnum=0;
|
|
|
+ }else{
|
|
|
+ $temp= $item['num'];
|
|
|
+ $sendnum-=$item['num'];
|
|
|
+ $item['num']=0;
|
|
|
+ }
|
|
|
+ $bnin[]=[
|
|
|
+ "outChildCode"=>$outchild['outChildCode'],
|
|
|
+ "orderCode"=>$out['orderCode'],
|
|
|
+ "outCode"=>$out['outCode'],
|
|
|
+ "bnCode"=>$item['bnCode'],
|
|
|
+ "num"=>$temp,
|
|
|
+ "origin_price"=>$item['origin_price'],
|
|
|
+ "total_bn_num"=>$temp
|
|
|
+ ];
|
|
|
+ $up = Db::name("sale_info")->where(["id"=>$item['id']])
|
|
|
+ ->inc("change_num",$temp)
|
|
|
+ ->update(["is_change_outbn"=>$item['num']==0?3:2,"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
+ if($up==false) throw new \Exception("订单bn更新失败");
|
|
|
+ if($sendnum==0)break;
|
|
|
+ }
|
|
|
+ $makeChild =Db::name("order_out_child")->insert($outchild);
|
|
|
+ if($makeChild==false) throw new \Exception("发货工单生成失败");
|
|
|
+ $makeBn=Db::name("child_bn")->insertAll($bnin);
|
|
|
+ if($makeBn==false) throw new \Exception("发货工单bn生成失败");
|
|
|
+ $up = Db::name("order_out")->where(["outCode"=>$param['outCode'],"is_del"=>0])->update(["send_status"=>4]);
|
|
|
+ if($up==false) throw new \Exception("发货单更新失败");
|
|
|
+ Db::commit();
|
|
|
+ return app_show(0,"发货工单生成完毕");
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ return error_show(1004,$e->getMessage());
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
}
|