WordAi.php
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?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;
}
}