无法在Laravel中维护Session

时间:2017-05-20 09:47:03

标签: php laravel session laravel-5 campaign-monitor

我正在使用Laravel 5.3并遇到有关会话的问题,当我使用查询字符串(UTM Querystring)点击URL时,该会话未被保留。没有查询字符串它可以正常工作并保持会话。

  1. mywebsite.com/booking(工作正常)
  2. mywebsite.com/booking?utm_source=affiliate&utm_medium=mailer&utm_campaign=Ad2click(销毁会话以及Cookie)
  3. 想知道,可能是什么原因?

    public function bookProduct(Request $request){
        $zone = $request->zone;
    
        $records = Zone::where('zone_name',$zone)->get();
    
        foreach($records as $record){
            $zone_id = $record->id;
        }
    
        if ( Session::get('LAST_ACTIVITY') && (time() - Session::get('LAST_ACTIVITY') > 1200 )){
    
            echo 'expired';
    
        }
    
        else{
    
            $CheckOTP = Session::get('otp');
    
            /* Check if User Entered OTP Matches System Generated OTP */
    
            if ( $CheckOTP == $request->get_otp ) {
    
                /* Create new Customer */
    
                $recordCount = Customer::where('email', $request->customer_email)->orWhere('contact_number',$request->customer_contact_no)->count();
    
                if( $recordCount > 0 ){
    
                    Customer::where('contact_number', $request->customer_contact_no)->update(['door_number' => $request->customer_pickup_door_no, 'building_name' => $request->customer_pickup_building_name, 'street_name' => $request->customer_pickup_street_name, 'area' => $request->customer_pickup_area, 'landmark' => $request->customer_pickup_landmark, 'pincode' => $request->customer_pickup_pincode, 'city'=>$request->customer_city]);
                }
    
                if($recordCount == 0 || $recordCount == ""){
    
                    $customer = new Customer;
    
                    $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
    
                    $pass = array(); //remember to declare $pass as an array
    
                    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    
                    for ($i = 0; $i < 8; $i++) {
    
                        $n = rand(0, $alphaLength);
    
                        $pass[] = $alphabet[$n];
    
                    }
    
                    $randomPass = implode($pass);
    
                    $password = Hash::make('a');
    
                    $customer->customer_name = $request->customer_name;
    
                    $customer->email = $request->customer_email;
    
                    $customer->contact_number = $request->customer_contact_no;
    
                    $customer->password = $password;
    
                    $customer->door_number = $request->customer_pickup_door_no;
    
                    //$customer->street_name = $request->customer_pickup_street_name;
    
                    //$customer->building_name = $request->customer_pickup_building_name;
    
                    $customer->area = $request->customer_pickup_area;
    
                    $customer->landmark = $request->customer_pickup_landmark;
    
                    $customer->pincode = $request->customer_pickup_pincode;
    
                    $customer->city = $request->customer_city;
    
                    $customer->save();
    
                    $id = $customer->id;
    
                    $measurement = new Measurement;
    
                    $measurement->customer_id = $id;
    
                    $address = $request->customer_pickup_door_no .",".$request->customer_pickup_area .",".$request->customer_pickup_landmark .",". $request->customer_city.",". $request->customer_pickup_pincode;
    
                    $measurement->save();
    
                    $datas =    $this->create_customer($request->customer_contact_no,$request->customer_name, $request->customer_email,$address,$request->customer_pickup_pincode);
    
                    $this->save_customers($request->customer_contact_no);
    
                }
    
                else{
    
                $address = $request->customer_pickup_door_no .",".$request->customer_pickup_area .",".$request->customer_pickup_landmark .",". $request->customer_city.",". $request->customer_pickup_pincode;
    
                     $datas =   $this->create_customer($request->customer_contact_no,$request->customer_name, $request->customer_email,$address,$request->customer_pickup_pincode);
                     $this->save_customers($request->customer_contact_no);
    
                        $fetchCustomer = Customer::where('email', $request->customer_email)->orWhere('contact_number',$request->customer_contact_no)->get();
    
                        foreach( $fetchCustomer as $customerId ){
    
                            $id = $customerId->id;
    
                        }
    
                }
    
    
                /* Store New Booking */
    
                /* Pickup address same as shipping address*/
    
                if( $request->duplicate_address == 'on'){
    
                    $request->customer_shipping_door_no = $request->customer_pickup_door_no;
    
                    //$request->customer_shipping_street_name = $request->customer_pickup_street_name;
    
                    //$request->customer_shipping_building_name = $request->customer_pickup_building_name;
    
                    $request->customer_shipping_area = $request->customer_pickup_area;
    
                    $request->customer_shipping_landmark = $request->customer_pickup_landmark;
    
                    $request->customer_shipping_pincode = $request->customer_pickup_pincode;
                }
    
                $booking = new Booking;
    
                $booking->customer_id = $id;
    
                $booking->look_id = Session::get("lookIds");
    
                $booking->time_slot_id = $request->slot;
    
                $booking->booking_date = strtr($request->booking_date, '/', '-');
    
                $booking->booking_date = date('Y-m-d', strtotime($booking->booking_date));
    
                $booking->door_number = $request->customer_shipping_door_no;
    
                //$booking->street_name = $request->customer_shipping_street_name;
    
                //$booking->building_name = $request->customer_shipping_building_name;
    
                $booking->landmark = $request->customer_shipping_landmark;
    
                $booking->pincode = $request->customer_shipping_pincode;
    
                $booking->city = $request->customer_city;
    
                $booking->area = $request->customer_shipping_area;
    
                $booking->fabric_availability = $request->fabric_material;
    
                $booking->otp = $CheckOTP;
    
                $booking->http_user_agent = $_SERVER['HTTP_USER_AGENT'];
    
                $zones = Zone::where('zone_name',$request->zone)->get();
    
                foreach( $zones as $zone){
    
                    $booking->zone_id = $zone->id;
                }
    
                /* Fetch Latitude & Longitude from address */
    
                //$address = $request->customer_pickup_door_no.' ,'.$request->customer_pickup_street_name.' ,'.$request->customer_pickup_building_name.' ,'.$request->customer_pickup_landmark;
    
                $address = $request->customer_pickup_door_no.' ,'.$request->customer_pickup_landmark.' ,'.$request->customer_shipping_area;
    
                $prepAddr = str_replace(' ','+',$address);
    
                $geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
    
                $output= json_decode($geocode);
    
    
                if( $output->status != "ZERO_RESULTS" ){
    
                    $latitude = $output->results[0]->geometry->location->lat;
    
                    $longitude = $output->results[0]->geometry->location->lng;
    
                }
                else{
    
                    $booking->latitude = "";
    
                    $booking->longitude = "";
                }
    
                $lastId = Booking::max('id');
    
                $lastId = $lastId+1;
    
                $booking->booking_id = 'BK'.date("ymd").str_pad($lastId, 4, '0', STR_PAD_LEFT); 
    
                $checkCouponApply = $request->check_coupon_apply;
    
                if($checkCouponApply == '1'){
    
                    $couponCode = $request->discount_coupon;
    
                    $booking->coupon_code = $request->discount_coupon;
    
                    $getDiscountPercentage = Discount::where('coupon_code',$couponCode)->pluck('coupon_percentage');
    
                    $getDiscountPercentage = $getDiscountPercentage[0];
    
                    Discount::where('coupon_code',$booking->coupon_code)->decrement('remaining_user_count');
    
    
                }
    
                $booking->save();
    
                Session::set('bookingId', $booking->id);
    
                if($request->trouser > 0 && $request->shirt > 0){
    
                    Session::set('productBought', 'Shirt & Trouser');
    
                }
                else if($request->trouser>0){
    
                    Session::set('productBought', 'Trouser');
    
                }
    
                else if($request->shirt>0){
    
                    Session::set('productBought', 'Shirt');
    
                }
    
                /* Store products data for Booking */
    
    
    
                $trouserRecord = Categories::where('category_name','Trouser')->pluck('id');
    
                $shirtRecord = Categories::where('category_name','Shirt')->pluck('id');
    
                $trouserPrice = ProductPrice::where('zone_id',$zone_id)
                                            ->where('category_id',$trouserRecord[0])
                                            ->pluck('price');
    
                $shirtPrice = ProductPrice::where('zone_id',$zone_id)
                                            ->where('category_id',$shirtRecord[0])
                                            ->pluck('price');
    
    
                $shirtUnitPrice = $shirtPrice[0];
    
                $trouserUnitPrice = $trouserPrice[0];
    
    
                $products = array('trouser' => array('count' => $request->trouser, 'category' => $trouserRecord[0], 'price'=>$trouserPrice[0], 'unit_price'=>$trouserUnitPrice), 'shirt' => array('count' => $request->shirt, 'category' => $shirtRecord[0], 'price'=>$shirtPrice[0], 'unit_price'=>$shirtUnitPrice));
    
                foreach($products as $product){
    
                    for($i=0;$i<$product['count'];$i++){
    
                        $subBooking = new SubBooking;
    
                        //Calculate tax tmount for each lined up product and save relavant data
    
                        $subBooking->booking_id = $booking->id;
    
                        if($product['category'] == '3'){
    
                            $subBooking->category_name = 'Shirt';
    
                        }
                        else if($product['category'] == '4'){
    
                            $subBooking->category_name = 'Trouser';
    
                        }
    
                        $setTaxes = Tax::all();
    
                        foreach($setTaxes as $taxes){
    
                            $tax[$taxes->tax_type] = $product['unit_price']*($taxes->percentage/100);
    
                            $tax[$taxes->tax_type.'Percentage'] = $taxes->percentage;
    
                        }
    
                        $subBooking->service_tax = $tax['Service Tax'];
    
                        $subBooking->service_tax_percentage = $tax['Service TaxPercentage'];
    
                        $subBooking->swachh_bharat = $tax['Swachh Bharat'];
    
                        $subBooking->swachh_bharat_percentage = $tax['Swachh BharatPercentage'];
    
                        $subBooking->krishi_kalyan = $tax['Krishi Kalyan'];
    
                        $subBooking->krishi_kalyan_percentage = $tax['Krishi KalyanPercentage'];
    
                        $subBooking->category_id = $product['category'];
    
                        $subBooking->unit_price = $product['unit_price'];
    
                        $subBooking->unit_price = $product['unit_price'];
    
                        $subBooking->quantity = 1;
    
                        $subBooking->save();
    
                    }
    
    
                }
    
                if($subBooking){
    
                        $this->storeReportingData('new');
    
                }
    
                $email = $request->customer_email;
                $booking_date_new = date("d M Y", strtotime($booking->booking_date));
    
                $time_slot_data = TimeSlot::where('id',$booking->time_slot_id)->first();
                $start = date("g:i a", strtotime($time_slot_data['start'])); 
                $end = date("g:i a", strtotime($time_slot_data['end'])); 
    
                $msg = "Thank you for booking with us. Your booking ref number is: $booking->booking_id and our appointment with you is on $booking_date_new ($start - $end).";  
    
                $action = 'New Booking';
    
                $description = "Booking has been created";
    
                $this->saveLog($booking->id, $action, $description);
    
                Session::forget('lookIds');
    
                $contact_no = $request->customer_contact_no;;
    
                $urlapi              = "https://api-in.bsmart.in/api/v3/sendsms/plain?";
    
                $user                = "USER";
    
                $password            = "SECRET";
    
                $senderid            = "SENDER_ID";
    
                $pin = mt_rand(1000, 9999);
    
                $msg_order_confirmation = urlencode("$msg");
    
                $msg2 = "Dear Customer, Please spare 45 minutes of your valuable time with our stylists for a perfect styling experience.";
    
                $sms_url = $urlapi."User=".$user."&Password=".$password."&Sender=".$senderid."&GSM=91".$contact_no."&SMSText=".$msg_order_confirmation;
    
                // Initialize session and set URL.
                $ch = curl_init();
    
                curl_setopt($ch, CURLOPT_URL, $sms_url);
    
                // Set so curl_exec returns the result instead of outputting it.
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    
                // Get the response and close the channel.
    
                $response = curl_exec($ch);
    
                curl_close($ch);
    
                $email_message = $msg." ".$msg2;
                //$this->sendEmail($email,$email_message);  
                $this->sendSMS($contact_no,$msg2);
    
                $sub_bookings = SubBooking::where('booking_id',$booking->id)->where('quantity','<>', 0)->get();
    
                $data = array();
    
                foreach($sub_bookings as $sub_booking){
    
                    $quantity = $sub_booking->quantity;
    
                    $category_data = Categories::where('id',$sub_booking->category_id)->first();
                    $category_name = $category_data['category_name']; 
    
                    $data[] = array('quantity'=>$quantity,'category_name'=>$category_name);  
                }  
    
                $appointment_date = date("d M Y", strtotime($booking->booking_date));
    
                $time_slot_data = TimeSlot::where('id',$booking->time_slot_id)->first();
                $start = date("g:i a", strtotime($time_slot_data['start'])); 
                $end = date("g:i a", strtotime($time_slot_data['end'])); 
    
                $customer_data = Customer::where('id',$booking->customer_id)->first();
                $customer_name = $customer_data['customer_name'];
    
                $email_data = array('email'=>$email,'customer_name'=>$customer_name,'from'=>'notifications-noreply@raymondcustomtailoring.com','from_name'=>'Raymond','appointment_date'=>$appointment_date,'appointment_id'=>$booking->booking_id,'customer_name'=>$customer_name,'address'=>$address,'pincode'=>$request->customer_shipping_pincode,'data'=>$data,'start'=>$start,'end'=>$end);
    
                /*Mail::send(['html'=>'confirm'],$email_data, function( $message ) use ($email_data)
                {
                    $message->to( $email_data['email'] )->from($email_data['from'],$email_data['from_name'] )->subject($email_data['appointment_id'].' Appointment Confirmed');
    
                });*/
                //return $booking->id;
    
            }
    
            else{
    
                echo 'mismatched';
    
            }
    
        }
    
    }
    

0 个答案:

没有答案