CreateKeywordLogic.php
6.2 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/**
* @remark :
* @name :CreateKeywordLogic.php
* @author :lyh
* @method :post
* @time :2023/12/19 9:45
*/
namespace App\Http\Logic\Aside\Optimize;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Com\CreateKeyword;
class CreateKeywordLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new CreateKeyword();
$this->param = $this->requestAll;
}
/**
* @remark :保存关键字
* @name :saveCreateKeyword
* @author :lyh
* @method :post
* @time :2023/12/19 9:47
*/
public function saveKeyword(){
$data = $this->handleParam($this->param);
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->model->edit($data,['id'=>$this->param['id']]);
}else{
$this->model->add($data);
}
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
return $this->success();
}
/**
* @remark :请求参数处理
* @name :handleParam
* @author :lyh
* @method :post
* @time :2023/12/19 10:03
*/
public function handleParam($param){
$data = [
'type'=>$param['type'],
'name'=>$param['name'],
'language_id'=>$param['language_id'] ?? 0
];
if(!isset($param['id'])){
$info = $this->model->read($data);
if($info !== false){
$this->fail('当前名称已存在');
}
}else{
$data['id'] = ['!=',$param['id']];
$info = $this->model->read($data);
if($info !== false){
$this->fail('当前名称已存在');
}
}
return $this->success($data);
}
/**
* @remark :创建关键词
* @name :createKeyword
* @author :lyh
* @method :post
* @time :2023/12/19 10:48
*/
public function createKeyword(){
$data = array();
if(empty($this->param['keyword'])){
return $this->success($data);
}
$except_k = ['Quality','Philippines','USA','UK','America','China','Wholesale','Hot Sale','Cheap','cheap','price','pricelist','hot sale','Price','Pricelist','With ','For ','And ','Oem','Odm','Supplier','Manufacturer','CE Certification','Factory','Exporters','Company','Companies','Suppliers','Manufacturers','Factories','Company','Companies','Exporters','Exporter','Buy ',' Buy','Where ','What ','When ','How ','Which ','Producer','Producers','Best Selling','Hot Selling','Near','Chinese','India','use','high quality','discount','online','custom','customized','Enterprise','Agent','Plant','Refinery','Foundry','Maker','Distributor'];
$filterKeywords = [];
foreach ($this->param['keyword'] as $k=>$keyword){
foreach ($except_k as $exc_k){
if(strpos(strtolower($keyword),strtolower($exc_k)) !== false){
unset($this->param['keyword'][$k]);
$filterKeywords[] = $keyword;
}
}
}
$prefix_keyword = $this->prefixKeyword($this->param['prefix'] ?? [],$this->param['keyword'],$except_k);
$keyword_suffix = $this->keywordSuffix($this->param['suffix'] ?? [],$this->param['keyword'],$except_k);
$prefix_keyword_suffix = $this->prefixKeywordSuffix($this->param['prefix'] ?? [],$this->param['suffix'] ?? [],$this->param['keyword'],$except_k);
$data = [
'prefix_keyword'=>$prefix_keyword,
'prefix_keyword_count'=>count($prefix_keyword),
'keyword_suffix'=>$keyword_suffix,
'keyword_suffix_count'=>count($keyword_suffix),
'prefix_keyword_suffix'=>$prefix_keyword_suffix,
'prefix_keyword_suffix_count'=>count($prefix_keyword_suffix),
'filterKeywords'=>$filterKeywords,
'filterKeywords_count'=>count($filterKeywords),
];
return $this->success($data);
}
/**
* @remark :前缀+关键词
* @name :
* @author :lyh
* @method :post
* @time :2023/12/19 11:11
*/
public function prefixKeyword($prefix,$keyword,$except_k){
$prefix_keyword = array();
if(!empty($prefix)){//前缀+关键词
foreach ($keyword as $keywordItem){
foreach ($prefix as $prefixItem) {
if (strpos($keywordItem, $prefixItem) === 0) {
continue;
}
$prefix_keyword[] =$prefixItem.' '.$keywordItem;
}
}
}
return $this->success($prefix_keyword);
}
/**
* @remark :关键词+后缀
* @name :
* @author :lyh
* @method :post
* @time :2023/12/19 11:11
*/
public function keywordSuffix($suffix,$keyword){
$suffix_keyword = array();
if(!empty($suffix)){//前缀+关键词
foreach ($keyword as $keywordItem){
foreach ($suffix as $suffixItem) {
if (str_ends_with($keywordItem, $suffixItem)) {
continue;
}
$suffix_keyword[] = $keywordItem.' '.$suffixItem;
}
}
}
return $this->success($suffix_keyword);
}
/**
* @remark :前缀+关键词+后缀
* @name :prefixKeywordSuffix
* @author :lyh
* @method :post
* @time :2023/12/19 11:59
*/
public function prefixKeywordSuffix($prefix,$suffix,$keyword){
$prefix_keyword_suffix = array();
if(!empty($prefix) && !empty($suffix)){
foreach ($keyword as $keywordItem){
foreach ($prefix as $prefixItem) {
if (strpos($keywordItem, $prefixItem) === 0) {
continue;
}
foreach ($suffix as $suffixItem) {
if (str_ends_with($keywordItem, $suffixItem)) {
continue;
}
$prefix_keyword_suffix[] = $prefixItem.' '.$keywordItem.' '.$suffixItem;
}
}
}
}
return $this->success($prefix_keyword_suffix);
}
}