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.
103 lines
3.3 KiB
103 lines
3.3 KiB
<?php
|
|
|
|
|
|
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
|
|
{
|
|
|
|
public function do()
|
|
{
|
|
// TODO: Implement do() method.
|
|
}
|
|
|
|
public function check($storeId)
|
|
{
|
|
$store = Store::query()->where([
|
|
['id','=',$storeId],
|
|
['is_rest','=',0],
|
|
['status','=',2]
|
|
])
|
|
->select('time1','time2','time3','time4')
|
|
->first();
|
|
if(!empty($store)){
|
|
$nowTime = time();
|
|
$startTime = strtotime(($store->time1));
|
|
if(!empty($store->time3) && !empty($store->time4)){
|
|
$time4 = strtotime(($store->time4));
|
|
$endTime = $time4;
|
|
}else{
|
|
$time2 = strtotime(($store->time2));
|
|
$endTime = $time2;
|
|
}
|
|
if($nowTime > $startTime && $nowTime < $endTime){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function undo()
|
|
{
|
|
// TODO: Implement undo() method.
|
|
}
|
|
|
|
public function detail($storeId)
|
|
{
|
|
return Store::query()
|
|
->with('market')
|
|
->where('id',$storeId)
|
|
->first();
|
|
}
|
|
|
|
public function getList($marketId, $page=1, $pagesize=10)
|
|
{
|
|
$market = Market::query()->withoutGlobalScope('normal')->find($marketId);
|
|
$builder = Store::query();
|
|
$paginate = $builder->where('market_id',$marketId)->paginate($pagesize);
|
|
$stores = $paginate->toArray();
|
|
$market->stores = $stores['data'];
|
|
return ['has_more_pages' => $paginate->hasMorePages(), 'market' => $market];
|
|
}
|
|
|
|
public function getListByMarketId($marketId, $page=1, $pagesize=10)
|
|
{
|
|
$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]);
|
|
|
|
$paginate = $builder->groupBy(''.$storeTable.'.sales')->paginate($pagesize);
|
|
$stores = $paginate->map(function ($item, $key) {
|
|
$item->goods;
|
|
return $item;
|
|
})->all();
|
|
|
|
return ['has_more_pages' => $paginate->hasMorePages(), 'stores' => $stores];
|
|
}
|
|
|
|
public function updateIsRest($storeId)
|
|
{
|
|
$store = Store::query()->withoutGlobalScope('normal')->find($storeId);
|
|
$isRest = $store->is_rest + 1;
|
|
$store->is_rest = $isRest % 2;
|
|
return $store->save();
|
|
}
|
|
}
|