|
|
|
1
|
+<?php
|
|
|
|
2
|
+/**
|
|
|
|
3
|
+ * @remark :
|
|
|
|
4
|
+ * @name :WordAi.php
|
|
|
|
5
|
+ * @author :lyh
|
|
|
|
6
|
+ * @method :post
|
|
|
|
7
|
+ * @time :2025/11/20 11:22
|
|
|
|
8
|
+ */
|
|
|
|
9
|
+
|
|
|
|
10
|
+namespace App\Jobs;
|
|
|
|
11
|
+
|
|
|
|
12
|
+use App\Models\AiRemove\AiRemove;
|
|
|
|
13
|
+use App\Services\WordAiService;
|
|
|
|
14
|
+use Illuminate\Bus\Queueable;
|
|
|
|
15
|
+use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
16
|
+use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
17
|
+use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
18
|
+use Illuminate\Queue\SerializesModels;
|
|
|
|
19
|
+
|
|
|
|
20
|
+class WordAi implements ShouldQueue
|
|
|
|
21
|
+{
|
|
|
|
22
|
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
23
|
+
|
|
|
|
24
|
+ protected $param;
|
|
|
|
25
|
+
|
|
|
|
26
|
+ public function __construct($data)
|
|
|
|
27
|
+ {
|
|
|
|
28
|
+ $this->param = $data;
|
|
|
|
29
|
+ }
|
|
|
|
30
|
+ /**
|
|
|
|
31
|
+ * @remark :执行数据
|
|
|
|
32
|
+ * @name :handle
|
|
|
|
33
|
+ * @author :lyh
|
|
|
|
34
|
+ * @method :post
|
|
|
|
35
|
+ * @time :2025/11/20 11:24
|
|
|
|
36
|
+ */
|
|
|
|
37
|
+ public function handle()
|
|
|
|
38
|
+ {
|
|
|
|
39
|
+ $model = new AiRemove();
|
|
|
|
40
|
+ $info = $model->read(['id'=>$this->param['id']]);
|
|
|
|
41
|
+ if($info !== false && !empty($info['origin_text'])) {
|
|
|
|
42
|
+ $model->edit(['status'=>$model::STATUS_ING],['id'=>$info['id']]);
|
|
|
|
43
|
+ $wordAiService = new WordAiService();
|
|
|
|
44
|
+ $data = $wordAiService->setApiAvoid($info['origin_text']);
|
|
|
|
45
|
+ if(isset($data['status']) && $data['status'] == 'success'){
|
|
|
|
46
|
+ //todo::更新当前任务状态,并记录返回的值
|
|
|
|
47
|
+ $model->edit(['target_text'=>$data['text'],'status'=>$model::STATUS_SUC],['id'=>$info['id']]);
|
|
|
|
48
|
+ }else{
|
|
|
|
49
|
+ //todo::更改执行次数,及错误结果
|
|
|
|
50
|
+ $model->edit(['error_msg'=>json_encode($data,JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),'status'=>$model::STATUS_FAL],['id'=>$info['id']]);
|
|
|
|
51
|
+ sleep(10);
|
|
|
|
52
|
+ }
|
|
|
|
53
|
+ }
|
|
|
|
54
|
+ return true;
|
|
|
|
55
|
+ }
|
|
|
|
56
|
+} |