13283339616 лет назад: 6
Родитель
Сommit
1e88e44271

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

@@ -12,6 +12,7 @@ use App\Models\UserMessage;
12 12
 use App\Models\Special;
13 13
 use App\Models\News;
14 14
 use App\Models\NewsCategory;
15
+use App\Models\CollectReceipt;
15 16
 use Illuminate\Http\Request;
16 17
 use Solr;
17 18
 use DB;
@@ -226,7 +227,7 @@ class FeaturesController extends BaseController
226 227
         foreach($data as $key=>$value){
227 228
             $data[$key]['url']=config('constants.HOST_URL').$value['url'];
228 229
         }
229
-        $json_menu_idarr=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->pluck('contain_recipes');
230
+        $json_menu_idarr=Special::whereNotIn('title',['上午','中午','下午'])->where('status',1)->where('releaseTime','<',$today)->pluck('contain_recipes');
230 231
         $json_menu_idarr=json_decode(json_encode($json_menu_idarr),true);
231 232
         $initArr=array();
232 233
         foreach($json_menu_idarr as $item){
@@ -236,11 +237,25 @@ class FeaturesController extends BaseController
236 237
         }
237 238
         $initArr=array_unique($initArr);
238 239
         $menuAll=DB::table('menu')->whereIn('id',$initArr)->where('status',1)->get();
240
+
241
+        $readArr=Menu::getReadNum($initArr);
242
+        $discountArr=Menu::getCollectNum($initArr);
243
+
239 244
         $menuAll=json_decode(json_encode($menuAll),true);
240 245
         foreach($menuAll as $key=>$value){
241 246
             if(!$this->startsWith($value['url'],'http') && $value['url'] !='None' && $value['url']!=''){
242 247
                 $menuAll[$key]['url']=config('constants.HOST_URL').$value['url'];
243 248
             }
249
+            if(array_key_exists($value['id'],$readArr)){
250
+                $menuAll[$key]['readingVolume']=intval(abs(crc32($value['id'])/1000000))+$readArr[$value['id']];
251
+            }else{
252
+                $menuAll[$key]['readingVolume']=intval(abs(crc32($value['id'])/1000000));
253
+            }
254
+            if(array_key_exists($value['id'],$discountArr)){
255
+                $menuAll[$key]['collectVolume']=intval(abs(crc32($value['id'])/100000000))+$discountArr[$value['id']];
256
+            }else{
257
+                $menuAll[$key]['collectVolume']=intval(abs(crc32($value['id'])/100000000));
258
+            }
244 259
         }
245 260
         $middleArr=array();
246 261
         foreach($menuAll as $item){
@@ -257,6 +272,10 @@ class FeaturesController extends BaseController
257 272
     }
258 273
     public function theLastRecipes(Request $request){
259 274
         $data=Menu::where('status',1)->orderBy('created_at','desc')->limit(50)->get();
275
+        $initArr=Menu::where('status',1)->orderBy('created_at','desc')->limit(50)->pluck('menu_id');
276
+        $initArr=json_decode(json_encode($initArr),true);
277
+        $readArr=Menu::getReadNum($initArr);
278
+        $discountArr=Menu::getCollectNum($initArr);
260 279
         if (!$data) {
261 280
             return $this->response->array(self::returnValue(['data' => 'Database error'], 9999));
262 281
         }
@@ -265,6 +284,16 @@ class FeaturesController extends BaseController
265 284
             if(!$this->startsWith($value['url'],'http') && $value['url'] !='None' && $value['url']!=''){
266 285
                 $data[$key]['url']=config('constants.HOST_URL').$value['url'];
267 286
             }
287
+            if(array_key_exists($value['id'],$readArr)){
288
+                $data[$key]['readingVolume']=intval(abs(crc32($value['id'])/1000000))+$readArr[$value['id']];
289
+            }else{
290
+                $data[$key]['readingVolume']=intval(abs(crc32($value['id'])/1000000));
291
+            }
292
+            if(array_key_exists($value['id'],$discountArr)){
293
+                $data[$key]['collectVolume']=intval(abs(crc32($value['id'])/100000000))+$discountArr[$value['id']];
294
+            }else{
295
+                $data[$key]['collectVolume']=intval(abs(crc32($value['id'])/100000000));
296
+            }
268 297
         }
269 298
         return $this->response->array(self::returnValue(['data' => $data], 200));
270 299
     }
@@ -287,11 +316,23 @@ class FeaturesController extends BaseController
287 316
             $idArr=explode(',',$special['contain_recipes']);
288 317
         }
289 318
         $menuList=Menu::whereIn('id',$idArr)->get();
319
+        $readArr=Menu::getReadNum($idArr);
320
+        $discountArr=Menu::getCollectNum($idArr);
290 321
         $menuList=json_decode(json_encode($menuList),true);
291 322
         foreach($menuList as $key=>$value){
292 323
             if(!$this->startsWith($value['url'],'http') && $value['url'] !='None' && $value['url']!=''){
293 324
                 $menuList[$key]['url']=config('constants.HOST_URL').$value['url'];
294 325
             }
326
+            if(array_key_exists($value['id'],$readArr)){
327
+                $menuList[$key]['readingVolume']=intval(abs(crc32($value['id'])/1000000))+$readArr[$value['id']];
328
+            }else{
329
+                $menuList[$key]['readingVolume']=intval(abs(crc32($value['id'])/1000000));
330
+            }
331
+            if(array_key_exists($value['id'],$discountArr)){
332
+                $menuList[$key]['collectVolume']=intval(abs(crc32($value['id'])/100000000))+$discountArr[$value['id']];
333
+            }else{
334
+                $menuList[$key]['collectVolume']=intval(abs(crc32($value['id'])/100000000));
335
+            }
295 336
         }
296 337
         return $this->response->array(self::returnValue(['data' => $menuList], 200));
297 338
     }
@@ -309,6 +350,26 @@ class FeaturesController extends BaseController
309 350
             $init[$origin[0]]=$origin[1];
310 351
         }
311 352
         $menu['ingredients']=$init;
353
+        $token   = $request->headers->get('token');
354
+        if($token==''){
355
+            $menu['is_collect']=0;
356
+        }else{
357
+            $user = DB::table('users')->where('token', $token)->first();
358
+            $tokendata= !empty($user) ? $user : null;
359
+            if(empty($tokendata) || ($token!=$tokendata->token && (($tokendata->last_login_time - 30 *86400) > time()))) {
360
+                $menu['is_collect']=0;
361
+            }else{
362
+                $user_id = Menu::getUserId($token);
363
+                //查询是否收藏过该商品  收藏过 - 取消收藏 ; 未收藏 - 进行收藏操作
364
+                $is_collect = Menu::isCollectTicket($user_id,$id);
365
+                if ($is_collect ==1 ){
366
+                    $menu['is_collect']=1;
367
+                }else{
368
+                    //未收藏该商品,进行收藏
369
+                    $menu['is_collect']=0;
370
+                }
371
+            }
372
+        }
312 373
         $menuDetail=DB::table('menu_step')->where('menu_id',$id)->get();
313 374
         $menuDetail=json_decode(json_encode($menuDetail),true);
314 375
         foreach($menuDetail as $key=>$value){
@@ -346,4 +407,65 @@ class FeaturesController extends BaseController
346 407
         $articleDetail['content'] = str_replace(array("/ueditor/php/upload/"), config('constants.HOST_URL')."/ueditor/php/upload/", $articleDetail['content']);
347 408
         return $this->response->array(self::returnValue(['data' => $articleDetail], 200));
348 409
     }
410
+
411
+    public function collectRecipes(Request $request){
412
+        $token=$request->header('token');
413
+        $user=DB::table('user')->where('token',$token)->first();
414
+        if(count($user)){
415
+            $data['user_id']=$user('user_id');
416
+        }else{
417
+            return $this->response->array(self::returnValue(['data' => 'user is not found'], 400));
418
+        }
419
+        $data['menu_id']=$request->input('menu_id');
420
+        $data['create_time']=date("Y-m-d H:i:s",time());
421
+        $data=DB::table('collect_recipes')->where('user_id',$data['user_id'])->where('menu_id',$data['menu_id'])->first();
422
+        if($data){
423
+            if($data['status']==1){
424
+                $status=0;
425
+            }else{
426
+                $status=1;
427
+            }
428
+            $res=DB::table('collect_recipes')->where('user_id',$data['user_id'])->where('menu_id',$data['menu_id'])->update(['status'=>$status,'create_time'=>$data['create_time']]);
429
+        }else{
430
+            DB::table('collect_recipes')->insert($data);
431
+        }
432
+        return $this->response->array(self::returnValue(['data' => '收藏成功'], 200));
433
+    }
434
+
435
+    public function receiptPersonList(Request $request){
436
+        $user_id=$request->input('user_id');
437
+        $list=DB::table('collect_recipes')->where('user_id',$user_id)->pluck('menu_id');
438
+        $menuList=Menu::whereIn('id',$list)->get();
439
+        $readArr=Menu::getReadNum($list);
440
+        $discountArr=Menu::getCollectNum($list);
441
+        $menuList=json_decode(json_encode($menuList),true);
442
+        foreach($menuList as $key=>$value){
443
+            if(!$this->startsWith($value['url'],'http') && $value['url'] !='None' && $value['url']!=''){
444
+                $menuList[$key]['url']=config('constants.HOST_URL').$value['url'];
445
+            }
446
+            if(array_key_exists($value['id'],$readArr)){
447
+                $menuList[$key]['readingVolume']=intval(abs(crc32($value['id'])/1000000))+$readArr[$value['id']];
448
+            }else{
449
+                $menuList[$key]['readingVolume']=intval(abs(crc32($value['id'])/1000000));
450
+            }
451
+            if(array_key_exists($value['id'],$discountArr)){
452
+                $menuList[$key]['collectVolume']=intval(abs(crc32($value['id'])/100000000))+$discountArr[$value['id']];
453
+            }else{
454
+                $menuList[$key]['collectVolume']=intval(abs(crc32($value['id'])/100000000));
455
+            }
456
+        }
457
+        return $this->response->array(self::returnValue(['data' => $menuList], 200));
458
+    }
459
+
460
+    public function menuRead(Request $request){
461
+        $menu_id=$request->input('menu_id');
462
+        $res=DB::table('menu_read_num')->where('menu_id',$menu_id)->first();
463
+        if($res){
464
+            $result=DB::table('menu_read_num')->where('menu_id',$menu_id)->increment('num');
465
+        }else{
466
+            $data['menu_id']=$menu_id;
467
+            $result=DB::table('menu_read_num')->insert($data);
468
+        }
469
+        return $this->response->array(self::returnValue(['data' => '阅读成功'], 200));
470
+    }
349 471
 }

+ 4 - 4
app/Api/V1/Controllers/UserController.php

@@ -130,7 +130,7 @@ class UserController extends BaseController {
130 130
 
131 131
     public function personalCentor(Request $request) {
132 132
 	    $user = User::getCurrentUser();
133
-        $channel_id = $request->header('channel_id');
133
+        $channel_id = $request->header('source');
134 134
         $channel = Channel::detail($channel_id);
135 135
         $user->iOS_share_url = $channel ? ($channel->url ?  $channel->url : "http://baidu.com") : "http://baidu.com";
136 136
 
@@ -243,7 +243,7 @@ class UserController extends BaseController {
243 243
         }
244 244
         $mobile = $request->input('mobile');
245 245
         $password = $request->input('password');
246
-        $channel_id = $request->header('channel_id',0);
246
+        $channel_id = $request->header('source',0);
247 247
         $user_info = self::checkUserByMobile($mobile, false);
248 248
         if (!$user_info) {
249 249
             $user_info = new User();
@@ -279,7 +279,7 @@ class UserController extends BaseController {
279 279
         }
280 280
         $mobile = $request->request->get('mobile');
281 281
         $password = $request->request->get('password');
282
-        $channel_id = $request->header('cid',0);
282
+        $channel_id = $request->header('source',0);
283 283
         $user_info = self::checkUserByMobile($mobile);
284 284
         if ($user_info) {
285 285
             if (Auth::attempt(['mobile' => $mobile, 'password' => $password])) {
@@ -319,7 +319,7 @@ class UserController extends BaseController {
319 319
         if ($validator->fails()) {
320 320
             return $this->response->array(self::returnValue(['msg'=>Base::formatValidator($validator)], 10009));
321 321
         }
322
-        $channel_id = $request->header('channel_id', 0);
322
+        $channel_id = $request->header('source', 0);
323 323
         $openid = $request->get('openid');
324 324
         $nickname = $request->get('nickname');
325 325
         $sex = $request->get('sex');

+ 41 - 0
app/Models/Menu.php

@@ -27,6 +27,47 @@ class Menu extends Model
27 27
         unset($v);
28 28
         return $value;
29 29
     }
30
+    public static function getReadNum($initArr=[]){
31
+        $keyArr=array();
32
+        $keyArr=DB::table('menu_read_num')->whereIn('menu_id',$initArr)->orderByRaw("FIELD(menu_id, " . implode(", ", $initArr) . ")")->pluck('menu_id');
33
+        $keyArr=json_decode(json_encode($keyArr),true);
34
+        if(count($keyArr)==0){
35
+            $keyArr=array();
36
+            $readArr=array();
37
+        }else{
38
+            $valueArr=DB::table('menu_read_num')->whereIn('menu_id',$keyArr)->orderByRaw("FIELD(menu_id, " . implode(", ", $keyArr) . ")")->pluck('num');
39
+            $valueArr=json_decode(json_encode($valueArr),true);
40
+            $readArr=array_combine($keyArr,$valueArr);
41
+        }
42
+        return $readArr;
43
+    }
44
+    public static function getCollectNum($initArr=[]){
45
+        $discountKeyArr=DB::table('collect_recipes')->whereIn('menu_id',$initArr)->orderByRaw("FIELD(menu_id, " . implode(", ", $initArr) . ")")->pluck('menu_id');
46
+        $discountKeyArr=json_decode(json_encode($discountKeyArr),true);
47
+        if(count($discountKeyArr)==0){
48
+            $discountKeyArr=array();
49
+            $discountArr=array();
50
+        }else{
51
+            $discountValueArr=DB::table('collect_recipes')->whereIn('menu_id',$initArr)->orderByRaw("FIELD(menu_id, " . implode(", ", $discountKeyArr) . ")")->pluck('menu_id');
52
+            $discountArr=array_combine($discountKeyArr,$discountValueArr);
53
+        }
54
+        return $discountArr;
55
+    }
56
+    public static function isCollectTicket($user_id,$menu_id){
57
+        $collect = DB::table('collect_recipes')->where('user_id',$user_id)->where('menu_id',$menu_id)->first();
58
+        if ($collect){
59
+            $is_collect = 1;
60
+        }else{
61
+            $is_collect = 0;
62
+        }
63
+        return $is_collect;
64
+    }
65
+    public static function getUserId($token) {
66
+        $user_id = DB::table('users')->where('token',$token)->pluck('id');
67
+        $user_id = json_decode($user_id,true);
68
+        return $user_id[0];
69
+    }
70
+
30 71
     // public static function selectMenuList($tagId,$time,$status=1){
31 72
     //     $menuListNum=config('view.menuListNum');
32 73
     //     $menuIdList=DB::table('tag_menu')->select('menu_id')->where('id',$tagId)->get()->toArray();

+ 13 - 0
routes/api.php

@@ -97,4 +97,17 @@ $api->version('v1', ['namespace' => 'App\Api\V1\Controllers'], function ($api) {
97 97
 
98 98
     //发现页面
99 99
     $api->post('finds/getFinds', 'FindsController@getFinds');
100
+
101
+    //个人收藏 //收藏菜谱
102
+    $api->post('features/collectRecipes', 'FeaturesController@collectRecipes');
103
+
104
+    //个人收藏 //收藏发现
105
+    $api->post('features/collectFind', 'FeaturesController@collectFind');
106
+
107
+    //菜谱个人收藏列表
108
+    $api->post('features/receiptPersonList', 'FeaturesController@receiptPersonList');
109
+
110
+    //菜谱阅读
111
+    $api->post('features/menuRead', 'FeaturesController@menuRead');
112
+
100 113
 });