Gutschriften

This commit is contained in:
Kevin Adametz 2021-04-23 14:52:25 +02:00
parent 35ae3da244
commit 6ac9fcc4d2
20 changed files with 510 additions and 63 deletions

View file

@ -6,6 +6,7 @@ use App\Mail\MailCheckout;
use App\Models\Setting;
use App\Models\ShoppingOrder;
use App\Models\ShoppingPayment;
use App\Models\UserPayCredit;
use App\User;
use Illuminate\Support\Facades\Mail;
@ -91,7 +92,22 @@ class Payment
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_payment->txaction).'">'.self::getFormattedTxaction($shopping_payment->txaction).'</span>';
}
public static function addUserPayCredits(User $user, $credit, $status, $message, $shopping_order_id = null){
$new_credit_total = $user->payment_credit;
UserPayCredit::create([
'user_id' => $user->id,
'credit' => $credit,
'old_credit_total' => $user->payment_credit,
'new_credit_total' => $user->payment_credit + $credit,
'message' => $message,
'status' => $status,
'shopping_order_id' => $shopping_order_id,
]);
$user->payment_credit = $user->payment_credit + $credit;
$user->save();
}
public static function paymentStatusPaidAction(ShoppingOrder $shopping_order, $paid){
$send_link = false;
@ -119,8 +135,10 @@ class Payment
// $user->payment_order_id = $shopping_order_item->product->id; //34
$user->payment_account = $date;
$user->wizard = 100;
$user->payment_credit = $shopping_order_item->product->price;
$user->save();
self::addUserPayCredits($user, $shopping_order_item->product->price, 1, 'payment_for_account');
$shopping_order->setUserHistoryValue(['status' => 9]);
}
/*if($shopping_order_item->product->getActionName($do) === 'payment_for_shop'){
$user->payment_order_id = $shopping_order_item->product->id; //35
@ -140,7 +158,7 @@ class Payment
$user->m_level = $shopping_order_item->product->upgrade_to_id;
}
}*/
$user->save();
//$user->save();
}
}
}
@ -154,10 +172,8 @@ class Payment
$shopping_order->shopping_order_margin->save();
//is payment credit, reduce
if($shopping_order->shopping_order_margin->from_payment_credit > 0){
$new_credit = $shopping_order->auth_user->payment_credit - $shopping_order->shopping_order_margin->from_payment_credit;
$new_credit = $new_credit < 0 ? 0 : $new_credit;
$shopping_order->auth_user->payment_credit = $new_credit;
$shopping_order->auth_user->save();
$credit = $shopping_order->shopping_order_margin->from_payment_credit * -1;
self::addUserPayCredits($shopping_order->auth_user, $credit, 2, 'user_order_deduction');
}
}