|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Console\Commands; |
| 4 | + |
| 5 | +use Illuminate\Console\Command; |
| 6 | +use App\Http\Controllers\SendPushNotification; |
| 7 | +use App\Http\Controllers\AdminController; |
| 8 | +use App\RequestFilter; |
| 9 | +use Carbon\Carbon; |
| 10 | +use App\Provider; |
| 11 | +use Setting; |
| 12 | +use DB; |
| 13 | + |
| 14 | +class CustomCommand extends Command |
| 15 | +{ |
| 16 | + /** |
| 17 | + * The name and signature of the console command. |
| 18 | + * |
| 19 | + * @var string |
| 20 | + */ |
| 21 | + protected $signature = 'cronjob:rides'; |
| 22 | + |
| 23 | + /** |
| 24 | + * The console command description. |
| 25 | + * |
| 26 | + * @var string |
| 27 | + */ |
| 28 | + protected $description = 'Updating the Scheduled Rides Timing'; |
| 29 | + |
| 30 | + /** |
| 31 | + * Create a new command instance. |
| 32 | + * |
| 33 | + * @return void |
| 34 | + */ |
| 35 | + public function __construct() |
| 36 | + { |
| 37 | + parent::__construct(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Execute the console command. |
| 42 | + * |
| 43 | + * @return mixed |
| 44 | + */ |
| 45 | + public function handle() |
| 46 | + { |
| 47 | + $UserRequest = DB::table('user_requests')->where('status','SCHEDULED') |
| 48 | + ->where('schedule_at','<=',\Carbon\Carbon::now()->addMinutes(config('constants.schedule_time', '20'))) |
| 49 | + ->get(); |
| 50 | + |
| 51 | + $hour = \Carbon\Carbon::now()->subHour(); |
| 52 | + $futurehours = \Carbon\Carbon::now()->addMinutes(config('constants.schedule_time', '20')); |
| 53 | + $date = \Carbon\Carbon::now(); |
| 54 | + |
| 55 | + \Log::info("Schedule Service Request Started.".$date."==".$hour."==".$futurehours); |
| 56 | + |
| 57 | + if(!empty($UserRequest)){ |
| 58 | + |
| 59 | + foreach($UserRequest as $ride){ |
| 60 | + |
| 61 | + $distance = config('constants.provider_search_radius', '10'); |
| 62 | + $latitude = $ride->s_latitude; |
| 63 | + $longitude = $ride->s_longitude; |
| 64 | + $service_type = $ride->service_type_id; |
| 65 | + |
| 66 | + $Providers = Provider::with('service') |
| 67 | + ->select(DB::Raw("(6371 * acos( cos( radians('$latitude') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('$longitude') ) + sin( radians('$latitude') ) * sin( radians(latitude) ) ) ) AS distance"),'id') |
| 68 | + ->where('status', 'approved') |
| 69 | + ->whereRaw("(6371 * acos( cos( radians('$latitude') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('$longitude') ) + sin( radians('$latitude') ) * sin( radians(latitude) ) ) ) <= $distance") |
| 70 | + ->whereHas('service', function($query) use ($service_type) { |
| 71 | + $query->where('status','active'); |
| 72 | + $query->where('service_type_id',$service_type); |
| 73 | + }) |
| 74 | + ->orderBy('distance','asc') |
| 75 | + ->get(); |
| 76 | + |
| 77 | + if(config('constants.manual_request',0) == 0){ |
| 78 | + foreach ($Providers as $key => $Provider) { |
| 79 | + |
| 80 | + if(config('constants.broadcast_request',0) == 1){ |
| 81 | + (new SendPushNotification)->IncomingRequest($Provider->id); |
| 82 | + } |
| 83 | + |
| 84 | + $Filter = new RequestFilter; |
| 85 | + // Send push notifications to the first provider |
| 86 | + // incoming request push to provider |
| 87 | + |
| 88 | + $Filter->request_id = $ride->id; |
| 89 | + $Filter->provider_id = $Provider->id; |
| 90 | + $Filter->save(); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + DB::table('user_requests') |
| 95 | + ->where('id',$ride->id) |
| 96 | + ->update(['status' => 'SEARCHING', 'assigned_at' =>Carbon::now() , 'schedule_at' => null ]); |
| 97 | + |
| 98 | + //scehule start request push to user |
| 99 | + (new SendPushNotification)->user_schedule($ride->user_id); |
| 100 | + //scehule start request push to provider |
| 101 | + //(new SendPushNotification)->provider_schedule($ride->provider_id); |
| 102 | + |
| 103 | + /*DB::table('provider_services')->where('provider_id',$ride->provider_id)->update(['status' =>'riding']);*/ |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + $CustomPush = DB::table('custom_pushes') |
| 108 | + ->where('schedule_at','<=',\Carbon\Carbon::now()->addMinutes(5)) |
| 109 | + ->get(); |
| 110 | + |
| 111 | + if(!empty($CustomPush)){ |
| 112 | + foreach($CustomPush as $Push){ |
| 113 | + DB::table('custom_pushes') |
| 114 | + ->where('id',$Push->id) |
| 115 | + ->update(['schedule_at' => null ]); |
| 116 | + |
| 117 | + // sending push |
| 118 | + (new AdminController)->SendCustomPush($Push->id); |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + } |
| 123 | +} |
0 commit comments