|
|
|
1
|
+<?php
|
|
|
|
2
|
+/**
|
|
|
|
3
|
+ * @remark :
|
|
|
|
4
|
+ * @name :UpdateController.php
|
|
|
|
5
|
+ * @author :lyh
|
|
|
|
6
|
+ * @method :post
|
|
|
|
7
|
+ * @time :2023/8/19 9:08
|
|
|
|
8
|
+ */
|
|
|
|
9
|
+
|
|
|
|
10
|
+namespace App\Http\Controllers\Aside\Com;
|
|
|
|
11
|
+
|
|
|
|
12
|
+use App\Helper\Common;
|
|
|
|
13
|
+use App\Http\Controllers\Bside\BaseController;
|
|
|
|
14
|
+use App\Services\ProjectServer;
|
|
|
|
15
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
16
|
+
|
|
|
|
17
|
+/**
|
|
|
|
18
|
+ * @remark :b端网站更新相关
|
|
|
|
19
|
+ * @name :UpdateController
|
|
|
|
20
|
+ * @author :lyh
|
|
|
|
21
|
+ * @method :post
|
|
|
|
22
|
+ * @time :2023/8/19 9:08
|
|
|
|
23
|
+ */
|
|
|
|
24
|
+class UpdateController extends BaseController
|
|
|
|
25
|
+{
|
|
|
|
26
|
+ /**
|
|
|
|
27
|
+ * @remark :一键更新所有tdk
|
|
|
|
28
|
+ * @name :updateSeoTdk
|
|
|
|
29
|
+ * @author :lyh
|
|
|
|
30
|
+ * @method :post
|
|
|
|
31
|
+ * @time :2023/8/19 9:25
|
|
|
|
32
|
+ */
|
|
|
|
33
|
+ public function updateSeoTdk(){
|
|
|
|
34
|
+ $this->request->validate([
|
|
|
|
35
|
+ 'project_id'=>'required',
|
|
|
|
36
|
+ ],[
|
|
|
|
37
|
+ 'project_id.required' => 'project_id不能为空',
|
|
|
|
38
|
+ ]);
|
|
|
|
39
|
+ ProjectServer::useProject($this->param['project_id']);
|
|
|
|
40
|
+ $this->updateProduct($this->param['project_id']);
|
|
|
|
41
|
+ $this->updateBlogs($this->param['project_id']);
|
|
|
|
42
|
+ $this->updateNews($this->param['project_id']);
|
|
|
|
43
|
+ DB::disconnect('custom_mysql');
|
|
|
|
44
|
+ $this->response('success');
|
|
|
|
45
|
+ }
|
|
|
|
46
|
+
|
|
|
|
47
|
+ /**
|
|
|
|
48
|
+ * @remark :更新产品tdk
|
|
|
|
49
|
+ * @name :updateProduct
|
|
|
|
50
|
+ * @author :lyh
|
|
|
|
51
|
+ * @method :post
|
|
|
|
52
|
+ * @time :2023/8/19 9:25
|
|
|
|
53
|
+ */
|
|
|
|
54
|
+ public function updateProduct($project_id){
|
|
|
|
55
|
+ $list = DB::connection('custom_mysql')->table('gl_product')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
|
|
|
|
56
|
+ if(!empty($list)){
|
|
|
|
57
|
+ foreach ($list as $v){
|
|
|
|
58
|
+ if(!empty($v['seo_mate'])){
|
|
|
|
59
|
+ $seo_arr = $v['seo_mate'];
|
|
|
|
60
|
+ //更新seo_title
|
|
|
|
61
|
+ if(!isset($seo_arr['title'])){
|
|
|
|
62
|
+ //生成seo_title
|
|
|
|
63
|
+ $seo_arr['title'] = $this->ai_send('product_seo_title',$v['title']);
|
|
|
|
64
|
+ }
|
|
|
|
65
|
+ //更新seo_keyword
|
|
|
|
66
|
+ if(!isset($seo_arr['keyword'])){
|
|
|
|
67
|
+ $seo_arr['keyword'] = $this->ai_send('product_seo_keyword',$v['title']);
|
|
|
|
68
|
+ }
|
|
|
|
69
|
+ //更新seo_keyword
|
|
|
|
70
|
+ if(!isset($seo_arr['description'])){
|
|
|
|
71
|
+ $seo_arr['description'] = $this->ai_send('product_seo_description',$v['title']);
|
|
|
|
72
|
+ }
|
|
|
|
73
|
+ $ser_str = json_encode($seo_arr,true);
|
|
|
|
74
|
+ DB::connection('custom_mysql')->table('gl_product')->where(['id'=>$v['id']])->update(['seo_mate'=>$ser_str]);
|
|
|
|
75
|
+ }
|
|
|
|
76
|
+ }
|
|
|
|
77
|
+ }
|
|
|
|
78
|
+ return true;
|
|
|
|
79
|
+ }
|
|
|
|
80
|
+
|
|
|
|
81
|
+ /**
|
|
|
|
82
|
+ * @remark :更新新闻Tdk
|
|
|
|
83
|
+ * @name :updateNews
|
|
|
|
84
|
+ * @author :lyh
|
|
|
|
85
|
+ * @method :post
|
|
|
|
86
|
+ * @time :2023/8/19 10:06
|
|
|
|
87
|
+ */
|
|
|
|
88
|
+ public function updateNews($project_id){
|
|
|
|
89
|
+ $list = DB::connection('custom_mysql')->table('gl_news')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
|
|
|
|
90
|
+ if(!empty($list)){
|
|
|
|
91
|
+ foreach ($list as $k => $v){
|
|
|
|
92
|
+ $data = [];
|
|
|
|
93
|
+ if(empty($v['seo_title'])){
|
|
|
|
94
|
+ $data['seo_title'] = $this->ai_send('news_seo_title',$v['name']);
|
|
|
|
95
|
+ }
|
|
|
|
96
|
+ if(empty($v['seo_keywords'])){
|
|
|
|
97
|
+ $data['seo_keywords'] = $this->ai_send('news_seo_keyword',$v['name']);
|
|
|
|
98
|
+ }
|
|
|
|
99
|
+ if(empty($v['seo_description'])){
|
|
|
|
100
|
+ $data['seo_description'] = $this->ai_send('news_seo_description',$v['name']);
|
|
|
|
101
|
+ }
|
|
|
|
102
|
+ DB::connection('custom_mysql')->table('gl_news')->where(['id'=>$v['id']])->update($data);
|
|
|
|
103
|
+ }
|
|
|
|
104
|
+ }
|
|
|
|
105
|
+ return true;
|
|
|
|
106
|
+ }
|
|
|
|
107
|
+
|
|
|
|
108
|
+ /**
|
|
|
|
109
|
+ * @remark :更新blogTdk
|
|
|
|
110
|
+ * @name :updateBlogs
|
|
|
|
111
|
+ * @author :lyh
|
|
|
|
112
|
+ * @method :post
|
|
|
|
113
|
+ * @time :2023/8/19 10:07
|
|
|
|
114
|
+ */
|
|
|
|
115
|
+ public function updateBlogs($project_id){
|
|
|
|
116
|
+ $list = DB::connection('custom_mysql')->table('gl_blog')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
|
|
|
|
117
|
+ if(!empty($list)){
|
|
|
|
118
|
+ foreach ($list as $k => $v){
|
|
|
|
119
|
+ $data = [];
|
|
|
|
120
|
+ if(empty($v['seo_title'])){
|
|
|
|
121
|
+ $data['seo_title'] = $this->ai_send('blog_seo_title',$v['name']);
|
|
|
|
122
|
+ }
|
|
|
|
123
|
+ if(empty($v['seo_keywords'])){
|
|
|
|
124
|
+ $data['seo_keywords'] = $this->ai_send('blog_seo_keyword',$v['name']);
|
|
|
|
125
|
+ }
|
|
|
|
126
|
+ if(empty($v['seo_description'])){
|
|
|
|
127
|
+ $data['seo_description'] = $this->ai_send('blog_seo_description',$v['name']);
|
|
|
|
128
|
+ }
|
|
|
|
129
|
+ DB::connection('custom_mysql')->table('gl_product')->where(['id'=>$v['id']])->update($data);
|
|
|
|
130
|
+ }
|
|
|
|
131
|
+ }
|
|
|
|
132
|
+ return true;
|
|
|
|
133
|
+ }
|
|
|
|
134
|
+
|
|
|
|
135
|
+ /**
|
|
|
|
136
|
+ * @remark :AI发送
|
|
|
|
137
|
+ * @name :ai_send
|
|
|
|
138
|
+ * @author :lyh
|
|
|
|
139
|
+ * @method :post
|
|
|
|
140
|
+ * @time :2023/8/19 10:40
|
|
|
|
141
|
+ */
|
|
|
|
142
|
+ public function ai_send($key,$keywords){
|
|
|
|
143
|
+ $chat_url = 'v2/openai_chat';
|
|
|
|
144
|
+ $param = [
|
|
|
|
145
|
+ 'key'=>$key,
|
|
|
|
146
|
+ 'keywords'=>$keywords,
|
|
|
|
147
|
+ ];
|
|
|
|
148
|
+ $data = Common::send_openai_msg($chat_url,$param);
|
|
|
|
149
|
+ return $data['text'];
|
|
|
|
150
|
+ }
|
|
|
|
151
|
+} |