LogisticTimingService.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Services;
  3. use App\Logistic;
  4. use App\LogisticTiming;
  5. use App\Province;
  6. Class LogisticTimingService
  7. {
  8. /**
  9. * @param string $cityName
  10. * @param string $provinceName
  11. * @param string $logisticName
  12. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  13. */
  14. public function findByParams($cityName,$provinceName,$logisticId)
  15. {
  16. $logistic = Logistic::query()->where('id',$logisticId)->first();
  17. if( str_starts_with($logistic->name,'顺丰')){
  18. $city = app(CityService::class)->findByName($cityName);
  19. $province = app(ProvinceService::class)->findByName($provinceName);
  20. if(isset($city) && isset($province)){
  21. return $this->findByCityIdAndProvinceIdAndLogisticName($city->id,$province->id,$logisticId);
  22. }
  23. return null;
  24. }
  25. $city = app(CityService::class)->findByName($cityName);
  26. $province = app(ProvinceService::class)->findByName($provinceName);
  27. if($city == null|| $province==null)return null;
  28. return $this->findByCityIdAndProvinceIdAndLogisticName($city->id,$province->id,$logisticId);
  29. }
  30. public function findByCityIdAndProvinceIdAndLogisticName($cityId,$provinceId,$logisticId)
  31. {
  32. return LogisticTiming::query()->where('to_province_id',$provinceId)->where('to_city_id',$cityId)->where('logistic_id',$logisticId)->first();
  33. }
  34. }