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.
|
|
<?php
namespace App\Service\v3\Implementations;
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(); $time1Arr = []; $time2Arr = []; $time3Arr = []; $time4Arr = []; $nowTime = time(); foreach($stores as $store){ if($store['is_rest'] == 1){ return $store['name'].'店铺已打烊'; } $time1 = strtotime(($store['time1'])); if($nowTime < $time1){ return $store['name'].'店铺已打烊'; } $time2 = strtotime(($store['time2'])); if(!empty($store['time3']) && !empty($store['time4'])){ $time3 = strtotime(($store['time3'])); $time4 = strtotime(($store['time4'])); array_push($time3Arr,$time3); array_push($time4Arr,$time4); $endTime = $time4; }else{ $endTime = $time2; } if($nowTime > $endTime){ return $store['name'].'店铺已打烊'; } array_push($time1Arr,$time1); array_push($time2Arr,$time2); } $time1Max = max($time1Arr); if($nowTime > $time1Max){ $time1Max = ceil($nowTime / 1800) * 1800; } $time2Min = min($time2Arr); $length = ceil(($time2Min - $time1Max) / 1800); for ($i=1;$i<=$length;$i++){ $addTime = $time1Max + (30*60*$i); $res[] = date('h:i',$addTime); } if(!empty($time3Arr) && !empty($time4Arr)){ $time3Max = max($time3Arr); if($nowTime > $time3Max){ $time3Max = ceil($nowTime / 1800) * 1800; } $time4Min = min($time4Arr); $length = ceil(($time4Min - $time3Max) / 1800); for ($i=1;$i<=$length;$i++){ $addTime = $time3Max + (30*60*$i); $res[] = date('H:i',$addTime); } } return $res; }}
|