cache Voucher stocks for 5 Minutes
This commit is contained in:
parent
1e0b246d74
commit
5921fef67e
@ -78,29 +78,40 @@ $ui->assign('dlog', $dlog);
|
|||||||
$log = ORM::for_table('tbl_logs')->count();
|
$log = ORM::for_table('tbl_logs')->count();
|
||||||
$ui->assign('log', $log);
|
$ui->assign('log', $log);
|
||||||
|
|
||||||
// Count stock
|
|
||||||
$tmp = $v = ORM::for_table('tbl_plans')->select('id')->select('name_plan')->find_many();
|
$cacheStocksfile = File::pathFixer('system/cache/VoucherStocks.temp');
|
||||||
$plans = array();
|
$cachePlanfile = File::pathFixer('system/cache/VoucherPlans.temp');
|
||||||
$stocks = array("used" => 0, "unused" => 0);
|
//Cache for 5 minutes
|
||||||
$n = 0;
|
if(file_exists($cacheStocksfile) && time()- filemtime($cacheStocksfile) < 600){
|
||||||
foreach ($tmp as $plan) {
|
$stocks = json_decode(file_get_contents($cacheStocksfile), true);
|
||||||
$unused = ORM::for_table('tbl_voucher')
|
$plans = json_decode(file_get_contents($cachePlanfile), true);
|
||||||
->where('id_plan', $plan['id'])
|
}else{
|
||||||
->where('status', 0)->count();
|
// Count stock
|
||||||
$used = ORM::for_table('tbl_voucher')
|
$tmp = $v = ORM::for_table('tbl_plans')->select('id')->select('name_plan')->find_many();
|
||||||
->where('id_plan', $plan['id'])
|
$plans = array();
|
||||||
->where('status', 1)->count();
|
$stocks = array("used" => 0, "unused" => 0);
|
||||||
if ($unused > 0 || $used > 0) {
|
$n = 0;
|
||||||
$plans[$n]['name_plan'] = $plan['name_plan'];
|
foreach ($tmp as $plan) {
|
||||||
$plans[$n]['unused'] = $unused;
|
$unused = ORM::for_table('tbl_voucher')
|
||||||
$plans[$n]['used'] = $used;
|
->where('id_plan', $plan['id'])
|
||||||
$stocks["unused"] += $unused;
|
->where('status', 0)->count();
|
||||||
$stocks["used"] += $used;
|
$used = ORM::for_table('tbl_voucher')
|
||||||
$n++;
|
->where('id_plan', $plan['id'])
|
||||||
|
->where('status', 1)->count();
|
||||||
|
if ($unused > 0 || $used > 0) {
|
||||||
|
$plans[$n]['name_plan'] = $plan['name_plan'];
|
||||||
|
$plans[$n]['unused'] = $unused;
|
||||||
|
$plans[$n]['used'] = $used;
|
||||||
|
$stocks["unused"] += $unused;
|
||||||
|
$stocks["used"] += $used;
|
||||||
|
$n++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
file_put_contents($cacheStocksfile, json_encode($stocks));
|
||||||
|
file_put_contents($cachePlanfile, json_encode($plans));
|
||||||
}
|
}
|
||||||
|
|
||||||
$cacheMRfile = File::pathFixer('system/cache/monthlyRegistered.json');
|
$cacheMRfile = File::pathFixer('system/cache/monthlyRegistered.temp');
|
||||||
//Cache for 1 hour
|
//Cache for 1 hour
|
||||||
if(file_exists($cacheMRfile) && time()- filemtime($cacheMRfile) < 3600){
|
if(file_exists($cacheMRfile) && time()- filemtime($cacheMRfile) < 3600){
|
||||||
$monthlyRegistered = json_decode(file_get_contents($cacheMRfile), true);
|
$monthlyRegistered = json_decode(file_get_contents($cacheMRfile), true);
|
||||||
@ -123,7 +134,7 @@ if(file_exists($cacheMRfile) && time()- filemtime($cacheMRfile) < 3600){
|
|||||||
file_put_contents($cacheMRfile, json_encode($monthlyRegistered));
|
file_put_contents($cacheMRfile, json_encode($monthlyRegistered));
|
||||||
}
|
}
|
||||||
|
|
||||||
$cacheMSfile = File::pathFixer('system/cache/monthlySales.json');
|
$cacheMSfile = File::pathFixer('system/cache/monthlySales.temp');
|
||||||
//Cache for 12 hours
|
//Cache for 12 hours
|
||||||
if(file_exists($cacheMSfile) && time()- filemtime($cacheMSfile) < 43200){
|
if(file_exists($cacheMSfile) && time()- filemtime($cacheMSfile) < 43200){
|
||||||
$monthlySales = json_decode(file_get_contents($cacheMSfile), true);
|
$monthlySales = json_decode(file_get_contents($cacheMSfile), true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user