NB-KMC / interview-php

0 stars 1 forks source link

gist #1

Open xoinstein opened 2 months ago

aeiac commented 1 month ago

https://gist.github.com/aeiac/2c6803a626c5ab4ed3c9e91a8f47b806

tangruiok commented 1 month ago

https://gist.github.com/tangruiok/75d0890cfc5e8e4dab63c3b85dca23c3

y1j2t commented 1 month ago

https://gist.github.com/y1j2t/8de067a0a6145ab0ba2c825bf38278fd

silenceSirius commented 1 month ago

protected function newGetCode($storehouse, $info, $config) { $usArea = $storehouse['us_area']; $storehouseName = $storehouse['name']; $weight = $info['weight']; $type = $info['type'];

$areaConfig = $this->getAreaConfig($usArea, $storehouseName, $config);
$defaults = $this->getDefaultCodes($usArea, $storehouseName);

return $this->determineCode($areaConfig, $weight, $type, $defaults);

}

private function getAreaConfig($usArea, $storehouseName, $config) { if ($usArea == StorehouseConstant::US_WEST) { return $config['US_WEST']['normal']; } elseif ($usArea == StorehouseConstant::US_SOUTH) { return $storehouseName == 'KC-GA2' ? $config['US_SOUTH']['GA'] : $config['US_SOUTH']['normal']; } else { return $config['US_EAST']['normal']; } }

private function getDefaultCodes($usArea, $storehouseName) { if ($usArea == StorehouseConstant::US_WEST) { return [ 'oversize' => 'FEDEXOVERSIZE', 'ahs_weight' => 'FEDEX-OS-GROUND', 'weight_range' => 'FEDEX-WEIGHT-HOME', 'ahs' => 'FEDEX-WEIGHT-HOME', 'normal' => 'FEDEX-HOMEDELIVERY', 'ups' => 'UPSGROUND' ]; } elseif ($usArea == StorehouseConstant::US_SOUTH) { if ($storehouseName == 'KC-GA2') { return [ 'oversize' => 'FEDEXOVERSIZE', 'ahs_weight' => 'GASA-FEDEX-GROUND', 'weight_range' => 'GASA-FEDEX-HD', 'ahs' => 'GASA-FEDEX-HD', 'normal' => 'FEDEX-HOMEDELIVERY', 'ups' => 'UPSGROUND' ]; } else { return [ 'oversize' => 'GANW-FEDEX-HD', 'normal' => 'GANW-FEDEX-GROUND' ]; } } else { return [ 'oversize' => 'FEDEXOVERSIZE', 'ahs_weight' => 'FEDEX-GROUND', 'weight_range' => 'FEDEX-HD-NJ', 'ahs' => 'FEDEX-HD-NJ', 'normal' => 'FEDEX-HOMEDELIVERY', 'ups' => 'UPSGROUND' ]; } }

private function determineCode($config, $weight, $type, $defaults) { if (in_array($type, [3, 4])) { return $config['oversize'] ?? $defaults['oversize']; } elseif ($weight > 70) { return $config['ahs_weight'] ?? $defaults['ahs_weight']; } elseif ($weight >= 47 && $weight <= 70) { return $config['weight_range'] ?? $defaults['weight_range']; } elseif ($type == 1) { return $config['ahs'] ?? $defaults['ahs']; } elseif ($weight >= 16 && $weight <= 46) { return $config['normal'] ?? $defaults['normal']; } else { return $config['ups'] ?? $defaults['ups']; } }

/**

/**