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.

99 lines
2.4 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
  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. $startTimeArr = [];
  33. $endTimeArr = [];
  34. $time1Arr = [];
  35. $time2Arr = [];
  36. $time3Arr = [];
  37. $time4Arr = [];
  38. $nowTime = time();
  39. foreach($stores as $store){
  40. if($store['is_rest'] == 1){
  41. return $store['name'].'店铺已打烊';
  42. }
  43. $time1 = strtotime(($store['time1']));
  44. if($nowTime < $time1){
  45. return $store['name'].'店铺已打烊';
  46. }
  47. $time2 = strtotime(($store['time2']));
  48. if(!empty($store['time3']) && !empty($store['time4'])){
  49. $time3 = strtotime(($store['time3']));
  50. $time4 = strtotime(($store['time4']));
  51. array_push($time3Arr,$time3);
  52. array_push($time4Arr,$time4);
  53. $endTime = $time4;
  54. }else{
  55. $endTime = $time2;
  56. }
  57. if($nowTime > $endTime){
  58. return $store['name'].'店铺已打烊';
  59. }
  60. array_push($time1Arr,$time1);
  61. array_push($time2Arr,$time2);
  62. }
  63. $time1Max = max($time1Arr);
  64. $time2Min = min($time2Arr);
  65. $endTime = $time2Min;
  66. if(!empty($time3Arr) && !empty($time4Arr)){
  67. $time3Max = max($time3Arr);
  68. $time4Min = min($time4Arr);
  69. $endTime = $time4Min;
  70. }
  71. if($nowTime > $time1Max){
  72. $time1Max = $nowTime;
  73. }
  74. for($i = 1;$i<=10;$i++){
  75. $time = time() + (30*60*$i);
  76. if($time < $time2Min){
  77. $time5 = $time1Max + (30*60*$i);
  78. }else{
  79. if(empty($time3Max)){
  80. return $res;
  81. }
  82. $time5 = $time3Max + (30*60*$i);
  83. }
  84. if($time5 >= $endTime){
  85. return $res;
  86. }
  87. $res[] = date('h:i',$time5);
  88. }
  89. // foreach ($stores as $store){
  90. //
  91. // }
  92. return $res;
  93. }
  94. }