ShippingChargeService.php 878 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Services\Shop;
  3. class ShippingChargeService
  4. {
  5. public function calc($shippingChargeDefaultSetup, $sub_total)
  6. {
  7. $setup = json_decode($shippingChargeDefaultSetup['C1'], true);
  8. switch ($shippingChargeDefaultSetup['C2']) {
  9. case 'amt':
  10. return $this->amtType($setup, $sub_total);
  11. case 'free':
  12. return $this->freeType($setup, $sub_total);
  13. }
  14. }
  15. public function amtType($setup, $sub_total)
  16. {
  17. $chargeAmt = 0;
  18. foreach ($setup['ShippingChargeBase'] ?? [] as $base) {
  19. if ($base['From'] <= $sub_total && $base['To'] > $sub_total) {
  20. $chargeAmt = $base['ChargeAmt'];
  21. break;
  22. }
  23. }
  24. return $chargeAmt;
  25. }
  26. public function freeType($setup, $sub_total)
  27. {
  28. return 0;
  29. }
  30. }