wip
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\staff\controller;
|
||||
namespace app\api\controller;
|
||||
|
||||
class Index
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return '您好!这是一个[staff]示例应用';
|
||||
return '您好!这是一个[api]示例应用';
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
<?php
|
||||
// 这是系统自动生成的公共文件
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
// 这是系统自动生成的event定义文件
|
||||
return [
|
||||
|
||||
];
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
// 这是系统自动生成的middleware定义文件
|
||||
return [
|
||||
|
||||
];
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
class SyncData extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('syncdata')->setDescription('从宝塔同步并处理数据');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('开始连接远程数据库...');
|
||||
|
||||
try {
|
||||
// 增加 count 确认远程到底有没有数据
|
||||
$total = Db::connect('remote')->table('tickets')->count();
|
||||
$output->writeln("远程表共有 {$total} 条数据待处理");
|
||||
|
||||
if ($total == 0) {
|
||||
$output->writeln('警告:远程表中没有找到数据,请检查表名或权限。');
|
||||
return 0;
|
||||
}
|
||||
|
||||
// chunk(100) 比较平衡,2 太小了
|
||||
Db::connect('remote')->table('tickets')->chunk(100, function ($remoteRows) use ($output) {
|
||||
$processedData = [];
|
||||
|
||||
foreach ($remoteRows as $row) {
|
||||
$operator = Db::name('company_operators')->where('operator_name', 'like', '%' . $row['operator'] . '%')->find();
|
||||
|
||||
$operator_id = $operator ? $operator['id'] : null;
|
||||
$company_id = $operator ? $operator['company_id'] : null;
|
||||
|
||||
|
||||
$processedData[] = [
|
||||
'id' => $row['id'], // 如果想用旧ID就取消注释,否则留空让本地表自增
|
||||
'website' => $row['website'],
|
||||
'datanum' => $row['datanum'],
|
||||
'create_time' => !empty($row['create_time']) ? $row['create_time'] : 0,
|
||||
'update_time' => !empty($row['update_time']) ? $row['update_time'] : 0,
|
||||
'progress' => $row['progress'],
|
||||
'remark' => $row['remark'] ?? '',
|
||||
'status' => $row['is_complete'],
|
||||
'lock_time' => $row['lock_time'] ?? 0,
|
||||
'operator_id' => $operator_id ?? 0,
|
||||
'company_id' => $company_id ?? 0,
|
||||
'user_id' => $row['staff_id'] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($processedData)) {
|
||||
// 使用 try-catch 捕获插入时的报错
|
||||
try {
|
||||
Db::name('tickets')->insertAll($processedData);
|
||||
$output->writeln("成功插入一批数据 (" . count($processedData) . " 条)");
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("本地插入失败: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("严重错误: " . $e->getMessage());
|
||||
}
|
||||
|
||||
$output->writeln('--- 同步流程结束 ---');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class TicketService
|
||||
private function applyScope($query, TicketScope $scope): void
|
||||
{
|
||||
match ($scope->type) {
|
||||
'admin' => null,
|
||||
'client' => null,
|
||||
'staff' => $query->where(fn($q) => $q
|
||||
->where('status', Tickets::STATUS_UNASSIGNED)
|
||||
->where('user_id', $scope->staffId)),
|
||||
@@ -141,6 +141,8 @@ class TicketService
|
||||
throw new \Exception('工单不存在');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 提取 $allowFields 允许修改的字段
|
||||
$updateData = [];
|
||||
foreach ($allowFields as $field) {
|
||||
|
||||
@@ -15,10 +15,13 @@ class Ticket extends BaseController
|
||||
{
|
||||
|
||||
$isUser = Session::get('user_info.role') === 'user'; // 获取当前登录ID
|
||||
$data = $this->request->post();
|
||||
$post = $this->request->post();
|
||||
|
||||
$allowFields = ['datanum', 'progress', 'status', 'remark', 'lock_time', 'user_id'];
|
||||
$data = [
|
||||
'datanum' => $post['datanum']
|
||||
]
|
||||
|
||||
|
||||
try {
|
||||
$result = $ticketService->updateTicket($id, $data, $allowFields, $isUser, false);
|
||||
return $this->success('更新成功', $result);
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
<?php
|
||||
// 这是系统自动生成的公共文件
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
// 这是系统自动生成的event定义文件
|
||||
return [
|
||||
|
||||
];
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
// 这是系统自动生成的middleware定义文件
|
||||
return [
|
||||
|
||||
];
|
||||
Reference in New Issue
Block a user