| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace App\Services;
- use App\Traits\ServiceAppAop;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Http;
- class ForeignZhenCangService
- {
- use ServiceAppAop;
- // protected $modelClass=ForeignZhenCang::class;
- public function broadcastBatch($batches)
- {
- $body=[];
- $body['id']=$batches->code;
- $body['slots'] = [];
- foreach ($batches->orders as $order){
- $orderArr = [];
- foreach ($order->orderCommodities as $orderCommodity){
- $orderArr['id']=$orderCommodity->location??'';
- $orderArr['sku']=$orderCommodity->commodity->sku??'';
- $orderArr['barcode']=$orderCommodity->commodity ? ($orderCommodity->commodity->barcodes?$orderCommodity->commodity->barcodes->first()['code']:'') : '';
- $orderArr['name']=$orderCommodity->commodity->name??'';
- $orderArr['amount']=$orderCommodity->amount??'';
- }
- $body['slots'][] = $orderArr;
- }
- $result=array();
- foreach($body['slots'] as $val){
- $key = $val['id'].'_'.$val['barcode'];
- if(!isset($result[$key])){
- $result[$key] = $val;
- }else{
- $result[$key]['amount'] += $val['amount'];
- }
- }
- $body['slots']=array_values($result);
- $response = Http::post('http://zc-it.cn/api/createBatch',$body);
- }
- }
|