You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.3 KiB
90 lines
2.3 KiB
<?php
|
|
|
|
|
|
namespace App\Service\v3\Implementations;
|
|
|
|
|
|
use App\Model\v3\Goods;
|
|
|
|
class SearchService implements \App\Service\v3\Interfaces\SearchServiceInterface
|
|
{
|
|
|
|
public function doForGoods($params)
|
|
{
|
|
|
|
$builder = Goods::query()
|
|
->with(['store' => function($query) {
|
|
return $query->select(['id', 'logo', 'name']);
|
|
}])
|
|
->where(['market_id' => $params['market_id']])
|
|
->where('inventory', '>', 0);
|
|
|
|
if (isset($params['type_id']) && $params['type_id']) {
|
|
$builder->where(['goods_type_id' => $params['type_id']]);
|
|
}
|
|
|
|
if (isset($params['keyword']) && $params['keyword']) {
|
|
$builder->where('name', 'like', '%'.$params['keyword'].'%');
|
|
}
|
|
|
|
if (isset($params['order_by']) && $params['order_by']) {
|
|
$sort = $params['sort'] ?? 'desc';
|
|
switch ($params['order_by']) {
|
|
case 'sales':
|
|
$builder->orderBySales($sort);
|
|
break;
|
|
case 'price':
|
|
$builder->orderByPrice($sort);
|
|
break;
|
|
default:
|
|
$builder->orderByDefault($sort);
|
|
break;
|
|
}
|
|
}
|
|
|
|
$builder->select(['id', 'store_id', 'cover_img', 'name', 'spec', 'tags', 'original_price', 'price', 'inventory', 'sales as total_sales']);
|
|
$goods = $builder->forPage($params['page'], $params['pagesize'])->get()->toArray();
|
|
|
|
$data = [];
|
|
foreach ($goods as $key => &$item) {
|
|
$store = (object)$item['store'];
|
|
unset($item['store']);
|
|
$data[] = [
|
|
'goods' => $item,
|
|
'store' => $store
|
|
];
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function doForStores()
|
|
{
|
|
// TODO: Implement doForStores() method.
|
|
}
|
|
|
|
public function getHotKeywords($type)
|
|
{
|
|
$keywords = [
|
|
'goods' => ['酱油','油','生蚝'],
|
|
'store' => ['黄姐','王姐','黄姐蔬菜摊'],
|
|
];
|
|
|
|
return $keywords[$type];
|
|
}
|
|
|
|
public function do()
|
|
{
|
|
// TODO: Implement do() method.
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
// TODO: Implement check() method.
|
|
}
|
|
|
|
public function undo()
|
|
{
|
|
// TODO: Implement undo() method.
|
|
}
|
|
}
|