Viewing file: Cron.php (3.6 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Cron extends CI_Controller { public function updatePrices($key = null)
{ $this->load->model('admin_model'); $servicesRu = $this->admin_model->db->get_where("services", "auto_price = 1 AND callback LIKE 'smsactivate%'")->result_array(); $services5 = $this->admin_model->db->get_where("services", "auto_price = 1 AND callback LIKE 'fivesim%'")->result_array(); $rub = 0.16; if (in_array($this->config->item("money_sign"), ['TL', 'TRY', '₺', 'tl'])) { $json = file_get_contents('https://dovizkurlari-l6vtviaacq-uc.a.run.app/api/doviz/rub'); $obj = json_decode($json); $rub = $obj->ForexSelling; $rub = floatval($rub) * 1.08; } $api_key = $this->config->item("smsactivate_api_key");
$url = "https://api.sms-activate.org/stubs/handler_api.php?api_key=$api_key&action=getPrices"; $data = json_decode(file_get_contents($url), 1);
foreach($data as $country => $content) { $serv = array_filter($servicesRu, function($d) use ($country) { return explode(',', $d['callback'])[1] == $country; }); foreach($serv as $service) { $s_code = explode(',', $service['callback'])[2]; if(isset($content[$s_code])) { $price = $content[$s_code]['cost'] * $rub; $price += ($price / 100) * floatval($service['rate']); $price = floatval(number_format($price, 2, '.', '')); if($price != $service['price']) { $this->admin_model->updateService($service['name'], $service['category'], $price, $service['callback'], $service['auto_price'], floatval($service['rate']), $service['id']); } } } } echo count($servicesRu) . " sms activate verisi güncellendi..<br/>"; //5sim $url = 'https://5sim.net/v1/guest/prices'; $data = json_decode(file_get_contents($url), 1);
foreach($data as $country => $content) { $serv = array_filter($services5, function($d) use ($country) { return explode(',', $d['callback'])[1] == $country; });
foreach($serv as $service) { $s_code = explode(',', $service['callback'])[2]; if(isset($content[$s_code])) { $serviceOperators = array_filter($content[$s_code], function($s){ return $s['cost'] > 0 && $s['count'] > 100; }); usort($serviceOperators, function ($operator1, $operator2) { if ($operator1['cost'] == $operator2['cost']) return 0; if ($operator1['cost'] < $operator2['cost']) return 1; if ($operator1['cost'] > $operator2['cost']) return -1; }); $price = $serviceOperators[0]['cost'] * $rub; $price += ($price / 100) * floatval($service['rate']); $price = floatval(number_format($price, 2, '.', ''));
if($price != $service['price']) { $this->admin_model->updateService($service['name'], $service['category'], $price, $service['callback'], $service['auto_price'], floatval($service['rate']), $service['id']); } } } } echo count($services5) . " 5sim verisi güncellendi."; }
}
|