Files
cm-web-legacy/application/controllers/admin/delete.later/cron_ep_view_ranking.php
2020-06-10 06:19:03 +09:00

89 lines
3.2 KiB
PHP
Executable File

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
* 맵툰 스케줄 1시간 마다 실행 됨
*/
class cron_ep_view_ranking extends CI_Controller {
#---------------------------------------------------------------------------
# PURPOSE : 실시간 맵툰 에피소드 조회 순위 등록
# CREATE : 2019-03-26
#---------------------------------------------------------------------------
// function maptoon_view_rank_update() {
function index() {
if (!is_dir('./logs/cron_mt_ep_ranking/'.date("Ym"))) mkdir('./logs/cron_mt_ep_ranking/'.date("Ym"), 0777, TRUE); //log file 생성
$contents = 'log description';
# file helper
$this->load->helper('file');
$contents = '['.date("Y-m-d H:i:s").'] mt_ep_ranking_work start'.chr(10);
# model -create rank array
$this->load->database();
$num=0;
$_time=1;
$result;
while($num==0){
$result=$this->db->query("SELECT * FROM mt_ep_hit_log WHERE reg_date>=\"".date("Y-m-d H:i:s",strtotime ("-$_time hours"))."\" Order by ep_idx");
$num=$result->num_rows();
$_time++;
}
$row=$result->result_array();
$rank_list=array();
$y=0;
$ep_idx=0;
foreach($row as $val){
if($ep_idx!=$val['ep_idx']){
$ep_idx=$val['ep_idx'];
$y=0;
}
array_push($rank_list,$ep_idx);
}
$rank_list=array_count_values($rank_list);
arsort($rank_list); //ep_idx view count sort
$ep_idx_rank_list=array_keys($rank_list); // only ep_idx array;
$insert_date=array();
$rank=1;//순위
foreach($ep_idx_rank_list as $val){
array_push($insert_date,array('ep_idx'=>$val,'rank'=>$rank));
$rank++;
}
if(count($ep_idx_rank_list)<10){
$result=$this->db->query("SELECT * FROM mt_episodes ORDER BY reg_date DESC limit 10");
$row = $result->result_array();
foreach($row as $val){
$is_same=false;
foreach($ep_idx_rank_list as $val2){
if($val['idx']==$val2){
$is_same=true;
}
}
if(!$is_same){ array_push($insert_date,array('ep_idx'=>$val['idx'],'rank'=>$rank)); $rank++;}
if(count($insert_date)==10){break;}
}
};
print_r($row);
# insert_data;
$this->db->insert_batch("mt_ep_view_rank",$insert_date);
$contents.= date("Y-m-d H:i:s",strtotime ("-$_time hours")).' 업데이트 완료'.chr(10);
$contents.= '['.date("Y-m-d H:i:s").'] episode veiw count ranking end'.chr(10);
$contents.= '-------------------------------------------------------------------------------------'.chr(10);
write_file('./logs/cron_mt_ep_ranking/'.date("Ym").'/'.date("Ymd").'.php', $contents, 'a+');
}
function epsiode_reservation(){
$this->load->model('maptoon/m_maptoon');
$result = $this->m_maptoon->get_epsiode_reservation_list();
print_r($result);
}
}
?>