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.
91 lines
3.1 KiB
91 lines
3.1 KiB
<?php
|
|
|
|
namespace App\Service\v3\Implementations;
|
|
|
|
use App\Constants\v3\ErrorCode;
|
|
use App\Exception\ErrorCodeException;
|
|
use App\Model\v3\ShoppingCart;
|
|
use App\Model\v3\Store;
|
|
use App\Service\v3\Interfaces\AppointmentTimeServiceInterface;
|
|
use phpDocumentor\Reflection\Types\Object_;
|
|
|
|
class AppointmentTimeService implements AppointmentTimeServiceInterface
|
|
{
|
|
public function do()
|
|
{
|
|
return [
|
|
'尽快送达',
|
|
'08:30 - 09:00',
|
|
'09:00 - 09:30',
|
|
'09:30 - 10:00',
|
|
'10:00 - 10:30'
|
|
];
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
// TODO: Implement check() method.
|
|
}
|
|
|
|
public function undo()
|
|
{
|
|
// TODO: Implement undo() method.
|
|
}
|
|
|
|
public function get($shopcartIds)
|
|
{
|
|
$shopcartIds = explode(',',$shopcartIds);
|
|
$sotreIds = ShoppingCart::query()->whereIn('id',$shopcartIds)->pluck('store_id');
|
|
$stores = Store::query()->whereIn('id',$sotreIds)->get()->toArray();
|
|
if(empty($stores)){
|
|
$msg = ['sotreIds'=>$sotreIds,"shopcartIds"=>$shopcartIds];
|
|
throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE,'',$msg);
|
|
}
|
|
$nowTime = time();
|
|
$startTime = ceil($nowTime / (30*60)) * (30*60);
|
|
//服务站最晚营业时间
|
|
if (env('APP_ENV') === 'prod') {
|
|
$endTime = strtotime(config('market.rest_time'));
|
|
if($nowTime > $endTime){
|
|
throw new ErrorCodeException(ErrorCode::MARKET_REST);
|
|
}
|
|
}else{
|
|
$endTime = strtotime(date('Y-m-d 23:59:59'));
|
|
}
|
|
//取得所有店铺营业时间交集
|
|
for($i = $startTime;$i<= $endTime;$i+=1800){
|
|
$in = true;
|
|
foreach($stores as $store){
|
|
$time1 = strtotime(($store['time1']));
|
|
$time2 = strtotime(($store['time2']));
|
|
if(empty($store['time3']) || empty($store['time4'])) {
|
|
if($i < $time1 || $i > $time2){
|
|
$in = false;
|
|
continue;
|
|
}
|
|
}else{
|
|
$time3 = strtotime(($store['time3'])) ;
|
|
$time4 = strtotime(($store['time4']));
|
|
if(($i < $time1 || $i > $time2) && ($i < $time3 || $i > $time4)){
|
|
$in = false;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
if($in){
|
|
if($i === $startTime){
|
|
$res['distribution'][] = ['title'=>'尽快送达','value'=>'尽快送达'];
|
|
$res['self_take'][] = ['title'=>'尽快自提','value'=>'尽快自提'];
|
|
}
|
|
$data['title'] = date('H:i',$i + 30 * 60) . ' - ' . date('H:i',$i + 30 * 60 * 2);
|
|
$data['value'] = date('H:i',$i + 30 * 60) . ' - ' . date('H:i',$i + 30 * 60 * 2);
|
|
$res['distribution'][] = $data;
|
|
$res['self_take'][]= $data;
|
|
}
|
|
}
|
|
if(empty($res['distribution']) || empty($res['self_take'])){
|
|
throw new ErrorCodeException(ErrorCode::STORE_BUSINESSS_HOURS_ERROR);
|
|
}
|
|
return $res;
|
|
}
|
|
}
|