144 lines
No EOL
4.7 KiB
PHP
144 lines
No EOL
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use App\Models\ShoppingOrder;
|
|
use App\Services\ShopApiOrderCart;
|
|
use App\Services\UserService;
|
|
use App\Services\Util;
|
|
use App\Models\UserHistory;
|
|
use App\Models\ShippingCountry;
|
|
use App\Models\ShoppingInstance;
|
|
use Auth;
|
|
use Yard;
|
|
use App\User;
|
|
|
|
|
|
|
|
class ShopApiRepository extends BaseRepository {
|
|
|
|
private $shopApiOrderCart;
|
|
|
|
public function __construct()
|
|
{
|
|
//$this->model = $model;
|
|
}
|
|
|
|
|
|
|
|
public function order($data)
|
|
{
|
|
$this->shopApiOrderCart = new ShopApiOrderCart();
|
|
$this->performOrderActionList($data, 0);
|
|
return $this->shopApiOrderCart;
|
|
}
|
|
|
|
public function remove($data){
|
|
$this->performActionList($data, 5);
|
|
return true;
|
|
|
|
}
|
|
|
|
public function reset($data){
|
|
$this->performActionList($data, 0);
|
|
return true;
|
|
}
|
|
|
|
|
|
public function checkout($data)
|
|
{
|
|
$user = User::find(Auth::user()->id);
|
|
$shopApiOrderCart = $this->performCheckout($data);
|
|
$time = time();
|
|
$date = date('d.m.Y H:i:s', $time);
|
|
Yard::instance('shopping')->destroy();
|
|
$cartItem = Yard::instance('shopping')->add($shopApiOrderCart->id, 'Sammelbestellung Extern '.$date, 1, $shopApiOrderCart->price_total, false, false, ['image' => "", 'slug' => $time, 'weight' => 0]);
|
|
Yard::setTax($cartItem->rowId, 0);
|
|
do {
|
|
$identifier = Util::getToken();
|
|
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
|
|
|
$shipping_country = ShippingCountry::whereCountryId($user->account->country_id)->first();
|
|
UserService::checkUserTaxShippingCountry($user, $shipping_country->id);
|
|
|
|
$data = [];
|
|
$data['is_from'] = 'collection';
|
|
|
|
$data['shop_price'] = $shopApiOrderCart->price_total;
|
|
$data['shop_price_net'] = $shopApiOrderCart->price_total_net;
|
|
$data['shop_price_tax'] = $shopApiOrderCart->tax_total;
|
|
$data['user_tax_free'] = false;
|
|
$data['shopping_collect_order_id'] = $shopApiOrderCart->id;
|
|
$data['is_for'] = 'co'; //colection
|
|
$data['user_price_infos'] = UserService::getYardInfo();
|
|
|
|
ShoppingInstance::create([
|
|
'identifier' => $identifier,
|
|
'user_shop_id' => 1, //is first faker shop for nuy intern
|
|
'auth_user_id' => $user->id,
|
|
'payment' => 2, //Berater Shop
|
|
'subdomain' => url('/'),
|
|
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
|
'language' => \App::getLocale(),
|
|
'shopping_data' => $data,
|
|
'back' => route('user_shop_api_orders'),
|
|
|
|
]);
|
|
|
|
Yard::instance('shopping')->store($identifier);
|
|
|
|
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
|
UserHistory::create(['user_id' => $user->id, 'action'=>'payment_collection', 'status'=>1, 'referenz'=>$shopApiOrderCart->id, 'identifier'=>$identifier]);
|
|
//$path = str_replace('http', 'https', $path);
|
|
return redirect()->secure($path);
|
|
}
|
|
|
|
|
|
private function performCheckout($data){
|
|
$this->shopApiOrderCart = new ShopApiOrderCart();
|
|
$this->performOrderCheckoutList($data, 1);
|
|
return $this->shopApiOrderCart;
|
|
}
|
|
|
|
|
|
private function performActionList($data, $status){
|
|
if(isset($data['api_action_list'])){
|
|
foreach($data['api_action_list'] as $orderItemId=>$v){
|
|
$ShoppingOrder = ShoppingOrder::findOrFail($orderItemId);
|
|
$ShoppingOrder->api_status = $status;
|
|
$ShoppingOrder->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
private function performOrderActionList($data, $status){
|
|
if(isset($data['api_action_list'])){
|
|
foreach($data['api_action_list'] as $orderItemId=>$v){
|
|
$ShoppingOrder = ShoppingOrder::findOrFail($orderItemId);
|
|
$this->shopApiOrderCart->add($ShoppingOrder);
|
|
$ShoppingOrder->api_status = $status; //<- no status change is the show list
|
|
$ShoppingOrder->save();
|
|
}
|
|
$this->shopApiOrderCart->calculate();
|
|
return $this->shopApiOrderCart;
|
|
}
|
|
}
|
|
|
|
private function performOrderCheckoutList($data, $status){
|
|
if(isset($data['api_action_list'])){
|
|
foreach($data['api_action_list'] as $k=>$orderItemId){
|
|
$ShoppingOrder = ShoppingOrder::findOrFail($orderItemId);
|
|
$this->shopApiOrderCart->add($ShoppingOrder);
|
|
$ShoppingOrder->api_status = $status;
|
|
$ShoppingOrder->save();
|
|
}
|
|
$this->shopApiOrderCart->calculate();
|
|
$this->shopApiOrderCart->store();
|
|
|
|
return $this->shopApiOrderCart;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} |