promotion 1.0
This commit is contained in:
parent
1cc8e025a1
commit
570d428b1c
60 changed files with 1596 additions and 272 deletions
|
|
@ -29,10 +29,19 @@ class CustomerPriority
|
|||
return $shopping_users;
|
||||
}
|
||||
|
||||
public static function checkOne($shopping_user, $mail=false, $newCustomer = true){
|
||||
//look for entry
|
||||
if(self::entryExists($shopping_user)){
|
||||
return 'exists';
|
||||
public static function checkOne($shopping_user, $mail=false, $newCustomer = true, $entryExistsLike = false){
|
||||
//look for entry
|
||||
if($entryExistsLike){
|
||||
if(self::entryExistsLike($shopping_user)){
|
||||
if($mail){ //send mail
|
||||
Mail::to(config('app.info_mail'))->send(new MailInfo($shopping_user, 'check_is_like_customer'));
|
||||
}
|
||||
return 'exists';
|
||||
}
|
||||
}else{
|
||||
if(self::entryExists($shopping_user)){
|
||||
return 'exists';
|
||||
}
|
||||
}
|
||||
if(self::entryLike($shopping_user)){
|
||||
if($mail){ //send mail
|
||||
|
|
@ -122,6 +131,7 @@ class CustomerPriority
|
|||
->where('number', '!=', NULL) //has number
|
||||
->where('id', '!=', $shopping_user->id)
|
||||
->where('billing_email', '=', $data['billing_email'])
|
||||
->where('member_id', '!=', $shopping_user->member_id)
|
||||
->get()->pluck('number', 'id')->unique()->toArray();
|
||||
if($found && count($found)){
|
||||
foreach ($found as $key=>$val){
|
||||
|
|
@ -139,6 +149,7 @@ class CustomerPriority
|
|||
->where('id', '!=', $shopping_user->id)
|
||||
->where('billing_lastname', '=', $data['billing_lastname'])
|
||||
->where('billing_zipcode', '=', $data['billing_zipcode'])
|
||||
->where('member_id', '!=', $shopping_user->member_id)
|
||||
->get()->pluck('number', 'id')->unique()->toArray();
|
||||
if($found && count($found)){
|
||||
foreach ($found as $key=>$val){
|
||||
|
|
@ -193,11 +204,30 @@ class CustomerPriority
|
|||
$shopping_user->shopping_order->member_id = $match->member_id;
|
||||
$shopping_user->shopping_order->save();
|
||||
}
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function entryExistsLike($shopping_user)
|
||||
{
|
||||
$matches = ShoppingUser::where('auth_user_id', '=', NULL)
|
||||
->where('number', '!=', NULL) //has number
|
||||
->where('id', '!=', $shopping_user->id)
|
||||
->where('member_id', '!=', $shopping_user->member_id)
|
||||
->where('billing_email', '=', $shopping_user->billing_email)
|
||||
->get()->pluck('number', 'id')->unique()->toArray();
|
||||
|
||||
if($matches && count($matches)){
|
||||
$shopping_user->is_like = true;
|
||||
$shopping_user->setNotice(self::$user_notice_key, $matches);
|
||||
$shopping_user->save();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function entryLike($shopping_user){
|
||||
//check same last name und PLZ
|
||||
$matches = ShoppingUser::select('*')
|
||||
|
|
@ -217,13 +247,16 @@ class CustomerPriority
|
|||
}
|
||||
|
||||
private static function newCustomer($shopping_user){
|
||||
if($shopping_user->shopping_order && $shopping_user->shopping_order->member_id) {
|
||||
$member_id = $shopping_user->shopping_order->member_id;
|
||||
if($shopping_user->member_id) {
|
||||
$member_id = $shopping_user->member_id;
|
||||
$shopping_user->member_id = $member_id;
|
||||
$shopping_user->number = self::nextNumber();
|
||||
$shopping_user->save();
|
||||
$shopping_user->shopping_order->member_id = $member_id;
|
||||
$shopping_user->shopping_order->save();
|
||||
if($shopping_user->shopping_order){
|
||||
$shopping_user->shopping_order->member_id = $member_id;
|
||||
$shopping_user->shopping_order->save();
|
||||
}
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +266,6 @@ class CustomerPriority
|
|||
$shopping_user->number = self::nextNumber();
|
||||
$shopping_user->save();
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
|
||||
}
|
||||
|
||||
private static function changeCustomer($shopping_user, $member_id, $number){
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use App\Models\ShoppingOrder;
|
|||
use App\Models\UserPayCredit;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\UserCreditMargin;
|
||||
use App\Models\PromotionUserOrder;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class Payment
|
||||
|
|
@ -135,7 +136,7 @@ class Payment
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
public static function paymentStatusPaidAction(ShoppingOrder $shopping_order, $paid){
|
||||
$send_link = false;
|
||||
|
||||
|
|
@ -197,7 +198,6 @@ class Payment
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
//if the order has action
|
||||
if($shopping_order->shopping_user->is_from === 'user_order'){
|
||||
//is margin -> set paid
|
||||
|
|
@ -209,10 +209,44 @@ class Payment
|
|||
return $send_link;
|
||||
}
|
||||
|
||||
public static function handelPromotionProduct(ShoppingOrder $shopping_order){
|
||||
//add the Promotion Product to Order
|
||||
$shopping_order = ShoppingOrder::find($shopping_order->id);
|
||||
foreach($shopping_order->shopping_order_items as $shopping_order_item){
|
||||
if($shopping_order_item->isFreeProduct()){
|
||||
if($promotion_user_product = $shopping_order_item->promotion_user_product){
|
||||
$promotion_admin_product = $promotion_user_product->promotion_admin_product;
|
||||
$PromotionUserOrder = PromotionUserOrder::create([
|
||||
'promotion_admin_id' => $promotion_user_product->promotion_admin_id,
|
||||
'promotion_user_id' => $shopping_order->promotion_user_id,
|
||||
'promotion_user_product_id' => $promotion_user_product->id,
|
||||
'product_id' => $promotion_user_product->product_id,
|
||||
'shopping_order_item_id' => $shopping_order_item->id,
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'shopping_user_id' => $shopping_order->shopping_user_id,
|
||||
'qty' => $shopping_order_item->qty,
|
||||
'price' => $promotion_admin_product->getPriceWith(false),
|
||||
'price_net' => $promotion_admin_product->getPriceWith(true),
|
||||
'tax_rate' => $promotion_admin_product->product->tax,
|
||||
]);
|
||||
|
||||
$promotion_user_product->open_items -= $PromotionUserOrder->qty;
|
||||
$promotion_user_product->sell_items += $PromotionUserOrder->qty;
|
||||
$promotion_user_product->used_budget_total += $PromotionUserOrder->price;
|
||||
$promotion_user_product->save();
|
||||
|
||||
//TODO Guthaben abziehen
|
||||
self::addUserPayCredits($promotion_user_product->promotion_user->user, ($PromotionUserOrder->price*-1), 5, 'promotion_order_deduction', $shopping_order->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//remove form credit, every sale fnc / vor / etc from CheckoutController
|
||||
//when stone, put it back SalesController
|
||||
public static function handelUserPayCredits(ShoppingOrder $shopping_order, $do){
|
||||
//is payment credit, reduce Sae
|
||||
//is payment credit, deduction or return
|
||||
if(!$shopping_order->shopping_order_margin){
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,11 +35,19 @@ class PromotionCart
|
|||
}
|
||||
}
|
||||
|
||||
public static function clearCart($data, $add=false)
|
||||
public static function clearCart($data)
|
||||
{
|
||||
Yard::instance('shopping')->destroy();
|
||||
}
|
||||
|
||||
|
||||
public static function switchShipping($data)
|
||||
{
|
||||
//pick_up//dhl_shipping
|
||||
Yard::instance('shopping')->setShippingOption($data['shipping_option']);
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
|
||||
}
|
||||
|
||||
public static function updateProduct($data, $add=false)
|
||||
{
|
||||
if($product = Product::find($data['product_id'])){
|
||||
|
|
@ -77,13 +85,13 @@ class PromotionCart
|
|||
//wenn kleiner wurde ein produkt entfernt aufgrund der Anzahl
|
||||
//wenn gleich löschen, da neue Versandkosten
|
||||
|
||||
if($row->options->free_product) {
|
||||
if($row->options->free_product_id) {
|
||||
Yard::instance('shopping')->remove($row->rowId);
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($data['free_poduct_id'])) {
|
||||
if ($product = Product::find($data['free_poduct_id'])) {
|
||||
if(isset($data['free_product_id'])) {
|
||||
if ($product = Product::find($data['product_id'])) {
|
||||
$image = "";
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
|
|
@ -92,8 +100,8 @@ class PromotionCart
|
|||
[
|
||||
'image' => $image,
|
||||
'slug' => $product->slug,
|
||||
'weight' => 0,
|
||||
'free_product' => 1,
|
||||
'weight' => $product->weight,
|
||||
'free_product_id' => intval($data['free_product_id']),
|
||||
'product_id' => $product->id
|
||||
]);
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class Yard extends Cart
|
|||
private $yard_margin;
|
||||
|
||||
private $global_tax_rate = 0;
|
||||
private $shipping_option; //pick_up//dhl_shipping
|
||||
|
||||
public function __construct(SessionManager $session, Dispatcher $events)
|
||||
{
|
||||
|
|
@ -53,42 +54,33 @@ class Yard extends Cart
|
|||
if($this->getYardExtra('shipping_price')){
|
||||
$this->shipping_price = (float) ($this->getYardExtra('shipping_price'));
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_price_net')){
|
||||
$this->shipping_price_net = (float) ($this->getYardExtra('shipping_price_net'));
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_tax_rate')){
|
||||
$this->shipping_tax_rate = (float) ($this->getYardExtra('shipping_tax_rate'));
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_tax')){
|
||||
$this->shipping_tax = (float) ($this->getYardExtra('shipping_tax'));
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_country_id')){
|
||||
$this->shipping_country_id = $this->getYardExtra('shipping_country_id');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shipping_is_for')){
|
||||
$this->shipping_is_for = $this->getYardExtra('shipping_is_for');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('shopping_user')){
|
||||
$this->user = $this->getYardExtra('shopping_user');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('user')){
|
||||
$this->user = $this->getYardExtra('user');
|
||||
}
|
||||
if($this->getYardExtra('payment_credit')){
|
||||
$this->payment_credit = $this->getYardExtra('payment_credit');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('yard_commission')){
|
||||
$this->yard_commission = $this->getYardExtra('yard_commission');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('yard_margin')){
|
||||
$this->yard_margin = $this->getYardExtra('yard_margin');
|
||||
}
|
||||
|
|
@ -97,10 +89,12 @@ class Yard extends Cart
|
|||
}else{
|
||||
$this->global_tax_rate = config('cart.tax');
|
||||
}
|
||||
|
||||
if($this->getYardExtra('num_comp')){
|
||||
$this->num_comp = $this->getYardExtra('num_comp');
|
||||
}
|
||||
if($this->getYardExtra('shipping_option')){
|
||||
$this->shipping_option = $this->getYardExtra('shipping_option');
|
||||
}
|
||||
|
||||
|
||||
parent::__construct($session, $events);
|
||||
|
|
@ -123,10 +117,31 @@ class Yard extends Cart
|
|||
}
|
||||
|
||||
public function setGlobalTaxRate($value){
|
||||
|
||||
$this->global_tax_rate = floatval($value);
|
||||
$this->putYardExtra('global_tax_rate', $this->global_tax_rate);
|
||||
}
|
||||
|
||||
public function setShippingOption($value){
|
||||
$this->shipping_option = $value;
|
||||
$this->putYardExtra('shipping_option', $this->shipping_option);
|
||||
}
|
||||
|
||||
public function getShippingOption(){
|
||||
return $this->shipping_option;
|
||||
}
|
||||
|
||||
public function isQuickShipping(){
|
||||
if($this->shipping_option === 'pick_up' && $this->totalWithShipping(2, '.', '') == 0.00){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isWithPayments(){
|
||||
if($this->totalWithShipping(2, '.', '') == 0.00){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function putYardExtra($key, $value){
|
||||
|
|
@ -272,7 +287,6 @@ class Yard extends Cart
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
$margin->setCommission($this->yard_commission);
|
||||
$margin->calculate();
|
||||
|
||||
|
|
@ -318,6 +332,15 @@ class Yard extends Cart
|
|||
|
||||
private function calculateShippingPrice(){
|
||||
|
||||
if($this->shipping_option && $this->shipping_option === 'pick_up'){
|
||||
$this->shipping_price = 0;
|
||||
$this->shipping_tax_rate = 0;
|
||||
$this->shipping_price_net = 0;
|
||||
$this->shipping_tax = 0;
|
||||
$this->putShippingPrices();
|
||||
return;
|
||||
}
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if(!$shippingCountry){
|
||||
return;
|
||||
|
|
@ -346,7 +369,6 @@ class Yard extends Cart
|
|||
}
|
||||
//default
|
||||
if(!$shipping_price){
|
||||
|
||||
$shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first();
|
||||
}
|
||||
}
|
||||
|
|
@ -368,14 +390,18 @@ class Yard extends Cart
|
|||
$this->shipping_price_net = round($price / ((100+$shipping_price->tax_rate) / 100), 2);
|
||||
$this->shipping_tax = round($price / (100+$shipping_price->tax_rate) * 100, 2);
|
||||
|
||||
$this->putYardExtra('num_comp', $this->num_comp);
|
||||
$this->putYardExtra('shipping_price', $this->shipping_price);
|
||||
$this->putYardExtra('shipping_tax_rate', $this->shipping_tax_rate);
|
||||
$this->putYardExtra('shipping_tax', $this->shipping_tax);
|
||||
$this->putYardExtra('shipping_price_net', $this->shipping_price_net);
|
||||
$this->putShippingPrices();
|
||||
}
|
||||
}
|
||||
|
||||
private function putShippingPrices(){
|
||||
$this->putYardExtra('num_comp', $this->num_comp);
|
||||
$this->putYardExtra('shipping_price', $this->shipping_price);
|
||||
$this->putYardExtra('shipping_tax_rate', $this->shipping_tax_rate);
|
||||
$this->putYardExtra('shipping_tax', $this->shipping_tax);
|
||||
$this->putYardExtra('shipping_price_net', $this->shipping_price_net);
|
||||
}
|
||||
|
||||
private function shippingPriceBySubTotal($prices, $total){
|
||||
foreach ($prices as $price){
|
||||
if($price->total_from > 0 && $price->total_to > 0){
|
||||
|
|
@ -386,6 +412,7 @@ class Yard extends Cart
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function shippingPriceByWeight($prices, $weight){
|
||||
foreach ($prices as $price){
|
||||
if($price->weight_from > 0 && $price->weight_to > 0){
|
||||
|
|
@ -686,8 +713,8 @@ class Yard extends Cart
|
|||
|
||||
public function getFreeProductId(){
|
||||
foreach ($this->content() as $row) {
|
||||
if($row->options->free_product) {
|
||||
return $row->options->product_id;
|
||||
if($row->options->free_product_id) {
|
||||
return $row->options->free_product_id;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -699,6 +726,8 @@ class Yard extends Cart
|
|||
foreach ($this->content() as $row) {
|
||||
if($row->options->comp){
|
||||
$comp[100+$row->options->comp] = $row;
|
||||
}elseif($row->options->free_product_id){
|
||||
$comp[200] = $row;
|
||||
}else{
|
||||
$ret[] = $row;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue