Browse Source

没有数据时增加演示产品

develop
李可松 4 years ago
parent
commit
8530243435
  1. 6
      app/Http/Controllers/Api/AgentProductController.php
  2. 8
      app/Http/Controllers/Api/ArticleController.php

6
app/Http/Controllers/Api/AgentProductController.php

@ -135,10 +135,12 @@ class AgentProductController extends Controller
//分页列表产品图片加域名 //分页列表产品图片加域名
private function paginatePicAddHost($list) private function paginatePicAddHost($list)
{ {
//如果是新入驻代理商没有数据,则显示最早的几条
//如果是新入驻代理商没有数据,且没有删除过的数据,则显示最早的几条
if ($list->isEmpty()) { 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(); $list = AgentProduct::list($this->agent_id)->orWhereRaw(1)->orderBy('id')->simplePaginate();
} else {
return $list; //因为只获取2页数据,不return可能会导入下面的代码出错
} }
} }

8
app/Http/Controllers/Api/ArticleController.php

@ -22,6 +22,14 @@ class ArticleController extends Controller
->orderBy('sort')->orderBy('id', 'DESC') ->orderBy('sort')->orderBy('id', 'DESC')
->simplePaginate()->toArray(); ->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 = []; $new_data = [];
$prefix = Storage::disk('public')->url(''); $prefix = Storage::disk('public')->url('');
foreach ($list['data'] as $k => &$item) { foreach ($list['data'] as $k => &$item) {

Loading…
Cancel
Save