完整版V1 加入爬虫功能
This commit is contained in:
@@ -58,6 +58,7 @@ class Number extends Backend
|
||||
$this->assignconfig('numberTypeList', $this->model->getNumberTypeList());
|
||||
$this->assignconfig('statusList', $this->model->getStatusList());
|
||||
$this->assignconfig('manualManageList', $this->model->getManualManageList());
|
||||
$this->assignconfig('platformStatusList', $this->model->getPlatformStatusList());
|
||||
|
||||
$this->setupPatchFrontend();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,11 @@ namespace app\admin\controller\split;
|
||||
use app\admin\model\split\Link as LinkModel;
|
||||
use app\admin\model\split\Ticket as TicketModel;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\service\SplitTicketRuleService;
|
||||
use app\common\service\SplitTicketSyncService;
|
||||
use think\Db;
|
||||
use think\Lang;
|
||||
use think\Loader;
|
||||
use think\Exception;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
@@ -45,11 +49,6 @@ class Ticket extends Backend
|
||||
|
||||
$lang = $this->request->langset();
|
||||
$lang = preg_match('/^([a-zA-Z\-_]{2,10})$/i', $lang) ? $lang : 'zh-cn';
|
||||
$langFile = ROOT_PATH . 'patches/application/admin/lang/' . $lang . '/split/ticket.php';
|
||||
if (is_file($langFile)) {
|
||||
\think\Lang::load($langFile);
|
||||
}
|
||||
|
||||
$this->model = new \app\admin\model\split\Ticket();
|
||||
$this->view->assign('ticketTypeList', $this->model->getTicketTypeList());
|
||||
$this->view->assign('numberTypeList', $this->model->getNumberTypeList());
|
||||
@@ -62,6 +61,32 @@ class Ticket extends Backend
|
||||
$this->setupPatchFrontend();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载工单语言包(优先 patches)
|
||||
*/
|
||||
protected function loadlang($name): void
|
||||
{
|
||||
$lang = $this->request->langset();
|
||||
$lang = preg_match('/^([a-zA-Z\-_]{2,10})$/i', $lang) ? $lang : 'zh-cn';
|
||||
$name = Loader::parseName($name);
|
||||
$name = preg_match('/^([a-zA-Z0-9_\.\/]+)$/i', $name) ? $name : 'index';
|
||||
|
||||
$files = [
|
||||
APP_PATH . 'admin/lang/' . $lang . '/' . str_replace('.', '/', $name) . '.php',
|
||||
ROOT_PATH . 'patches/application/admin/lang/' . $lang . '/split/ticket.php',
|
||||
];
|
||||
$loaded = false;
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
Lang::load($file);
|
||||
$loaded = true;
|
||||
}
|
||||
}
|
||||
if (!$loaded) {
|
||||
parent::loadlang($name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 未部署 JS 时指向 script 接口
|
||||
*/
|
||||
@@ -146,10 +171,9 @@ class Ticket extends Backend
|
||||
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
||||
$ticketTable = $this->model->getTable();
|
||||
$clickSub = TicketModel::buildClickCountSubQuery();
|
||||
// 勿 with(splitLink):eagerlyType=0 为 JOIN 预载入,会重写 field 导致子查询 SQL 语法错误
|
||||
$list = $this->model
|
||||
->field($ticketTable . '.*')
|
||||
->fieldRaw($clickSub)
|
||||
->with(['splitLink'])
|
||||
->field($ticketTable . '.*,' . $clickSub)
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
@@ -177,11 +201,95 @@ class Ticket extends Backend
|
||||
$params['sync_status'],
|
||||
$params['sync_time'],
|
||||
$params['sync_message'],
|
||||
$params['sync_fail_count'],
|
||||
$params['speed_snapshot_count'],
|
||||
$params['speed_snapshot_time'],
|
||||
$params['click_count']
|
||||
);
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动同步选中工单
|
||||
*/
|
||||
public function sync(): void
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$ids = $this->request->post('ids', '');
|
||||
if ($ids === '') {
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
$pk = $this->model->getPk();
|
||||
$list = $this->model->where($pk, 'in', $ids)->select();
|
||||
if (!$list || count($list) === 0) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$service = new SplitTicketSyncService();
|
||||
$ok = 0;
|
||||
$fail = 0;
|
||||
$messages = [];
|
||||
|
||||
foreach ($list as $row) {
|
||||
if (is_array($adminIds) && !in_array((int) $row[$this->dataLimitField], $adminIds, true)) {
|
||||
$fail++;
|
||||
$messages[] = '#' . $row['id'] . ': 无权限';
|
||||
continue;
|
||||
}
|
||||
$result = $service->syncOne((int) $row['id'], true);
|
||||
if ($result['success']) {
|
||||
$ok++;
|
||||
} else {
|
||||
$fail++;
|
||||
$messages[] = '#' . $row['id'] . ': ' . ($result['message'] ?? '失败');
|
||||
}
|
||||
}
|
||||
|
||||
$summary = sprintf('成功 %d 条,失败 %d 条', $ok, $fail);
|
||||
if ($fail > 0) {
|
||||
$summary .= ';' . implode(';', array_slice($messages, 0, 5));
|
||||
}
|
||||
$this->success($summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新:工单状态变更时联动号码
|
||||
*
|
||||
* @param string $ids
|
||||
*/
|
||||
public function multi($ids = '')
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$ids = $ids ?: $this->request->post('ids', '');
|
||||
if ($ids === '') {
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
|
||||
$params = $this->request->post('params', '');
|
||||
parse_str((string) $params, $values);
|
||||
$ruleService = new SplitTicketRuleService();
|
||||
|
||||
if (isset($values['status'])) {
|
||||
$pk = $this->model->getPk();
|
||||
$rows = $this->model->where($pk, 'in', $ids)->select();
|
||||
parent::multi($ids);
|
||||
foreach ($rows as $row) {
|
||||
$fresh = $this->model->get($row['id']);
|
||||
if ($fresh) {
|
||||
$ruleService->syncNumbersWithTicketStatus($fresh);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
parent::multi($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws DbException
|
||||
|
||||
Reference in New Issue
Block a user