223 lines
9.2 KiB
PHP
223 lines
9.2 KiB
PHP
<?php
|
|
namespace App\Services;
|
|
|
|
|
|
use App\User;
|
|
use App\Models\UserLevel;
|
|
use App\Mail\MailCheckout;
|
|
use App\Models\ProductBuying;
|
|
use App\Models\ShoppingOrder;
|
|
use App\Models\UserCreditItem;
|
|
use App\Models\ShoppingPayment;
|
|
use App\Services\ShopApiOrderCart;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use App\Repositories\InvoiceRepository;
|
|
|
|
class Payment
|
|
{
|
|
|
|
public static $txaction_text = [
|
|
'paid' => "bezahlt",
|
|
'appointed' => "offen",
|
|
'failed' => "abbruch",
|
|
'extern' => "offen", //offen
|
|
'extern_paid' => "bezahlt",
|
|
'invoice_open' => "offen",
|
|
'invoice_paid' => "bezahlt",
|
|
'invoice_non' => "keine Zahlung",
|
|
'NULL' => 'keine Zahlung',
|
|
];
|
|
|
|
public static $txaction_filter_text = [
|
|
'paid' => "Zahlung bezahlt",
|
|
'appointed' => "Zahlung offen",
|
|
'failed' => "Zahlung abbruch",
|
|
'extern' => "Extern offen", //offen
|
|
'extern_paid' => "Extern bezahlt",
|
|
'invoice_open' => "Rechnung offen",
|
|
'invoice_paid' => "Rechnung bezahlt",
|
|
'invoice_non' => "Rechnung keine Zahlung",
|
|
'NULL' => 'keine Zahlung',
|
|
];
|
|
|
|
public static $txaction_invoice = [
|
|
'invoice_open' => "Rechnung offen",
|
|
'invoice_paid' => "Rechnung bezahlt",
|
|
'invoice_non' => 'keine Zahlung',
|
|
];
|
|
|
|
public static $txaction_color = [
|
|
'paid' => "success",
|
|
'appointed' => "warning",
|
|
'failed' => "danger",
|
|
'extern' => "warning",
|
|
'extern_paid' => "success",
|
|
'invoice_open' => "warning",
|
|
'invoice_paid' => "success",
|
|
'invoice_non' => "failed",
|
|
];
|
|
|
|
|
|
public static function getFormattedTxaction($txaction){
|
|
if($txaction && isset(self::$txaction_text[$txaction])){
|
|
return self::$txaction_text[$txaction];
|
|
}
|
|
return self::$txaction_text['NULL'];
|
|
}
|
|
|
|
public static function getFormattedTxactionColor($txaction){
|
|
if($txaction && isset(self::$txaction_color[$txaction])){
|
|
return self::$txaction_color[$txaction];
|
|
}
|
|
return "warning";
|
|
}
|
|
|
|
public static function getShoppingOrderBadge(ShoppingOrder $shopping_order){
|
|
if($shopping_order->mode === 'test'){
|
|
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_order->mode).' - '.self::getFormattedTxaction($shopping_order->txaction).'</span>';
|
|
}
|
|
if($shopping_order->mode === 'dev'){
|
|
return '<span class="badge badge-pill badge-info">'.strtoupper($shopping_order->mode).' - '.self::getFormattedTxaction($shopping_order->txaction).'</span>';
|
|
}
|
|
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_order->txaction).'">'.self::getFormattedTxaction($shopping_order->txaction).'</span>';
|
|
}
|
|
|
|
public static function getShoppingPaymentBadge(ShoppingPayment $shopping_payment){
|
|
if($shopping_payment->mode === 'test'){
|
|
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_payment->mode).' - '.self::getFormattedTxaction($shopping_payment->txaction).'</span>';
|
|
}
|
|
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_payment->txaction).'">'.self::getFormattedTxaction($shopping_payment->txaction).'</span>';
|
|
}
|
|
|
|
public static function addUserCreditMargin(User $user, $credit, $status, $message){
|
|
UserCreditItem::create([
|
|
'user_id' => $user->id,
|
|
'credit' => $credit,
|
|
'message' => $message,
|
|
'status' => $status,
|
|
]);
|
|
}
|
|
|
|
public static function addBuyingRestriction(User $user, $product_id){
|
|
ProductBuying::create([
|
|
'user_id' => $user->id,
|
|
'product_id' => $product_id,
|
|
'amount' => 1
|
|
]);
|
|
}
|
|
|
|
public static function updateUserLevel(User $user, $to_level_id){
|
|
//nur updaten, wenn der user->m_level kleiner ist als $to_level_id
|
|
if($user->user_level){
|
|
$ToUserLevel = UserLevel::find($to_level_id);
|
|
if($user->user_level->pos < $ToUserLevel->pos){
|
|
$user->m_level = $to_level_id;
|
|
}
|
|
}else{
|
|
$user->m_level = $to_level_id;
|
|
}
|
|
$user->save();
|
|
}
|
|
/*
|
|
Wir bei Zahlung aufgerufen.
|
|
Betätigung durch Payone oder Zahlung auf MIVITA Rechnung
|
|
$paid = Status der Zahlung, Payone = true, MIVITA Rechnung = false damit kann später die rechnung auf bezahlt gesetzt werden.
|
|
*/
|
|
|
|
public static function paymentStatusPaidAction(ShoppingOrder $shopping_order, $paid){
|
|
$send_link = false;
|
|
$shopping_order->setUserHistoryValue(['status' => 8]);
|
|
Shop::userOrders();
|
|
$shopping_order->paid = $paid;
|
|
$shopping_order->save();
|
|
|
|
//if product has actions
|
|
if($shopping_order->shopping_order_items && $shopping_order->auth_user_id){
|
|
foreach($shopping_order->shopping_order_items as $shopping_order_item){
|
|
if($shopping_order_item->product){
|
|
$user = User::findOrFail($shopping_order->auth_user_id);
|
|
$user->save();
|
|
if($shopping_order_item->product->buying_restriction){
|
|
self::addBuyingRestriction($user, $shopping_order_item->product->id);
|
|
}
|
|
if($shopping_order_item->product->action){
|
|
$send_link = true;
|
|
//new date
|
|
$date = \Carbon::now()->modify('1 year');
|
|
if($user->payment_account && $user->daysActiveAccount()>0){
|
|
$date = \Carbon::parse($user->payment_account)->modify('1 year');
|
|
}
|
|
foreach ($shopping_order_item->product->action as $do){
|
|
if($shopping_order_item->product->getActionName($do) === 'payment_for_account'){
|
|
$user->payment_order_id = $shopping_order_item->product->id; //34
|
|
$user->payment_account = $date;
|
|
$user->wizard = 100;
|
|
$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
|
|
$user->payment_shop = $date;
|
|
$user->wizard = 100;
|
|
$shopping_order->setUserHistoryValue(['status' => 9]);
|
|
}
|
|
if($shopping_order_item->product->getActionName($do) === 'payment_for_shop_upgrade'){
|
|
if($shopping_order_item->product->upgrade_to_id){
|
|
$user->payment_order_id = $shopping_order_item->product->upgrade_to_id;
|
|
}
|
|
$user->payment_shop = $user->payment_account; //same Date, is upgrade
|
|
$shopping_order->setUserHistoryValue(['status' => 9]);
|
|
}
|
|
if($shopping_order_item->product->getActionName($do) === 'payment_for_lead_upgrade'){
|
|
if($shopping_order_item->product->upgrade_to_id){
|
|
self::updateUserLevel($user, $shopping_order_item->product->upgrade_to_id);
|
|
}
|
|
}
|
|
$user->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
if($shopping_order->homeparty){
|
|
$shopping_order->setUserHistoryValue(['status' => 9]);
|
|
$shopping_order->homeparty->completed = 1;
|
|
$shopping_order->homeparty->save();
|
|
}
|
|
|
|
if($shopping_order->shopping_collect_order){
|
|
$shopping_order->setUserHistoryValue(['status' => 9]);
|
|
ShopApiOrderCart::finishOrder($shopping_order->shopping_collect_order);
|
|
}
|
|
|
|
//make Invoice and
|
|
|
|
$invoice_repo = new InvoiceRepository($shopping_order);
|
|
if(!$shopping_order->isInvoice()){
|
|
$invoice_repo->createAndSalesVolume();
|
|
}
|
|
return $send_link;
|
|
}
|
|
|
|
public static function paymentStatusSendMail(ShoppingOrder $shopping_order, $shopping_payment, $data){
|
|
$bcc = [];
|
|
$billing_email = $shopping_order->shopping_user->billing_email;
|
|
if(!$billing_email){
|
|
if($data['mode'] === 'test'){
|
|
$billing_email = config('app.checkout_test_mail');
|
|
}else{
|
|
$billing_email = config('app.checkout_mail');
|
|
}
|
|
}
|
|
if($data['mode'] === 'test'){
|
|
$bcc[] = config('app.checkout_test_mail');
|
|
}else{
|
|
$bcc[] = config('app.checkout_mail');
|
|
}
|
|
|
|
if(!$shopping_order->shopping_user->is_like && $shopping_order->shopping_user->member){
|
|
$bcc[] = $shopping_order->shopping_user->member->email;
|
|
}
|
|
Mail::to($billing_email)->bcc($bcc)->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment, $data['send_link'], $data['mode']));
|
|
}
|
|
}
|