Commit 9828719e by Phạm Văn Đoan

cập nhật hiển thị thứ hạng

parent 9bed8390
...@@ -24,6 +24,9 @@ class CmsRanking extends CI_Controller ...@@ -24,6 +24,9 @@ class CmsRanking extends CI_Controller
$this->load->model('crawler_listen_history_model'); $this->load->model('crawler_listen_history_model');
} }
/**
* BXH theo ngày ---------------------------------------------------------------------------------------------------
*/
public function listByDaily() public function listByDaily()
{ {
$this->_data['functionName'] = 'BXH Theo ngày'; $this->_data['functionName'] = 'BXH Theo ngày';
...@@ -48,6 +51,7 @@ class CmsRanking extends CI_Controller ...@@ -48,6 +51,7 @@ class CmsRanking extends CI_Controller
$totalRecord = $this->report_views_daily_model->cmsCountAll($fByName); $totalRecord = $this->report_views_daily_model->cmsCountAll($fByName);
$data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId); $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
$data['listData'] = $this->report_views_daily_model->cmsGetPagination($limit, $offset, $fByName); $data['listData'] = $this->report_views_daily_model->cmsGetPagination($limit, $offset, $fByName);
$data['previousRanking'] = $this->report_views_daily_model->previousRanking($fByName);
// //
$this->load->view('backend/ajax/cms_ranking/list_by_daily_view', $data); $this->load->view('backend/ajax/cms_ranking/list_by_daily_view', $data);
} }
...@@ -78,9 +82,8 @@ class CmsRanking extends CI_Controller ...@@ -78,9 +82,8 @@ class CmsRanking extends CI_Controller
$totalRecord = $this->report_views_weekly_model->cmsCountAll($fByName); $totalRecord = $this->report_views_weekly_model->cmsCountAll($fByName);
$data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId); $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
$data['listData'] = $this->report_views_weekly_model->cmsGetPagination($limit, $offset, $fByName); $data['listData'] = $this->report_views_weekly_model->cmsGetPagination($limit, $offset, $fByName);
$data['previousRanking'] = $this->report_views_weekly_model->previousRanking($fByName);
// //
// print_r($fByName);
$this->load->view('backend/ajax/cms_ranking/list_by_weekly_view', $data); $this->load->view('backend/ajax/cms_ranking/list_by_weekly_view', $data);
} }
...@@ -110,6 +113,7 @@ class CmsRanking extends CI_Controller ...@@ -110,6 +113,7 @@ class CmsRanking extends CI_Controller
$totalRecord = $this->report_views_monthly_model->cmsCountAll($fByName); $totalRecord = $this->report_views_monthly_model->cmsCountAll($fByName);
$data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId); $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
$data['listData'] = $this->report_views_monthly_model->cmsGetPagination($limit, $offset, $fByName); $data['listData'] = $this->report_views_monthly_model->cmsGetPagination($limit, $offset, $fByName);
$data['previousRanking'] = $this->report_views_monthly_model->previousRanking($fByName);
// //
$this->load->view('backend/ajax/cms_ranking/list_by_monthly_view', $data); $this->load->view('backend/ajax/cms_ranking/list_by_monthly_view', $data);
} }
......
...@@ -802,6 +802,40 @@ class MyHelper ...@@ -802,6 +802,40 @@ class MyHelper
return $html; return $html;
} }
/**
* Hàm lấy thông tin so sánh tuần trước, tháng trước, ngày trước
*
* @param $track_id
* @param $order
* @param $previousRanking
*
* @return string
*/
public static function getRankingCompare($track_id, $order, $previousRanking)
{
$compare = 1000;
if (is_array($previousRanking) && count($previousRanking) > 0) {
if (array_key_exists($track_id, $previousRanking)) {
$old_ranking = $previousRanking[$track_id];
$compare = $old_ranking - $order;
}
}
$resutl = '';
if ($compare == 1000) {
$resutl = '<span>Mới</span>';
} else {
if ($compare < 0) {
$resutl = '<i class="fa fa-caret-down" aria-hidden="true" style="font-size: 20px; color: #f50202"></i>&nbsp;&nbsp;' . abs($compare);
} else if ($compare == 0) {
$resutl = '<i class="fa fa-minus" aria-hidden="true" style="font-size: 20px; color: #999999"></i>';
} else {
$resutl = '<i class="fa fa-caret-up" aria-hidden="true" style="font-size: 20px; color: #22ba4e"></i>&nbsp;&nbsp;' . $compare;
}
}
return $resutl;
}
} }
/* End */ /* End */
\ No newline at end of file
...@@ -50,4 +50,34 @@ class Report_views_daily_model extends CI_Model ...@@ -50,4 +50,34 @@ class Report_views_daily_model extends CI_Model
return $query->result_array(); return $query->result_array();
} }
/**
* Hàm lấy xếp hạng tháng trước để so sánh tăng/giảm hạng
*
* @param $date
* @return array
*/
public function previousRanking($date)
{
$this->db->select('track_id, ranking, month, year');
$this->db->from($this->_table);
if ($date != null) {
$yesterday = date('Y-m-d', strtotime($date) - 86400);
$this->db->where('date', $yesterday);
}
$this->db->where('ranking <=', 100);
$query = $this->db->get();
$data = $query->result_array();
$result = [];
if ($data) {
foreach ($data as $key => $val) {
$result[$val['track_id']] = $val['ranking'];
}
}
return $result;
}
} }
\ No newline at end of file
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
class Report_views_monthly_model extends CI_Model class Report_views_monthly_model extends CI_Model
{ {
protected $_table = 'reports_views_monthly'; protected $_table = 'report_views_monthly_new';
protected $_table_new = 'report_views_monthly_new';
public function __construct(){ public function __construct(){
parent::__construct(); parent::__construct();
...@@ -29,44 +28,72 @@ class Report_views_monthly_model extends CI_Model ...@@ -29,44 +28,72 @@ class Report_views_monthly_model extends CI_Model
track_user.name AS singer_name2, tracks.title AS name_song, track_user.name AS singer_name2, tracks.title AS name_song,
GROUP_CONCAT(track_user.`name` SEPARATOR ",") AS all_name, tracks.art AS art'); GROUP_CONCAT(track_user.`name` SEPARATOR ",") AS all_name, tracks.art AS art');
$this->db->from($this->_table); $this->db->from($this->_table);
$this->db->join('track_user', 'track_user.track_id = reports_views_monthly.track_id', 'left'); $this->db->join('track_user', 'track_user.track_id = ' . $this->_table . '.track_id', 'left');
$this->db->join('tracks', 'tracks.id = reports_views_monthly.track_id', 'left'); $this->db->join('tracks', 'tracks.id = ' . $this->_table . '.track_id', 'left');
$this->db->join('users u1', 'u1.id = track_user.user_id', 'left'); $this->db->join('users u1', 'u1.id = track_user.user_id', 'left');
if($name != null) { if($name != null) {
$data = explode('-', $name); $data = explode('-', $name);
$this->db->where('month', $data[0]); $this->db->where('month', $data[0]);
$this->db->where('year', $data[1]); $this->db->where('year', $data[1]);
} else {
// $this->db->select('month, year');
// $this->db->from($this->_table);
// $this->db->distinct($this->_table . '.month');
// $this->db->order_by( $this->_table . '.year desc');
// $this->db->order_by( $this->_table . '.month desc');
// $this->db->limit(1);
// $query = $this->db->get();
// $data = $query->result_array();
// $this->db->where('month', $data[0]['month']);
// $this->db->where('year', $data[0]['year']);
} }
$this->db->group_by('reports_views_monthly.id'); $this->db->group_by($this->_table . '.id');
$this->db->order_by($this->_table . '.total_point', 'desc'); $this->db->order_by($this->_table . '.total_point', 'desc');
// $this->db->order_by($this->_table . '.title', 'asc');
$this->db->limit($record); $this->db->limit($record);
$query = $this->db->get(); $query = $this->db->get();
return $query->result_array(); return $query->result_array();
} }
public function selectSearch() { public function selectSearch()
{
error_log('a:'. $this->_table);
$this->db->select('month, year'); $this->db->select('month, year');
$this->db->from($this->_table); $this->db->from($this->_table);
$this->db->distinct($this->_table . '.month'); $this->db->distinct($this->_table . '.month');
$this->db->order_by( $this->_table . '.year desc'); $this->db->order_by( $this->_table . '.year desc');
$this->db->order_by( $this->_table . '.month desc'); $this->db->order_by( $this->_table . '.month desc');
$this->db->limit(3);
$query = $this->db->get(); $query = $this->db->get();
return $query->result_array(); return $query->result_array();
} }
/**
* Hàm lấy xếp hạng tháng trước để so sánh tăng/giảm hạng
*
* @param $month_year
* @return array
*/
public function previousRanking($month_year)
{
$this->db->select('track_id, order, month, year');
$this->db->from($this->_table);
if ($month_year != null) {
$data = explode('-', $month_year);
$month = intval($data[0]);
$year = intval($data[1]);
if ($month == 1) {
$month = 12;
$year = $year - 1;
} else {
$month = $month - 1;
}
$this->db->where('month', $month);
$this->db->where('year', $year);
}
$this->db->where('order <=', 100);
$query = $this->db->get();
$data = $query->result_array();
$result = [];
if ($data) {
foreach ($data as $key => $val) {
$result[$val['track_id']] = $val['order'];
}
}
return $result;
}
} }
\ No newline at end of file
...@@ -61,4 +61,41 @@ class Report_views_weekly_model extends CI_Model ...@@ -61,4 +61,41 @@ class Report_views_weekly_model extends CI_Model
return $query->result_array(); return $query->result_array();
} }
/**
* Hàm lấy xếp hạng tuần trước để so sánh tăng/giảm hạng
*
* @param $week_year
* @return array
*/
public function previousRanking($week_year)
{
$this->db->select('track_id, order, week, year');
$this->db->from($this->_table);
if ($week_year != null) {
$data = explode('-', $week_year);
$week = intval($data[0]);
$year = intval($data[1]);
if ($week == 1) {
return [];
} else {
$week = $week - 1;
}
$this->db->where('week', $week);
$this->db->where('year', $year);
}
$this->db->where('order <=', 100);
$query = $this->db->get();
$data = $query->result_array();
$result = [];
if ($data) {
foreach ($data as $key => $val) {
$result[$val['track_id']] = $val['order'];
}
}
return $result;
}
} }
\ No newline at end of file
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
<table class="table table-striped table-bordered table-hover"> <table class="table table-striped table-bordered table-hover">
<thead> <thead>
<tr> <tr>
<th style="text-align: center">TT</th> <th style="text-align: center">Xếp hạng</th>
<!--<th style="text-align: center">#ID</th>--> <th style="text-align: center">Đánh giá</th>
<th style="text-align: center">Ảnh</th> <th style="text-align: center">Ảnh</th>
<th style="text-align: center"><i class="fa fa-music color-red"></i> Tên bài hát</th> <th style="text-align: center"><i class="fa fa-music color-red"></i> Tên bài hát</th>
<th style="text-align: center"><i class="fa fa-line-chart color-red"></i> Lịch sử</th> <th style="text-align: center"><i class="fa fa-line-chart color-red"></i> Lịch sử</th>
...@@ -19,9 +19,15 @@ ...@@ -19,9 +19,15 @@
<?php if(count($listData) > 0): foreach($listData as $key => $data): ?> <?php if(count($listData) > 0): foreach($listData as $key => $data): ?>
<tr> <tr>
<td style="text-align: center"><?php echo ($key+1+$offset); ?></td> <td style="text-align: center"><?php echo ($key+1+$offset); ?></td>
<!--<td style="text-align: center">#<?php /*echo $data['track_id']; */?></td>--> <td style="text-align: center">
<?php echo MyHelper::getRankingCompare($data['track_id'], $data['ranking'], $previousRanking) ?>
</td>
<td style="text-align: center"><img src="<?php echo MyHelper::getArtByTrack($data['art']); ?>" style="max-width: 50px; max-height: 50px"></td> <td style="text-align: center"><img src="<?php echo MyHelper::getArtByTrack($data['art']); ?>" style="max-width: 50px; max-height: 50px"></td>
<td style="text-align: left"><?php echo $data['name_song'] . ' (#' . $data['track_id'] . ')'; ?></td> <td style="text-align: left">
<?php echo $data['name_song']; ?>
<br>
<span style="color: #adadad">ID: <?php echo $data['track_id']; ?></span>
</td>
<td style="text-align: center"> <td style="text-align: center">
<a href="javascript:void(0)" title="Click để xem lịch sử lượt nghe" <a href="javascript:void(0)" title="Click để xem lịch sử lượt nghe"
onclick="showHistory(<?php echo $data['track_id']?>, '<?php echo $data['name_song'] ?>')"> onclick="showHistory(<?php echo $data['track_id']?>, '<?php echo $data['name_song'] ?>')">
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
<table class="table table-striped table-bordered table-hover"> <table class="table table-striped table-bordered table-hover">
<thead> <thead>
<tr> <tr>
<th style="text-align: center">TT</th> <th style="text-align: center">Xếp hạng</th>
<th style="text-align: center">#ID</th> <th style="text-align: center">Đánh giá</th>
<th style="text-align: center">Ảnh</th> <th style="text-align: center">Ảnh</th>
<th style="text-align: center">Tên bài hát</th> <th style="text-align: center">Tên bài hát</th>
<th style="text-align: center">Ca sĩ</th> <th style="text-align: center">Ca sĩ</th>
...@@ -14,9 +14,15 @@ ...@@ -14,9 +14,15 @@
<?php if(count($listData) > 0): foreach($listData as $key => $data): ?> <?php if(count($listData) > 0): foreach($listData as $key => $data): ?>
<tr> <tr>
<td style="text-align: center"><?php echo ($key+1+$offset); ?></td> <td style="text-align: center"><?php echo ($key+1+$offset); ?></td>
<td style="text-align: center">#<?php echo $data['track_id']; ?></td> <td style="text-align: center">
<?php echo MyHelper::getRankingCompare($data['track_id'], $data['order'], $previousRanking) ?>
</td>
<td style="text-align: center"><img style="max-width: 50px" src="<?php echo MyHelper::getArtByTrack($data['art']); ?>"></td> <td style="text-align: center"><img style="max-width: 50px" src="<?php echo MyHelper::getArtByTrack($data['art']); ?>"></td>
<td style="text-align: left"><?php echo $data['name_song']; ?></td> <td style="text-align: left">
<?php echo $data['name_song']; ?>
<br>
<span style="color: #adadad">ID: <?php echo $data['track_id']; ?></span>
</td>
<td style="text-align: left"><?php echo $data['all_name']; ?></td> <td style="text-align: left"><?php echo $data['all_name']; ?></td>
<td style="text-align: right"><?php echo number_format($data['total_point'], 0, ',', '.'); ?></td> <td style="text-align: right"><?php echo number_format($data['total_point'], 0, ',', '.'); ?></td>
</tr> </tr>
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
<table class="table table-striped table-bordered table-hover"> <table class="table table-striped table-bordered table-hover">
<thead> <thead>
<tr> <tr>
<th style="text-align: center">TT</th> <th style="text-align: center">Xếp hạng</th>
<th style="text-align: center">#ID</th> <th style="text-align: center">Đánh giá</th>
<th style="text-align: center">Ảnh</th> <th style="text-align: center">Ảnh</th>
<th style="text-align: center">Tên bài hát</th> <th style="text-align: center">Tên bài hát</th>
<th style="text-align: center">Ca sĩ</th> <th style="text-align: center">Ca sĩ</th>
...@@ -14,9 +14,15 @@ ...@@ -14,9 +14,15 @@
<?php if(count($listData) > 0): foreach($listData as $key => $data): ?> <?php if(count($listData) > 0): foreach($listData as $key => $data): ?>
<tr> <tr>
<td style="text-align: center"><?php echo ($key+1+$offset); ?></td> <td style="text-align: center"><?php echo ($key+1+$offset); ?></td>
<td style="text-align: center">#<?php echo $data['track_id']; ?></td> <td style="text-align: center">
<?php echo MyHelper::getRankingCompare($data['track_id'], $data['order'], $previousRanking) ?>
</td>
<td style="text-align: center"><img style="max-width: 50px" src="<?php echo MyHelper::getArtByTrack($data['art']); ?>"></td> <td style="text-align: center"><img style="max-width: 50px" src="<?php echo MyHelper::getArtByTrack($data['art']); ?>"></td>
<td style="text-align: left"><?php echo $data['name_song']; ?></td> <td style="text-align: left">
<?php echo $data['name_song']; ?>
<br>
<span style="color: #adadad">ID: <?php echo $data['track_id']; ?></span>
</td>
<td style="text-align: left"><?php echo $data['all_name']; ?></td> <td style="text-align: left"><?php echo $data['all_name']; ?></td>
<td style="text-align: right"><?php echo number_format($data['total_point'], 0, ',', '.'); ?></td> <td style="text-align: right"><?php echo number_format($data['total_point'], 0, ',', '.'); ?></td>
</tr> </tr>
...@@ -30,4 +36,4 @@ ...@@ -30,4 +36,4 @@
</table> </table>
</div> </div>
<!-- /.row --> <!-- /.row -->
<div style="text-align: center;"><?php //echo $pagination; ?></div> <div style="text-align: center;"><?php //echo $pagination; ?></div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment