ForeignZhenCangService.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Services;
  3. use App\Traits\ServiceAppAop;
  4. use Carbon\Carbon;
  5. use Illuminate\Support\Facades\Http;
  6. class ForeignZhenCangService
  7. {
  8. use ServiceAppAop;
  9. // protected $modelClass=ForeignZhenCang::class;
  10. public function broadcastBatch($batches)
  11. {
  12. $body=[];
  13. $body['id']=$batches->code;
  14. $body['slots'] = [];
  15. foreach ($batches->orders as $order){
  16. $orderArr = [];
  17. foreach ($order->orderCommodities as $orderCommodity){
  18. $orderArr['id']=$orderCommodity->location??'';
  19. $orderArr['sku']=$orderCommodity->commodity->sku??'';
  20. $orderArr['barcode']=$orderCommodity->commodity ? ($orderCommodity->commodity->barcodes?$orderCommodity->commodity->barcodes->first()['code']:'') : '';
  21. $orderArr['name']=$orderCommodity->commodity->name??'';
  22. $orderArr['amount']=$orderCommodity->amount??'';
  23. }
  24. $body['slots'][] = $orderArr;
  25. }
  26. $result=array();
  27. foreach($body['slots'] as $val){
  28. $key = $val['id'].'_'.$val['barcode'];
  29. if(!isset($result[$key])){
  30. $result[$key] = $val;
  31. }else{
  32. $result[$key]['amount'] += $val['amount'];
  33. }
  34. }
  35. $body['slots']=array_values($result);
  36. $response = Http::post('http://zc-it.cn/api/createBatch',$body);
  37. }
  38. }