13283339616 6 years ago
parent
commit
052a5016eb
1 changed files with 50 additions and 0 deletions
  1. 50 0
      app/Api/V1/Controllers/FeaturesController.php

+ 50 - 0
app/Api/V1/Controllers/FeaturesController.php

191
     {
191
     {
192
         SearchRecord::insertSearchValue($value, $type);
192
         SearchRecord::insertSearchValue($value, $type);
193
     }
193
     }
194
+    public function startsWith($str, $prefix)
195
+    {
196
+        for ($i = 0; $i < strlen($prefix); ++$i) {
197
+            if ($prefix[$i] !== $str[$i]) {
198
+                return false;
199
+            }
200
+        }
194
 
201
 
202
+        return true;
203
+    }
195
     //早中晚专题
204
     //早中晚专题
196
     public function earlyMiddleAndLateTheme(Request $request){
205
     public function earlyMiddleAndLateTheme(Request $request){
197
         $data=Special::whereIn('title',['上午','中午','下午'])->get();
206
         $data=Special::whereIn('title',['上午','中午','下午'])->get();
198
         if (!$data) {
207
         if (!$data) {
199
             return $this->response->array(self::returnValue(['data' => 'Database error'], 9999));
208
             return $this->response->array(self::returnValue(['data' => 'Database error'], 9999));
200
         }
209
         }
210
+        $data=json_decode(json_encode($data),true);
211
+        foreach($data as $key=>$value){
212
+            $data[$key]['url']=config('constants.HOST_URL').$value['url'];
213
+        }
201
         return $this->response->array(self::returnValue(['data' => $data], 200));
214
         return $this->response->array(self::returnValue(['data' => $data], 200));
202
     }
215
     }
203
     //其他专题
216
     //其他专题
210
         $today=strtotime(date('Y-m-d'));
223
         $today=strtotime(date('Y-m-d'));
211
         $data=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->where('releaseTime','<',$today)->get();
224
         $data=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->where('releaseTime','<',$today)->get();
212
         $data=json_decode(json_encode($data),true);
225
         $data=json_decode(json_encode($data),true);
226
+        foreach($data as $key=>$value){
227
+            $data[$key]['url']=config('constants.HOST_URL').$value['url'];
228
+        }
213
         $json_menu_idarr=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->pluck('contain_recipes');
229
         $json_menu_idarr=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->pluck('contain_recipes');
214
         $json_menu_idarr=json_decode(json_encode($json_menu_idarr),true);
230
         $json_menu_idarr=json_decode(json_encode($json_menu_idarr),true);
215
         $initArr=array();
231
         $initArr=array();
221
         $initArr=array_unique($initArr);
237
         $initArr=array_unique($initArr);
222
         $menuAll=DB::table('menu')->whereIn('id',$initArr)->where('status',1)->get();
238
         $menuAll=DB::table('menu')->whereIn('id',$initArr)->where('status',1)->get();
223
         $menuAll=json_decode(json_encode($menuAll),true);
239
         $menuAll=json_decode(json_encode($menuAll),true);
240
+        foreach($menuAll as $key=>$value){
241
+            if(!$this->startsWith($value['url'],'http') && $value['url'] !='None' && $value['url']!=''){
242
+                $menuAll[$key]['url']=config('constants.HOST_URL').$value['url'];
243
+            }
244
+        }
224
         $middleArr=array();
245
         $middleArr=array();
225
         foreach($menuAll as $item){
246
         foreach($menuAll as $item){
226
             $middleArr["".$item['id']]=$item;
247
             $middleArr["".$item['id']]=$item;
239
         if (!$data) {
260
         if (!$data) {
240
             return $this->response->array(self::returnValue(['data' => 'Database error'], 9999));
261
             return $this->response->array(self::returnValue(['data' => 'Database error'], 9999));
241
         }
262
         }
263
+        $data=json_decode(json_encode($data),true);
264
+        foreach($data as $key=>$value){
265
+            if(!$this->startsWith($value['url'],'http') && $value['url'] !='None' && $value['url']!=''){
266
+                $data[$key]['url']=config('constants.HOST_URL').$value['url'];
267
+            }
268
+        }
242
         return $this->response->array(self::returnValue(['data' => $data], 200));
269
         return $this->response->array(self::returnValue(['data' => $data], 200));
243
     }
270
     }
244
     public function menuList(Request $request){
271
     public function menuList(Request $request){
260
             $idArr=explode(',',$special['contain_recipes']);
287
             $idArr=explode(',',$special['contain_recipes']);
261
         }
288
         }
262
         $menuList=Menu::whereIn('id',$idArr)->get();
289
         $menuList=Menu::whereIn('id',$idArr)->get();
290
+        $menuList=json_decode(json_encode($menuList),true);
291
+        foreach($menuList as $key=>$value){
292
+            if(!$this->startsWith($value['url'],'http') && $value['url'] !='None' && $value['url']!=''){
293
+                $menuList[$key]['url']=config('constants.HOST_URL').$value['url'];
294
+            }
295
+        }
263
         return $this->response->array(self::returnValue(['data' => $menuList], 200));
296
         return $this->response->array(self::returnValue(['data' => $menuList], 200));
264
     }
297
     }
265
 
298
 
266
     public function menuDetail(Request $request){
299
     public function menuDetail(Request $request){
267
         $id=$request->input('id');
300
         $id=$request->input('id');
268
         $menu=Menu::where('id',$id)->first();
301
         $menu=Menu::where('id',$id)->first();
302
+        if(!$this->startsWith($menu['url'],'http') && $menu['url'] !='None' && $menu['url']!=''){
303
+            $menu['url']=config('constants.HOST_URL').$menu['url'];
304
+        }
269
         $init=array();
305
         $init=array();
270
         $list=explode(';',$menu['ingredients']);
306
         $list=explode(';',$menu['ingredients']);
271
         foreach($list as $item){
307
         foreach($list as $item){
274
         }
310
         }
275
         $menu['ingredients']=$init;
311
         $menu['ingredients']=$init;
276
         $menuDetail=DB::table('menu_step')->where('menu_id',$id)->get();
312
         $menuDetail=DB::table('menu_step')->where('menu_id',$id)->get();
313
+        $menuDetail=json_decode(json_encode($menuDetail),true);
314
+        foreach($menuDetail as $key=>$value){
315
+            if(!$this->startsWith($value['url'],'http')  && $value['url'] !='None' && $value['url']!=''){
316
+                $menuDetail[$key]['url']=config('constants.HOST_URL').$value['url'];
317
+            }
318
+        }
277
         return $this->response->array(self::returnValue(['data' => $menu,'detailData'=>$menuDetail], 200));
319
         return $this->response->array(self::returnValue(['data' => $menu,'detailData'=>$menuDetail], 200));
278
     }
320
     }
279
 
321
 
285
         $data=json_decode(json_encode($data),true);
327
         $data=json_decode(json_encode($data),true);
286
         foreach($data as $key=>$item){
328
         foreach($data as $key=>$item){
287
             $data[$key]['category']=$type[$item['category']];
329
             $data[$key]['category']=$type[$item['category']];
330
+            if(!$this->startsWith($item['imgurl'],'http') && $item['imgurl'] !='None' && $item['imgurl']!=''){
331
+                $data[$key]['imgurl']=config('constants.HOST_URL').$item['imgurl'];
332
+            }
288
         }
333
         }
289
         return $this->response->array(self::returnValue(['data' => $data], 200));
334
         return $this->response->array(self::returnValue(['data' => $data], 200));
290
     }
335
     }
291
     public function articleDetail(Request $request){
336
     public function articleDetail(Request $request){
292
         $id=$request->input('id');
337
         $id=$request->input('id');
293
         $articleDetail=News::where('id',$id)->first();
338
         $articleDetail=News::where('id',$id)->first();
339
+        $articleDetail=json_decode(json_encode($articleDetail),true);
340
+        if(!$this->startsWith($articleDetail['imgurl'],'http') && $articleDetail['imgurl'] !='None' && $articleDetail['imgurl']!=''){
341
+            $articleDetail['imgurl']=config('constants.HOST_URL').$articleDetail['imgurl'];
342
+        }
294
         $type=NewsCategory::pluck('name','abbreviation');
343
         $type=NewsCategory::pluck('name','abbreviation');
295
         $articleDetail['category']=$type[$articleDetail['category']];
344
         $articleDetail['category']=$type[$articleDetail['category']];
296
         $articleDetail['content'] = str_replace(array("\r\n", "\r", "\n"), "", $articleDetail['content']);
345
         $articleDetail['content'] = str_replace(array("\r\n", "\r", "\n"), "", $articleDetail['content']);
346
+        $articleDetail['content'] = str_replace(array("/ueditor/php/upload/"), config('constants.HOST_URL')."/ueditor/php/upload/", $articleDetail['content']);
297
         return $this->response->array(self::returnValue(['data' => $articleDetail], 200));
347
         return $this->response->array(self::returnValue(['data' => $articleDetail], 200));
298
     }
348
     }
299
 }
349
 }