作者 李忠强
1 个管道 的构建 通过 耗费 1 秒

更新

@@ -118,11 +118,11 @@ class Index extends Api @@ -118,11 +118,11 @@ class Index extends Api
118 ->paginate(10,false,['page'=>$num]); 118 ->paginate(10,false,['page'=>$num]);
119 $list = $list->toArray(); 119 $list = $list->toArray();
120 foreach ($list['data'] as $key=>$value){ 120 foreach ($list['data'] as $key=>$value){
121 - $db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$value['id'])->select();  
122 - foreach ($db as $k => $val){  
123 - $detail['collection_status'] = isset($val['type']) && $val['type'] == 2 ? 1:0;  
124 - $detail['experience_status'] = isset($val['type']) && $val['type'] == 1 ? 1:0;  
125 - } 121 + $db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$value['id'])->where('type',2)->value('id');
  122 + $list['data'][$key]['collection_status'] = $db ? 1:0;
  123 + $db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$value['id'])->where('type',1)->value('id');
  124 + $list['data'][$key]['experience_status'] = $db ? 1:0;
  125 +
126 } 126 }
127 $this->success('条件搜索列表',['list'=>$list]); 127 $this->success('条件搜索列表',['list'=>$list]);
128 } 128 }
@@ -180,11 +180,10 @@ class Index extends Api @@ -180,11 +180,10 @@ class Index extends Api
180 $detail->getRelation('idea_type')->visible(['name']); 180 $detail->getRelation('idea_type')->visible(['name']);
181 $detail->visible(['title','id','all_number','collection','duration','mid_feel','idea_type']); 181 $detail->visible(['title','id','all_number','collection','duration','mid_feel','idea_type']);
182 $detail = $detail->toArray(); 182 $detail = $detail->toArray();
183 - $db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->select();  
184 - foreach ($db as $key => $value){  
185 - $detail['collection_status'] = isset($value['type']) && $value['type'] == 2 ? 1:0;  
186 - $detail['experience_status'] = isset($value['type']) && $value['type'] == 1 ? 1:0;  
187 - } 183 + $db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',2)->value('id');
  184 + $detail['collection_status'] = $db ? 1:0;
  185 + $db = Db::name('user_idea_record')->where('user_id',$this->auth->id)->where('idea_id',$id)->where('type',1)->value('id');
  186 + $detail['experience_status'] = $db ? 1:0;
188 187
189 $this->success('点子详情',['detail'=>$detail]); 188 $this->success('点子详情',['detail'=>$detail]);
190 } 189 }