添加whatshub工单
This commit is contained in:
Regular → Executable
+130
@@ -29,6 +29,9 @@ class Number extends Backend
|
||||
|
||||
protected $dataLimit = 'personal';
|
||||
|
||||
/** 关联 splitLink 预载入时需为筛选/排序字段加表别名,避免 status 等列歧义 */
|
||||
protected $relationSearch = true;
|
||||
|
||||
protected $modelValidate = true;
|
||||
|
||||
protected $modelSceneValidate = true;
|
||||
@@ -62,6 +65,8 @@ class Number extends Backend
|
||||
$this->assignconfig('statusList', $this->model->getStatusList());
|
||||
$this->assignconfig('manualManageList', $this->model->getManualManageList());
|
||||
$this->assignconfig('platformStatusList', $this->model->getPlatformStatusList());
|
||||
$this->assignconfig('splitLinkFilterList', $this->buildNumberSplitLinkFilterList());
|
||||
$this->assignconfig('splitLinkSelectList', $this->buildSplitLinkSelectConfig());
|
||||
|
||||
$this->setupPatchFrontend();
|
||||
}
|
||||
@@ -111,6 +116,52 @@ class Number extends Backend
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 已有号码关联的分流链接(供列表筛选下拉)
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function buildNumberSplitLinkFilterList(): array
|
||||
{
|
||||
$numberTable = $this->model->getTable();
|
||||
$linkTable = (new LinkModel())->getTable();
|
||||
$query = Db::table($numberTable)
|
||||
->alias('n')
|
||||
->join($linkTable . ' l', 'n.split_link_id = l.id')
|
||||
->where('n.split_link_id', '>', 0)
|
||||
->group('n.split_link_id')
|
||||
->field('l.id,l.link_code,l.description')
|
||||
->order('l.id', 'desc');
|
||||
if ($this->dataLimit) {
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
if (is_array($adminIds)) {
|
||||
$query->where('n.admin_id', 'in', $adminIds);
|
||||
}
|
||||
}
|
||||
$list = [];
|
||||
foreach ($query->select() as $row) {
|
||||
$code = (string) $row['link_code'];
|
||||
$desc = (string) $row['description'];
|
||||
$label = $desc !== '' ? $code . ' - ' . $desc : $code;
|
||||
$list[(string) $row['id']] = $label;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部分流链接(供批量操作弹窗可搜索下拉)
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function buildSplitLinkSelectConfig(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->buildSplitLinkList() as $row) {
|
||||
$list[(string) $row['id']] = (string) $row['label'];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
private function fetchPatch(string $template): string
|
||||
{
|
||||
$patchFile = ROOT_PATH . self::PATCH_VIEW_DIR . $template . '.html';
|
||||
@@ -395,6 +446,85 @@ class Number extends Backend
|
||||
$this->success(__('Batch update success'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 按分流链接 + 号码文本批量开启/关闭/删除
|
||||
*/
|
||||
public function batchoperate(): void
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
|
||||
$splitLinkId = (int) $this->request->post('split_link_id', 0);
|
||||
$numbersText = (string) $this->request->post('numbers', '');
|
||||
$action = (string) $this->request->post('action', '');
|
||||
|
||||
if ($splitLinkId <= 0) {
|
||||
$this->error(__('Please select split link'));
|
||||
}
|
||||
|
||||
$numberList = NumberModel::parseNumbersText($numbersText);
|
||||
if ($numberList === []) {
|
||||
$this->error(__('Please fill at least one number'));
|
||||
}
|
||||
|
||||
$allowedActions = ['enable', 'disable', 'delete'];
|
||||
if (!in_array($action, $allowedActions, true)) {
|
||||
$this->error(__('Invalid batch operate action'));
|
||||
}
|
||||
|
||||
$linkQuery = (new LinkModel())->where('id', $splitLinkId)->where('status', 'normal');
|
||||
if ($this->dataLimit) {
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
if (is_array($adminIds)) {
|
||||
$linkQuery->where('admin_id', 'in', $adminIds);
|
||||
}
|
||||
}
|
||||
if (!$linkQuery->find()) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$query = $this->model
|
||||
->where('split_link_id', $splitLinkId)
|
||||
->where('number', 'in', $numberList);
|
||||
if ($this->dataLimit) {
|
||||
$adminIds = $this->getDataLimitAdminIds();
|
||||
if (is_array($adminIds)) {
|
||||
$query->where('admin_id', 'in', $adminIds);
|
||||
}
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($action === 'delete') {
|
||||
$rows = $query->select();
|
||||
foreach ($rows as $row) {
|
||||
if ($row->delete()) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$status = $action === 'enable' ? 'normal' : 'hidden';
|
||||
$manualManage = $action === 'enable' ? 0 : 1;
|
||||
$count = (int) $query->update([
|
||||
'status' => $status,
|
||||
'manual_manage' => $manualManage,
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
if ($count <= 0) {
|
||||
$this->error(__('No matching numbers found'));
|
||||
}
|
||||
|
||||
$this->success(sprintf(__('Batch operate success'), $count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 排除不可由表单提交的字段
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user