作者 刘锟

update

@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 9
10 namespace App\Http\Logic\Aside\Geo; 10 namespace App\Http\Logic\Aside\Geo;
11 11
  12 +use App\Helper\Arr;
12 use App\Http\Logic\Aside\BaseLogic; 13 use App\Http\Logic\Aside\BaseLogic;
13 use App\Models\Geo\GeoPlatform; 14 use App\Models\Geo\GeoPlatform;
14 use App\Models\Geo\GeoQuestion; 15 use App\Models\Geo\GeoQuestion;
@@ -189,8 +190,30 @@ class GeoQuestionLogic extends BaseLogic @@ -189,8 +190,30 @@ class GeoQuestionLogic extends BaseLogic
189 ]); 190 ]);
190 191
191 //删除问题 192 //删除问题
192 - $lists = $this->model->select(['id','question'])->where('project_id', $project_id)->whereJsonContains('question', [['Value' => $question]])->get()->toArray();  
193 - dd($lists); 193 + $lists = $this->model->select(['id','question'])->where('project_id', $project_id) ->whereRaw('JSON_CONTAINS(`question`,\'"'.$question.'"\')')->get();
  194 + if($lists->count() > 0){
  195 + foreach ($lists as $item){
  196 + if(count($item['question']) == 1){
  197 + //主问题只包含这一个子问题,直接删除主问题
  198 + $item->delete();
  199 + }else{
  200 + //主问题包含多个问题,只删除当前问题,保留剩下问题
  201 + $new_question = [];
  202 + foreach ($item['question'] as $vq){
  203 + if($vq == $question){
  204 + continue;
  205 + }
  206 + $new_question[] = $vq;
  207 + }
  208 + if(empty($new_question)){
  209 + $item->delete();
  210 + }else{
  211 + $item->question = Arr::a2s($new_question);
  212 + $item->save();
  213 + }
  214 + }
  215 + }
  216 + }
194 217
195 DB::commit(); 218 DB::commit();
196 }catch (\Exception $e){ 219 }catch (\Exception $e){