13283339616 %!s(int64=6) %!d(string=před) roky
rodič
revize
052a5016eb
1 změnil soubory, kde provedl 50 přidání a 0 odebrání
  1. 50 0
      app/Api/V1/Controllers/FeaturesController.php

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

@@ -191,13 +191,26 @@ class FeaturesController extends BaseController
191 191
     {
192 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 205
     public function earlyMiddleAndLateTheme(Request $request){
197 206
         $data=Special::whereIn('title',['上午','中午','下午'])->get();
198 207
         if (!$data) {
199 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 214
         return $this->response->array(self::returnValue(['data' => $data], 200));
202 215
     }
203 216
     //其他专题
@@ -210,6 +223,9 @@ class FeaturesController extends BaseController
210 223
         $today=strtotime(date('Y-m-d'));
211 224
         $data=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->where('releaseTime','<',$today)->get();
212 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 229
         $json_menu_idarr=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->pluck('contain_recipes');
214 230
         $json_menu_idarr=json_decode(json_encode($json_menu_idarr),true);
215 231
         $initArr=array();
@@ -221,6 +237,11 @@ class FeaturesController extends BaseController
221 237
         $initArr=array_unique($initArr);
222 238
         $menuAll=DB::table('menu')->whereIn('id',$initArr)->where('status',1)->get();
223 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 245
         $middleArr=array();
225 246
         foreach($menuAll as $item){
226 247
             $middleArr["".$item['id']]=$item;
@@ -239,6 +260,12 @@ class FeaturesController extends BaseController
239 260
         if (!$data) {
240 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 269
         return $this->response->array(self::returnValue(['data' => $data], 200));
243 270
     }
244 271
     public function menuList(Request $request){
@@ -260,12 +287,21 @@ class FeaturesController extends BaseController
260 287
             $idArr=explode(',',$special['contain_recipes']);
261 288
         }
262 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 296
         return $this->response->array(self::returnValue(['data' => $menuList], 200));
264 297
     }
265 298
 
266 299
     public function menuDetail(Request $request){
267 300
         $id=$request->input('id');
268 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 305
         $init=array();
270 306
         $list=explode(';',$menu['ingredients']);
271 307
         foreach($list as $item){
@@ -274,6 +310,12 @@ class FeaturesController extends BaseController
274 310
         }
275 311
         $menu['ingredients']=$init;
276 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 319
         return $this->response->array(self::returnValue(['data' => $menu,'detailData'=>$menuDetail], 200));
278 320
     }
279 321
 
@@ -285,15 +327,23 @@ class FeaturesController extends BaseController
285 327
         $data=json_decode(json_encode($data),true);
286 328
         foreach($data as $key=>$item){
287 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 334
         return $this->response->array(self::returnValue(['data' => $data], 200));
290 335
     }
291 336
     public function articleDetail(Request $request){
292 337
         $id=$request->input('id');
293 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 343
         $type=NewsCategory::pluck('name','abbreviation');
295 344
         $articleDetail['category']=$type[$articleDetail['category']];
296 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 347
         return $this->response->array(self::returnValue(['data' => $articleDetail], 200));
298 348
     }
299 349
 }