Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $result = $request->all();
     list($items, $total) = $this->getOrderInfo($request, 'content');
     $extra = ['identifier' => time() . $request->get('phone', '')];
     $result = array_merge($result, $total, $extra);
     $order = Order::create($result);
     if ($order) {
         return Redirect::to('/pay')->withOrder($order);
     }
 }
Example #2
0
 public function checkoutStep4()
 {
     $obj = new helpers();
     $shp_address = array();
     $sitesettings = DB::table('sitesettings')->get();
     if (!empty($sitesettings)) {
         foreach ($sitesettings as $each_sitesetting) {
             if ($each_sitesetting->name == 'shipping_rate') {
                 $shipping_rate = (double) $each_sitesetting->value;
             }
             if ($each_sitesetting->name == 'free_discount_rate') {
                 $free_discount_rate = (double) $each_sitesetting->value;
             }
         }
     }
     if (Request::isMethod('post')) {
         Session::put('name_card', Input::get('name_card'));
         //Input::get('name_card');
         Session::put('card_number', Input::get('card_number'));
         //Input::get('card_number'); //"4042760173301988";//
         Session::put('card_exp_month', Input::get('card_exp_month'));
         // "03"; //
         Session::put('card_exp_year', Input::get('card_exp_year'));
         // "19"; //
         //checkout as guest
         if (!Session::has('member_userid')) {
             $guestdata = Session::get('guest_array');
             $shiping_address = array('address_title' => 'default address', 'first_name' => $guestdata["guest_fname"], 'last_name' => $guestdata["guest_lname"], 'email' => $guestdata["guest_email"], 'phone' => $guestdata["guest_phone"], 'address' => $guestdata["guest_address"], 'address2' => $guestdata["guest_address2"], 'city' => $guestdata["guest_city"], 'zone_id' => $guestdata["guest_state"], 'country_id' => $guestdata["guest_country_id"], 'postcode' => $guestdata["guest_zip_code"]);
             $want_reg = Request::input('register_user');
             if ($want_reg == 'register') {
                 //register the member
                 Session::put('guest_username_sess', Request::input('guest_username'));
                 $brandmember = Brandmember::create(['fname' => $guestdata['guest_fname'], 'lname' => $guestdata['guest_lname'], 'email' => $guestdata['guest_email'], 'username' => Request::input('guest_username'), 'password' => Hash::make(Request::input('guest_password')), 'role' => 0, 'admin_status' => 1, 'status' => 1, 'updated_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s')]);
                 $lastInsertedId = $brandmember->id;
                 $shiping_address['mem_brand_id'] = $brandmember->id;
                 $shp_address = Address::create($shiping_address);
                 $lastAddressId = DB::getPdo()->lastInsertId();
                 $user_id = $brandmember->id;
                 // Update Address id in brandmember table
                 $addressId = $shp_address->id;
                 $dataUpdateAddress = DB::table('brandmembers')->where('id', $brandmember->id)->update(['address' => $addressId]);
             } else {
                 //set userid for not loggedin users to pass the order
                 $user_id = NULL;
                 $shp_address['id'] = NULL;
                 $shp_address = (object) $shp_address;
                 //print_r($shp_address); exit;
             }
             // End of registration ==================================================
             /* To get the country code And Zone code */
             $shp_country = DB::table('countries')->where('country_id', $guestdata["guest_country_id"])->first();
             $shp_zone = DB::table('zones')->where('zone_id', $guestdata["guest_state"])->first();
             $shiping_address = array('address_title' => 'default address', 'first_name' => $guestdata["guest_fname"], 'last_name' => $guestdata["guest_lname"], 'email' => $guestdata["guest_email"], 'phone' => $guestdata["guest_phone"], 'address' => $guestdata["guest_address"], 'address2' => $guestdata["guest_address2"], 'city' => $guestdata["guest_city"], 'zone_id' => $shp_zone->code, 'country_id' => $shp_country->iso_code_3, 'postcode' => $guestdata["guest_zip_code"]);
             //print_r($shiping_address); exit;
             $shiping_address_serial = serialize($shiping_address);
         } else {
             //for logged-in users
             $shp_address = DB::table('addresses')->leftjoin('countries', 'countries.country_id', '=', 'addresses.country_id')->leftjoin('zones', 'zones.zone_id', '=', 'addresses.zone_id')->select('addresses.*', 'countries.name as country_name', 'countries.iso_code_3 as country_code', 'zones.name as zone_name', 'zones.code as zone_code')->where('mem_brand_id', Session::get('member_userid'))->where('id', Session::get('selected_address_id'))->first();
             //echo "<pre>111111";print_r($shp_address); exit;
             // Serialize the Shipping Address because If user delete there address from "addresses" table,After that the address also store in the "order" table for  getting order history//
             $shiping_address = array('address_title' => $shp_address->address_title, 'mem_brand_id' => $shp_address->mem_brand_id, 'first_name' => $shp_address->first_name, 'last_name' => $shp_address->last_name, 'email' => $shp_address->email, 'phone' => $shp_address->phone, 'address' => $shp_address->address, 'address2' => $shp_address->address2, 'city' => $shp_address->city, 'zone_id' => $shp_address->zone_code, 'country_id' => $shp_address->country_code, 'postcode' => $shp_address->postcode);
             $shiping_address_serial = serialize($shiping_address);
             //echo "pm= ".Session::get('payment_method'); exit;
             $user_id = Session::get('member_userid');
         }
         $order = Order::create(['order_total' => Request::input('grand_total'), 'sub_total' => Request::input('sub_total'), 'discount' => Request::input('discount'), 'redeem_amount' => Request::input('redeem_amount'), 'order_status' => 'pending', 'shipping_address_id' => $shp_address->id, 'shipping_cost' => Request::input('shipping_rate'), 'shipping_type' => 'flat', 'user_id' => $user_id, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'payment_method' => Session::get('payment_method'), 'transaction_id' => '', 'transaction_status' => '', 'shiping_address_serialize' => $shiping_address_serial, 'created_at' => date('Y-m-d H:s:i'), 'updated_at' => date('Y-m-d H:s:i')]);
         $last_order_id = $order->id;
         $obj = new helpers();
         $order_number = 'ORD-' . $obj->random_string(5) . '-' . $last_order_id;
         // Generate random String for order number
         $update_order_number = DB::table('orders')->where('id', $last_order_id)->update(['order_number' => $order_number]);
         Session::put('order_number', $order_number);
         Session::put('order_id', $last_order_id);
         ///we are not storing new registered cart in cart table as it will be destroyed soon
         if (Session::has('member_userid')) {
             $allCart = DB::table('carts')->where('user_id', Session::get('member_userid'))->get();
         } else {
             $allCart = $obj->content();
             foreach ($allCart as $each_content) {
                 $each_content->product_id = $each_content->id;
                 $each_content->form_factor = $each_content->options->form_factor;
                 $each_content->row_id = $each_content->rowid;
                 $each_content->product_name = $each_content->name;
                 $each_content->quantity = $each_content->qty;
                 $each_content->amount = $each_content->price;
                 $each_content->duration = $each_content->options->duration;
                 $each_content->sub_total = $each_content->subtotal;
                 $each_content->no_of_days = $each_content->options->no_of_days;
             }
         }
         foreach ($allCart as $eachCart) {
             $product_details = DB::table('products')->where('id', $eachCart->product_id)->first();
             // echo $each_content->brandmember_id; exit;
             $brandmember_deatils = DB::table('products')->leftJoin('brandmembers', 'brandmembers.id', '=', 'products.brandmember_id')->select('products.*', 'brandmembers.fname', 'brandmembers.lname', 'brandmembers.username', 'brandmembers.email', 'brandmembers.slug', 'brandmembers.pro_image', 'brandmembers.brand_details', 'brandmembers.brand_sitelink', 'brandmembers.status', 'brandmembers.admin_status')->where('products.id', '=', $eachCart->product_id)->first();
             //echo "<pre>";print_r($brandmember_deatils); exit;
             //echo $brandmember->slug ; exit;
             $brand_member_name = $brandmember_deatils->fname ? $brandmember_deatils->fname . ' ' . $brandmember_deatils->lname : $brandmember_deatils->username;
             $formfactor = DB::table('form_factors')->where('id', '=', $eachCart->form_factor)->first();
             $order_item = OrderItems::create(['order_id' => $last_order_id, 'brand_id' => $brandmember_deatils->brandmember_id, 'brand_name' => $brand_member_name, 'brand_email' => $brandmember_deatils->email, 'product_id' => $eachCart->product_id, 'product_name' => $eachCart->product_name, 'product_image' => $product_details->image1, 'quantity' => $eachCart->quantity, 'price' => $eachCart->amount, 'form_factor_id' => $formfactor->id, 'form_factor_name' => $formfactor->name, 'duration' => $eachCart->duration, 'no_of_days' => $eachCart->no_of_days]);
             //All Cart deleted from cart table after inserting all data to order and order_item table.
             if (Session::has('member_userid')) {
                 $deleteCart = DB::table('carts')->where('user_id', '=', Session::get('member_userid'))->delete();
             }
             Cart::destroy();
             // After inserting all cart data into Order and Order_item Table database
         }
         //set points for users on purchase
         if (Session::get('payment_method') == 'creditcard') {
             return redirect('/checkout-authorize/' . $last_order_id);
         } elseif (Session::get('payment_method') == 'paypal') {
             return redirect('/checkout-paypal/' . $last_order_id);
         }
     }
     //end of post
     /*
     		
     
     // All Cart Contain  In Session Will Display Here //
     $content = DB::table('carts')->where('user_id',Session::get('member_userid'))->get();
     //echo "<pre>";print_r($content); exit;
     foreach($content as $each_content)
     	        {
     	            
     	            $product_res = DB::table('products')->where('id',$each_content->product_id)->first();
     	           // echo $each_content->brandmember_id; exit;
     	            $brandmember = DB::table('products')
     	                                ->leftJoin('brandmembers', 'brandmembers.id', '=', 'products.brandmember_id')
     	                                ->select('products.*', 'brandmembers.fname', 'brandmembers.lname', 'brandmembers.username', 'brandmembers.slug', 'brandmembers.pro_image', 'brandmembers.brand_details', 'brandmembers.brand_sitelink', 'brandmembers.status', 'brandmembers.admin_status')
     	                                ->where('products.id','=',$each_content->product_id)
     	                                ->first();
     	                                //echo "<pre>";print_r($brandmember); 
     	                                //echo $brandmember->slug ; exit;
     	            $brand_name = ($brandmember->fname)?($brandmember->fname.' '.$brandmember->lname):$brandmember->username;
     
     	            $formfactor = DB::table('form_factors')->where('id','=',$each_content->form_factor)->first();
     	            $formfactor_name = $formfactor->name;
     	            $formfactor_id = $formfactor->id;
     
     	            $cart_result[] = array('rowid'=>$each_content->row_id,
     	                'product_name'=>$each_content->product_name,
     	                'product_slug'=>$brandmember->product_slug,
     	                'product_image'=>$product_res->image1,
     	                'qty'=>$each_content->quantity,
     	                'price'=>$each_content->amount,
     	                'duration'=>$each_content->duration,
     	                'formfactor_name'=>$formfactor_name,
     	                'formfactor_id'=>$formfactor_id,
     	                'brand_name'=>$brand_name,
     	                'brand_slug'=>$brandmember->slug,
     	                'subtotal'=>$each_content->sub_total);
     
     	        }
     	    
     
                 //echo "sph= ".$shipping_rate; exit;
     return view('frontend.checkout.checkout_setp4',compact('body_class','cart_result','shipping_rate'),array('title'=>'MIRAMIX | Checkout-Step4'));
     */
 }
Example #3
0
 public function checkoutStep4()
 {
     $obj = new helpers();
     if ($obj->checkMemberLogin() && !$obj->checkBrandLogin()) {
         $sitesettings = DB::table('sitesettings')->get();
         if (!empty($sitesettings)) {
             foreach ($sitesettings as $each_sitesetting) {
                 if ($each_sitesetting->name == 'shipping_rate') {
                     $shipping_rate = (int) $each_sitesetting->value;
                 }
             }
         }
         if (Request::isMethod('post')) {
             $shp_address = DB::table('addresses')->where('mem_brand_id', Session::get('member_userid'))->where('id', Session::get('selected_address_id'))->first();
             // Serialize the Shipping Address because If user delete there address from "addresses" table,After that the address also store in the "order" table for  getting order history//
             $shiping_address = array('address_title' => $shp_address->address_title, 'mem_brand_id' => $shp_address->mem_brand_id, 'first_name' => $shp_address->first_name, 'last_name' => $shp_address->last_name, 'email' => $shp_address->email, 'phone' => $shp_address->phone, 'address' => $shp_address->address, 'address2' => $shp_address->address2, 'city' => $shp_address->city, 'zone_id' => $shp_address->zone_id, 'country_id' => $shp_address->country_id, 'postcode' => $shp_address->postcode);
             $shiping_address_serial = serialize($shiping_address);
             $order = Order::create(['order_total' => Request::input('grand_total'), 'sub_total' => Request::input('sub_total'), 'order_status' => 'pending', 'shipping_address_id' => Session::get('selected_address_id'), 'shipping_cost' => $shipping_rate, 'shipping_type' => 'flat', 'user_id' => Session::get('member_userid'), 'ip_address' => $_SERVER['REMOTE_ADDR'], 'payment_method' => Session::get('payment_method'), 'transaction_id' => '', 'transaction_status' => '', 'shiping_address_serialize' => $shiping_address_serial, 'created_at' => date('Y-m-d H:s:i'), 'updated_at' => date('Y-m-d H:s:i')]);
             $last_order_id = $order->id;
             $allCart = DB::table('carts')->where('user_id', Session::get('member_userid'))->get();
             foreach ($allCart as $eachCart) {
                 $product_details = DB::table('products')->where('id', $eachCart->product_id)->first();
                 // echo $each_content->brandmember_id; exit;
                 $brandmember_deatils = DB::table('products')->leftJoin('brandmembers', 'brandmembers.id', '=', 'products.brandmember_id')->select('products.*', 'brandmembers.fname', 'brandmembers.lname', 'brandmembers.username', 'brandmembers.slug', 'brandmembers.pro_image', 'brandmembers.brand_details', 'brandmembers.brand_sitelink', 'brandmembers.status', 'brandmembers.admin_status')->where('products.id', '=', $eachCart->product_id)->first();
                 //echo "<pre>";print_r($brandmember_deatils); exit;
                 //echo $brandmember->slug ; exit;
                 $brand_member_name = $brandmember_deatils->fname ? $brandmember_deatils->fname . ' ' . $brandmember_deatils->lname : $brandmember_deatils->username;
                 $formfactor = DB::table('form_factors')->where('id', '=', $eachCart->form_factor)->first();
                 $order_item = OrderItems::create(['order_id' => $last_order_id, 'brand_id' => $brandmember_deatils->brandmember_id, 'brand_name' => $brand_member_name, 'product_id' => $eachCart->product_id, 'product_name' => $eachCart->product_name, 'product_image' => $product_details->image1, 'quantity' => $eachCart->quantity, 'price' => $eachCart->amount, 'form_factor_id' => $formfactor->id, 'form_factor_name' => $formfactor->name]);
                 // All Cart deleted from cart table after inserting all data to order and order_item table.
                 //$deleteCart =  Cart::where('user_id', '=', Session::get('member_userid'))->delete();
             }
             if (Session::get('payment_method') == 'creditcard') {
                 return redirect('/checkout-authorize/' . $last_order_id);
             } elseif (Session::get('payment_method') == 'paypal') {
                 return redirect('/checkout-paypal/' . $last_order_id);
             }
         }
         // All Cart Contain  In Session Will Display Here //
         $content = DB::table('carts')->where('user_id', Session::get('member_userid'))->get();
         //echo "<pre>";print_r($content); exit;
         foreach ($content as $each_content) {
             $product_res = DB::table('products')->where('id', $each_content->product_id)->first();
             // echo $each_content->brandmember_id; exit;
             $brandmember = DB::table('products')->leftJoin('brandmembers', 'brandmembers.id', '=', 'products.brandmember_id')->select('products.*', 'brandmembers.fname', 'brandmembers.lname', 'brandmembers.username', 'brandmembers.slug', 'brandmembers.pro_image', 'brandmembers.brand_details', 'brandmembers.brand_sitelink', 'brandmembers.status', 'brandmembers.admin_status')->where('products.id', '=', $each_content->product_id)->first();
             //echo "<pre>";print_r($brandmember);
             //echo $brandmember->slug ; exit;
             $brand_name = $brandmember->fname ? $brandmember->fname . ' ' . $brandmember->lname : $brandmember->username;
             $formfactor = DB::table('form_factors')->where('id', '=', $each_content->form_factor)->first();
             $formfactor_name = $formfactor->name;
             $formfactor_id = $formfactor->id;
             $cart_result[] = array('rowid' => $each_content->row_id, 'product_name' => $each_content->product_name, 'product_slug' => $brandmember->product_slug, 'product_image' => $product_res->image1, 'qty' => $each_content->quantity, 'price' => $each_content->amount, 'duration' => $each_content->duration, 'formfactor_name' => $formfactor_name, 'formfactor_id' => $formfactor_id, 'brand_name' => $brand_name, 'brand_slug' => $brandmember->slug, 'subtotal' => $each_content->sub_total);
         }
         //echo "sph= ".$shipping_rate; exit;
         return view('frontend.checkout.checkout_setp4', compact('body_class', 'cart_result', 'shipping_rate'), array('title' => 'MIRAMIX | Checkout-Step4'));
     } else {
         redirect('/checkout-step1');
     }
 }
Example #4
0
 /**
  *
  * @SWG\Api(
  *   path="/orders",
  *   @SWG\Operation(
  *     method="POST", summary="生成订单", notes="生成订单",type="Order",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="order_info",
  *         description="提交的订单信息",
  *         paramType="body",
  *         required=true,
  *         type="newOrderParams"
  *     )
  *   )
  * )
  */
 public function store(Request $request)
 {
     DB::beginTransaction();
     $response = new BaseResponse();
     $content = json_decode($request->getContent(false));
     $accessToken = $content->accessToken;
     $goodsList = $content->goodsList;
     $total_fee = 0;
     $coupon_total = 0;
     foreach ($goodsList as $g) {
         $goods = Goods::find($g->goods_id);
         if ($goods != null) {
             //检查是否购买过新用户福利(0元福利)
             //是否是新用户福利商品
             $homeButtonGoods = HomeButtonGoods::where('goods_id', $goods->id)->first();
             if ($homeButtonGoods != null) {
                 //判断是否购买过
                 $homeButtonGoodsBuyRecords = HomeButtonGoodsBuyRecords::where('home_button_goods_id', $homeButtonGoods->id)->where('user_id', $content->user_id)->first();
                 if ($homeButtonGoodsBuyRecords != null) {
                     $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
                     $response->Message = "商品" . $goods->name . "为新用户福利,只能购买一次,您已经购买过了";
                     DB::rollback();
                     return $response->toJson();
                 } else {
                     $newHomeButtonGoodsRecords = new HomeButtonGoodsBuyRecords();
                     $newHomeButtonGoodsRecords->user_id = $content->user_id;
                     $newHomeButtonGoodsRecords->home_button_goods_id = $homeButtonGoods->id;
                     $newHomeButtonGoodsRecords->save();
                 }
             }
             //如果在约惠列表里,不减去优惠金额 要扣券
             if (ActivityClassificationGoods::where('goods_id', $goods->id)->count() > 0 || FreePostGoods::where('goods_id', $goods->id)->count() > 0 || ConversionGoods::where('goods_id', $goods->id)->count() > 0) {
                 $total_fee = $total_fee + $goods->price * $g->num;
                 $coupon_total = $coupon_total + $goods->coupon_amount * $g->num;
                 $goods->num = $goods->num - $g->num;
                 if ($goods->num < 0) {
                     $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
                     $response->Message = "商品库存不够";
                     DB::rollback();
                     return $response->toJson();
                 }
                 $goods->save();
                 continue;
             }
             if ($g->use_coupon == 1) {
                 $total_fee = $total_fee + $goods->price * $g->num - $goods->coupon_amount * $g->num;
                 $coupon_total = $coupon_total + $goods->coupon_amount * $g->num;
             } else {
                 $total_fee = $total_fee + $goods->price * $g->num;
             }
             $goods->num = $goods->num - $g->num;
             if ($goods->num < 0) {
                 $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
                 $response->Message = "商品库存不够";
                 DB::rollback();
                 return $response->toJson();
             }
             $goods->save();
         } else {
             $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
             $response->Message = "get goods failed!";
             DB::rollback();
             return $response->toJson();
         }
     }
     unset($content->goodsList);
     //        DB::rollback();s
     //        echo $coupon_total;exit;
     //检测礼券充足
     $apiParam = ['accessToken' => $accessToken, 'coupon' => $coupon_total];
     $res = $this->post('/zhmf/member/consumerCoupon/isCouponEnough', $apiParam);
     $res = json_decode($res);
     if ($res->Code == 0 && $res->Data->enough == false) {
         $response->Code = -1;
         $response->Message = "礼券不足";
         DB::rollback();
         return $response->toJson();
     }
     if ($total_fee <= 0) {
         $total_fee = 0;
     }
     $content->total_fee = $total_fee;
     $content->shipping_fee = 10;
     //总运费
     $content->out_trade_no = $this->buildOrderNo();
     if ($total_fee == 0) {
         $content->status = 1;
     }
     $order = Order::create((array) $content);
     $useCouponRecords = new UseCouponRecords();
     $useCouponRecords->user_id = $content->user_id;
     $useCouponRecords->order_id = $order->id;
     $useCouponRecords->access_token = $accessToken;
     $useCouponRecords->coupon = $coupon_total;
     if ($total_fee == 0) {
         $useCouponRecords->status = 2;
         $apiParam = ['accessToken' => $useCouponRecords->access_token, 'coupon' => $useCouponRecords->coupon, 'orderId' => $content->out_trade_no];
         $res = $this->post('/zhmf/member/consumerCoupon/useCoupon', $apiParam);
         $res = json_decode($res);
         if ($res->Code == 0) {
             $useCouponRecords->status = 1;
         }
     } else {
         $useCouponRecords->status = 0;
     }
     $useCouponRecords->save();
     foreach ($goodsList as $v) {
         $orderGoods = new OrderGoods();
         $orderGoods->order_id = $order->id;
         $orderGoods->goods_id = $v->goods_id;
         $orderGoods->num = $v->num;
         $orderGoods->properties = json_encode($v->properties);
         if (isset($v->message)) {
             $orderGoods->message = $v->message;
         }
         $orderGoods->save();
     }
     $response->Data = $order;
     DB::commit();
     return $response->toJson();
     //var_dump($content);
     //echo $this->sign_request(['array'],'../config/rsa_private_key.pem');
 }