13283339616 il y a 6 ans
Parent
commit
6c04e28e31
6 fichiers modifiés avec 145 ajouts et 3 suppressions
  1. 100 1
      app/Api/V1/Controllers/FeaturesController.php
  2. 11 0
      app/Models/News.php
  3. 11 0
      app/Models/Special.php
  4. 1 1
      config/app.php
  5. 1 1
      public/index.php
  6. 21 0
      routes/api.php

+ 100 - 1
app/Api/V1/Controllers/FeaturesController.php

@@ -9,9 +9,11 @@ use App\Models\SearchRecord;
9 9
 use App\Models\SearchStatistics;
10 10
 use App\Models\Tag;
11 11
 use App\Models\UserMessage;
12
+use App\Models\Special;
13
+use App\Models\News;
12 14
 use Illuminate\Http\Request;
13 15
 use Solr;
14
-
16
+use DB;
15 17
 class FeaturesController extends BaseController
16 18
 {
17 19
 
@@ -188,4 +190,101 @@ class FeaturesController extends BaseController
188 190
     {
189 191
         SearchRecord::insertSearchValue($value, $type);
190 192
     }
193
+
194
+    //早中晚专题
195
+    public function earlyMiddleAndLateTheme(Request $request){
196
+        $data=Special::whereIn('title',['上午','中午','下午'])->get();
197
+        if (!$data) {
198
+            return $this->response->array(self::returnValue(['data' => 'Database error'], 9999));
199
+        }
200
+        return $this->response->array(self::returnValue(['data' => $data], 200));
201
+    }
202
+    //其他专题
203
+
204
+    /**
205
+     * @param Request $request
206
+     * @return mixed
207
+     */
208
+    public function otherTheme(Request $request){
209
+        $today=strtotime(date('Y-m-d'));
210
+        $data=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->where('releaseTime','<',$today)->get();
211
+        $data=json_decode(json_encode($data),true);
212
+        $json_menu_idarr=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->pluck('contain_recipes');
213
+        $json_menu_idarr=json_decode(json_encode($json_menu_idarr),true);
214
+        $initArr=array();
215
+        foreach($json_menu_idarr as $item){
216
+            if($item){
217
+                $initArr=array_merge($initArr,explode(',',$item));
218
+            }
219
+        }
220
+        $initArr=array_unique($initArr);
221
+        $menuAll=DB::table('menu')->whereIn('id',$initArr)->where('status',1)->get();
222
+        $menuAll=json_decode(json_encode($menuAll),true);
223
+        $middleArr=array();
224
+        foreach($menuAll as $item){
225
+            $middleArr["".$item['id']]=$item;
226
+        }
227
+        foreach($data as $key=>$item){
228
+            if($item['contain_recipes']){
229
+                foreach(explode(',',$item['contain_recipes']) as $inneritem){
230
+                    $data[$key]['menuList'][]=$middleArr[$inneritem];
231
+                }
232
+            }
233
+        }
234
+        return $this->response->array(self::returnValue(['data' => $data], 200));
235
+    }
236
+    public function theLastRecipes(Request $request){
237
+        $data=Menu::where('status',1)->orderBy('created_at','desc')->limit(50)->get();
238
+        if (!$data) {
239
+            return $this->response->array(self::returnValue(['data' => 'Database error'], 9999));
240
+        }
241
+        return $this->response->array(self::returnValue(['data' => $data], 200));
242
+    }
243
+    public function menuList(Request $request){
244
+        $id=$request->input('id');
245
+        $special=Special::where('id',$id)->first();
246
+        if($special['title']=='上午' || $special['title']=='中午' || $special['title']=='下午'){
247
+            $contain_recipes_time=json_decode($special['contain_recipes_time']);
248
+            $idArr=array();
249
+            $today=date('Y-m-d');
250
+            foreach($contain_recipes_time as $key=>$value){
251
+                if($value < $today){
252
+                    $idArr[]=$key;
253
+                }
254
+            }
255
+            $lastarr=explode(',',$special['contain_recipes']);
256
+            $idArr=array_intersect_assoc($idArr,$lastarr);
257
+        }else{
258
+            $idArr=explode(',',$special['contain_recipes']);
259
+        }
260
+        $menuList=Menu::whereIn('id',$idArr)->get();
261
+        return $this->response->array(self::returnValue(['data' => $menuList], 200));
262
+    }
263
+
264
+    public function menuDetail(Request $request){
265
+        $id=$request->input('id');
266
+        $menu=Menu::where('id',$id)->first();
267
+        $init=array();
268
+        $list=explode(',',$menu['ingredients']);
269
+        foreach($list as $item){
270
+            $origin=explode(':',$item);
271
+            $init[$origin[0]]=$origin[1];
272
+        }
273
+        $menu['ingredients']=$init;
274
+        $menuDetail=DB::table('menu_step')->where('menu_id',$id)->get();
275
+        return $this->response->array(self::returnValue(['data' => $menu,'detailData'=>$menuDetail], 200));
276
+    }
277
+
278
+    public function articleList(Request $request){
279
+        $page=$request->has('page')?$request->input('page'):1;
280
+        $start=intval((intval($page)-1)*intval(20));
281
+        $data=News::where('status',1)->select('id','imgurl','title','createTime')->orderBy('createTime','desc')->offset($start)->limit(20)->get();
282
+        return $this->response->array(self::returnValue(['data' => $data], 200));
283
+    }
284
+    public function articleDetail(Request $request){
285
+        $id=$request->input('id');
286
+        $articleDetail=News::where('id',$id)->first();
287
+        $articleDetail['content'] = str_replace(array("\r\n", "\r", "\n"), "", $articleDetail['content']);
288
+        return $this->response->array(self::returnValue(['data' => $articleDetail], 200));
289
+    }
191 290
 }

+ 11 - 0
app/Models/News.php

@@ -0,0 +1,11 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class News extends Model
8
+{
9
+    protected $table   = 'news';
10
+    public $timestamps = false;
11
+}

+ 11 - 0
app/Models/Special.php

@@ -0,0 +1,11 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class Special extends Model
8
+{
9
+    protected $table   = 'special';
10
+    public $timestamps = false;
11
+}

+ 1 - 1
config/app.php

@@ -64,7 +64,7 @@ return [
64 64
     |
65 65
     */
66 66
 
67
-    'timezone' => 'UTC',
67
+    'timezone' => 'PRC',
68 68
 
69 69
     /*
70 70
     |--------------------------------------------------------------------------

+ 1 - 1
public/index.php

@@ -6,7 +6,7 @@
6 6
  * @package  Laravel
7 7
  * @author   Taylor Otwell <taylor@laravel.com>
8 8
  */
9
-require __DIR__ . '/../app/check/check.php';
9
+//require __DIR__ . '/../app/check/check.php';
10 10
 /*
11 11
 |--------------------------------------------------------------------------
12 12
 | Register The Auto Loader

+ 21 - 0
routes/api.php

@@ -31,6 +31,27 @@ $api->version('v1', ['namespace' => 'App\Api\V1\Controllers'], function ($api) {
31 31
     //收藏
32 32
     $api->post('features/addCollection', 'FeaturesController@addCollection');
33 33
 
34
+    //2.0菜谱
35
+    //早中晚专题
36
+    $api->post('features/earlyMiddleAndLateTheme', 'FeaturesController@earlyMiddleAndLateTheme');
37
+    //其他专题
38
+    $api->post('features/otherTheme', 'FeaturesController@otherTheme');
39
+    //最近50条菜谱
40
+    $api->post('features/theLastRecipes', 'FeaturesController@theLastRecipes');
41
+
42
+    //菜谱列表详情
43
+    $api->post('features/menuList', 'FeaturesController@menuList');
44
+
45
+    //菜谱详情
46
+    $api->post('features/menuDetail', 'FeaturesController@menuDetail');
47
+
48
+    //文章列表
49
+    $api->post('features/articleList', 'FeaturesController@articleList');
50
+
51
+    //文章详情
52
+    $api->post('features/articleDetail', 'FeaturesController@articleDetail');
53
+
54
+
34 55
     //发现页面
35 56
     $api->post('finds/getFinds', 'FindsController@getFinds');
36 57
 });