log(__METHOD__,__FUNCTION__,'WMS requesting:.'.'|'.json_encode($request->all())); $errors=$this->validatorForNew($request->all())->errors(); if(count($errors)>0){ $this->log(__METHOD__, 'error_' . __FUNCTION__, json_encode($request->getContent())); (new Controller())->log(__METHOD__,'error_'.__FUNCTION__,'fields wrong, see Errors report please.'.'|'.json_encode($request->all()).'|'.json_encode($errors)); return response()->json(['response'=>['return'=>['returnFlag'=>'0','returnCode'=>'0001','returnDesc'=>'消息处理失败:Failure','resultInfo'=>'', 'errors'=>$errors]]]) ->setEncodingOptions(JSON_UNESCAPED_UNICODE); } $receivedInputtings=$request->input('request'); foreach ($receivedInputtings as $receiveInputting){ if(!WMSWaybill::create($receiveInputting)){ Controller::logS(__METHOD__,'error_'.__FUNCTION__,'运单WMS写入错误'.'|'.json_encode($receiveInputting)); return response()->json(['response'=>['return'=>['returnFlag'=>'0','returnCode'=>'0001','returnDesc'=>'运单WMS写入错误'.'|' .json_encode($receiveInputting),'resultInfo'=>'']]]) ->setEncodingOptions(JSON_UNESCAPED_UNICODE); } foreach ($receiveInputting['order_list'] as $orderInputting){ $orderInputting['OrderNo']=$receiveInputting['OrderNo']; if(!WMSWaybillOrder::create($orderInputting)){ Controller::logS(__METHOD__,'error_'.__FUNCTION__,'运单订单行WMS写入错误'.'|'.json_encode($orderInputting)); return response()->json(['response'=>['return'=>['returnFlag'=>'0','returnCode'=>'0001','returnDesc'=>'运单订单行WMS写入错误'.'|' .json_encode($orderInputting),'resultInfo'=>'']]]) ->setEncodingOptions(JSON_UNESCAPED_UNICODE); } } $owner=Owner::where('code',$receiveInputting['CustomerID'])->first(); if (!$owner){$owner=new Owner(['name'=>$receiveInputting['CustomerID'],'code'=>$receiveInputting['CustomerID']]);$owner->save();} $city=City::where('name',$receiveInputting['C_City'])->first(); $zfCar=config('bszf.ZFList'); $waybill=new Waybill([ 'type'=>isset($zfCar[$receiveInputting['CarrierID']])&&$zfCar[$receiveInputting['CarrierID']]?"直发车":"专线", 'waybill_number'=>Uuid::uuid1(), 'owner_id'=>$owner->id, 'wms_bill_number'=>$receiveInputting['OrderNo'], 'origination'=>"上海市松江区泗砖路351号宝时松江仓", 'destination'=>$receiveInputting['C_Address1'], 'recipient'=>$receiveInputting['ConsigneeName'], 'recipient_mobile'=>$receiveInputting['C_Tel'], 'destination_city_id'=>$city['id'], ]); $waybill->save(); if ($waybill->type=='直发车'){ $waybill_number='BSZF'.date ("ymd").str_pad($waybill->id>99999?$waybill->id%99999:$waybill->id,4,"0",STR_PAD_LEFT); $waybill->waybill_number=$waybill_number; $waybill->update(); }else{ $waybill_number='BSZX'.date ("ymd").str_pad($waybill->id>99999?$waybill->id%99999:$waybill->id,4,"0",STR_PAD_LEFT); $waybill->waybill_number=$waybill_number; $waybill->update(); } } return response()->json(['response'=>['return'=>['returnFlag'=>'1','returnCode'=>'0000','returnDesc'=>'正确接收','resultInfo'=>'']]]) ->setEncodingOptions(JSON_UNESCAPED_UNICODE); } protected function validatorForNew(array $data) { return Validator::make($data, [ 'request' => ['required', 'array', 'min:1'], 'request.*.OrderNo' => ['required', 'string', 'max:191','unique:w_m_s_waybills,OrderNo'], 'request.*.CustomerID' => ['required', 'string', 'max:191'], 'request.*.CarrierID' => ['required', 'string', 'max:191'], 'request.*.ConsigneeName' => ['nullable', 'string', 'max:191'], 'request.*.C_Tel' => ['nullable', 'string', 'max:191'], 'request.*.C_Address1' => ['required', 'string', 'max:191'], 'request.*.C_Province' => ['required', 'string', 'max:191'], 'request.*.C_City' => ['nullable', 'string', 'max:191'], 'request.*.C_District' => ['nullable', 'string', 'max:191'], 'request.*.order_list' => ['required', 'array', 'min:1'], 'request.*.order_list.*.SKU_Descr_c' => ['nullable', 'string', 'max:191'], 'request.*.order_list.*.SKU' => ['required', 'string', 'max:191'], 'request.*.order_list.*.Alternate_sku1' => ['required', 'string', 'max:191'], 'request.*.order_list.*.Qtyordered_each' => ['required', 'string', 'max:191'], 'request.*.order_list.*.Cubic' => ['nullable', 'string', 'max:191'], 'request.*.order_list.*.GrossWeight' => ['nullable', 'string', 'max:191'], 'request.*.order_list.*.NetWeight' => ['nullable', 'string', 'max:191'], ]); } public function accomplishToWMS(Waybill $waybill) { $json=" { \"request\": [ { \"OrderNo\": \"{$waybill['wms_bill_number']}\", \"DELIVERYNO\": \"{$waybill['waybill_number']}\" } ] } "; $sendingJson = json_decode($json,true); $url=url(config('api.flux.waybill.new')); $response = Zttp::post($url, $sendingJson); $responseJson = $response->json(); if(!$responseJson||!isset($responseJson['Response'])||!$responseJson['Response']['return']['returnFlag']=='1'){ Controller::logS(__METHOD__,'error_'.__FUNCTION__,"向WMS提交运单失败!!SO单号:{$waybill['wms_bill_number']}。提交:{$json},返回:{$response->body()}, URL:{$url}",Auth::user()['id']); return false; } Controller::logS(__METHOD__,''.__FUNCTION__,"向WMS提交运单成功,SO单号:{$waybill['wms_bill_number']}。返回:{$response->body()}",Auth::user()['id']); return true; } }