|
|
|
@ -8,7 +8,6 @@ use App\Models\AgentProduct; |
|
|
|
use App\Models\AgentProductSpec; |
|
|
|
use App\Models\Category; |
|
|
|
use App\Models\UserFav; |
|
|
|
use App\Models\Views\AgentProduct as AgentProductView; |
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
use Illuminate\Support\Facades\Storage; |
|
|
|
|
|
|
|
@ -23,13 +22,13 @@ class AgentProductController extends Controller |
|
|
|
public function index() |
|
|
|
{ |
|
|
|
$formData = request()->only(['category_id', 'type', 'by', 'lat', 'lng']); |
|
|
|
$category_id = $formData['category_id'] ?? 0; |
|
|
|
$category_id = (int)$formData['category_id'] ?? 0; |
|
|
|
$type = $formData['type'] ?? 0; |
|
|
|
$by = $formData['by'] ?? 0; |
|
|
|
$lat = $formData['lat'] ?? 0; |
|
|
|
$lng = $formData['lng'] ?? 0; |
|
|
|
|
|
|
|
$list = AgentProductView::list($this->agent_id); |
|
|
|
$list = AgentProduct::list($this->agent_id); |
|
|
|
if ($category_id) { |
|
|
|
$list = $list->whereIn('category_id', [$category_id, ...$this->get_category_child_ids($category_id)]); |
|
|
|
} |
|
|
|
@ -49,10 +48,14 @@ round( |
|
|
|
)) * 1000),0) AS `distance_m` |
|
|
|
SQL |
|
|
|
)); |
|
|
|
$by = 1; //距离排序默认升序
|
|
|
|
} |
|
|
|
$fields = ['id', 'sale', 'updated_at', 'price', 'distance_m']; //排序字段
|
|
|
|
|
|
|
|
//距离排序只有升序
|
|
|
|
if ($type == 4) { |
|
|
|
$by = 1; |
|
|
|
} |
|
|
|
|
|
|
|
$field = $fields[$type] ?? $fields[0]; |
|
|
|
$by = $by == 0 ? 'desc' : 'asc'; |
|
|
|
|
|
|
|
@ -336,7 +339,7 @@ SQL |
|
|
|
$prefix = Storage::disk('public')->url(''); |
|
|
|
foreach ($list->items() as $k=>&$v) { |
|
|
|
$v->pictures = array_map(function($item) use ($prefix) { |
|
|
|
return strpos($item, $prefix) === false ? $prefix . $item : $item; |
|
|
|
return !str_contains($item, $prefix) ? $prefix . $item : $item; |
|
|
|
}, $v->pictures); |
|
|
|
} |
|
|
|
|
|
|
|
|