|
|
@@ -158,10 +158,95 @@ class TestController extends Controller
|
|
|
dd("方法不存在");
|
|
|
}
|
|
|
}
|
|
|
+ function process(Request $request){
|
|
|
+ $token = trim($request->input('token'));
|
|
|
+ $station_id = 'test';
|
|
|
+ $batch_id = 'W211111001514-6';
|
|
|
+
|
|
|
+ $childIndex = null;
|
|
|
+ $arr = explode('-',$batch_id);
|
|
|
+ if (count($arr)==2){
|
|
|
+ $batch_id = $arr[0];
|
|
|
+ $childIndex = (int)$arr[1];
|
|
|
+ $request->offsetSet("batch_id",$batch_id);
|
|
|
+ }
|
|
|
|
|
|
+ /** @var Batch|\stdClass $batch */
|
|
|
+ $batch=Batch::query()->where('code',$batch_id)->orderBy('id','desc')->first();
|
|
|
+ $data=[
|
|
|
+ 'result'=>'success',
|
|
|
+ 'station_id'=>$station_id,
|
|
|
+ 'batch_id'=>$batch_id,
|
|
|
+ 'orders'=>[]
|
|
|
+ ];
|
|
|
+ if ($childIndex!==null && $batch->split_size){
|
|
|
+ $start = (($childIndex-1)*$batch->split_size)+1;
|
|
|
+ $end = $childIndex*$batch->split_size;
|
|
|
+ $sql = <<<SQL
|
|
|
+SELECT ORDERNO
|
|
|
+FROM (SELECT T.ORDERNO, ROWNUM AS NO
|
|
|
+FROM (SELECT ORDERNO FROM DOC_WAVE_DETAILS WHERE WAVENO = '{$batch_id}' ORDER BY SEQNO) T)
|
|
|
+WHERE NO BETWEEN {$start} AND {$end}
|
|
|
+SQL;
|
|
|
+ dd($sql);
|
|
|
+ $waves = DB::connection("oracle")->select(DB::raw($sql));
|
|
|
+ $codes = array_column($waves,'orderno');
|
|
|
+ $orders = Order::query()->with(["bin","owner","orderCommodities.commodity.barcodes"])->whereIn("code",$codes)->get();
|
|
|
+ }else $orders = $batch->orders()->with(["bin","owner","orderCommodities.commodity.barcodes"])->get();
|
|
|
+
|
|
|
+ $ordersSorted=$orders->sortBy(function(Order $order){
|
|
|
+ return $order->bin->number;
|
|
|
+ });
|
|
|
+ $ordersSorted->each(function(Order $order)use(&$data,$request,$childIndex,$batch){
|
|
|
+ if($order['status']=='取消')return;
|
|
|
+ $orderData=[
|
|
|
+ 'order_id'=>$order['code'],
|
|
|
+ 'owner'=>$order->owner->code,
|
|
|
+ 'status'=>$order['status']=='未处理'?'available':$order['status'],
|
|
|
+ 'created_at'=>$order['created_at']->toDateTimeString(),
|
|
|
+ 'bin'=>(function()use($order,$childIndex,$batch){
|
|
|
+ $bin=$order->bin->number??'';
|
|
|
+ if(!$bin){
|
|
|
+ $bin=OracleDOCWaveDetails::query()->where('orderno', 'SO201230003574')->get('seqno')->first()['seqno']??'';
|
|
|
+ LogService::log(__METHOD__,__FUNCTION__,'bin缺失补查:'.$bin.'. order:'.$order->toJson());
|
|
|
+ return $childIndex!==null ? $bin-(($childIndex-1)*$batch->split_size) : $bin;
|
|
|
+ }
|
|
|
+ return $childIndex!==null ? $bin-(($childIndex-1)*$batch->split_size) : $bin;
|
|
|
+ })(),
|
|
|
+ 'barcodes'=>[]
|
|
|
+ ];
|
|
|
+ $order->orderCommodities->each(function(OrderCommodity $orderCommodity)use(&$orderData,$request){
|
|
|
+ $commodity=$orderCommodity->commodity;
|
|
|
+ if(!$commodity){
|
|
|
+ app('LogService')->log(__METHOD__, 'error' . __FUNCTION__, '播种位数据准备出错,找不到订单对应的Commodity id的对象'.$orderCommodity['commodity_id'].',是否表数据在波次生成后丢失?'.json_encode($request->all()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $barcodeStr=$commodity->barcodes->map(function(CommodityBarcode $barcode){
|
|
|
+ return $barcode['code'];
|
|
|
+ })->filter(function($code){
|
|
|
+ return $code&&(!preg_match('/[\x{4e00}-\x{9fa5}]/u',$code));
|
|
|
+ })->join(',');
|
|
|
+ $orderData['barcodes'][]=[
|
|
|
+ 'id'=>$orderCommodity['id']??'',
|
|
|
+ 'barcode_id'=>$barcodeStr??'',
|
|
|
+ 'name'=>$commodity['name']??'',
|
|
|
+ 'sku'=>$commodity['sku']??'',
|
|
|
+ 'amount'=>$orderCommodity['amount']??'',
|
|
|
+ 'location'=>$orderCommodity['location']??'',
|
|
|
+ ];
|
|
|
+ });
|
|
|
+ $data['orders'][]=$orderData;
|
|
|
+ });
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
|
|
|
public function test(Request $request)
|
|
|
{
|
|
|
+ dd(1);
|
|
|
+
|
|
|
+ dd($this->process($request));
|
|
|
+ $batch = Batch::query()->where("code","W211111001514")->first();
|
|
|
+ dd($batch->orders()->with("bin")->first());
|
|
|
$path = '';
|
|
|
$id = 109;
|
|
|
|