|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name :WordAi.php
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/11/20 11:22
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Models\AiRemove\AiRemove;
|
|
|
|
use App\Services\WordAiService;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
|
|
class WordAi implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $param;
|
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
|
|
|
$this->param = $data;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @remark :执行数据
|
|
|
|
* @name :handle
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/11/20 11:24
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$model = new AiRemove();
|
|
|
|
$info = $model->read(['id'=>$this->param['id']]);
|
|
|
|
if($info !== false && !empty($info['origin_text'])) {
|
|
|
|
$model->edit(['status'=>$model::STATUS_ING],['id'=>$info['id']]);
|
|
|
|
$wordAiService = new WordAiService();
|
|
|
|
$data = $wordAiService->setApiAvoid($info['origin_text']);
|
|
|
|
if(isset($data['status']) && $data['status'] == 'success'){
|
|
|
|
//todo::更新当前任务状态,并记录返回的值
|
|
|
|
$model->edit(['target_text'=>$data['text'],'status'=>$model::STATUS_SUC],['id'=>$info['id']]);
|
|
|
|
}else{
|
|
|
|
//todo::更改执行次数,及错误结果
|
|
|
|
$model->edit(['error_msg'=>json_encode($data,JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),'status'=>$model::STATUS_FAL],['id'=>$info['id']]);
|
|
|
|
sleep(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|