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.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Model\v3\ShoppingCart;
  4. use App\Model\v3\Store;
  5. use App\Service\v3\Interfaces\AppointmentTimeServiceInterface;
  6. use phpDocumentor\Reflection\Types\Object_;
  7. class AppointmentTimeService implements AppointmentTimeServiceInterface
  8. {
  9. public function do()
  10. {
  11. return [
  12. '尽快送达',
  13. '08:30 - 09:00',
  14. '09:00 - 09:30',
  15. '09:30 - 10:00',
  16. '10:00 - 10:30'
  17. ];
  18. }
  19. public function check()
  20. {
  21. // TODO: Implement check() method.
  22. }
  23. public function undo()
  24. {
  25. // TODO: Implement undo() method.
  26. }
  27. public function get($shopcartIds)
  28. {
  29. $shopcartIds = explode(',',$shopcartIds);
  30. $sotreIds = ShoppingCart::query()->whereIn('id',$shopcartIds)->pluck('store_id');
  31. $stores = Store::query()->whereIn('id',$sotreIds)->get()->toArray();
  32. $time1Arr = [];
  33. $time2Arr = [];
  34. $time3Arr = [];
  35. $time4Arr = [];
  36. $nowTime = time();
  37. foreach($stores as $store){
  38. if($store['is_rest'] == 1){
  39. return $store['name'].'店铺已打烊';
  40. }
  41. $time1 = strtotime(($store['time1']));
  42. if($nowTime < $time1){
  43. return $store['name'].'店铺已打烊';
  44. }
  45. $time2 = strtotime(($store['time2']));
  46. if(!empty($store['time3']) && !empty($store['time4'])){
  47. $time3 = strtotime(($store['time3']));
  48. $time4 = strtotime(($store['time4']));
  49. array_push($time3Arr,$time3);
  50. array_push($time4Arr,$time4);
  51. $endTime = $time4;
  52. }else{
  53. $endTime = $time2;
  54. }
  55. if($nowTime > $endTime){
  56. return $store['name'].'店铺已打烊';
  57. }
  58. array_push($time1Arr,$time1);
  59. array_push($time2Arr,$time2);
  60. }
  61. $time1Max = max($time1Arr);
  62. if($nowTime > $time1Max){
  63. $time1Max = ceil($nowTime / 1800) * 1800;
  64. }
  65. $time2Min = min($time2Arr);
  66. $length = ceil(($time2Min - $time1Max) / 1800);
  67. for ($i=1;$i<=$length;$i++){
  68. $addTime = $time1Max + (30*60*$i);
  69. $res[] = date('h:i',$addTime);
  70. }
  71. if(!empty($time3Arr) && !empty($time4Arr)){
  72. $time3Max = max($time3Arr);
  73. if($nowTime > $time3Max){
  74. $time3Max = ceil($nowTime / 1800) * 1800;
  75. }
  76. $time4Min = min($time4Arr);
  77. $length = ceil(($time4Min - $time3Max) / 1800);
  78. for ($i=1;$i<=$length;$i++){
  79. $addTime = $time3Max + (30*60*$i);
  80. $res[] = date('H:i',$addTime);
  81. }
  82. }
  83. return $res;
  84. }
  85. }