|
|
@@ -13,6 +13,7 @@ use App\Services\LogService;
|
|
|
use App\Services\OracleDOCOrderHeaderService;
|
|
|
use App\Services\OrderCommodityService;
|
|
|
use App\Services\OrderService;
|
|
|
+use App\Services\WaveService;
|
|
|
use App\SortingStation;
|
|
|
use App\User;
|
|
|
use App\UserToken;
|
|
|
@@ -63,25 +64,31 @@ class SortingController extends Controller
|
|
|
$token = trim($request->input('token'));
|
|
|
$station_id = $request->input('station_id');
|
|
|
$batch_id = $request->input('batch_id');
|
|
|
+ app('LogService')->log("浩创", "process", '分拨墙播种请求:'.json_encode($request->all()));
|
|
|
|
|
|
// 二次分拣拆分波次
|
|
|
$childIndex = null;
|
|
|
- $arr = explode('-',$batch_id);
|
|
|
- if (count($arr)==2){
|
|
|
- $batch_id = $arr[0];
|
|
|
- $childIndex = (int)$arr[1];
|
|
|
- $request->offsetSet("batch_id",$batch_id);
|
|
|
- }
|
|
|
+
|
|
|
+ $ownerId = null;// 货主ID
|
|
|
+ $warehouseId = null;// 仓库ID
|
|
|
+ $number = 0;// 总拣数量
|
|
|
// 容器号获取波次
|
|
|
if (strlen($batch_id) != 13 && substr($batch_id, 0, 1) != 'W') {
|
|
|
// 请求JAVA端获取对应波次号
|
|
|
$url = config('api.java.base').config('api.java.device.picking.getContainerOfWave');
|
|
|
$get = Http::get($url, ["container" => $batch_id]);
|
|
|
$result = $get->json();
|
|
|
- if ($result != 200) {
|
|
|
+ if ($result["code"] != 200) {
|
|
|
return response()->json(['result'=>'failure','fail_info'=>$result["message"]])->setEncodingOptions(JSON_UNESCAPED_UNICODE);
|
|
|
}
|
|
|
$request->offsetSet("batch_id",$result["data"]);
|
|
|
+ } else {
|
|
|
+ $arr = explode('-',$batch_id);
|
|
|
+ if (count($arr)==2){
|
|
|
+ $batch_id = $arr[0];
|
|
|
+ $childIndex = (int)$arr[1];
|
|
|
+ $request->offsetSet("batch_id",$batch_id);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$errors=$this->processValidator($request->all())->errors();
|
|
|
@@ -118,11 +125,18 @@ SQL;
|
|
|
$ordersSorted=$orders->sortBy(function(Order $order){
|
|
|
return $order->bin->number;
|
|
|
});
|
|
|
- $ordersSorted->each(function(Order $order)use(&$data,$request,$childIndex,$batch){
|
|
|
+ $ordersSorted->each(function(Order $order)use(&$data,$request,$childIndex,$batch,&$ownerId,&$warehouseId,&$number){
|
|
|
if($order['status']=='取消')return;
|
|
|
+ $owner = $order->owner;
|
|
|
+ if ($ownerId == null && $owner != null) {
|
|
|
+ $ownerId = $owner->id;
|
|
|
+ }
|
|
|
+ if ($warehouseId == null) {
|
|
|
+ $warehouseId = $order['warehouse_id'];
|
|
|
+ }
|
|
|
$orderData=[
|
|
|
'order_id'=>$order['code'],
|
|
|
- 'owner'=>$order->owner->code,
|
|
|
+ 'owner'=>$owner->code,
|
|
|
'status'=>$order['status']=='未处理'?'available':$order['status'],
|
|
|
'created_at'=>$order['created_at']->toDateTimeString(),
|
|
|
'bin'=>(function()use($order,$childIndex,$batch){
|
|
|
@@ -136,7 +150,7 @@ SQL;
|
|
|
})(),
|
|
|
'barcodes'=>[]
|
|
|
];
|
|
|
- $order->orderCommodities->each(function(OrderCommodity $orderCommodity)use(&$orderData,$request){
|
|
|
+ $order->orderCommodities->each(function(OrderCommodity $orderCommodity)use(&$orderData,$request,&$number){
|
|
|
$commodity=$orderCommodity->commodity;
|
|
|
if(!$commodity){
|
|
|
app('LogService')->log(__METHOD__, 'error' . __FUNCTION__, '播种位数据准备出错,找不到订单对应的Commodity id的对象'.$orderCommodity['commodity_id'].',是否表数据在波次生成后丢失?'.json_encode($request->all()));
|
|
|
@@ -147,6 +161,7 @@ SQL;
|
|
|
})->filter(function($code){
|
|
|
return $code&&(!preg_match('/[\x{4e00}-\x{9fa5}]/u',$code));
|
|
|
})->join(',');
|
|
|
+ $number += (int)$orderCommodity['amount'] ?? 0;
|
|
|
$orderData['barcodes'][]=[
|
|
|
'id'=>$orderCommodity['id']??'',
|
|
|
'barcode_id'=>$barcodeStr??'',
|
|
|
@@ -167,6 +182,10 @@ SQL;
|
|
|
|
|
|
$station = SortingStation::findOrCreate($station_id);
|
|
|
$station->setProcessingBatch($batch);
|
|
|
+
|
|
|
+ $messageId = $batch_id.($childIndex == null ? '' : '#'.$childIndex);
|
|
|
+ (new WaveService())->sendPiece("HC-ST-".$messageId, UserToken::getUser($token)->id ?? '0', $ownerId,
|
|
|
+ $warehouseId, date("Y-m-d H:i:s"), $number);
|
|
|
return $data;
|
|
|
}
|
|
|
|