This commit is contained in:
xavier
2025-05-26 15:54:46 +08:00
parent 58f943acb0
commit 4f900ab7de
2 changed files with 113 additions and 8 deletions

View File

@@ -51,11 +51,11 @@ class TaskServer extends Server
// todo 临时测试,回头封装到类里调用,每个任务一个类
Timer::add(5, function () use ($current_worker_id, $process_count_for_status_0) {
if ($current_worker_id == self::PROCESS_COUNT - 1) {
// TODO 专门检查添加后的情况,是否通过
// TODO 专门检查添加后的情况,是否通过 使用独立的进程和定时器处理周期改为1min
$tasks = Db::name('task_customer')
->where('status', 1)
->limit(100)
->limit(50)
->select();
if ($tasks) {
// TODO 检查是否添加成功是否需要再次发送然后更新状态为2或3 ...
@@ -68,16 +68,55 @@ class TaskServer extends Server
$tasks = Db::name('task_customer')
->where('status', 0)
->whereRaw("id % $process_count_for_status_0 = {$current_worker_id}")
->limit(100)
->limit(50)
->select();
if ($tasks) {
// ... 更新状态为1然后处理再更新为2或3 ...
// ... 更新状态为1然后处理~~再更新为2或3~~ ...
foreach ($tasks as $task) {
// 查找 ck_customer_acquisition_task 表是否存在该任务然后拿到任务配置详情童谣的任务id需要缓存信息不要重复查询
$task_id = $task['task_id'];
// 先读取缓存
$task_info = cache('task_info_' . $task_id);
if (!$task_info) {
$task_info = Db::name('customer_acquisition_task')
->where('id', $task_id)
->find();
if ($task_info) {
cache('task_info_' . $task['task_id'], $task_info);
} else {
continue;
}
}
if (empty($task_info['status']) || empty($task_info['reqConf'])) {
continue;
}
// 先更新状态为1
Db::name('task_customer')
->where('id', $task['id'])
->update(['status' => 1]);
// todo 基于 $task['phone'] 和 $task_info['reqConf'] 进行处理
//通过conpany_id拿到设备/微信,判断这些微信的状态(是否在线,是否能加人)
// ~~// 更新状态为1 || 4~~
// // 更新状态为2
// Db::name('task_customer')
// ->where('id', $task['id'])
// ->update(['status' => 1]);
// 之后可能会更新为~~失败~~或者不处理 -- 失败一定是另一个进程/定时器在检查的
}
}
}
});
}
}