183 lines
6.2 KiB
PHP
183 lines
6.2 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
/**
|
|
* Notes:私域直播_黑名单管理
|
|
* Created on: 2022/10/21 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class Blacklist extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('market/Market_sylive_blacklist_model', 'mdSyliveBlacklist');
|
|
}
|
|
|
|
/**
|
|
* Notes:黑名单管理列表
|
|
* Created on: 2022/9/20 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function page_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$mobile = $this->input_param('mobile');
|
|
$page = $this->input_param('page');
|
|
$limit = $this->input_param('limit');
|
|
$sort = $this->input_param('sort');
|
|
$order = $this->input_param('order');
|
|
!$page && $page = 1;
|
|
!$limit && $limit = 10;
|
|
$sort_order = 'blacklistId desc';
|
|
if ($sort && $order) {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
$where['blacklistId>'] = 0;
|
|
$mobile && $where['mobile LIKE "%' . trim($mobile) . '%"'] = null;
|
|
$activityId && $where['activityId'] = $activityId;
|
|
$count = $this->mdSyliveBlacklist->count($where);
|
|
$list = [];
|
|
if ($count) {
|
|
$res = $this->mdSyliveBlacklist->select($where, $sort_order, $page, $limit);
|
|
foreach ($res as $v) {
|
|
$list[] = ['blacklistId' => $v['blacklistId'], 'activityId' => $v['activityId'],
|
|
'mobile' => $v['mobile'], 'createTime' => $v['createTime']];
|
|
}
|
|
}
|
|
$date = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:添加黑名单
|
|
* Created on: 2022/10/21 16:46
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_post()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$mobile = $this->input_param('mobile');
|
|
if (!$activityId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
if (!$mobile) {
|
|
$this->return_json('请输入手机号');
|
|
}
|
|
$re = $this->mdSyliveBlacklist->get(['activityId' => $activityId,'mobile' => $mobile]);
|
|
if ($re) {
|
|
$this->return_json('手机号已在黑名单中');
|
|
}
|
|
$addDate = ['activityId' => $activityId, 'mobile' => $mobile, 'createTime' => date('Y-m-d H:i:s')];
|
|
$id = $this->mdSyliveBlacklist->add($addDate);
|
|
if (!$id) {
|
|
$this->return_json('添加黑名单失败');
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:修改黑名单
|
|
* Created on: 2022/10/21 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_put()
|
|
{
|
|
$blacklistId = intval($this->input_param('blacklistId'));
|
|
$mobile = $this->input_param('mobile');
|
|
if (!$blacklistId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
if (!$mobile) {
|
|
$this->return_json('请输入黑名单标题');
|
|
}
|
|
$upDate = ['mobile' => $mobile];
|
|
$this->mdSyliveBlacklist->update($upDate, ['blacklistId' => $blacklistId]);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:批量删除黑名单
|
|
* Created on: 2022/10/21 17:11
|
|
* Created by: dengbw
|
|
*/
|
|
public function batch_delete()
|
|
{
|
|
$ids = $this->input_param('ids');
|
|
if (!$ids) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$str_ids = implode(',', $ids);
|
|
if ($str_ids) {
|
|
$this->mdSyliveBlacklist->delete(["blacklistId in($str_ids)" => null]);
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:导入黑名单
|
|
* Created on: 2023/3/06 17:24
|
|
* Created by: dengbw
|
|
* @throws PHPExcel_Exception
|
|
* @throws PHPExcel_Reader_Exception
|
|
*/
|
|
public function import_post()
|
|
{
|
|
require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php';
|
|
$res = $this->upload();
|
|
if (!$res['code']) {
|
|
return $this->return_json($res['message']);
|
|
}
|
|
$file = $res['path'];
|
|
if ($res['file_ext'] == '.xls') {
|
|
$reader = \PHPExcel_IOFactory::createReader('Excel5'); // 读取 excel 文档
|
|
} elseif ($res['file_ext'] == '.xlsx') {
|
|
$reader = \PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档
|
|
} else {
|
|
return $this->return_json('文件无法识别');
|
|
}
|
|
$PHPExcel = $reader->load($file); // 文档名称
|
|
$objWorksheet = $PHPExcel->getActiveSheet();
|
|
$rowCnt = $objWorksheet->getHighestRow(); //获取总行数
|
|
if ($rowCnt > 800) {
|
|
@unlink($file);
|
|
$this->return_json('数据大于800请拆分多个表格导入');
|
|
}
|
|
$activityId = $_POST['activityId'];
|
|
$addDate = [];
|
|
for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容
|
|
$mobile = $objWorksheet->getCell('A' . $_row)->getValue();
|
|
if ($mobile) {
|
|
$re = $this->mdSyliveBlacklist->get(['activityId' => $activityId, 'mobile' => $mobile]);
|
|
if (!$re) {
|
|
$addDate[] = ['mobile' => $mobile, 'activityId' => $activityId, 'createTime' => date('Y-m-d H:i:s')];
|
|
}
|
|
}
|
|
}
|
|
$count = count($addDate);
|
|
if ($count) {
|
|
$this->mdSyliveBlacklist->add_batch($addDate);
|
|
}
|
|
@unlink($file);
|
|
$this->return_response('', "成功新增{$count}个黑名单");
|
|
}
|
|
|
|
private function upload()
|
|
{
|
|
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/';
|
|
$config['allowed_types'] = '*';
|
|
$config['max_size'] = 5120;
|
|
$config['file_name'] = 'blacklist_' . time() . rand(1, 99999);
|
|
$this->load->library('upload', $config);
|
|
if (!$this->upload->do_upload('file')) {
|
|
return ['code' => SYS_CODE_FAIL, 'message' => $this->upload->display_errors('', '')];
|
|
} else {
|
|
$data = $this->upload->data();
|
|
return ['code' => SYS_CODE_SUCCESS, 'path' => $data['full_path'], 'file_ext' => $data['file_ext']];
|
|
}
|
|
}
|
|
|
|
}
|