From 853024343530511be86f2e9a64e219b1007ca587 Mon Sep 17 00:00:00 2001 From: liapples Date: Wed, 15 Sep 2021 14:00:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=95=B0=E6=8D=AE=E6=97=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=BC=94=E7=A4=BA=E4=BA=A7=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/AgentProductController.php | 6 ++++-- app/Http/Controllers/Api/ArticleController.php | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/AgentProductController.php b/app/Http/Controllers/Api/AgentProductController.php index 1af06c3..ab5e599 100644 --- a/app/Http/Controllers/Api/AgentProductController.php +++ b/app/Http/Controllers/Api/AgentProductController.php @@ -135,10 +135,12 @@ class AgentProductController extends Controller //分页列表产品图片加域名 private function paginatePicAddHost($list) { - //如果是新入驻代理商没有数据,则显示最早的几条 + //如果是新入驻代理商没有数据,且没有删除过的数据,则显示最早的几条 if ($list->isEmpty()) { - if (AgentProduct::list($this->agent_id)->count() === 0) { + if (AgentProduct::list($this->agent_id)->withTrashed()->count() === 0 && request('page', 1) <= 2) { //只获取2页数据 $list = AgentProduct::list($this->agent_id)->orWhereRaw(1)->orderBy('id')->simplePaginate(); + } else { + return $list; //因为只获取2页数据,不return可能会导入下面的代码出错 } } diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php index c1cb8cf..a034d64 100644 --- a/app/Http/Controllers/Api/ArticleController.php +++ b/app/Http/Controllers/Api/ArticleController.php @@ -22,6 +22,14 @@ class ArticleController extends Controller ->orderBy('sort')->orderBy('id', 'DESC') ->simplePaginate()->toArray(); + //如果没有数据,且没有软删除的数据,显示默认的几条数据,主要用于新代理商入驻时显示默认文章 + if (empty($list['data'])) { + if (Article::withTrashed()->where('agent_id', $this->agent_id)->count() === 0 && request('page', 1) < 2) { + $list = Article::select('id', 'image', 'title', 'type', 'updated_at') + ->orderBy('id')->simplePaginate()->toArray(); + } + } + $new_data = []; $prefix = Storage::disk('public')->url(''); foreach ($list['data'] as $k => &$item) {