LogisticService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Services;
  3. use App\Logistic;
  4. use App\OracleBasCustomer;
  5. use Illuminate\Support\Facades\Auth;
  6. Class LogisticService
  7. {
  8. public function getSelection($column = ['id','name']){
  9. return Logistic::query()->select($column)->get();
  10. }
  11. public function getWASLogisticsByWMSOrderHeaders($WMSOrderHeaders){
  12. $carrierIds = [];
  13. foreach ($WMSOrderHeaders as $WMSOrderHeader) {
  14. array_push($carrierIds,$WMSOrderHeader['carrierid']);
  15. }
  16. $carrierIds = array_unique($carrierIds);
  17. $carrierIds = array_diff($carrierIds,['*','',null]);
  18. $logistics = Logistic::query()->whereIn('code',$carrierIds)->get();
  19. $fillables = [];
  20. if(count($carrierIds) > count($logistics)){
  21. $logistics_fillter= data_get($logistics,'*.code');
  22. $logisticDiff = array_diff($carrierIds, $logistics_fillter);
  23. $basCustomers = OracleBasCustomer::query()->where('Customer_Type','CA')->whereIn('CustomerID',$logisticDiff)->get();
  24. foreach ($basCustomers as $basCustomer){
  25. $fillable = ['name' => $basCustomer['descr_c'], 'code' => $basCustomer['customerid']];
  26. array_push($fillables,$fillable);
  27. }
  28. }
  29. try {
  30. if(count($fillables) > 0){
  31. Logistic::query()->insert($fillables);
  32. LogService::log(__METHOD__,__FUNCTION__,'批量创建'.json_encode($fillables));
  33. }
  34. } catch (\Exception $e) {
  35. LogService::log(__METHOD__,__FUNCTION__,'创建失败「' .json_encode($fillables). $e->getMessage().$e->getTraceAsString());
  36. } finally {
  37. return $logistics = Logistic::query()->whereIn('code',$carrierIds)->get();
  38. }
  39. }
  40. public function firstOrCreate(array $params, array $values = null){
  41. $logistic = Logistic::query();
  42. if ($values)return $logistic->firstOrCreate($params, $values);
  43. return $logistic->firstOrCreate($params);
  44. }
  45. }