· 5 years ago · Nov 19, 2020, 06:42 PM
1<?php
2
3namespace App\Http\Controllers\Mobile;
4use Illuminate\Support\Facades\Auth;
5
6use App\Events\OrderEvent;
7
8use Illuminate\Http\Request;
9use GuzzleHttp\Client;
10use App\Store;
11use App\Zone;
12use App\ServiceCategory;
13use App\User;
14use App\AppPreference;
15use App\Service;
16use App\NewService;
17use App\CityCode;
18use App\FirebaseToken;
19use App\ServiceRequestPickFromStore;
20use App\Coupon;
21use App\RefferalPoint;
22use Carbon\Carbon;
23use App\Product;
24use App\StoreProduct;
25use App\Session;
26use App\Order;
27use App\Notification;
28use App\OrderDetail;
29use App\Events\LiveDashboard;
30// use App\FareTiming;
31use App\PricingDeliveryService;
32use Illuminate\Support\Facades\Validator;
33use App\Http\Controllers\Controller;
34use Helper;
35
36use Razorpay\Api\Api;
37
38class PickCalController extends Controller{
39
40 public function continueStore(Request $request){
41
42 $stores = json_decode($request ->store);
43 // dd($stores);
44 $items = json_decode($request->items);
45 $len = sizeof($items);
46 $product_wt = 0;
47 $product_mrp = 0;
48 for($i=0; $i < $len; $i++){
49 (int)$qty= $items[$i]->qty;
50 (int)$id= $items[$i]->id;
51 if($id != 0){
52 $product = Product::withTrashed()->where('id',$id)->first();
53 // $product_wt = $product_wt + $qty*(Product::select()->where('id',$id)->first()->weight_cal) ;
54 $product_wt = $product_wt + $qty*(1) ;
55 $product_wt_type = $product->weight_type_cal;
56 // dd(Product::select()->where('id',$id)->first()->selling_price);
57 if(\DB::table('sessions')->where('user_id',Auth::user()->id)->where('store_id','!=',NULL)->count() > 0){
58 $session = Session::where('user_id',Auth::user()->id)->first();
59 if(!isset($session->store_type)){
60 $session_store_type = 'gold';
61 }else{
62 $session_store_type = strtolower($session->store_type);
63 }
64 if(StoreProduct::where('store_id',$session->store_id)->where('product_id',$product->product_id)->where($session_store_type,'!=','NULL')->count() > 0){
65 $mrp = StoreProduct::where('store_id',$session->store_id)->where('product_id',$product->product_id)->first()->{$session_store_type};
66 }else{
67 $mrp = Product::withTrashed()->where('id',$id)->first()->mrp;
68 }
69 }else{
70 $mrp = Product::withTrashed()->where('id',$id)->first()->mrp;
71 }
72 $product_mrp =$product_mrp + $qty*($mrp);
73 if($product_wt_type == 'kg'){
74 $product_wt = $product_wt * 1000;
75 }
76 else{
77 $product_wt = $product_wt;
78 }
79 }
80 }
81
82 $delivery_location = $request->delivery_location;
83 $coupon = $request->coupon;
84
85 if(isset($request->favstore_location)){
86
87 $del_lat_lng = explode(',',$delivery_location);
88 $favstore_location = explode(',',$request->favstore_location);
89
90 $lat = $favstore_location[0];
91 $lng = $favstore_location[1];
92
93 $lat1 = $del_lat_lng[0];
94 $lng1 = $del_lat_lng[1];
95
96 //
97 // $R = 6371; // Radius of the earth in km
98 // $dLat = deg2rad($lat1 - $lat); // deg2rad below
99 // $dLon = deg2rad($lng1 - $lng);
100 // $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($lat)) *cos(deg2rad($lat1)) * sin($dLon / 2) * sin($dLon / 2);
101 // $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
102 // $d = $R * $c; // Distance in km
103 //
104 // $dist1 = (int) $d; //in meters
105
106 //
107 $theta = $lng1 - $lng;
108 $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat)) + cos(deg2rad($lat1)) * cos(deg2rad($lat)) * cos(deg2rad($theta));
109 $dist = acos($dist);
110 $dist = rad2deg($dist);
111 $miles = $dist * 60 * 1.1515;
112 // $unit = strtoupper($unit);
113 // $dist = number_format(($miles * 1.609344),2);
114 $dist = number_format(($miles * 1.9),2);
115 $dist_in_kms = ceil($dist);
116 $dist = (int)($dist_in_kms *1000);
117 $dist1 = $dist/1000;
118
119
120 //
121 //
122 // $client = new Client();
123 //
124 // $res = $client->request('GET', 'https://maps.googleapis.com/maps/api/distancematrix/json?origins='.$delivery_location.'&destinations='.$request->favstore_location.'&mode=bike&language=fr-FR&key='.env("GOOGLE_MAPS_API_KEY",""));
125 //
126 // $res = json_decode($res->getBody(),true);
127 //
128 // $dist1 = $res['rows'][0]['elements'][0]['distance']['value'];
129 // $dist1 = $dist1/1000;
130 // $dist1 = (int)($dist1);
131
132 }else{
133 $dist1 = (int)AppPreference::where('id',8)->first()->value;
134 }
135 // dd($dist1);
136 // $dist1 = 17;
137 $favstore_address = $request->favstore_address;
138 $favstore_location = $request->favstore_location;
139
140 $wt = (int)AppPreference::where('id',15)->first()->value;
141 $pick_time = Carbon::now();
142 $pick_time = $pick_time->addMinutes(45)->format('H:i:s');
143
144 // Fare Helper
145 if(isset($request->service_id)){
146 $service_id = $request->service_id;
147 }else{
148 $service_id = 2;
149 }
150
151 // Territory
152 $territory = $request->pick_territory_id;
153
154
155
156 $fare = Helper::pickFromStore($dist1,$wt,$pick_time,$coupon,$product_mrp,$service_id,$stores,$territory,$favstore_address,$favstore_location);
157
158 $data = $fare->getData();
159
160 $fare = (int)($data->total);
161
162 // $fare = $fare + $product_mrp;
163
164 // return response()->json([
165 // 'status' => 'Success',
166 // 'status_code' => 200,
167 // 'message' => 'Distance and Time and Fare',
168 // 'weight' => $wt,
169 // 'distance_in_km' => $dist1,
170 // // 'time_in_min' => $distance_in_mins,
171 // 'fare'=> $fare,
172 // 'convenience_fee_actual'=>(int)(($fare / 100)*2.5),
173 // 'convenience_fee_applied'=>0,
174 // 'delivery_fee_actual'=>25,
175 // 'delivery_fee_applied'=>25,
176 // 'coupon'=>$coupon,
177 // 'total_distance'=>$dist1,
178 // 'base_charge'=>$data->base_charge,
179 // 'distance_charge'=>$data->rs_per_km,
180 // 'grand_total'=>$fare,
181 // // 'pick_date'=>$pick_date,
182 // 'pick_time'=>$pick_time,
183 // 'time_surge'=>$data->time_surge
184 // ]);
185
186 // if($product_wt > 25000){
187 // $no_of_orders_split = ceil($product_wt/25000);
188 // return response()->json([
189 // 'status' => 'Success',
190 // 'status_code' =>200,
191 // 'message' => 'Weight was Excedded, the order was splitted to '.$no_of_orders_split .' Orders',
192 // 'weight_of_items' => ceil($product_wt/1000).' Kg',
193 // 'items_price' => $product_mrp.' Rs',
194 // 'delivery_location' => $delivery_location,
195 // 'coupon_code' =>$coupon,
196 // 'no_of_orders' => $no_of_orders_split,
197 // 'stores' =>$stores,
198 // 'split_order' => 'false',
199 // ]);
200 // }
201
202 $api = new Api(env('RAZOR_ID'), env('RAZOR_SECRET'));
203
204 // return "sfadf";
205 $orderData = [
206 'receipt' => 3456,
207 'amount' => 2000 * 100, // 2000 rupees in paise
208 'currency' => 'INR',
209 'payment_capture' => 1 // auto capture
210 ];
211
212 $razorpayOrder = $api->order->create($orderData);
213
214 $razorpayOrderId = $razorpayOrder['id'];
215
216 $items_confirmation_popup = 'All the Item prices in the App are estimated rates and are subjected to change with store price. Any difference in Price would be intimated through a call for your confirmation.';
217
218 if(NewService::where('id',$service_id)->first()->offer_mode == 1){
219 $items_confirmation_popup = 'All the promo offers are subjective to availability of items at the store.';
220 $locate_store_link_status = 0;
221 }else{
222 $locate_store_link_status = AppPreference::where('id',73)->first()->value;
223 }
224
225 return response()->json([
226 'status' => 'Success',
227 'status_code' =>200,
228 'message' => 'Data',
229 'weight_of_items' => ceil($product_wt/1000) .'Kg',
230 'delivery_location' => $delivery_location,
231 'coupon_code' =>$coupon,
232 'no_of_orders' => 1,
233 'split_order' => 'true',
234 'stores' =>$stores,
235 'razorpay_order_id'=>$razorpayOrderId,
236 'base_charge'=>$data->base_charge,
237 'distance_charge'=>$data->rs_per_km,
238 'total_distance'=>$dist1,
239 // 'pick_date'=>$pick_date,
240 'pick_time'=>$pick_time,
241 'time_surge'=>$data->time_surge,
242 // 'delivery_fee_actual'=>30,
243 'delivery_fee'=>'Rs. '.$data->with_out_coupon,
244 'convenience_fee_actual'=>'Rs. '.(int)(($fare / 100)*2.5),
245 'convenience_fee_applied'=>'Rs. 0',
246 'items_price' => 'Rs. '.$product_mrp,
247 'total'=>'Rs. '.($data->with_out_coupon + $product_mrp + $data->gst),
248 'coupon'=>'Rs. '.$data->coupon,
249 'cancellation_fee'=>'Rs. '.$data->cancellation_fee,
250 'grand_total'=>'Rs. '.$fare,
251 'store_discount_applied'=>'Rs. '.$data->store_discount,
252 'gst'=>'Rs. '.$data->gst,
253 'note' =>'Final Bill May Show Different Price Based on Modifications Done to Order.',
254 'fav_store_link_text'=>'Shop From Favorite Store! Locate Store?',
255 'fav_store_info'=>'You can locate your favourite store for the products you are looking for, ChotaBeta will buy these prodcuts from your selected store only.',
256 'items_price_disclaimer'=>'All the items price in the cart are estimated and are subject to change with the store price',
257 'store_vicinity'=>AppPreference::where('id',70)->first()->value,
258 'google_maps_pinning_status'=>AppPreference::where('id',72)->first()->value,
259 'items_confirmation_popup'=>$items_confirmation_popup,
260 'fav_store_confirmation_popup'=>'Delivery Fee will be applicable based on the distance from store to delivery location',
261 'locate_store_link_status'=>$locate_store_link_status,
262 'schedule_time'=>0
263 ]);
264 }
265
266 public function payStore(Request $request){
267 if(Auth::user()->address != NULL){
268 if(CityCode::where('name',Auth::user()->address)->count() > 0){
269 $u1 = CityCode::where('name',Auth::user()->address)->first()->code;
270 if($u1 == NULL){
271 $u1 = substr((Auth::user()->address),0,1) .''. substr((Auth::user()->address),1,2);
272 }else{
273 if(Auth::user()->city_not_selected != NULL){
274 $u1 = AppPreference::where('id',65)->first()->value;
275 }else{
276 $u1 = substr(($u1),0,1) .''. substr(($u1),1,2);
277 }
278 }
279 }else{
280 $u1 = substr((Auth::user()->address),0,1) .''. substr((Auth::user()->address),1,2);
281 }
282 }else{
283 $u1 = substr((Auth::user()->address),0,1) .''. substr((Auth::user()->address),1,2);
284 }
285 $u2 = chr(rand(65,90));
286 $u3 = rand(0,9);
287 $u4 = rand(0,9);
288 $u5 = substr((Carbon::now()->timestamp),-3);
289 $u6 = substr((Auth::user()->mobile),-2);
290 $unique = $u1.''.$u2.''.$u3.''.$u4.''.$u5.''.$u6;
291
292 $stores = json_decode($request ->store);
293 $items = json_decode($request->items);
294 $len = sizeof($items);
295 $product_wt = 0;
296 $product_mrp = 0;
297 $item1 = array();
298 // $c = $request->items;
299 // dd($items);
300 foreach($items as $item){
301
302 // dump('a');
303 if($item->id != 0){
304
305
306 $product_detail = Product::withTrashed()->where('id',$item->id)->first();
307 $p_id = $product_detail->id;
308 $p_name = $product_detail->name;
309 $b = $product_detail->brand;
310 if(\DB::table('sessions')->where('user_id',Auth::user()->id)->where('store_id','!=',NULL)->count() > 0){
311 $session = Session::where('user_id',Auth::user()->id)->first();
312 if(!isset($session->store_type)){
313 $session_store_type = 'gold';
314 }else{
315 $session_store_type = strtolower($session->store_type);
316 }
317 if(StoreProduct::where('store_id',$session->store_id)->where('product_id',$product_detail->product_id)->where($session_store_type,'!=','NULL')->count() > 0){
318 $p_price = StoreProduct::where('store_id',$session->store_id)->where('product_id',$product_detail->product_id)->first()->{$session_store_type};
319 }else{
320 $p_price = $product_detail->mrp;
321 }
322 }else{
323 $p_price = $product_detail->mrp;
324 }
325 $weight = $product_detail->weight;
326 $weight_description = $product_detail->weight_description;
327 $its = ["id"=>$p_id,"cost"=>$p_price * $item->qty ,"name"=>ucwords($b).' '.$p_name,"qty"=>$item->qty,"weight"=>$weight,"weight_desc"=>$weight_description,'info'=>'',
328 'item_image'=>url('/public/uploads/items/'.$product_detail->product_id.'.jpg')
329 ];
330 // dd($its);
331 if($item->qty != 0){
332 array_push($item1,$its);
333 }
334 }
335 }
336 if($request->store != NULL and $request->store != "[]"){
337 $store1 = array();
338 foreach ($stores as $store) {
339 $ii = ["latlng"=>$store->latlng,"address"=>$store->address,"id"=>$store->id,"name"=>$store->name];
340 array_push($store1,$ii);
341 }
342 }else{
343 $store1 = array();
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360 //
361 //
362 // $client = new Client();
363 // $key = env("GOOGLE_MAPS_API_KEY","");
364 // // $key1 = env("GOOGLE_MAPS_API_KEY_PLACE_PHOTO","");
365 // $location = $request->delivery_location;
366 //
367 //
368 //
369 // $radius = (int)AppPreference::where('id',6)->first()->value;
370 // // $radius = 10000;
371 // $radius = rand(500,$radius);
372 //
373 //
374 //
375 //
376 //
377 // //
378 // if(($request->service_id != NULL)){
379 // if($request->service_id == 2){
380 // $type = ServiceCategory::where('id',$request->category_id)->first()->store_search_query;
381 // if($type == NULL){
382 // $type = 'Groceries';
383 // }
384 // }else{
385 // $type = Service::where('id',$request->service_id)->first()->store_search_query;
386 // if($type == NULL){
387 // $type = 'Groceries';
388 // }
389 // }
390 // }else{
391 // if($request->type != NULL){
392 // $type = $request->type;
393 // }else{
394 // $type = 'Groceries';
395 // }
396 // }
397 // // $keyword = $type;
398 //
399 // // dd($type);
400 //
401 //
402 // // $type = $request->type;
403 // // $type = explode(" ",$request->type);
404 // // $keyword = '';
405 // // foreach ($type as $t) {
406 // // $keyword = $keyword.$t.',';
407 // // }
408 //
409 // $type = $type;
410 // $type = explode(" ",$type);
411 // $keyword = '';
412 // foreach ($type as $t) {
413 // $keyword = $keyword.$t.',';
414 // }
415 //
416 //
417 //
418 //
419 //
420 // // dd('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location='.$location.'&radius='.$radius.'&type='.$type[0].'&keyword='.$keyword.'&key='.$key);
421 // $res = $client->request('GET', 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location='.$location.'&radius='.$radius.'&type='.$request->type.'&keyword='.$keyword.'&key='.$key);
422 //
423 //
424 // $res = json_decode($res->getBody(),true);
425 // $result = array();
426 // $i = 0;
427 //
428 // $loc = explode(',',$request->delivery_location);
429 // $loc = explode(',',$location);
430 // $lat1 = $loc[0];
431 // $lng1 = $loc[1];
432 //
433 //
434 // foreach($res['results'] as $resp){
435 // // If Store Name Exists
436 // if(isset($res['results'][$i]['name'])){
437 // $store_name = $res['results'][$i]['name'];
438 // }else{
439 // $store_name = false;
440 // }
441 //
442 // // If Open Now Exists
443 // if(isset($res['results'][$i]['opening_hours']['open_now'])){
444 // $open_now = $res['results'][$i]['opening_hours']['open_now'];
445 // }else{
446 // $open_now = false;
447 // }
448 //
449 // // If Address Exists
450 // if(isset($res['results'][$i]['vicinity'])){
451 // $shop_address = $res['results'][$i]['vicinity'];
452 // }else{
453 // $shop_address = false;
454 // }
455 //
456 // // If Photo Exists
457 // if(isset($res['results'][$i]['photos'][0]['photo_reference'])){
458 // $photo_reference = $res['results'][$i]['photos'][0]['photo_reference'];
459 // $store_image = 'https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference='.$photo_reference.'&key='.$key;
460 // }else{
461 // $store_image = null;
462 // }
463 //
464 // // If Lat Exists
465 // if(isset($res['results'][$i]['geometry']['location']['lat'])){
466 // $lat = $res['results'][$i]['geometry']['location']['lat'];
467 // $lat = number_format($lat,7);
468 // }else{
469 // $lat = 0;
470 // }
471 //
472 // // If Lng Exists
473 // if(isset($res['results'][$i]['geometry']['location']['lng'])){
474 // $lng = $res['results'][$i]['geometry']['location']['lng'];
475 // $lng = number_format($lng,7);
476 // }else{
477 // $lng = 0;
478 // }
479 //
480 // // If Store Id Exists
481 // if(isset($res['results'][$i]['place_id'])){
482 // $store_id = $res['results'][$i]['place_id'];
483 // // If Store is Tied Up With CB
484 // if(Store::where('place_id',$store_id)->count() > 0){
485 // $tied_up = true;
486 // if(Store::where('place_id',$store_id)->first()->discount == NULL){
487 // $discount = 0;
488 // }
489 // else{
490 // $discount = (int)(Store::where('place_id',$store_id)->first()->discount);
491 // }
492 // }else {
493 // $tied_up = false;
494 // $discount = 0;
495 // }
496 // }else{
497 // $store_id = false;
498 // }
499 //
500 // if($lat != 0 && $lng != 0){
501 // if (($lat1 == $lat) && ($lng1 == $lng)) {
502 // $distance_in_mins = 0;
503 // }
504 // else {
505 // $theta = $lng1 - $lng;
506 // $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat)) + cos(deg2rad($lat1)) * cos(deg2rad($lat)) * cos(deg2rad($theta));
507 // $dist = acos($dist);
508 // $dist = rad2deg($dist);
509 // $miles = $dist * 60 * 1.1515;
510 // // $unit = strtoupper($unit);
511 // $dist = number_format(($miles * 1.609344),2);
512 // $dist_in_kms = ceil($dist);
513 // $dist = $dist * 1000;
514 //
515 // // $secs = $dist/2.8;
516 // $secs = $dist/5.6;
517 // // $secs = (int)($secs);
518 // // $secs = floatval($secs);
519 //
520 // // dd(getType($secs));
521 // // $init = $secs;
522 // // $hours = floor($init / 3600);
523 // // $minutes = floor(($init / 60) % 60);
524 // // $seconds = $init % 60;
525 // // $distance_in_mins = "$hours h : $minutes m : $seconds s";
526 // // $distance_in_mins = $secs/60 + 20;
527 // $distance_in_mins = $secs/60 + 15;
528 // $distance_in_mins = (int)$distance_in_mins;
529 // // $distance_in_mins = $dist;
530 // // if ($unit == "K") {
531 // // return ($miles * 1.609344);
532 // // } else if ($unit == "N") {
533 // // return ($miles * 0.8684);
534 // // } else {
535 // // return $miles;
536 // // }
537 // }
538 // }else{
539 // $distance_in_mins = 0;
540 // }
541 //
542 //
543 //
544 //
545 // $arr = [
546 // 's.no' => $i,
547 // 'store_name' => $store_name,
548 // 'distance_in_mins' => $distance_in_mins,
549 // 'distance_in_kms' => $dist_in_kms,
550 // 'open_now' => $open_now,
551 // 'shop_address' => $shop_address,
552 // 'store_image' => $store_image,
553 // 'lat' => $lat,
554 // 'lng' => $lng,
555 // 'store_id' => $store_id,
556 // 'store_tied_up' => $tied_up,
557 // 'discount' => $discount,
558 //
559 // ];
560 // array_push($result, $arr);
561 // $i += 1;
562 // }
563 //
564 // if(Service::where('name',$request->type)->count() > 0){
565 // $type = Service::where('name',$request->type)->first()->type;
566 // }else{
567 // $type = 'G';
568 // }
569 //
570 // $opened = array();
571 // $closed = array();
572 //
573 // foreach($result as $r){
574 // if($r['open_now'] == true){
575 // array_push($opened,$r);
576 // }
577 // }
578 //
579 // foreach($result as $r){
580 // if($r['open_now'] == false){
581 // array_push($closed,$r);
582 // }
583 // }
584 // // return response()->json([
585 // // 'type' => $type,
586 // // 'opened_stores' => $opened,
587 // // 'closed_stores' => $closed,
588 // // 'store_selected'=> 0,
589 // // ]);
590 //
591 //
592 //
593 //
594 //
595 //
596 //
597 //
598 //
599 //
600 //
601 //
602 // // dd($opened[0]->lat);
603 // foreach ($opened as $store) {
604 // // dd($store['lat']);
605 // $ii = ["latlng"=>$store['lat'].','.$store['lng'],"address"=>$store['shop_address'],"id"=>$store['store_id'],"name"=>$store['store_name']];
606 // array_push($store1,$ii);
607 // }
608
609
610 // dd($opened);
611 // $ii = ["latlng"=>"17.3711105,78.4243939","address"=>"Athapur","id"=>"CHMDPA","name"=>"Roy\'s Store"];
612 // $ii = ["latlng"=>"17.3711105,78.4243939","address"=>"Athapur","id"=>"CHMDPA","name"=>"Roy\'s Store"];
613 // array_push($store1,$ii);
614
615
616
617 $store1 = [
618 [
619 's.no' => 1,
620 'store_name' => 'Store One',
621 'distance_in_mins' => 10,
622 'distance_in_kms' => 5,
623 'open_now' => true,
624 'shop_address' => 'Store Address',
625 'store_image' => 'https://chotabeta.com/assets/logo2.png',
626 'lat' => 17.7035617,
627 'lng' => 83.1932626,
628 'store_id' => 'TempStoreOne',
629 'store_tied_up' => 'No',
630 'discount' => 0,
631 'id' => 1,
632 'name' => 'Store One',
633 'address' => 'Store Address',
634 'latlng' => '17.7035617,78.5112',
635 ],
636 [
637 's.no' => 2,
638 'store_name' => 'Store Two',
639 'distance_in_mins' => 10,
640 'distance_in_kms' => 5,
641 'open_now' => true,
642 'shop_address' => 'Store Address',
643 'store_image' => 'https://chotabeta.com/assets/logo2.png',
644 'lat' => 0,
645 'lng' => 0,
646 'store_id' => 'TempStoreTwo',
647 'store_tied_up' => 'No',
648 'discount' => 0,
649 'id' => 1,
650 'name' => 'Store One',
651 'address' => 'Store Address',
652 'latlng' => '17.7035617,78.5112',
653 ],
654 [
655 's.no' => 1,
656 'store_name' => 'Store Three',
657 'distance_in_mins' => 10,
658 'distance_in_kms' => 5,
659 'open_now' => true,
660 'shop_address' => 'Store Address',
661 'store_image' => 'https://chotabeta.com/assets/logo2.png',
662 'lat' => 0,
663 'lng' => 0,
664 'store_id' => 'TempStoreThree',
665 'store_tied_up' => 'No',
666 'discount' => 0,
667 'id' => 1,
668 'name' => 'Store One',
669 'address' => 'Store Address',
670 'latlng' => '17.7035617,78.5112',
671 ]
672 ];
673
674
675
676
677 if(sizeof($store1) >= 3){
678 $store1 = array_slice($store1, 0, 3);
679 }else if(sizeof($store1) < 3 and sizeof($store1) > 0) {
680 $store1 = $store1;
681 }else{
682 return response()->json([
683 'status'=>'Error',
684 'status_code'=>204,
685 'message'=>'Stores Not Serving the Order Now.'
686 ]);
687 }
688 $stores = $store1;
689 }
690
691
692
693
694
695
696
697
698
699 // dd($item1);
700 //items
701 for($i=0; $i < $len; $i++){
702 $pickStore = new ServiceRequestPickFromStore;
703 $qty= $items[$i]->qty;
704 $id= $items[$i]->id;
705 $pickStore->order_id = $unique;
706 // $product_wt =$product_wt + $qty*(Product::select()->where('id',$id)->first()->weight_cal) ;
707 $service_request_product = Product::select()->withTrashed()->where('id',$id)->first();
708 $product_wt = $product_wt + $qty*(1) ;
709 $product_wt_type = $service_request_product->weight_type_cal;
710 $product_name = $service_request_product->name;
711 if(\DB::table('sessions')->where('user_id',Auth::user()->id)->where('store_id','!=',NULL)->count() > 0){
712 $session = Session::where('user_id',Auth::user()->id)->first();
713 if(!isset($session->store_type)){
714 $session_store_type = 'gold';
715 }else{
716 $session_store_type = strtolower($session->store_type);
717 }
718 if(StoreProduct::where('store_id',$session->store_id)->where('product_id',$service_request_product->product_id)->where($session_store_type,'!=','NULL')->count() > 0){
719 $selected_product_mrp = StoreProduct::where('store_id',$session->store_id)->where('product_id',$service_request_product->product_id)->first()->{$session_store_type};
720 }else{
721 $selected_product_mrp = Product::withTrashed()->where('id',$id)->first()->mrp;
722 }
723 }else{
724 $selected_product_mrp = $service_request_product->mrp;
725 }
726 $product_mrp =$product_mrp + $qty*($selected_product_mrp);
727 if($product_wt_type == 'kg'){
728 $product_wt = $product_wt * 1000;
729 }
730 else{
731 $product_wt = $product_wt;
732 }
733 $pickStore->product_id = $id;
734 $pickStore->order_id = $unique;
735 $pickStore->price = $selected_product_mrp;
736 $pickStore->product_name = $product_name;
737 $pickStore->qty = $qty;
738 if($qty != 0){
739 $pickStore->save();
740 }
741 }
742
743 $delivery_location = $request->delivery_location;
744 $delivery= $request->delivery;
745 $delivery_lat_lng = $request->delivery_location;
746
747
748
749 $coupon = $request->coupon;
750
751
752
753 if(isset($request->favstore_location)){
754
755 $del_lat_lng = explode(',',$delivery_location);
756 $favstore_location = explode(',',$request->favstore_location);
757
758 $lat = $favstore_location[0];
759 $lng = $favstore_location[1];
760
761 $lat1 = $del_lat_lng[0];
762 $lng1 = $del_lat_lng[1];
763
764
765 $R = 6371; // Radius of the earth in km
766 $dLat = deg2rad($lat1 - $lat); // deg2rad below
767 $dLon = deg2rad($lng1 - $lng);
768 $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($lat)) *cos(deg2rad($lat1)) * sin($dLon / 2) * sin($dLon / 2);
769 $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
770 $d = $R * $c; // Distance in km
771
772 $dist1 = (int) $d; //in meters
773 // dd($dist1);
774 }else{
775 $dist1 = (int)AppPreference::where('id',8)->first()->value;
776 }
777
778 $favstore_address = $request->favstore_address;
779 $favstore_location = $request->favstore_location;
780
781
782
783
784 $wt = (int)AppPreference::where('id',15)->first()->value;
785 $pick_time = Carbon::now();
786 $pick_time = $pick_time->addMinutes(45)->format('H:i:s');
787
788 // Fare Helper
789 if(isset($request->service_id)){
790 $service_id = $request->service_id;
791 }else{
792 $service_id = 2;
793 }
794
795 // Territory
796 $territory = $request->pick_territory_id;
797
798 $fare = Helper::pickFromStore($dist1,$wt,$pick_time,$coupon,$product_mrp,$service_id,$stores,$territory,$favstore_address,$favstore_location);
799
800 $data = $fare->getData();
801
802 $fare = (int)($data->total);
803
804 // $fare = $fare + $product_mrp;
805
806 // if($product_wt > 25000){
807 // $no_of_orders_split = ceil($product_wt/25000);
808 // return response()->json([
809 // 'status' => 'Success',
810 // 'status_code' =>200,
811 // 'message' => 'Weight was Excedded, the order want splitted to '.$no_of_orders_split .' Orders',
812 // 'weight_of_items' => ceil($product_wt/1000).' Kg',
813 // 'items_price' => $product_mrp.' Rs',
814 // 'delivery_location' => $delivery_location,
815 // 'coupon_code' =>$coupon,
816 // 'no_of_orders' => $no_of_orders_split,
817 // 'stores' =>$stores,
818 // 'split_order' => 'false',
819 // ]);
820 //
821 // }
822
823
824
825 // Coupon Calculation
826 // if($coupon != NULL){
827 // if(Coupon::select()->where('code',$coupon)->whereDate('from_Date','<',Carbon::today())->where('to_date','>=',Carbon::today())->count() > 0){
828 // $coupon1 = Coupon::select()->where('code',$coupon)->whereDate('from_Date','<',Carbon::today())->where('to_date','>=',Carbon::today())->first();
829 // $per = $coupon1->percent;
830 // $f = ((int)$fare/100)*(int)$per;
831 // $total = (int)$fare - (int)$f;
832 // $coupon_value = $f;
833 // }
834 //
835 // if($coupon == Auth::user()->ref_code){
836 // // Credited Points
837 // if(RefferalPoint::where('user_id',Auth::user()->id)->where('points_credited','!=',NULL)->count() > 0){
838 // $credited_points = RefferalPoint::where('user_id',Auth::user()->id)->where('points_credited','!=',NULL)->get();
839 // $credit = 0;
840 // foreach ($credited_points as $credits) {
841 // $credit += $credits->points_credited;
842 // }
843 // }else{
844 // $credit = 0;
845 // }
846 // // Debited Points
847 // if(RefferalPoint::where('user_id',Auth::user()->id)->where('points_debited','!=',NULL)->count() > 0){
848 // $debited_points = RefferalPoint::where('user_id',Auth::user()->id)->where('points_debited','!=',NULL)->get();
849 // $debit = 0;
850 // foreach ($debited_points as $debits) {
851 // $debit += $debits->points_debited;
852 // }
853 // }else{
854 // $debit = 0;
855 // }
856 //
857 //
858 // // Redeem Points
859 // $redeem_points = $credit - $debit;
860 //
861 // $total = $total - $redeem_points;
862 // $coupon_value = $redeem_points;
863 //
864 //
865 // $redeemed_points = new RefferalPoint();
866 // $redeemed_points->user_id = Auth::user()->id;
867 // $redeemed_points->points_debited = $redeem_points;
868 // $redeemed_points->reason = "Used for Order: ".$unique;
869 // $redeemed_points->save();
870 //
871 // }
872 // }
873
874 // Coupon Calculation
875 if($coupon != NULL){
876 if(Coupon::select()->where('code',$coupon)->whereDate('from_Date','<',Carbon::today())->where('to_date','>=',Carbon::today())->count() > 0){
877 $coupon1 = Coupon::select()->where('code',$coupon)->whereDate('from_Date','<',Carbon::today())->where('to_date','>=',Carbon::today())->first();
878 $per = $coupon1->percent;
879 $f = ((int)$fare/100)*(int)$per;
880 // $fare = (int)$fare - (int)$f;
881 $coupon_value = $f;
882 }
883
884 if($coupon == Auth::user()->ref_code){
885 // Credited Points
886 if(RefferalPoint::where('user_id',Auth::user()->id)->where('points_credited','!=',NULL)->count() > 0){
887 $credited_points = RefferalPoint::where('user_id',Auth::user()->id)->where('points_credited','!=',NULL)->get();
888 $credit = 0;
889 foreach ($credited_points as $credits) {
890 $credit += $credits->points_credited;
891 }
892 }else{
893 $credit = 0;
894 }
895 // Debited Points
896 if(RefferalPoint::where('user_id',Auth::user()->id)->where('points_debited','!=',NULL)->count() > 0){
897 $debited_points = RefferalPoint::where('user_id',Auth::user()->id)->where('points_debited','!=',NULL)->get();
898 $debit = 0;
899 foreach ($debited_points as $debits) {
900 $debit += $debits->points_debited;
901 }
902 }else{
903 $debit = 0;
904 }
905
906
907 // Redeem Points
908 $redeem_points = $credit - $debit;
909
910 $each_point_value = AppPreference::where('id',33)->first()->value;
911 $redeem_points = ($redeem_points * $each_point_value);
912 // $redeem_points = $credit - $debit;
913 $redeemed_points = new RefferalPoint();
914 $redeemed_points->user_id = Auth::user()->id;
915 $redeemed_points->referral_type = 1;
916 $redeemed_points->points_debited = $data->coupon * (100/(AppPreference::where('id',33)->first()->value * 100));
917 $redeemed_points->reason = "Used for Order: ".$unique;
918 $redeemed_points->save();
919 // if($fare > $redeem_points){
920 // $total = $fare - $redeem_points;
921 // $coupon_value = $redeem_points;
922 //
923 //
924 // $redeemed_points = new RefferalPoint();
925 // $redeemed_points->user_id = Auth::user()->id;
926 // $redeemed_points->points_debited = $redeem_points;
927 // $redeemed_points->reason = "Used for Order: ".$unique;
928 // $redeemed_points->save();
929 // }elseif($fare <= $redeem_points){
930 // $redeem_points = $fare;
931 // $total = $fare - $redeem_points;
932 // $coupon_value = $redeem_points;
933 //
934 //
935 // $redeemed_points = new RefferalPoint();
936 // $redeemed_points->user_id = Auth::user()->id;
937 // $redeemed_points->points_debited = $redeem_points;
938 // $redeemed_points->reason = "Used for Order: ".$unique;
939 // $redeemed_points->save();
940 // }
941 }
942 }
943
944
945
946 // Cancellation Fee Fine
947 if(Order::where('cancellation_fee','!=',NULL)->where('cancellation_fee_status',NULL)->where('user_id',Auth::user()->id)->count() > 0){
948 $cancellation_fees = Order::where('cancellation_fee','!=',NULL)->where('cancellation_fee_status',NULL)->where('user_id',Auth::user()->id)->get();
949
950 $cancellation_fee = 0;
951 foreach($cancellation_fees as $c_f){
952 $c_f->cancellation_fee_status = Carbon::now();
953 $c_f->save();
954 }
955 }
956
957
958
959
960
961
962
963
964 // Order Defaulter Status Check
965 if(($request->payment_mode == 'COD') or ($request->payment_mode == 'cod')){
966 $default_status = Helper::customerDefaulterStatusCheck(Auth::user()->mobile);
967 $status_data = $default_status->getData();
968
969 if($status_data->status == TRUE){
970 return response()->json([
971 'status'=>'Error',
972 'status_code'=>204,
973 'message'=>$status_data->message
974 ]);
975 }
976 }
977
978
979
980
981 if(($request->payment_mode == 'POD') or ($request->payment_mode == 'pod')){
982 $default_status = Helper::customerDefaulterStatusCheck(Auth::user()->mobile);
983 $status_data = $default_status->getData();
984
985 if($status_data->status == TRUE){
986 return response()->json([
987 'status'=>'Error',
988 'status_code'=>204,
989 'message'=>$status_data->message
990 ]);
991 }
992 }
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006 $order = new Order();
1007 if($request->payment_mode == 'Online'){
1008 $order->online = $fare;
1009 }
1010
1011 if(isset($request->schedule_timestamp)){
1012 $order->actual_schedule_timestamp = $request->schedule_timestamp;
1013 }
1014 if(isset($request->pick_terriotry_id)){
1015 $order->pick_territory_id = $request->pick_territory_id;
1016 }
1017 if(isset($request->drop_territory_id)){
1018 $order->drop_territory_id = $request->drop_territory_id;
1019 }
1020 if(Zone::where('id',$request->territory_id)->count() > 0){
1021 $order->state = Zone::where('id',$request->territory_id)->first()->state;
1022 $order->pincode = Zone::where('id',$request->territory_id)->first()->pincode;
1023 }
1024 $order->uid = $unique;
1025 $order->service_id = $request->service_id;
1026 $order->category_id = $request->category_id;
1027 $order->user_instructions = $request->user_instructions;
1028 $order->user_id = Auth::user()->id;
1029 $order->weight= ceil($product_wt/1000);
1030 $order->from_location = $delivery;
1031 $order->from_lat_lng = $delivery_lat_lng;
1032 if(Auth::user()->current_app_version == '1.2.1'){
1033 $order->to_lat_lng = $request->delivery_location;
1034 }else{
1035 $order->to_lat_lng = $request->to_location;
1036 }
1037 $order->to_location = $request->to_address;
1038 $order->items_price = $data->items_price;
1039 $order->amount = $fare;
1040 $order->gst = $data->gst;
1041 $order->estimated_amount = $data->delivery_fee;
1042 $order->store_discount_applied = $data->store_discount_applied;
1043 // dd($store1);
1044 $order->preferred_stores =json_encode($stores);
1045
1046 $order->payment_status = $request->payment_status;
1047 if(($request->payment_mode != "Online")){
1048 $order->status = 701;
1049 }else if($request->payment_status == "paid"){
1050 $order->status = 701;
1051 }
1052 else{
1053 $order->status = 705;
1054 }
1055
1056 $order_status = $order->status;
1057
1058 $order->payment_mode = $request->payment_mode;
1059
1060 $order->custom_item = $request->custom_item;
1061
1062 if($order_status != 705){
1063 if(FirebaseToken::select()->where('user_id',Auth::user()->id)->count() > 0){
1064 if(User::where('id',Auth::user()->id)->first()->device == 'IOS'){
1065 $notif_key = env('FIRE_BASE_APP_KEY_IOS');
1066 }else{
1067 $notif_key = env('FIRE_BASE_APP_KEY_USER');
1068 }
1069
1070 $user_current_app_version = User::where('id',Auth::user()->id)->first()->current_app_version;
1071 if(($user_current_app_version != NULL) and ($user_current_app_version != '0.2.9')){
1072 $notif_key = env('FIRE_BASE_APP_KEY_USER2');
1073 }
1074 $user_token = FirebaseToken::select()->where('user_id',Auth::user()->id)->first()->token;
1075
1076 $fcmUrl = env('FIRE_BASE_APP_SEND_URL', '');
1077 $notification = [
1078 'title' => 'Order For: Pick From Store',
1079 'body' => 'Your Order has Been Placed Successfully. Order Id: '.$unique,
1080 'icon' =>'myIcon',
1081 'sound' => 'mySound'
1082 ];
1083
1084 $extraNotificationData = ["message" => $notification,"moredata" =>'--'];
1085 $fcmNotification = [
1086 //multple token array
1087 // 'registration_ids' => $tokens,
1088 //single token
1089 'to' => $user_token,
1090 'notification' => $notification,
1091 'data' => $extraNotificationData
1092 ];
1093
1094 // dd($notification);
1095 $headers = [
1096 'Authorization: key=' . $notif_key,
1097 'Content-Type: application/json'
1098 ];
1099 $ch = curl_init();
1100 curl_setopt($ch, CURLOPT_URL,$fcmUrl);
1101 curl_setopt($ch, CURLOPT_POST, true);
1102 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
1103 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1104 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1105 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
1106 $result = curl_exec($ch);
1107 curl_close($ch);
1108
1109 $resultArr = json_decode($result, true);
1110 // dd($result);
1111 // dd($resultArr);
1112 // if($resultArr['success'] != 0 ){
1113 // return 'TRUE';
1114 // }else{
1115 // return 'FALSE';
1116 // }
1117
1118 }
1119
1120 $user = User::where('id',Auth::user()->id)->first();
1121
1122 // $guzzle = new Client([
1123 // 'base_uri' => env('SMS_HOST', '')
1124 // ]);
1125 //
1126 // $response = $guzzle->request('GET', 'bulk-sms', [
1127 // 'query' => [
1128 // 'username' => env('SMS_USERNAME', ''),
1129 // 'password' => env('SMS_PASSWORD', ''),
1130 // 'from' => 'CHBETA',
1131 // 'to' => $user->mobile,
1132 // 'message' => 'Hi '.$user->name.', Your Order Was Placed Successfully, For Service: Pick From Store, Order Id: '.$unique,
1133 // 'sms_type' => 2
1134 // ]
1135 // ]);
1136
1137 // $client = new Client();
1138 // $message = 'Hi '.$user->name.', Your Order Was Placed Successfully, For Service: Pick From Store, Order Id: '.$unique;
1139
1140 // $response = $client->get('http://login.adwingssolutions.com/api/v1/sendSMS.php?user=vaibhavroycb&password=Chota@123&senderid=ChBeta&number='.$user->mobile.'&text='.$message);
1141
1142 $message = 'Hi '.$user->name.', Your Order Was Placed Successfully, For Service: "Pick From Store", Order Id: '.$unique.'Note: Orders between 9.0 PM and 6.0 AM will be fulfilled the next day.';
1143
1144 Helper::sendSms($user->mobile,$message);
1145 if($user->test_account != 1){
1146
1147 $admins = AppPreference::where('id',17)->first()->value;
1148
1149 $admins = explode(',',$admins);
1150
1151 foreach ($admins as $admin) {
1152 $message = 'Hi! User Name: '.$user->name.'('.$user->mobile.') Placed an Order, For Service: Pick From Store, Order Id: '.$unique .' Location: '.$delivery;
1153
1154 Helper::sendSms($admin,$message);
1155 }
1156
1157 }
1158
1159
1160 $notif_track = new Notification();
1161 $notif_track->subject = 'Order For: Pick From Store';
1162
1163 $notif_track->message = 'Your Order has Been Placed Successfully. Order Id: '.$unique;
1164
1165 $notif_track->to_id = Auth::user()->id;
1166
1167 $notif_track->save();
1168 }
1169
1170 $order->coupon = $request->coupon;
1171 $order->coupon_value = $data->coupon;
1172 $order->transaction_id = $request->transaction_id;
1173
1174 // Contact Details
1175 $order->pick_name = $request->pick_name;
1176 $order->pick_phone = $request->pick_phone;
1177 $order->drop_name = $request->drop_name;
1178 $order->drop_phone = $request->drop_phone;
1179 $order->territory_id = $request->territory_id;
1180 $order->user_instructions = $request->user_instructions;
1181 $order->favstore_address = $request->favstore_address;
1182 $order->favstore_location = $request->favstore_location;
1183 $order->call_customer_count = AppPreference::where('id',76)->first()->value;
1184 $order->actual_schedule_timestamp = Carbon::now();
1185
1186
1187 if(Order::where('transaction_id',$request->transaction_id)->count() == 0){
1188 $order->save();
1189 }
1190
1191 //
1192 if(isset($request->custom_item)){
1193 $ci = json_decode($request->custom_item);
1194 if($ci !='[NA]' and $ci != NULL){
1195 foreach ($ci as $cia) {
1196 $cim = array('id'=>0,'cost'=>0,'item_image'=> 'https://www.stackroger.com/public/uploads/category/Others.png');
1197 $cia->id = 0;
1198 $cia->cost = 0;
1199 $cia->info = '';
1200 $cia->item_image = 'https://www.stackroger.com/public/uploads/category/Others.png';
1201 $cia = (array)$cia;
1202 array_push($item1,$cia);
1203 }
1204 }
1205 }
1206
1207 //
1208 // dd($item1);
1209 $order_lat = Order::select()->where('uid',$unique)->first();
1210 // dd($order_lat->id);
1211 $user = User::select()->where('id',$order_lat->user_id)->first();
1212
1213 {
1214 $message = [
1215 'order_id' =>$order_lat->id,
1216 'uid' =>$unique,
1217 'order_type' => 2,
1218 'change_status'=>1,
1219 'status' => 1,
1220 'total_bill' => $order->amount,
1221 'pay_pick_up' => 0,
1222 'collect_from_customer' => 0,
1223 'scheduled_time' => '0',
1224 'stores'=>$store1,
1225 "delivery_name"=> $request->pick_name,
1226 "delivery_phone"=> $request->pick_phone,
1227 'from_address' => $order->from_location,
1228 'from_location' => $order->from_lat_lng,
1229 'time_stamp' => Carbon::parse($order->created_at)->format('D h:i a').': '.Service::where('id',$order->service_id)->first()->name,
1230 'weight_of_items' => ceil($product_wt/1000) .'Kgs',
1231 'to_address' => $order->to_location,
1232 'to_location' => $order->to_lat_lng,
1233 'user_name' => $user->name,
1234 'mobile' => $user->mobile,
1235 'claimed_status' => 0,
1236 'claimed_counter' => 0,
1237 'transaction_id'=>$request->transaction_id,
1238 'pick_name'=>$request->pick_name,
1239 'pick_phone'=>$request->pick_phone,
1240 'drop_name'=>$request->drop_name,
1241 'drop_phone'=>$request->drop_phone,
1242 'user_instructions'=>$request->user_instructions,
1243 // 'pick_territory_id'=>$request->pick_territory_id,
1244 // 'drop_territory_id'=>$request->drop_territory_id,
1245 'items_list' =>$item1,
1246 'roud_trip' => 'No',
1247 'car_logo' => 'No',
1248 'car_type' => 'Manual',
1249 'car_model' => 'Sedan',
1250 ];
1251 }
1252
1253
1254
1255 // Partner Notification
1256 // $user = User::where('role_code',602)->get();
1257 //
1258 // foreach($user as $u){
1259 // if(FirebaseToken::where('user_id',$u->id)->count() > 0){
1260 //
1261 // $notif_key = env('FIRE_BASE_APP_KEY_DELIVERY');
1262 // $user_token = FirebaseToken::where('user_id',$u->id)->first()->token;
1263 // $broadcast_data = array(
1264 // "order_lat_lng"=>$delivery_lat_lng,
1265 // "notification_type"=>"Broadcast",
1266 // "notification_vicinity_in_mts"=>AppPreference::where('id',4)->first()->value,
1267 // "role_code"=>602
1268 // );
1269 // $user_name = explode(' ',$u->name);
1270 // $fcmUrl = env('FIRE_BASE_APP_SEND_URL', '');
1271 // $notification = [
1272 // 'title' =>'Order BroadCast',
1273 // 'body' => 'Pick from Store Order Placed',
1274 // 'image' =>'',
1275 // // 'icon' =>$icon_url,
1276 // 'sound' => 'mySound'
1277 // ];
1278 //
1279 // $extraNotificationData = ["message" => $notification,"moredata" =>'--'];
1280 // $fcmNotification = [
1281 // 'to' => $user_token,
1282 // 'notification' => $notification,
1283 // 'data' => $broadcast_data
1284 // ];
1285 //
1286 // // dd($fcmNotification);
1287 // $headers = [
1288 // 'Authorization: key=' . $notif_key,
1289 // 'Content-Type: application/json'
1290 // ];
1291 //
1292 // $ch = curl_init();
1293 // curl_setopt($ch, CURLOPT_URL,$fcmUrl);
1294 // curl_setopt($ch, CURLOPT_POST, true);
1295 // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
1296 // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1297 // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1298 // curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
1299 // $result = curl_exec($ch);
1300 // curl_close($ch);
1301 //
1302 // $resultArr = json_decode($result, true);
1303 // }
1304 // }
1305
1306 event(new LiveDashboard('LiveDashboard'));
1307
1308 if($order_status != 705){
1309 event(new OrderEvent($message));
1310
1311 // $role_code = 602;
1312 // $del_boys = User::where('role_code',$role_code)->where('user_status',0)->pluck('id')->toArray();
1313 // $tokens = FirebaseToken::whereIn('user_id',$del_boys)->pluck('token')->toArray();
1314 // $title = 'Pick From Store Order';
1315 // $body = 'Order From Pick From Store Service Received';
1316 // $image_url = '';
1317 // $notif_type = 'Broadcast';
1318 // $notif_key = env('FIRE_BASE_APP_KEY_DELIVERY');
1319 // $notif_range = 30000;
1320 // $order_lat_lng = $request->from_location;
1321 //
1322 //
1323 // $notif_resp = Helper::sendNotificationToBulkTokens($title,$body,$image_url,$tokens,$notif_key,$notif_type,$notif_range,$role_code,$order_lat_lng);
1324
1325 }
1326
1327 if(\DB::table('sessions')->where('user_id',Auth::user()->id)->count() > 0){
1328 $session = Session::where('user_id',Auth::user()->id)->first();
1329 $session->store_id = NULL;
1330 $session->save();
1331 }
1332
1333 // return view('order',compact('message'));
1334 return response()->json([
1335 'status' => 'Success',
1336 'status_code' =>200,
1337 'message' => 'Data',
1338 'order_id' => $unique,
1339 'weight_of_items' => ceil($product_wt/1000) .'Kg',
1340 'items_price' => $fare .'Rs',
1341 'delivery_location' => $delivery_location,
1342 'coupon_code' =>$coupon,
1343 'no_of_orders' => 1,
1344 'split_order' => 'true',
1345 'stores' =>$store1,
1346 ]);
1347 }
1348}
1349