Commit 09dbeac6 by Phạm Văn Đoan

cập nhật

parent 39f3f1b9
......@@ -18,6 +18,7 @@ class CmsRanking extends CI_Controller
parent::__construct();
date_default_timezone_set("Asia/Ho_Chi_Minh");
//
$this->load->model('common_model');
$this->load->model('track_model');
$this->load->model('user_model');
$this->load->model('report_views_daily_model');
......@@ -419,6 +420,7 @@ class CmsRanking extends CI_Controller
$time = $this->input->post('time');
$scope = $this->input->post('scope');
//
$ranking_id = $this->input->post('ranking_id');
$keep_ranking = $this->input->post('keep_ranking');
$keep_track_id = $this->input->post('keep_track_id');
$keep_track_title = $this->input->post('keep_track_title');
......@@ -427,7 +429,7 @@ class CmsRanking extends CI_Controller
$delete_track_id = $this->input->post('delete_track_id');
$delete_track_title = $this->input->post('delete_track_title');
//
if ($delete_track_id > 0 && in_array($scope, ['DAILY', 'WEEKLY', 'MONTHLY'])) {
if ($ranking_id > 0 && $delete_track_id > 0 && in_array($scope, ['DAILY', 'WEEKLY', 'MONTHLY'])) {
$date = null;
$week = null;
$month = null;
......@@ -455,6 +457,7 @@ class CmsRanking extends CI_Controller
}
$data_insert = [
'scope' => $scope,
'ranking_id' => $ranking_id,
'date' => $date,
'week' => $week,
'month' => $month,
......@@ -504,7 +507,57 @@ class CmsRanking extends CI_Controller
if (in_array($scope, ['DAILY', 'WEEKLY', 'MONTHLY'])) {
$overlap = $this->report_violation_model->getById($id, 0);
if (isset($overlap[0])) {
print_r($overlap);
$limit = 105;
$offset = 0;
// Xử lý xóa và lấy ds sau khi xóa
switch ($scope) {
case 'DAILY':
$this->common_model->delete('report_views_daily', $overlap[0]['ranking_id']);
//
$date = $overlap[0]['date'];
$ranking = $this->report_views_daily_model->cmsGetPagination($limit, $offset, $date);
break;
case 'WEEKLY':
$this->common_model->delete('report_views_weekly_new', $overlap[0]['ranking_id']);
//
$time = $overlap[0]['week'] . '-' . $overlap[0]['year'];
$ranking = $this->report_views_weekly_model->cmsGetPagination($limit, $offset, $time);
break;
case 'MONTHLY':
$this->common_model->delete('report_views_monthly_new', $overlap[0]['ranking_id']);
//
$time = $overlap[0]['month'] . '-' . $overlap[0]['year'];
$ranking = $this->report_views_monthly_model->cmsGetPagination($limit, $offset, $time);
break;
default:
$ranking = [];
}
// Xử lý cập nhật lại BXH sau khi xóa
if (is_array($ranking) && count($ranking) > 0) {
$temp = [];
foreach ($ranking as $key => $item) {
if ($scope == 'DAILY') {
$temp[] = [ 'id' => $item['id'], 'ranking' => $key + 1 ];
} else {
$temp[] = [ 'id' => $item['id'], 'order' => $key + 1 ];
}
}
switch ($scope) {
case 'DAILY':
$this->common_model->update_batch('report_views_daily', $temp, 'id');
break;
case 'WEEKLY':
$this->common_model->update_batch('report_views_weekly_new', $temp, 'id');
break;
case 'MONTHLY':
$this->common_model->update_batch('report_views_monthly_new', $temp, 'id');
break;
default:
}
}
// Cập nhật trạng thái đã xử lý
$this->report_violation_model->update();
redirect(base_url($this->overlap_ranking_list));
} else {
redirect(base_url($this->overlap_ranking_list));
}
......
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Common_model extends CI_Model
{
public function __construct()
{
parent::__construct();
date_default_timezone_set("Asia/Ho_Chi_Minh");
}
public function update($table, $id, $data_update)
{
try{
$this->db->where('id', $id);
$this->db->update($table, $data_update);
return true;
} catch (Exception $e) {
return false;
}
}
/**
* https://codeigniter.com/userguide3/database/query_builder.html#updating-data
*
* @param $table
* @param $data
* @param string $update_by_field
* @return bool
*/
public function update_batch($table, $data, $update_by_field = 'id')
{
if ($table && is_array($data) && count($data) > 0) {
try {
$this->db->update_batch($table, $data, $update_by_field);
return true;
} catch (Exception $e) {
return false;
}
} else {
return false;
}
}
public function delete($table, $id)
{
if ($table && $id > 0) {
$this->db->where('id', $id);
$this->db->delete($table);
//
return true;
} else {
return false;
}
}
}
\ No newline at end of file
<?php if(is_array($ranking) && count($ranking) > 0): ?>
<option value="-1" ranking="-1">- Chọn -</option>
<?php foreach ($ranking as $item): $ranking = isset($item['ranking']) ? $item['ranking'] : $item['order']; ?>
<option value="<?php echo $item['track_id']; ?>" ranking="<?php echo $ranking ?>">
<option value="<?php echo $item['track_id']; ?>" ranking="<?php echo $ranking ?>" ranking_id="<?php echo $item['id']; ?>">
<?php echo $ranking . '. ' . $item['name_song'] . ' (ID= '.$item['track_id'].')'; ?>
</option>
<?php endforeach; ?>
......
......@@ -26,6 +26,8 @@
</td>
<td style="text-align: left">
<?php echo $data['delete_track_title']; ?>
<br>
<span style="color: #adadad">ID: <?php echo $data['ranking_id']; ?></span>
</td>
<td>
<?php echo (($data['status'] == 1) ? 'Đã xử lý' : 'Chờ xử lý') ?>
......
......@@ -6,6 +6,7 @@
$('#keep_track_title').val($('#ranking_true option:selected').text().trim());
});
$("#ranking_false").change(function(){
$('#ranking_id').val($('#ranking_false option:selected').attr('ranking_id'));
$('#delete_ranking').val($('#ranking_false option:selected').attr('ranking'));
$('#delete_track_title').val($('#ranking_false option:selected').text().trim());
});
......@@ -41,6 +42,7 @@
// Hàm gửi data báo cáo sai sót
function sendReportOverlapping() {
var ranking_id = $('#ranking_id').val();
var keep_ranking = $('#keep_ranking').val();
var keep_track_id = $('#ranking_true').val();
var keep_track_title = $('#keep_track_title').val();
......@@ -58,6 +60,7 @@
csrf_name: '<?php echo $this->security->get_csrf_hash(); ?>',
time: ($("#input-date-picker").val()) ? $("#input-date-picker").val() : null,
scope: '<?php echo (isset($tags) ? $tags : 'DAILY')?>',
ranking_id: ranking_id,
keep_ranking: keep_ranking,
keep_track_id: keep_track_id,
keep_track_title: (keep_track_title) ? keep_track_title.trim() : keep_track_title,
......
......@@ -10,6 +10,7 @@
<div class="col-md-12">
<div class="form-group">
<label>BXH: <span id="ranking_at" style="color: red"></span></label>
<input type="hidden" id="ranking_id" value="">
<input type="hidden" id="keep_ranking" value="-1">
<input type="hidden" id="delete_ranking" value="-1">
<input type="hidden" id="keep_track_title" value="">
......
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