|
@@ -84,48 +84,44 @@ class GeoQuestionLogic extends BaseLogic |
|
@@ -84,48 +84,44 @@ class GeoQuestionLogic extends BaseLogic |
|
84
|
*/
|
84
|
*/
|
|
85
|
public function saveGeoQuestion(){
|
85
|
public function saveGeoQuestion(){
|
|
86
|
//处理数据
|
86
|
//处理数据
|
|
|
|
87
|
+ $max_num = 200;//最大数量
|
|
87
|
$count = count($this->param['question']);
|
88
|
$count = count($this->param['question']);
|
|
88
|
- $sum = $this->model->where('project_id',$this->param['project_id'])->sum('question_num') ?? 0;
|
|
|
|
89
|
- if($sum >= 200 || $count >= 200){
|
89
|
+ if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
90
|
+ //编辑
|
|
|
|
91
|
+ $sum = $this->model->where('project_id',$this->param['project_id'])->where('id','!=',$this->param['id'])->sum('question_num') ?? 0;
|
|
|
|
92
|
+ }else{
|
|
|
|
93
|
+ //新增
|
|
|
|
94
|
+ $sum = $this->model->where('project_id',$this->param['project_id'])->sum('question_num') ?? 0;
|
|
|
|
95
|
+ }
|
|
|
|
96
|
+ if(($count + $sum) > $max_num){
|
|
90
|
$this->fail('当前问题数量大于最大数量200个问题,不允许保存');
|
97
|
$this->fail('当前问题数量大于最大数量200个问题,不允许保存');
|
|
91
|
}
|
98
|
}
|
|
92
|
$question = $this->param['question'];
|
99
|
$question = $this->param['question'];
|
|
93
|
$this->param['url'] = json_encode($this->param['url'] ?? [],true);
|
100
|
$this->param['url'] = json_encode($this->param['url'] ?? [],true);
|
|
94
|
$this->param['keywords'] = json_encode($this->param['keywords'] ?? [],true);
|
101
|
$this->param['keywords'] = json_encode($this->param['keywords'] ?? [],true);
|
|
95
|
- if($count <= 20){
|
|
|
|
96
|
- $this->param['question_num'] = $count;
|
|
|
|
97
|
- if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
98
|
- $id = $this->param['id'];
|
|
|
|
99
|
- $this->model->edit($this->param,['id'=>$id]);
|
|
|
|
100
|
- }else{
|
|
|
|
101
|
- $this->param['next_time'] = date('Y-m-d');
|
|
|
|
102
|
- $id = $this->model->addReturnId($this->param);
|
|
|
|
103
|
- }
|
|
|
|
104
|
- return $this->success(['id'=>$id]);
|
|
|
|
105
|
- }else{
|
|
|
|
106
|
- $chunks = array_chunk($question, 20);
|
|
|
|
107
|
- if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
108
|
- foreach ($chunks as $index => $chunk) {
|
|
|
|
109
|
- $this->param['question_num'] = count($chunk);
|
|
|
|
110
|
- $this->param['question'] = json_encode($chunk ?? [],true);
|
|
|
|
111
|
- if($index == 0){
|
|
|
|
112
|
- $id = $this->param['id'];
|
|
|
|
113
|
- $this->model->edit($this->param,['id'=>$id]);
|
|
|
|
114
|
- }else{
|
|
|
|
115
|
- unset($this->param['id']);
|
|
|
|
116
|
- $id = $this->model->addReturnId($this->param);
|
|
|
|
117
|
- }
|
|
|
|
118
|
- }
|
|
|
|
119
|
- }else{
|
|
|
|
120
|
- $this->param['next_time'] = date('Y-m-d');
|
|
|
|
121
|
- foreach ($chunks as $chunk) {
|
|
|
|
122
|
- $this->param['question_num'] = count($chunk);
|
|
|
|
123
|
- $this->param['question'] = json_encode($chunk ?? [],true);
|
102
|
+ $chunks = array_chunk($question, 20);
|
|
|
|
103
|
+ if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
104
|
+ foreach ($chunks as $index => $chunk) {
|
|
|
|
105
|
+ $this->param['question_num'] = count($chunk);
|
|
|
|
106
|
+ $this->param['question'] = json_encode($chunk ?? [],true);
|
|
|
|
107
|
+ if($index == 0){
|
|
|
|
108
|
+ $id = $this->param['id'];
|
|
|
|
109
|
+ $this->model->edit($this->param,['id'=>$id]);
|
|
|
|
110
|
+ }else{
|
|
|
|
111
|
+ unset($this->param['id']);
|
|
124
|
$id = $this->model->addReturnId($this->param);
|
112
|
$id = $this->model->addReturnId($this->param);
|
|
125
|
}
|
113
|
}
|
|
126
|
}
|
114
|
}
|
|
127
|
- return $this->success(['id'=>$id]);
|
115
|
+ }else{
|
|
|
|
116
|
+ $this->param['next_time'] = date('Y-m-d');
|
|
|
|
117
|
+ foreach ($chunks as $chunk) {
|
|
|
|
118
|
+ $this->param['question_num'] = count($chunk);
|
|
|
|
119
|
+ $this->param['question'] = json_encode($chunk ?? [],true);
|
|
|
|
120
|
+ $id = $this->model->addReturnId($this->param);
|
|
|
|
121
|
+ }
|
|
128
|
}
|
122
|
}
|
|
|
|
123
|
+ return $this->success(['id'=>$id]);
|
|
|
|
124
|
+
|
|
129
|
}
|
125
|
}
|
|
130
|
|
126
|
|
|
131
|
/**
|
127
|
/**
|