promotion 1.0
This commit is contained in:
parent
1cc8e025a1
commit
570d428b1c
60 changed files with 1596 additions and 272 deletions
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue