promotion 1.0
This commit is contained in:
parent
1cc8e025a1
commit
570d428b1c
60 changed files with 1596 additions and 272 deletions
|
|
@ -265,7 +265,7 @@ class ShoppingUserController extends Controller
|
|||
$shopping_user = ShoppingUser::create($data);
|
||||
|
||||
//Kundenhoheit prüfen
|
||||
$priority = CustomerPriority::checkOne($shopping_user, true, false);
|
||||
$priority = CustomerPriority::checkOne($shopping_user, true, false, true);
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
//exists //like //update
|
||||
$user = $this->prepareForShow($shopping_user);
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ class PayController extends Controller
|
|||
|
||||
private $reference;
|
||||
|
||||
private $payment_method;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
|
@ -77,6 +79,7 @@ class PayController extends Controller
|
|||
public function setPrePayment($payment_method, $amount, $currency, $ret = []){
|
||||
|
||||
$this->reference = $this->shopping_order->created_at->format('Ym').$this->shopping_order->id;//substr(uniqid('m', false), 0, 16);
|
||||
$this->payment_method = $payment_method;
|
||||
$this->setMethod($payment_method, $ret);
|
||||
|
||||
$this->prepayment = [
|
||||
|
|
@ -86,7 +89,6 @@ class PayController extends Controller
|
|||
"param" => $this->shopping_order->id,
|
||||
|
||||
];
|
||||
|
||||
$this->shopping_payment = ShoppingPayment::create([
|
||||
'shopping_order_id' => $this->shopping_order->id,
|
||||
'clearingtype' => $this->method["clearingtype"],
|
||||
|
|
@ -119,6 +121,15 @@ class PayController extends Controller
|
|||
private function setMethod($payment_method, $ret = []){
|
||||
|
||||
//vorkasse
|
||||
if($payment_method === 'non'){
|
||||
$this->method = [
|
||||
"clearingtype" => "non",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "authorization",
|
||||
];
|
||||
}
|
||||
|
||||
if($payment_method === 'vor'){
|
||||
$this->method = [
|
||||
"clearingtype" => "vor",
|
||||
|
|
@ -138,12 +149,21 @@ class PayController extends Controller
|
|||
];
|
||||
}
|
||||
|
||||
//Rechnungskauf
|
||||
if($payment_method === 'pp'){
|
||||
$this->method = [
|
||||
"clearingtype" => "pp",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "CAPTURE",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function ResponseData($identifier){
|
||||
public function ResponseData($identifier, $payment_for = false){
|
||||
|
||||
$request = array_merge($this->default, $this->personalData, $this->deliveryData, $this->method, $this->prepayment, $this->urls);
|
||||
//RECHNUNG MIV
|
||||
|
||||
$payt = PaymentTransaction::create([
|
||||
'shopping_payment_id' => $this->shopping_payment->id,
|
||||
|
|
@ -155,10 +175,26 @@ class PayController extends Controller
|
|||
'txaction' => 'prev',
|
||||
'mode' => $this->shopping_payment->mode,
|
||||
]);
|
||||
//paypal
|
||||
if($this->payment_method === 'pp'){
|
||||
$paypal = new PayPalController;
|
||||
$redirect = $paypal->payment($this->shopping_payment, $payt, $identifier, $this->shopping_order->promotion_user_id);
|
||||
Util::setUserHistoryValue(['status'=>4], $identifier);
|
||||
return $redirect;
|
||||
|
||||
}
|
||||
|
||||
Util::setUserHistoryValue(['status'=>5], $identifier);
|
||||
return redirect(route('user_checkout_final', [$payt->id, $this->reference, $identifier]));
|
||||
switch ($payment_for) {
|
||||
case 4: //promotion
|
||||
return redirect(route('web_promotion_goto', ['thanksorder', $this->shopping_order->promotion_user_id, $payt->id, $this->reference, $identifier]));
|
||||
break;
|
||||
|
||||
default:
|
||||
return redirect(route('user_checkout_final', [$payt->id, $this->reference, $identifier]));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
95
app/Http/Controllers/Pay/PayPalController.php
Normal file
95
app/Http/Controllers/Pay/PayPalController.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Pay;
|
||||
use Request;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Srmklive\PayPal\Services\PayPal as PayPalClient;
|
||||
|
||||
|
||||
class PayPalController extends Controller
|
||||
{
|
||||
|
||||
public function payment($shopping_payment, $payt, $identifier, $promotion_user_id)
|
||||
{
|
||||
$provider = new PayPalClient;
|
||||
// Through facade. No need to import namespaces
|
||||
|
||||
$provider = \PayPal::setProvider();
|
||||
$provider->setApiCredentials(config('paypal'));
|
||||
$provider->setAccessToken($provider->getAccessToken());
|
||||
$provider->setCurrency('EUR');
|
||||
|
||||
$order = $provider->createOrder([
|
||||
"intent"=> "CAPTURE",
|
||||
"purchase_units"=> [
|
||||
[
|
||||
"reference_id" => $shopping_payment->reference,
|
||||
"shopping_order_id" => $shopping_payment->shopping_order_id,
|
||||
"amount"=> [
|
||||
"currency_code"=> "USD",
|
||||
"value"=> ($shopping_payment->amount / 100)
|
||||
],
|
||||
'description' => 'test'
|
||||
]
|
||||
],
|
||||
'application_context' => [
|
||||
'cancel_url' => route('cancel.paypal_payment', [$promotion_user_id, $payt->id, $shopping_payment->reference, $identifier]),
|
||||
'return_url' => route('success.paypal_payment', [$promotion_user_id, $payt->id, $shopping_payment->reference, $identifier])
|
||||
]
|
||||
|
||||
]);
|
||||
$payt->key = $order['id'];
|
||||
$payt->save();
|
||||
return redirect($order['links'][1]['href'])->send();
|
||||
|
||||
}
|
||||
|
||||
public function paymentSuccess($id, $transactionId=false, $reference=false, $identifier=false)
|
||||
{
|
||||
$PromotionUser = PromotionUser::findOrFail($id);
|
||||
$payt = PaymentTransaction::findOrFail($transactionId);
|
||||
if($payt->shopping_payment->reference != $reference){
|
||||
abort(404);
|
||||
}
|
||||
// Init PayPal
|
||||
$provider = \PayPal::setProvider();
|
||||
$provider->setApiCredentials(config('paypal'));
|
||||
$provider->setAccessToken($provider->getAccessToken());
|
||||
|
||||
// Get PaymentOrder using our transaction ID
|
||||
$order = $provider->capturePaymentOrder($payt->key);
|
||||
if(isset($order['type'])){
|
||||
abort(403, 'PayPal Type: '.$order['type']);
|
||||
}
|
||||
|
||||
if(!isset($order['status']) || $order['status'] !== "COMPLETED"){
|
||||
abort(403, 'Error: Order Status ');
|
||||
}
|
||||
|
||||
if(Request::get('token') !== $payt->key){
|
||||
abort(403, 'Error: PayPal token');
|
||||
}
|
||||
$payt->request = $order['status'];
|
||||
$payt->save();
|
||||
return redirect(route('web_promotion_goto', ['thanksorder', $id, $payt->id, $reference, $identifier]));
|
||||
|
||||
}
|
||||
|
||||
public function paymentCancel($id, $transactionId=false, $reference=false, $identifier=false)
|
||||
{
|
||||
$PromotionUser = PromotionUser::findOrFail($id);
|
||||
|
||||
return redirect(url($PromotionUser->url));
|
||||
dd('Your payment has been declend. The payment cancelation page goes here!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -224,8 +224,8 @@ class SalesController extends Controller
|
|||
if($ShoppingOrder->shopping_user->is_for === 'ot'){
|
||||
return '<span class="badge badge-pill badge-info">Kundenbestellung</span>';
|
||||
}
|
||||
if($ShoppingOrder->shopping_user->is_for === 'hp'){
|
||||
return '<span class="badge badge-pill badge-dark">Homepartybestellung</span>';
|
||||
if($ShoppingOrder->shopping_user->is_for === 'pr'){
|
||||
return '<span class="badge badge-pill badge-dark">Promotion</span>';
|
||||
}
|
||||
return '-';
|
||||
})
|
||||
|
|
@ -249,6 +249,7 @@ class SalesController extends Controller
|
|||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('is_for', 'is_for $1')
|
||||
->orderColumn('member_id', 'member_id $1')
|
||||
->orderColumn('shipped', 'shipped $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
|
|
|
|||
|
|
@ -106,7 +106,6 @@ class CheckoutController extends Controller
|
|||
$shopping_user->billing_state = Shop::getCountryShippingCountryId($shopping_user->billing_country_id);
|
||||
$shopping_user->shipping_state = Shop::getCountryShippingCountryId($shopping_user->shipping_country_id);
|
||||
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; //reinvert
|
||||
|
||||
}
|
||||
if($shopping_user->same_as_billing === NULL){
|
||||
$shopping_user->same_as_billing = false;
|
||||
|
|
@ -518,6 +517,7 @@ class CheckoutController extends Controller
|
|||
$this->putPayments('shopping_order_margin_id', $shopping_order_margin->id);
|
||||
}
|
||||
}
|
||||
|
||||
private function putPayments($key, $value){
|
||||
$content = $this->getContent();
|
||||
$content->put($key, $value);
|
||||
|
|
@ -581,8 +581,6 @@ class CheckoutController extends Controller
|
|||
];
|
||||
Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -45,10 +45,12 @@ class PaymentController extends Controller
|
|||
->addColumn('message', function (UserPayCredit $user_pay_credit) {
|
||||
if($user_pay_credit->status === 3){
|
||||
return nl2br($user_pay_credit->message);
|
||||
}elseif($user_pay_credit->status === 5 || $user_pay_credit->status === 6){
|
||||
return trans('payment.'.$user_pay_credit->message).
|
||||
' <a class="btn btn-outline-secondary btn-xs" href="'.route('user_sales_order_detail', [$user_pay_credit->shopping_order_id]).'"><i class="ion ion-md-eye"></i></a>';
|
||||
}else{
|
||||
return trans('payment.'.$user_pay_credit->message).
|
||||
' <a class="btn btn-outline-secondary btn-xs" href="'.route('user_order_detail', [$user_pay_credit->shopping_order_id]).'"><i class="ion ion-md-eye"></i></a>';
|
||||
|
||||
}
|
||||
})
|
||||
->addColumn('credit', function (UserPayCredit $user_pay_credit) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,10 @@ class PromotionController extends Controller
|
|||
if($user_promotion->user_id != Auth::user()->id){
|
||||
abort(404);
|
||||
}
|
||||
$user_promotion->about_you = !$user_promotion->about_you ? $user_promotion->user->account->about_you : $user_promotion->about_you;
|
||||
|
||||
$user_promotion->description = $user_promotion->description ? $user_promotion->description : $user_promotion->promotion_admin->user_description;
|
||||
$about_you = $user_promotion->user->account->about_you ?$user_promotion->user->account->about_you : $user_promotion->promotion_admin->user_about;
|
||||
$user_promotion->about_you = $user_promotion->about_you ? $user_promotion->about_you : $about_you;
|
||||
$data = [
|
||||
'checkPaymentCredit' => $user_promotion->checkPaymentCredit(),
|
||||
'user_promotion_cart' => PromotionUser::preCalculateCart($user_promotion, 'user_promotion'),
|
||||
|
|
@ -66,7 +69,6 @@ class PromotionController extends Controller
|
|||
return redirect(route('user_promotion_detail', [$id]))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$model = $this->promoRepo->update($id, Request::all());
|
||||
|
||||
}
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect(route('user_promotion_detail', [$model->id]));
|
||||
|
|
|
|||
84
app/Http/Controllers/User/SalesController.php
Executable file
84
app/Http/Controllers/User/SalesController.php
Executable file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\Payment;
|
||||
use App\User;
|
||||
|
||||
|
||||
class SalesController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
$data = [
|
||||
];
|
||||
return view('user.sales.orders', $data);
|
||||
}
|
||||
|
||||
public function orderDetail($id)
|
||||
{
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
if($shopping_order->member_id !== $user->id){
|
||||
abort(404);
|
||||
}
|
||||
$data = [
|
||||
'shopping_order' => $shopping_order,
|
||||
'isAdmin' => false,
|
||||
];
|
||||
return view('user.sales.order_detail', $data);
|
||||
}
|
||||
|
||||
public function ordersDatatable(){
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')->where('shopping_orders.member_id', $user->id);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<a href="' . route('user_sales_order_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->created_at->format("d.m.Y");
|
||||
})
|
||||
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getFormattedTotalShipping();
|
||||
})
|
||||
->addColumn('orders', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->orders : '';
|
||||
})
|
||||
->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
|
||||
})
|
||||
->addColumn('is_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
if($ShoppingOrder->shopping_user->is_for === 'me'){
|
||||
return '<span class="badge badge-pill badge-secondary">Vertriebspartnerbestellung</span>';
|
||||
}
|
||||
if($ShoppingOrder->shopping_user->is_for === 'ot'){
|
||||
return '<span class="badge badge-pill badge-info">Kundenbestellung</span>';
|
||||
}
|
||||
if($ShoppingOrder->shopping_user->is_for === 'pr'){
|
||||
return '<span class="badge badge-pill badge-dark">Promotion</span>';
|
||||
}
|
||||
return '-';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->rawColumns(['id', 'is_for', 'txaction', 'user_shop_id'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ use App\Services\Payment;
|
|||
use App\User;
|
||||
|
||||
|
||||
class ShopSalesController extends Controller
|
||||
class SalesController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
|
|
|
|||
|
|
@ -2,16 +2,22 @@
|
|||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use Yard;
|
||||
use Request;
|
||||
use Response;
|
||||
use Validator;
|
||||
use App\Services\Util;
|
||||
use App\Models\Product;
|
||||
use App\Models\UserHistory;
|
||||
use App\Models\PaymentMethod;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Services\PromotionCart;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\CheckoutRepository;
|
||||
use App\Services\Payment;
|
||||
|
||||
class PromotionController extends Controller
|
||||
{
|
||||
|
|
@ -47,9 +53,8 @@ class PromotionController extends Controller
|
|||
return view('web.promotion.index', $data);
|
||||
}
|
||||
|
||||
public function goto($load, $id){
|
||||
public function goto($load, $id, $transactionId=false, $reference=false, $identifier=false){
|
||||
$PromotionUser = PromotionUser::findOrFail($id);
|
||||
|
||||
$data = [
|
||||
'promotion_user' => $PromotionUser,
|
||||
];
|
||||
|
|
@ -57,15 +62,29 @@ class PromotionController extends Controller
|
|||
if($load === 'thanksreminder'){
|
||||
return view('web.promotion.thanksreminder', $data);
|
||||
}
|
||||
if($load === 'thanksorder'){
|
||||
return view('web.promotion.thanksorder', $data);
|
||||
}
|
||||
if($load === 'notactive'){
|
||||
return view('web.promotion.notactive', $data);
|
||||
}
|
||||
if($load === 'thanksorder'){
|
||||
$payt = PaymentTransaction::findOrFail($transactionId);
|
||||
if($payt->shopping_payment->reference != $reference){
|
||||
abort(404);
|
||||
}
|
||||
Yard::instance('shopping')->destroy();
|
||||
$checkRepo = new CheckoutRepository();
|
||||
$checkRepo->destroy();
|
||||
if(($payt->status === 'fnc' || $payt->status === 'vor' || $payt->status === 'pp' || $payt->status === 'non') && $payt->txaction === 'prev'){
|
||||
$this->directPaymentStatus($payt, $identifier);
|
||||
}
|
||||
$data = [
|
||||
'promotion_user' => $PromotionUser,
|
||||
'order_reference' => $payt->shopping_payment->reference,
|
||||
'pay_trans' => $payt,
|
||||
];
|
||||
return view('web.promotion.thanksorder', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function store($id){
|
||||
|
||||
$PromotionUser = PromotionUser::findOrFail($id);
|
||||
|
|
@ -78,13 +97,106 @@ class PromotionController extends Controller
|
|||
return redirect(route('web_promotion_goto', ['thanksreminder', $PromotionUser->id]));
|
||||
|
||||
}
|
||||
|
||||
if($data['action'] === 'submit-promotion-order'){
|
||||
return redirect(route('web_promotion_goto', ['thanksorder', $PromotionUser->id]));
|
||||
$rules = array(
|
||||
'billing_firstname'=>'required',
|
||||
'billing_lastname'=>'required',
|
||||
'billing_address'=>'required',
|
||||
'billing_zipcode'=>'required',
|
||||
'billing_city' => 'required',
|
||||
'billing_state' => 'required',
|
||||
'billing_email'=>'required|email',
|
||||
);
|
||||
|
||||
if(Request::get('same_as_billing')){
|
||||
$rules = array_merge($rules, [
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required'
|
||||
]);
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$identifier = Util::getToken();
|
||||
$data['is_from'] = 'shopping';
|
||||
$data['is_for'] = 'pr';
|
||||
unset($data['_token']);
|
||||
Yard::instance('shopping')->putYardExtra('shopping_data', $data);
|
||||
|
||||
UserHistory::create(['user_id' => $PromotionUser->user_id, 'action'=>'web_promotion_payment', 'status'=>1, 'product_id'=>null, 'identifier'=>$identifier]);
|
||||
$checkRepo = new CheckoutRepository();
|
||||
$checkRepo->setPromotion(4, $PromotionUser);
|
||||
$checkRepo->init($identifier, $data);
|
||||
return $checkRepo->makePayment();
|
||||
|
||||
//$path = str_replace('http', 'https', $path);
|
||||
//return redirect()->secure($path);
|
||||
// return redirect(route('user_checkout', [$identifier]));
|
||||
|
||||
}
|
||||
|
||||
dd($PromotionUser);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function directPaymentStatus(PaymentTransaction $payt, $identifier){
|
||||
|
||||
if(isset($payt->transmitted_data['param'])){
|
||||
$shopping_order = ShoppingOrder::find($payt->transmitted_data['param']);
|
||||
$shopping_payment = ShoppingPayment::where('reference', $payt->transmitted_data['reference'])->first();
|
||||
|
||||
$shopping_order->txaction = 'open';
|
||||
$shopping_order->save();
|
||||
$payt->txaction = "open";
|
||||
|
||||
//is Promotion Handel it
|
||||
if($shopping_order->promotion_user_id > 0){
|
||||
Payment::handelPromotionProduct($shopping_order);
|
||||
}
|
||||
if($shopping_payment){
|
||||
//Payment::handelUserPayCredits($shopping_order, 'deduction');
|
||||
if($payt->status === 'vor'){
|
||||
$shopping_payment->txaction = 'open';
|
||||
$shopping_order->txaction = 'open';
|
||||
$payt->txaction = "open";
|
||||
}
|
||||
if($payt->status === 'pp'){
|
||||
$send_link = Payment::paymentStatusPaidAction($shopping_order, true);
|
||||
$shopping_payment->txaction = 'paid';
|
||||
$shopping_order->txaction = 'paid';
|
||||
$payt->txaction = "paid";
|
||||
}
|
||||
if($payt->status === 'fnc'){
|
||||
$send_link = Payment::paymentStatusPaidAction($shopping_order, true);
|
||||
$shopping_payment->txaction = 'open';
|
||||
$shopping_order->txaction = 'open';
|
||||
$payt->txaction = "open";
|
||||
}
|
||||
if($payt->status === 'non'){
|
||||
$send_link = Payment::paymentStatusPaidAction($shopping_order, true);
|
||||
$shopping_payment->txaction = 'paid';
|
||||
$shopping_order->txaction = 'paid';
|
||||
$payt->txaction = "paid";
|
||||
$shopping_order->save();
|
||||
\App\Services\Shop::newUserOrder($shopping_order->shopping_user->number);
|
||||
}
|
||||
$shopping_payment->save();
|
||||
}
|
||||
$payt->save();
|
||||
$data = [
|
||||
'mode' => $payt->transmitted_data['mode'],
|
||||
'txaction' => $payt->txaction,
|
||||
'send_link' => false,
|
||||
];
|
||||
Payment::paymentStatusSendMail($shopping_order, $shopping_payment, $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function load(){
|
||||
$data = Request::all();
|
||||
$ret = "";
|
||||
|
|
@ -94,32 +206,36 @@ class PromotionController extends Controller
|
|||
$product = Product::find($data['id']); //current user form order
|
||||
$ret = view("web.promotion.show_product", compact('product', 'data'))->render();
|
||||
}
|
||||
if($data['action'] === 'switch-free-product'){
|
||||
\App\Services\PromotionCart::updateFeeProduct($data);
|
||||
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
|
||||
if($data['perform']){
|
||||
if($data['action'] === 'switch-free-product'){
|
||||
\App\Services\PromotionCart::updateFeeProduct($data);
|
||||
}
|
||||
if($data['action'] === 'add-shop-product'){
|
||||
$data['qty'] = \App\Services\PromotionCart::updateProduct($data, true);
|
||||
}
|
||||
if($data['action'] === 'update-shop-product'){
|
||||
$data['qty'] = \App\Services\PromotionCart::updateProduct($data);
|
||||
}
|
||||
if($data['action'] === 'remove-shop-product'){
|
||||
\App\Services\PromotionCart::updateProduct($data);
|
||||
$data['qty'] = 0;
|
||||
}
|
||||
if($data['action'] === 'clear-cart'){
|
||||
\App\Services\PromotionCart::clearCart($data);
|
||||
}
|
||||
if($data['action'] === 'switch-shipping'){
|
||||
\App\Services\PromotionCart::switchShipping($data);
|
||||
}
|
||||
$cart = view("web.promotion._promotion_cart", compact('data'))->render();
|
||||
if(Yard::instance('shopping')->isQuickShipping()){
|
||||
$invoice = view("web.promotion._invoice_details_quick")->render();
|
||||
}else{
|
||||
$invoice = view("web.promotion._invoice_details")->render();
|
||||
}
|
||||
$checkout = view("web.promotion._checkout")->render();
|
||||
|
||||
return response()->json(['response' => $data, 'cart'=>$cart, 'invoice'=>$invoice, 'checkout'=>$checkout, 'status'=>$status]);
|
||||
}
|
||||
if($data['action'] === 'add-shop-product'){
|
||||
$data['qty'] = \App\Services\PromotionCart::updateProduct($data, true);
|
||||
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
|
||||
}
|
||||
if($data['action'] === 'update-shop-product'){
|
||||
$data['qty'] = \App\Services\PromotionCart::updateProduct($data);
|
||||
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
|
||||
}
|
||||
if($data['action'] === 'remove-shop-product'){
|
||||
\App\Services\PromotionCart::updateProduct($data);
|
||||
$data['qty'] = 0;
|
||||
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
|
||||
}
|
||||
if($data['action'] === 'clear-cart'){
|
||||
\App\Services\PromotionCart::clearCart($data);
|
||||
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
|
||||
}
|
||||
|
||||
if($data['action'] === 'switch-shipping'){
|
||||
$ret = view("web.promotion._promotion_cart", compact('data'))->render();
|
||||
}
|
||||
|
||||
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,11 @@ class MailCheckout extends Mailable
|
|||
$this->mode = $mode;
|
||||
|
||||
if($this->txaction === 'paid'){
|
||||
$this->subject = __('email.checkout_subject_paid')." ";
|
||||
if($this->shopping_payment->clearingtype === 'non')
|
||||
$this->subject = __('email.checkout_subject_non_paid')." ";
|
||||
else{
|
||||
$this->subject = __('email.checkout_subject_paid')." ";
|
||||
}
|
||||
}elseif($this->txaction === 'extern'){
|
||||
$this->subject = __('email.checkout_subject_extern').": ";
|
||||
$this->subject .= $shopping_order->member->account->m_first_name." ".$shopping_order->member->account->m_last_name." - ";
|
||||
|
|
@ -45,7 +49,6 @@ class MailCheckout extends Mailable
|
|||
}*/
|
||||
}
|
||||
|
||||
|
||||
public function build()
|
||||
{
|
||||
$salutation = __('email.hello').",";
|
||||
|
|
@ -82,6 +85,5 @@ class MailCheckout extends Mailable
|
|||
'mode' => $this->mode
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -53,6 +53,10 @@ use Illuminate\Database\Eloquent\Collection;
|
|||
* @property-read int|null $promotion_admin_products_active_count
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereShop($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereType($value)
|
||||
* @property string|null $user_description
|
||||
* @property string|null $user_about
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereUserAbout($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereUserDescription($value)
|
||||
*/
|
||||
class PromotionAdmin extends Model
|
||||
{
|
||||
|
|
@ -77,6 +81,8 @@ class PromotionAdmin extends Model
|
|||
'type',
|
||||
'name',
|
||||
'description',
|
||||
'user_description',
|
||||
'user_about',
|
||||
'from',
|
||||
'to',
|
||||
'shop',
|
||||
|
|
|
|||
126
app/Models/PromotionUserOrder.php
Normal file
126
app/Models/PromotionUserOrder.php
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class PromotionUserOrder
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $promotion_admin_id
|
||||
* @property int $promotion_user_id
|
||||
* @property int $promotion_user_product_id
|
||||
* @property int $product_id
|
||||
* @property int $shopping_order_item_id
|
||||
* @property int $shopping_order_id
|
||||
* @property int $shopping_user_id
|
||||
* @property int|null $qty
|
||||
* @property float|null $price
|
||||
* @property float|null $price_net
|
||||
* @property float|null $tax_rate
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property Product $product
|
||||
* @property PromotionAdmin $promotion_admin
|
||||
* @property PromotionUser $promotion_user
|
||||
* @property PromotionUserProduct $promotion_user_product
|
||||
* @property ShoppingOrder $shopping_order
|
||||
* @property ShoppingOrderItem $shopping_order_item
|
||||
* @property ShoppingUser $shopping_user
|
||||
* @package App\Models
|
||||
* @property int|null $status
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder wherePrice($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder wherePriceNet($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereProductId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder wherePromotionAdminId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder wherePromotionUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder wherePromotionUserProductId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereQty($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereShoppingOrderId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereShoppingOrderItemId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereShoppingUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereStatus($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereTaxRate($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserOrder whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class PromotionUserOrder extends Model
|
||||
{
|
||||
protected $table = 'promotion_user_orders';
|
||||
|
||||
protected $casts = [
|
||||
'promotion_admin_id' => 'int',
|
||||
'promotion_user_id' => 'int',
|
||||
'promotion_user_product_id' => 'int',
|
||||
'product_id' => 'int',
|
||||
'shopping_order_item_id' => 'int',
|
||||
'shopping_order_id' => 'int',
|
||||
'shopping_user_id' => 'int',
|
||||
'qty' => 'int',
|
||||
'price' => 'float',
|
||||
'price_net' => 'float',
|
||||
'tax_rate' => 'float',
|
||||
'status' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'promotion_admin_id',
|
||||
'promotion_user_id',
|
||||
'promotion_user_product_id',
|
||||
'product_id',
|
||||
'shopping_order_item_id',
|
||||
'shopping_order_id',
|
||||
'shopping_user_id',
|
||||
'qty',
|
||||
'price',
|
||||
'price_net',
|
||||
'tax_rate',
|
||||
'status'
|
||||
];
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function promotion_admin()
|
||||
{
|
||||
return $this->belongsTo(PromotionAdmin::class);
|
||||
}
|
||||
|
||||
public function promotion_user()
|
||||
{
|
||||
return $this->belongsTo(PromotionUser::class);
|
||||
}
|
||||
|
||||
public function promotion_user_product()
|
||||
{
|
||||
return $this->belongsTo(PromotionUserProduct::class);
|
||||
}
|
||||
|
||||
public function shopping_order()
|
||||
{
|
||||
return $this->belongsTo(ShoppingOrder::class);
|
||||
}
|
||||
|
||||
public function shopping_order_item()
|
||||
{
|
||||
return $this->belongsTo(ShoppingOrderItem::class);
|
||||
}
|
||||
|
||||
public function shopping_user()
|
||||
{
|
||||
return $this->belongsTo(ShoppingUser::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -41,6 +41,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @property int|null $num_comp
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice whereNumComp($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingPrice wherePriceComp($value)
|
||||
* @property int|null $shipping_for
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShippingPrice whereShippingFor($value)
|
||||
*/
|
||||
class ShippingPrice extends Model
|
||||
{
|
||||
|
|
|
|||
|
|
@ -99,6 +99,11 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereShippedAt($value)
|
||||
* @property string|null $invoice_number
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereInvoiceNumber($value)
|
||||
* @property int|null $promotion_user_id
|
||||
* @property string|null $shipping_option
|
||||
* @property-read \App\Models\PromotionUser|null $promotion_user
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder wherePromotionUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrder whereShippingOption($value)
|
||||
*/
|
||||
class ShoppingOrder extends Model
|
||||
{
|
||||
|
|
@ -110,7 +115,9 @@ class ShoppingOrder extends Model
|
|||
protected $fillable = [
|
||||
'shopping_user_id',
|
||||
'auth_user_id',
|
||||
'promotion_user_id',
|
||||
'member_id',
|
||||
'payment_for',
|
||||
'country_id',
|
||||
'user_shop_id',
|
||||
'total',
|
||||
|
|
@ -135,6 +142,7 @@ class ShoppingOrder extends Model
|
|||
'mode',
|
||||
'shipped',
|
||||
'shipped_at',
|
||||
'shipping_option',
|
||||
'tracking'
|
||||
];
|
||||
|
||||
|
|
@ -152,6 +160,15 @@ class ShoppingOrder extends Model
|
|||
10 => 'storniert'
|
||||
];
|
||||
|
||||
public static $paymentForTypes = [
|
||||
0 => '',
|
||||
1 => 'wizzard',
|
||||
2 => 'user_order me',
|
||||
3 => 'user_order ot',
|
||||
4 => 'Promotion',
|
||||
10 => ''
|
||||
];
|
||||
|
||||
public static $apiShippedTypes = [
|
||||
0 => 'open', //(Fullfilment durch Händler)',
|
||||
1 => 'process', //(Fullfilment durch MIVITA: nicht Versand)
|
||||
|
|
@ -183,6 +200,11 @@ class ShoppingOrder extends Model
|
|||
return $this->belongsTo('App\Models\ShippingCountry','country_id');
|
||||
}
|
||||
|
||||
public function promotion_user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\PromotionUser','promotion_user_id');
|
||||
}
|
||||
|
||||
//can null
|
||||
public function member()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @property float|null $price_net
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem whereComp($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShoppingOrderItem wherePriceNet($value)
|
||||
* @property int|null $free_product_id
|
||||
* @property-read \App\Models\PromotionUserProduct|null $promotion_user_product
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ShoppingOrderItem whereFreeProductId($value)
|
||||
*/
|
||||
class ShoppingOrderItem extends Model
|
||||
{
|
||||
|
|
@ -58,6 +61,7 @@ class ShoppingOrderItem extends Model
|
|||
'row_id',
|
||||
'product_id',
|
||||
'comp',
|
||||
'free_product_id',
|
||||
'qty',
|
||||
'price',
|
||||
'price_net',
|
||||
|
|
@ -97,4 +101,14 @@ class ShoppingOrderItem extends Model
|
|||
return formatNumber($this->attributes['price_net'] * $this->attributes['qty']);
|
||||
}
|
||||
|
||||
public function isFreeProduct()
|
||||
{
|
||||
return $this->free_product_id > 0 ? true : false;
|
||||
}
|
||||
|
||||
public function promotion_user_product()
|
||||
{
|
||||
return $this->belongsTo('App\Models\PromotionUserProduct','free_product_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -88,6 +88,9 @@ class ShoppingPayment extends Model
|
|||
if($this->clearingtype === 'fnc') {
|
||||
return 'Rechnung';
|
||||
}
|
||||
if($this->clearingtype === 'non') {
|
||||
return 'keine';
|
||||
}
|
||||
}
|
||||
|
||||
public function getPaymentAmount(){
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ class UserPayCredit extends Model
|
|||
2 => 'deduction from payment',
|
||||
3 => 'manually added credit',
|
||||
4 => 'return from order',
|
||||
|
||||
5 => 'deduction from promotion',
|
||||
6 => 'return from promotion',
|
||||
];
|
||||
protected $table = 'user_pay_credits';
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||
*/
|
||||
protected function mapApiRoutes()
|
||||
{
|
||||
Route::domain('api.'.config('app.domain'))
|
||||
Route::domain('api.'.config('app.api_domain'))
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
|
|
|
|||
226
app/Repositories/CheckoutRepository.php
Normal file
226
app/Repositories/CheckoutRepository.php
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Yard;
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Services\CustomerPriority;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use App\Http\Controllers\Pay\PayController;
|
||||
|
||||
|
||||
|
||||
class CheckoutRepository {
|
||||
|
||||
private $payment_for;
|
||||
private $PromotionUser;
|
||||
private $session;
|
||||
private $instance;
|
||||
private $shopping_user;
|
||||
private $shopping_order;
|
||||
private $identifier;
|
||||
private $data;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->session = app(SessionManager::class);;
|
||||
$this->instance = sprintf('%s.%s', 'cart', 'payments');
|
||||
}
|
||||
|
||||
public function setPromotion($payment_for, PromotionUser $PromotionUser)
|
||||
{
|
||||
$this->payment_for = $payment_for;
|
||||
$this->PromotionUser = $PromotionUser;
|
||||
}
|
||||
|
||||
public function init($identifier, $data)
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
$this->data = $data;
|
||||
if($this->getPayments('identifier') !== $identifier){
|
||||
$this->destroy();
|
||||
$this->putPayments('identifier', $identifier);
|
||||
}
|
||||
|
||||
$shopping_data = Yard::instance('shopping')->getYardExtra('shopping_data');
|
||||
$this->data['is_from'] = isset($shopping_data['is_from']) ? $shopping_data['is_from'] : 'shopping'; //shopping
|
||||
$this->data['is_from'] = isset($shopping_data['is_for']) ? $shopping_data['is_for'] : 'pr'; //promotion
|
||||
|
||||
$this->shopping_user = $this->makeShoppingUser($data);
|
||||
$this->shopping_order = $this->makeShoppingOrder($this->shopping_user);
|
||||
|
||||
//CustomerPriority
|
||||
if($this->shopping_user->is_from === 'shopping'){
|
||||
CustomerPriority::checkOne(ShoppingUser::find($this->shopping_user->id), true);
|
||||
}
|
||||
Util::setUserHistoryValue(['status'=>2, 'shopping_order_id'=>$this->shopping_order->id], $this->identifier);
|
||||
|
||||
}
|
||||
|
||||
public function makePayment()
|
||||
{
|
||||
//check credi t Card
|
||||
if(!isset($this->data['payment_method'])){
|
||||
$this->data['payment_method'] = 'non';
|
||||
}
|
||||
$ret = [];
|
||||
//Rechnungskauf ohne PAYONE
|
||||
if($this->data['payment_method'] === 'fnc#MIV'){
|
||||
|
||||
}
|
||||
if($this->data['payment_method'] === 'pp'){
|
||||
|
||||
}
|
||||
//other
|
||||
$pay = new PayController();
|
||||
$pay->init($this->shopping_user, $this->shopping_order);
|
||||
$amount = Yard::instance('shopping')->totalWithShipping(2, '.', '') * 100;
|
||||
$reference = $pay->setPrePayment($this->data['payment_method'], $amount, 'EUR', $ret);
|
||||
$this->putPayments('payment_reference', $reference);
|
||||
$pay->setPersonalData();
|
||||
return $pay->ResponseData($this->identifier, $this->payment_for);
|
||||
}
|
||||
|
||||
|
||||
private function makeShoppingUser($data){
|
||||
$data['same_as_billing'] = isset($data['same_as_billing']) ? false : true; //reinvert
|
||||
$data['accepted_data'] = isset($data['accepted_data']) ? true : false;
|
||||
$data['billing_country_id'] = Shop::getShippingCountryCountryId($data['billing_state']);
|
||||
$data['shipping_country_id'] = $data['billing_country_id'];
|
||||
$data['member_id'] = $this->PromotionUser->user_id;
|
||||
|
||||
if(isset($data['shipping_state'])){
|
||||
$data['shipping_country_id'] = Shop::getShippingCountryCountryId($data['shipping_state']);
|
||||
}
|
||||
$shopping_user = false;
|
||||
if($this->getPayments('shopping_user_id')){
|
||||
$shopping_user = ShoppingUser::find($this->getPayments('shopping_user_id'));
|
||||
if($shopping_user){
|
||||
$shopping_user->fill($data);
|
||||
$shopping_user->mode = null;
|
||||
$shopping_user->save();
|
||||
}
|
||||
}
|
||||
if(!$shopping_user){
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
}
|
||||
$this->putPayments('shopping_user_id', $shopping_user->id);
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
private function makeShoppingOrder($shopping_user){
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'auth_user_id' => $shopping_user->auth_user_id,
|
||||
'promotion_user_id' => $this->PromotionUser->id,
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'payment_for' => $this->payment_for,
|
||||
'total' => Yard::instance('shopping')->total(2, '.', ''),
|
||||
'subtotal_full' => Yard::instance('shopping')->subtotal(2, '.', '', false),
|
||||
'discount' => 0,
|
||||
'subtotal' => Yard::instance('shopping')->subtotal(2, '.', ''),
|
||||
'shipping' => Yard::instance('shopping')->shipping(2, '.', ','),
|
||||
'shipping_net' => Yard::instance('shopping')->shippingNet(2, '.', ''),
|
||||
'subtotal_shipping' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ''),
|
||||
'tax' => Yard::instance('shopping')->taxWithShipping(2, '.', ''),
|
||||
'total_without_credit' => Yard::instance('shopping')->totalWithShippingWithoutCredit(2, '.', ''),
|
||||
'payment_credit' => Yard::instance('shopping')->totalfromCredit(2, '.', ''),
|
||||
'total_shipping' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'points' => Yard::instance('shopping')->points(),
|
||||
'weight' => Yard::instance('shopping')->weight(),
|
||||
'txaction' => 'prev',
|
||||
'shipping_option' => Yard::instance('shopping')->getShippingOption(),
|
||||
'mode' => Util::getUserShoppingMode(),
|
||||
];
|
||||
|
||||
$shopping_order= false;
|
||||
if($this->getPayments('shopping_order_id')){
|
||||
$shopping_order = ShoppingOrder::find($this->getPayments('shopping_order_id'));
|
||||
if($shopping_order){
|
||||
$shopping_order->fill($data);
|
||||
$shopping_order->save();
|
||||
}
|
||||
}
|
||||
if(!$shopping_order){
|
||||
$shopping_order = ShoppingOrder::create($data);
|
||||
}
|
||||
//$this->makeOrderMargin($shopping_order);
|
||||
|
||||
$this->putPayments('shopping_order_id', $shopping_order->id);
|
||||
$items = Yard::instance('shopping')->getContentByOrder();
|
||||
$shopping_order->shopping_order_items()->each(function($model) use ($items, $shopping_order, $shopping_user) {
|
||||
foreach ($items as $item) {
|
||||
if ($model->row_id === $item->rowId) {
|
||||
$data = [
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'free_product_id' => $item->options->free_product_id, //promotion_user_product_id
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
'price_net' => Yard::instance('shopping')->rowPriceNet($item, 3, '.', ''),
|
||||
'tax_rate' => $item->taxRate,
|
||||
'slug' => $item->options->slug,
|
||||
];
|
||||
$model->fill($data)->save();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $model->delete();
|
||||
});
|
||||
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (!ShoppingOrderItem::where('shopping_order_id', $shopping_order->id)->where('row_id', $item->rowId)->count()){
|
||||
$data = [
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'free_product_id' => $item->options->free_product_id, //promotion_user_product_id
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
'price_net' => Yard::instance('shopping')->rowPriceNet($item, 3, '.', ''),
|
||||
'tax_rate' => $item->taxRate,
|
||||
'slug' => $item->options->slug
|
||||
];
|
||||
$shopping_order_item = ShoppingOrderItem::create($data);
|
||||
}
|
||||
}
|
||||
return $shopping_order;
|
||||
}
|
||||
|
||||
private function putPayments($key, $value){
|
||||
$content = $this->getContent();
|
||||
$content->put($key, $value);
|
||||
$this->session->put($this->instance, $content);
|
||||
|
||||
}
|
||||
|
||||
private function getPayments($key){
|
||||
$content = $this->getContent();
|
||||
if ($content->has($key)){
|
||||
return $content->get($key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getContent()
|
||||
{
|
||||
if (is_null($this->session->get($this->instance))) {
|
||||
return new Collection([]);
|
||||
}
|
||||
return $this->session->get($this->instance);
|
||||
}
|
||||
|
||||
public function destroy()
|
||||
{
|
||||
$this->session->remove($this->instance);
|
||||
}
|
||||
}
|
||||
|
|
@ -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