Permalink
Browse files

switch 計算運費

  • Loading branch information...
1 parent 6a2c6c4 commit c6bac6e69c5da414daed040ca2c286fc3d466063 Sam.IO.Hsiao committed Nov 27, 2016
Showing with 29 additions and 24 deletions.
  1. +29 −24 app/Services/ShippingService.php
@@ -14,30 +14,35 @@ public function calculateFee(array $weightArray, string $companyName): int
{
$amount = 0;
- if ($companyName == 'BlackCat') {
- $weights = collect($weightArray);
-
- foreach ($weights as $weight) {
- $amount = $amount + (100 + $weight * 10);
- }
- } elseif ($companyName == 'Hsinchu') {
- $weights = collect($weightArray);
-
- foreach ($weights as $weight) {
- $amount = $amount + (80 + $weight * 15);
- }
- } else if ($companyName == 'PostOffice') {
- $weights = collect($weightArray);
-
- foreach ($weights as $weight) {
- $amount = $amount + (60 + $weight * 20);
- }
- } else {
- $weights = collect($weightArray);
-
- foreach ($weights as $weight) {
- $amount = $amount + (100 + $weight * 10);
- }
+ switch ($companyName) {
+ case 'BlackCat':
+ $weights = collect($weightArray);
+
+ foreach ($weights as $weight) {
+ $amount = $amount + (100 + $weight * 10);
+ }
+ break;
+ case 'Hsinchu':
+ $weights = collect($weightArray);
+
+ foreach ($weights as $weight) {
+ $amount = $amount + (80 + $weight * 15);
+ }
+ break;
+ case 'PostOffice':
+ $weights = collect($weightArray);
+
+ foreach ($weights as $weight) {
+ $amount = $amount + (60 + $weight * 20);
+ }
+ break;
+ default:
+ $weights = collect($weightArray);
+
+ foreach ($weights as $weight) {
+ $amount = $amount + (100 + $weight * 10);
+ }
+ break;
}
return $amount;

0 comments on commit c6bac6e

Please sign in to comment.