From ced4e4695db0dedabf411311ffe558edb821b866 Mon Sep 17 00:00:00 2001 From: liapples Date: Wed, 28 Jul 2021 18:50:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=95=B0=E6=8D=AE=E6=97=A0?= =?UTF-8?q?=E9=9C=80=E7=99=BB=E5=BD=95=E8=8E=B7=E5=8F=96=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E5=88=99=E5=AD=98=E5=85=A5=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/IndexController.php | 34 ++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/IndexController.php b/app/Http/Controllers/Api/IndexController.php index f97f3df..59586b3 100644 --- a/app/Http/Controllers/Api/IndexController.php +++ b/app/Http/Controllers/Api/IndexController.php @@ -24,11 +24,38 @@ class IndexController extends Controller ->orderBy('sort')->orderBy('id', 'DESC')->limit(10)->get(['title','url']); # 公告 - $notice = Notice::where('agent_id', $this->agent_id)->limit(10)->get(['title', 'updated_at']); + $notice = Notice::where('agent_id', $this->agent_id)->limit(10)->get(['id', 'title', 'updated_at']); # 我的频道 - $channel_ids = UserChannel::where('user_id', $this->user_id)->value('channels'); - $my_channels = Channel::whereIn('id', $channel_ids)->get(['id', 'name', 'icon']); + if ($this->user_id) { + $channel_ids = UserChannel::where('user_id', $this->user_id)->value('channels'); + //如果不存在则存入初始数据 + if (!$channel_ids) { + $channel_ids = Channel::where([ + ['agent_id', '=', $this->agent_id], + ['pid', '<>', 0], + ]) + ->orderBy('id') + ->limit(8) + ->pluck('id') + ->toArray(); + //存入user_channel + UserChannel::where('user_id', $this->user_id) + ->insert([ + 'user_id' => $this->user_id, + 'channels' => json_encode($channel_ids) + ]); + } + $my_channels = Channel::where('agent_id', $this->agent_id) + ->whereIn('id', $channel_ids) + ->get(['id', 'name', 'icon']); + } else { + $my_channels = Channel::where('agent_id', $this->agent_id) + ->where('pid', '<>', 0) + ->orderBy('id') + ->limit(8) + ->get(['id', 'name', 'icon']); + } # 专题列表 $special = Special::query() @@ -39,6 +66,7 @@ class IndexController extends Controller # 人气爆款 $hots = AgentProduct::query() + ->where('agent_id', $this->agent_id) ->select('id', 'sale', 'product_id', 'price', 'original_price') //必须查询product_id才能with ->with('product:id,title,pictures') //必须查询ID才能正常查询 ->limit(6)->get();