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
3.1 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
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\Constants\v3\ErrorCode;
  4. use App\Exception\ErrorCodeException;
  5. use App\Model\v3\ShoppingCart;
  6. use App\Model\v3\Store;
  7. use App\Service\v3\Interfaces\AppointmentTimeServiceInterface;
  8. use phpDocumentor\Reflection\Types\Object_;
  9. class AppointmentTimeService implements AppointmentTimeServiceInterface
  10. {
  11. public function do()
  12. {
  13. return [
  14. '尽快送达',
  15. '08:30 - 09:00',
  16. '09:00 - 09:30',
  17. '09:30 - 10:00',
  18. '10:00 - 10:30'
  19. ];
  20. }
  21. public function check()
  22. {
  23. // TODO: Implement check() method.
  24. }
  25. public function undo()
  26. {
  27. // TODO: Implement undo() method.
  28. }
  29. public function get($shopcartIds)
  30. {
  31. $shopcartIds = explode(',',$shopcartIds);
  32. $sotreIds = ShoppingCart::query()->whereIn('id',$shopcartIds)->pluck('store_id');
  33. $stores = Store::query()->whereIn('id',$sotreIds)->get()->toArray();
  34. if(empty($stores)){
  35. $msg = ['sotreIds'=>$sotreIds,"shopcartIds"=>$shopcartIds];
  36. throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE,'',$msg);
  37. }
  38. $nowTime = time();
  39. $startTime = ceil($nowTime / (30*60)) * (30*60);
  40. //服务站最晚营业时间
  41. if (env('APP_ENV') === 'prod') {
  42. $endTime = strtotime(config('market.rest_time'));
  43. if($nowTime > $endTime){
  44. throw new ErrorCodeException(ErrorCode::MARKET_REST);
  45. }
  46. }else{
  47. $endTime = strtotime(date('Y-m-d 23:59:59'));
  48. }
  49. //取得所有店铺营业时间交集
  50. for($i = $startTime;$i<= $endTime;$i+=1800){
  51. $in = true;
  52. foreach($stores as $store){
  53. $time1 = strtotime(($store['time1']));
  54. $time2 = strtotime(($store['time2']));
  55. if(empty($store['time3']) || empty($store['time4'])) {
  56. if($i < $time1 || $i > $time2){
  57. $in = false;
  58. continue;
  59. }
  60. }else{
  61. $time3 = strtotime(($store['time3'])) ;
  62. $time4 = strtotime(($store['time4']));
  63. if(($i < $time1 || $i > $time2) && ($i < $time3 || $i > $time4)){
  64. $in = false;
  65. continue;
  66. }
  67. }
  68. }
  69. if($in){
  70. if($i === $startTime){
  71. $res['distribution'][] = ['title'=>'尽快送达','value'=>'尽快送达'];
  72. $res['self_take'][] = ['title'=>'尽快自提','value'=>'尽快自提'];
  73. }
  74. $data['title'] = date('H:i',$i + 30 * 60) . ' - ' . date('H:i',$i + 30 * 60 * 2);
  75. $data['value'] = date('H:i',$i + 30 * 60) . ' - ' . date('H:i',$i + 30 * 60 * 2);
  76. $res['distribution'][] = $data;
  77. $res['self_take'][]= $data;
  78. }
  79. }
  80. if(empty($res['distribution']) || empty($res['self_take'])){
  81. throw new ErrorCodeException(ErrorCode::STORE_BUSINESSS_HOURS_ERROR);
  82. }
  83. return $res;
  84. }
  85. }