修复号码数量列的数据统计方式

This commit is contained in:
root
2026-07-08 01:07:08 +08:00
parent 92b4faf61f
commit 76692e0021
16 changed files with 497 additions and 29 deletions
@@ -27,6 +27,7 @@ CREATE TABLE `fa_split_ticket` (
`number_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '号码数量含离线封号(同步)',
`number_offline_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '离线号码数(同步)',
`number_banned_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '封号号码数(同步)',
`active_number_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '本地开启号码数(status=normal)',
`online_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '在线人数(同步)',
`sync_status` enum('success','error','pending') NOT NULL DEFAULT 'pending' COMMENT '同步状态',
`sync_time` bigint(16) DEFAULT NULL COMMENT '最近同步时间',
@@ -0,0 +1,21 @@
-- 工单表:本地开启号码数(status=normal),列表直接读字段,避免子查询
SET NAMES utf8mb4;
ALTER TABLE `fa_split_ticket`
ADD COLUMN `active_number_count` int(10) unsigned NOT NULL DEFAULT 0
COMMENT '本地开启号码数(status=normal)' AFTER `number_banned_count`;
-- 历史数据回填
UPDATE `fa_split_ticket` t
SET t.`active_number_count` = (
SELECT COUNT(*)
FROM `fa_split_number` n
WHERE n.`admin_id` = t.`admin_id`
AND n.`split_link_id` = t.`split_link_id`
AND n.`ticket_name` = t.`ticket_name`
AND n.`status` = 'normal'
);
-- 加速按工单统计 status=normal 数量
ALTER TABLE `fa_split_number`
ADD KEY `idx_ticket_active` (`admin_id`, `split_link_id`, `ticket_name`(50), `status`);
@@ -7,6 +7,7 @@ namespace app\admin\controller\split;
use app\admin\model\split\Link as LinkModel;
use app\admin\model\split\Number as NumberModel;
use app\common\controller\Backend;
use app\common\service\SplitTicketActiveNumberCountService;
use think\Db;
use think\Exception;
use think\exception\DbException;
@@ -225,6 +226,7 @@ class Number extends Backend
$this->error($e->getMessage());
}
if ($count > 0) {
(new SplitTicketActiveNumberCountService())->refreshForNumberIds(explode(',', (string) $ids));
$this->success();
}
$this->error(__('No rows were updated'));
@@ -331,6 +333,12 @@ class Number extends Backend
$this->error($e->getMessage());
}
(new SplitTicketActiveNumberCountService())->refreshForTicketKeys(
(int) ($baseRow['admin_id'] ?? $adminId),
$splitLinkId,
(string) ($baseRow['ticket_name'] ?? '')
);
$msg = __('Inserted %d number(s)', $inserted);
if ($skipped > 0) {
$msg .= '' . __('Skipped %d duplicate(s)', $skipped);
@@ -378,6 +386,7 @@ class Number extends Backend
}
$result = false;
$before = $row->getData();
Db::startTrans();
try {
if ($this->modelValidate) {
@@ -397,9 +406,50 @@ class Number extends Backend
if ($result === false) {
$this->error(__('No rows were updated'));
}
(new SplitTicketActiveNumberCountService())->refreshAfterNumberEdit($before, $row->getData());
$this->success();
}
/**
* 删除号码后回写工单本地开启号码数
*
* @param string|null $ids
*/
public function del($ids = null)
{
if (false === $this->request->isPost()) {
$this->error(__('Invalid parameters'));
}
$ids = $ids ?: $this->request->post('ids');
if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
$countService = new SplitTicketActiveNumberCountService();
Db::startTrans();
try {
foreach ($list as $item) {
$count += $item->delete();
}
Db::commit();
} catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$countService->refreshFromNumberRows($list);
$this->success();
}
$this->error(__('No rows were deleted'));
}
/**
* 批量更新号码状态与手动管理
*/
@@ -444,6 +494,7 @@ class Number extends Backend
if ($count === false || $count === 0) {
$this->error(__('No rows were updated'));
}
(new SplitTicketActiveNumberCountService())->refreshForNumberIds($ids);
$this->success(__('Batch update success'));
}
@@ -496,6 +547,8 @@ class Number extends Backend
}
$count = 0;
$countService = new SplitTicketActiveNumberCountService();
$keyRows = (clone $query)->field('admin_id,split_link_id,ticket_name')->select();
Db::startTrans();
try {
if ($action === 'delete') {
@@ -523,6 +576,7 @@ class Number extends Backend
$this->error(__('No matching numbers found'));
}
$countService->refreshFromNumberRows($keyRows);
$this->success(sprintf(__('Batch operate success'), $count));
}
@@ -268,6 +268,7 @@ class Ticket extends Backend
$params['inbound_count'],
$params['speed_per_hour'],
$params['number_count'],
$params['active_number_count'],
$params['number_offline_count'],
$params['number_banned_count'],
$params['online_count'],