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.

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