GeoQuestionLogic.php
5.5 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
<?php
/**
* @remark :
* @name :GeoQuestionLogic.php
* @author :lyh
* @method :post
* @time :2025/7/2 17:51
*/
namespace App\Http\Logic\Aside\Geo;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Geo\GeoPlatform;
use App\Models\Geo\GeoQuestion;
use App\Models\Geo\GeoQuestionResult;
use App\Models\Project\Project;
class GeoQuestionLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new GeoQuestion();
}
/**
* @remark :设置geo状态
* @name :setGeoStatus
* @author :lyh
* @method :post
* @time :2025/7/2 17:51
*/
public function setGeoStatus(){
$projectModel = new Project();
$data = $projectModel->edit(['geo_status'=>$this->param['geo_status'],'geo_frequency'=>$this->param['geo_frequency']],['id'=>$this->param['project_id']]);
$questionModel = new GeoQuestion();
$questionModel->edit(['status'=>$this->param['geo_status']],['project_id'=>$this->param['project_id']]);
return $this->success($data);
}
/**
* @remark :获取类型
* @name :getType
* @author :lyh
* @method :post
* @time :2025/7/3 10:47
*/
public function getType(){
$data['type'] = $this->model->brandType();
$data['frequency'] = $this->model->frequency;
$geoPlatformModel = new GeoPlatform();
$data['platform'] = $geoPlatformModel->getList();
return $this->success($data);
}
/**
* @remark :获取问题列表
* @name :getGeoQuestionList
* @author :lyh
* @method :post
* @time :2025/7/3 9:12
*/
public function getGeoQuestionList($map,$page,$row,$order,$field = ['*']){
$data = $this->model->lists($map,$page,$row,$order,$field);
if(!empty($data) && !empty($data['list'])){
foreach ($data['list'] as $key => $item){
$item['type_name'] = $this->model->brandType()[$item['type']];
$data['list'][$key] = $item;
}
}
return $this->success($data);
}
/**
* @remark :保存数据
* @name :saveGeoQuestion
* @author :lyh
* @method :post
* @time :2025/7/3 9:47
* @param : question->提交的问题
* @param : url->提交的网址
* @param : keywords->提交的关键字
* @param : project_id->项目id
*/
public function saveGeoQuestion(){
//处理数据
$max_num = 200;//最大数量
$count = count($this->param['question']);
if(isset($this->param['id']) && !empty($this->param['id'])){
//编辑
$sum = $this->model->where('project_id',$this->param['project_id'])->where('id','!=',$this->param['id'])->sum('question_num') ?? 0;
}else{
//新增
$sum = $this->model->where('project_id',$this->param['project_id'])->sum('question_num') ?? 0;
}
if(($count + $sum) > $max_num){
$this->fail('当前问题数量大于最大数量200个问题,不允许保存');
}
$question = $this->param['question'];
$this->param['url'] = json_encode($this->param['url'] ?? [],true);
$this->param['keywords'] = json_encode($this->param['keywords'] ?? [],true);
$chunks = array_chunk($question, 20);
if(isset($this->param['id']) && !empty($this->param['id'])){
foreach ($chunks as $index => $chunk) {
$this->param['question_num'] = count($chunk);
$this->param['question'] = json_encode($chunk ?? [],true);
if($index == 0){
$id = $this->param['id'];
$this->model->edit($this->param,['id'=>$id]);
}else{
unset($this->param['id']);
$id = $this->model->addReturnId($this->param);
}
}
}else{
$this->param['next_time'] = date('Y-m-d');
foreach ($chunks as $chunk) {
$this->param['question_num'] = count($chunk);
$this->param['question'] = json_encode($chunk ?? [],true);
$id = $this->model->addReturnId($this->param);
}
}
return $this->success(['id'=>$id]);
}
/**
* @remark :删除数据
* @name :delGeoQuestion
* @author :lyh
* @method :post
* @time :2025/7/3 10:13
*/
public function delGeoQuestion(){
$data = $this->model->del(['id'=>['in',$this->param['ids']]]);
return $this->success($data);
}
/**
* 获取未名字的问题列表
* @return array
* @author Akun
* @date 2025/11/25 16:44
*/
public function getUnHitQuestionList(){
$data = GeoQuestionResult::where('project_id',$this->param['project_id'])->where('hit',0)->select('platform','question')->get()->toArray();
$list = [];
if(!empty($data)){
$temp = [];
$question_list = [];
foreach ($data as $item){
if(in_array($item['question'],$question_list)){
array_push($temp[$item['question']],$item['platform']);
}else{
$temp[$item['question']][] = $item['platform'];
$question_list[] = $item['question'];
}
}
if(!empty($temp)){
foreach ($temp as $kt=>$vt){
$list[] = ['question'=>$kt,'platform'=>$vt];
}
}
}
return $this->success($list);
}
}