Commit c59c76ea by Phạm Văn Đoan

cập nhật thêm ko lấy lượt nghe

parent 017ecde8
...@@ -403,8 +403,10 @@ $config['csrf_exclude_uris'] = array( ...@@ -403,8 +403,10 @@ $config['csrf_exclude_uris'] = array(
'backend/cmsRanking/getTrackHistoryAjax', 'backend/cmsRanking/getTrackHistoryAjax',
'backend/cmsTrack/listTrackAjax', 'backend/cmsTrack/listTrackAjax',
'backend/cmsArtist/listArtistAjax',
'backend/cmsTrack/addTrack', 'backend/cmsTrack/addTrack',
'backend/cmsTrack/updateBlacklistByAjax',
'backend/cmsArtist/listArtistAjax',
'backend/cmsArtist/addArtistAjax', 'backend/cmsArtist/addArtistAjax',
'backend/cmsSetting/listGroupAjax', 'backend/cmsSetting/listGroupAjax',
......
...@@ -17,6 +17,7 @@ class CmsTrack extends CI_Controller ...@@ -17,6 +17,7 @@ class CmsTrack extends CI_Controller
$this->load->model('track_model'); $this->load->model('track_model');
$this->load->model('user_model'); $this->load->model('user_model');
$this->load->model('actionlog_model'); $this->load->model('actionlog_model');
$this->load->model('crawler_listen_blacklist_model');
} }
/** /**
...@@ -444,6 +445,7 @@ class CmsTrack extends CI_Controller ...@@ -444,6 +445,7 @@ class CmsTrack extends CI_Controller
// //
$this->_data['track']= $this->track_model->getById($track_id); $this->_data['track']= $this->track_model->getById($track_id);
$this->_data['blacklist']= $this->crawler_listen_blacklist_model->getSrcByTrackId($track_id, null);
$this->_data['singers']= $this->track_model->getSingerLítByTrackId($track_id); $this->_data['singers']= $this->track_model->getSingerLítByTrackId($track_id);
// //
$this->_data['functionName'] = 'Thông tin Bài Hát'; $this->_data['functionName'] = 'Thông tin Bài Hát';
...@@ -548,4 +550,27 @@ class CmsTrack extends CI_Controller ...@@ -548,4 +550,27 @@ class CmsTrack extends CI_Controller
return false; return false;
} }
public function updateBlacklistByAjax()
{
$track_id = $this->input->post('track_id');
$src = $this->input->post('src');
$selected = $this->input->post('selected');
//
$result = $this->crawler_listen_blacklist_model->checkAndUpdate($track_id, $src, $selected);
//
if ($result) {
echo json_encode([
'code' => 200,
'message' => 'Cập nhật thành công',
'data' => null
]);
} else {
echo json_encode([
'code' => 400,
'message' => 'Cập nhật không thành công',
'data' => null
]);
}
}
} }
\ No newline at end of file
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Crawler_listen_blacklist_model extends CI_Model
{
protected $_table = 'crawler_listen_blacklists';
public function __construct()
{
parent::__construct();
date_default_timezone_set("Asia/Ho_Chi_Minh");
}
public function add($dataInsert){
$this->db->insert($this->_table, $dataInsert);
$insert_id = $this->db->insert_id();
return $insert_id;
}
public function update($id, $dataUpdate){
$this->db->where('id', $id);
$this->db->update($this->_table, $dataUpdate);
return true;
}
public function delete($id){
$this->db->where('id', $id);
$this->db->delete($this->_table);
return true;
}
public function getSrcByTrackId($track_id, $src=null)
{
$this->db->select($this->_table . '.src');
$this->db->from($this->_table);
$this->db->where($this->_table . '.track_id', $track_id);
if (! empty($src)) {
$this->db->where($this->_table . '.src', $src);
}
$query = $this->db->get();
$result = $query->result_array();
$data = [];
if ($result) {
foreach ($result as $key => $val) {
$data[] = $val['src'];
}
}
return $data;
}
public function checkAndUpdate($track_id, $src, $selected)
{
$this->db->select($this->_table . '.*');
$this->db->from($this->_table);
$this->db->where($this->_table . '.track_id', $track_id);
$this->db->where($this->_table . '.src', $src);
$query = $this->db->get();
$result = $query->result_array();
//
if (isset($result[0])) {
if ($selected == 0) {
$this->db->where('id', $result[0]['id']);
$this->db->delete($this->_table);
}
return true;
} else {
$this->db->insert($this->_table, [
'track_id' => $track_id,
'src' => strtolower($src),
'title' => null,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
]);
return true;
}
//
return false;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
\ No newline at end of file
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<th style="text-align: center">Ảnh</th> <th style="text-align: center">Ảnh</th>
<th style="text-align: center">#ID</th> <th style="text-align: center">#ID</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</th> <th style="text-align: center">Nghệ</th>
<th style="text-align: center">Sáng tác</th> <th style="text-align: center">Trang không lấy<br>lượt nghe</th>
<th style="text-align: center">Xử lý</th> <th style="text-align: center">Xử lý</th>
</tr> </tr>
</thead> </thead>
...@@ -24,8 +24,12 @@ ...@@ -24,8 +24,12 @@
<br> <br>
<?php echo MyHelper::getSourceIcon($data['id_zing'], $data['id_nct'], $data['id_keeng']) ?> <?php echo MyHelper::getSourceIcon($data['id_zing'], $data['id_nct'], $data['id_keeng']) ?>
</td> </td>
<td style="text-align: left"><?php echo $data['singer_list']; ?></td> <td style="text-align: left">
<td style="text-align: left"><?php echo $data['composer_list']; ?></td> Ca sĩ: <span style="font-weight: bold"><?php echo $data['singer_list']; ?></span>
<br>
Sáng tác: <span style="font-weight: bold"><?php echo $data['composer_list']; ?></span>
</td>
<td style="text-align: left"><?php echo strtoupper($data['blacklist_listen']); ?></td>
<td style="text-align: center"> <td style="text-align: center">
<a href="<?php echo base_url().'backend/cmsTrack/showTrack/'.$data['id']; ?>" title="Xem chi tiết"> <a href="<?php echo base_url().'backend/cmsTrack/showTrack/'.$data['id']; ?>" title="Xem chi tiết">
<i class="ace-icon fa fa-eye bigger-130"></i> <i class="ace-icon fa fa-eye bigger-130"></i>
......
...@@ -92,13 +92,33 @@ ...@@ -92,13 +92,33 @@
<?php endif ?> <?php endif ?>
</div> </div>
</div> </div>
<div class="profile-info-row">
<div class="profile-info-name color-red" style="color: red">Không lấy lượt nghe ở trang nào thì tích chọn</div>
<div class="profile-info-value">
<label>
<input type="checkbox" value="zing" id="chk_zing"
onclick="updateBlacklistByAjax(<?php echo $track[0]['id'] ?>, 'zing')"
<?php echo (in_array('zing', $blacklist) ? 'checked' : '') ?>>&nbsp;Zing
</label><br>
<label>
<input type="checkbox" value="nct" id="chk_nct"
onclick="updateBlacklistByAjax(<?php echo $track[0]['id'] ?>, 'nct')"
<?php echo (in_array('nct', $blacklist) ? 'checked' : '') ?>>&nbsp;NCT
</label><br>
<label>
<input type="checkbox" value="keeng" id="chk_keeng"
onclick="updateBlacklistByAjax(<?php echo $track[0]['id'] ?>, 'keeng')"
<?php echo (in_array('keeng', $blacklist) ? 'checked' : '') ?>>&nbsp;Keeng
</label>
</div>
</div>
</div> </div>
</div> </div>
<br> <br>
<div class="row"> <div class="row">
<div class="col-lg-3"> <div class="col-lg-3">
<a href="<?php echo base_url('backend/cmsTrack/listTrack');?>" <a href="<?php echo base_url('backend/cmsTrack/listTrack');?>">
onclick="return confirm('Bạn có chắc chắn muốn quay lại Danh sách không?')">
<button type="button" class="btn btn-sm btn-default"> <button type="button" class="btn btn-sm btn-default">
<i class="ace-icon fa fa-arrow-left"></i>Quay lại <i class="ace-icon fa fa-arrow-left"></i>Quay lại
</button> </button>
...@@ -107,4 +127,40 @@ ...@@ -107,4 +127,40 @@
</div> </div>
<?php else: ?> <?php else: ?>
<p>Không tìm thấy thông tin Bài hát!</p> <p>Không tìm thấy thông tin Bài hát!</p>
<?php endif; ?> <?php endif; ?>
\ No newline at end of file <script>
function updateBlacklistByAjax(track_id, src) {
var selected = 0;
if ($('#chk_' + src).is(":checked")) {
selected = 1;
} else {
selected = 0;
}
callAjax(track_id, src, selected);
}
function callAjax(track_id, src, selected) {
var csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>';
var url = '<?php echo base_url("backend/cmsTrack/updateBlacklistByAjax"); ?>';
var dataReq = {
csrf_name: csrf_value,
track_id: track_id,
src: src,
selected: selected
};
//Ajax
$.ajax({
type: "POST",
url: url,
data: dataReq,
dataType: "JSON",
cache: false,
success: function(data) {
console.log(data);
//$('#data-loading').hide();
}
});
}
</script>
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