0){ $data['expired'] = time() + 300; Cache::set($cacheKey, $data, time() + 300); } } return $rate>0? floatval($rate * $amount) : $amount; } /** * 转换汇率金额(卢比) * @param $amount * @param string $from * @param string $to * @return float|mixed */ public static function transferRp($amount, $from='CNY', $to='IDR') { if(empty($from) || empty($to)){ return $amount; } $cacheKey = "cache:rates:{$from}_{$to}"; $data = Cache::get($cacheKey); $rate = isset($data['rate'])? floatval($data['rate']) : 0.00; $expired = isset($data['expired'])? intval($data['expired']) : 0; if($rate<=0 || $expired 0){ $data['expired'] = time() + 300; Cache::set($cacheKey, $data, time() + 300); } } return $rate>0? floatval($rate * $amount) : $amount; } /** * 转换汇率金额 * @param $amount * @param string $from * @param string $to * @return float|mixed */ public static function getRate($from='CNY', $to='USD') { $cacheKey = "cache:rates:{$from}_{$to}"; $data = Cache::get($cacheKey); $rate = isset($data['rate'])? floatval($data['rate']) : 0.00; $expired = isset($data['expired'])? intval($data['expired']) : 0; if($rate<=0 || $expired 0){ $data['expired'] = time() + 300; Cache::set($cacheKey, $data, time() + 300); } } return $rate; } } ?>