修改自动推广的相关任务
This commit is contained in:
@@ -6,6 +6,7 @@ use think\Db;
|
||||
use think\Env;
|
||||
use think\Cache;
|
||||
use think\Queue;
|
||||
use think\Config;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use think\Validate;
|
||||
use app\common\PromotionService;
|
||||
@@ -1758,7 +1759,24 @@ class EmailClient extends Base
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$service = new PromotionService();
|
||||
$service->dispatchPrepareEmails($data['id']);
|
||||
$taskId = intval($data['id']);
|
||||
|
||||
// 调用前快照:用于解释"为什么没入队"
|
||||
$task = \think\Db::name('promotion_task')->where('task_id', $taskId)->find();
|
||||
$pending = \think\Db::name('promotion_email_log')
|
||||
->where('task_id', $taskId)
|
||||
->where('state', 0)
|
||||
->where('prepared_at', 0)
|
||||
->count();
|
||||
|
||||
$result = $service->dispatchPrepareEmails($taskId);
|
||||
|
||||
return jsonSuccess([
|
||||
'task_id' => $taskId,
|
||||
'task_state' => $task ? intval($task['state']) : null, // 0 才能 dispatch;5 已准备完
|
||||
'pending_before' => intval($pending), // 调用前还能入队的 log 数
|
||||
'dispatch_result' => $result, // ['dispatched' => N, ...]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1771,7 +1789,65 @@ class EmailClient extends Base
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$service = new PromotionService();
|
||||
$service->prepareSingleEmail($data['id']);
|
||||
$result = $service->prepareSingleEmail(intval($data['id']));
|
||||
return jsonSuccess($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 队列调试:查看 Redis 里队列长度(不依赖 redis-cli)。
|
||||
*
|
||||
* GET/POST 参数:
|
||||
* queue 队列名(默认 PromotionPrepareEmail)
|
||||
*
|
||||
* 返回:
|
||||
* - ready/reserved/delayed 长度
|
||||
* - queue 配置关键字段
|
||||
*/
|
||||
public function queueDebug()
|
||||
{
|
||||
$queue = trim((string)$this->request->param('queue', 'PromotionPrepareEmail'));
|
||||
if ($queue === '') {
|
||||
$queue = 'PromotionPrepareEmail';
|
||||
}
|
||||
|
||||
try {
|
||||
$cfg = Config::get('queue');
|
||||
$redis = new \Redis();
|
||||
$connectMethod = !empty($cfg['persistent']) ? 'pconnect' : 'connect';
|
||||
$redis->$connectMethod($cfg['host'] ?? '127.0.0.1', $cfg['port'] ?? 6379);
|
||||
if (!empty($cfg['password'])) {
|
||||
$redis->auth($cfg['password']);
|
||||
}
|
||||
$redis->select($cfg['select'] ?? 0);
|
||||
|
||||
$readyKey = 'queues:' . $queue;
|
||||
$reservedKey = 'queues:' . $queue . ':reserved';
|
||||
$delayedKey = 'queues:' . $queue . ':delayed';
|
||||
|
||||
return jsonSuccess([
|
||||
'queue' => $queue,
|
||||
'redis' => [
|
||||
'db' => $cfg['select'] ?? 0,
|
||||
'host' => $cfg['host'] ?? '127.0.0.1',
|
||||
'port' => $cfg['port'] ?? 6379,
|
||||
'persistent' => !empty($cfg['persistent']) ? 1 : 0,
|
||||
'expire' => $cfg['expire'],
|
||||
],
|
||||
'keys' => [
|
||||
'ready' => $readyKey,
|
||||
'reserved' => $reservedKey,
|
||||
'delayed' => $delayedKey,
|
||||
],
|
||||
'len' => [
|
||||
'ready' => (int)$redis->lLen($readyKey),
|
||||
'reserved' => (int)$redis->zCard($reservedKey),
|
||||
'delayed' => (int)$redis->zCard($delayedKey),
|
||||
],
|
||||
'ping' => (string)$redis->ping(),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return jsonError('queueDebug failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2395,6 +2471,17 @@ class EmailClient extends Base
|
||||
return jsonSuccess($result);
|
||||
}
|
||||
|
||||
|
||||
public function testYbpard(){
|
||||
$service = new PromotionService();
|
||||
$expert['application_link_yeditorial_board'] = $service->buildYboardApplyUrl(
|
||||
intval(259116),
|
||||
intval(3)
|
||||
);
|
||||
return jsonSuccess($expert);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 每日自动触发发送(把 prepared 的任务启动),供 crontab 调用
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user