|
|
|
@ -3,9 +3,13 @@ |
|
|
|
|
|
|
|
namespace App\Service\v3\Implementations; |
|
|
|
|
|
|
|
use App\Constants\v3\Goods as GoodsConstants; |
|
|
|
use App\Constants\v3\Store as StoreConstants; |
|
|
|
use App\Model\v3\Market; |
|
|
|
use App\Model\v3\Store; |
|
|
|
use App\Model\v3\Goods; |
|
|
|
use App\Service\v3\Interfaces\StoreServiceInterface; |
|
|
|
use Hyperf\Utils\ApplicationContext; |
|
|
|
|
|
|
|
class StoreService implements StoreServiceInterface |
|
|
|
{ |
|
|
|
@ -66,13 +70,37 @@ class StoreService implements StoreServiceInterface |
|
|
|
|
|
|
|
public function getListByMarketId($marketId, $page=1, $pagesize=10) |
|
|
|
{ |
|
|
|
$builder = Store::query(); |
|
|
|
$paginate = $builder->where('market_id',$marketId)->with(['goods' => function($query){ |
|
|
|
$query->where(function ($query){ |
|
|
|
$query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1); |
|
|
|
}); |
|
|
|
}])->orderByDesc('sales')->paginate($pagesize); |
|
|
|
$storeList = $paginate->toArray(); |
|
|
|
return ['has_more_pages' => $paginate->hasMorePages(), 'store_list' => $storeList['data']]; |
|
|
|
$storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable(); |
|
|
|
$goodsTable = ApplicationContext::getContainer()->get(Goods::class)->getTable(); |
|
|
|
|
|
|
|
$builder = Store::query() |
|
|
|
->select(''.$storeTable.'.*') |
|
|
|
->join($goodsTable,''.$storeTable.'.id', '=', ''.$goodsTable.'.store_id') |
|
|
|
->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES]) |
|
|
|
->where([''.$goodsTable.'.market_id' => $marketId]) |
|
|
|
->where(function ($query) use ($goodsTable) { |
|
|
|
$query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1); |
|
|
|
}) |
|
|
|
->whereRaw(''.$goodsTable.'.deleted_at IS NULL') |
|
|
|
->where([''.$storeTable.'.market_id' => $marketId, ''.$storeTable.'.is_rest' => StoreConstants::IS_REST_NO]); |
|
|
|
|
|
|
|
if (isset($params['order_by']) && $params['order_by']) { |
|
|
|
$sort = $params['sort'] ?? 'desc'; |
|
|
|
switch ($params['order_by']) { |
|
|
|
case 'sales': |
|
|
|
$builder->orderBySales($sort); |
|
|
|
break; |
|
|
|
default: |
|
|
|
$builder->orderByDefault($sort); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
$paginate = $builder->groupBy(''.$storeTable.'.id')->paginate($params['pagesize']); |
|
|
|
$stores = $paginate->map(function ($item, $key) { |
|
|
|
$item->goods; |
|
|
|
return $item; |
|
|
|
})->all(); |
|
|
|
|
|
|
|
return ['has_more_pages' => $paginate->hasMorePages(), 'stores' => $stores]; |
|
|
|
} |
|
|
|
} |