update 20.10.2025
This commit is contained in:
parent
8c11130b5d
commit
a939cd51ef
616 changed files with 84821 additions and 4121 deletions
322
dev/app-bak/Http/Controllers/User/AboController.php
Normal file
322
dev/app-bak/Http/Controllers/User/AboController.php
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserAbo;
|
||||
use App\Models\UserAboItem;
|
||||
use App\Repositories\AboRepository;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\AboOrderCart;
|
||||
use App\Services\Shop;
|
||||
use App\Services\UserService;
|
||||
use App\User;
|
||||
use Request;
|
||||
use Yard;
|
||||
|
||||
class AboController extends Controller
|
||||
{
|
||||
protected $aboRepository;
|
||||
|
||||
public function __construct(AboRepository $aboRepository)
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
$this->aboRepository = $aboRepository;
|
||||
}
|
||||
|
||||
public function index($view)
|
||||
{
|
||||
|
||||
if ($view === 'me') {
|
||||
// Nur Abos des aktuellen Benutzers
|
||||
$user_abos = UserAbo::where('user_id', \Auth::user()->id)
|
||||
->where('status', '>', 1);
|
||||
|
||||
if ($user_abos->count() > 0) {
|
||||
return redirect(route('user_abos_detail', ['me', $user_abos->first()->id]));
|
||||
}
|
||||
|
||||
return view('user.abo.index', [
|
||||
'user_abos' => [],
|
||||
'view' => 'me',
|
||||
'isAdmin' => false
|
||||
]);
|
||||
}
|
||||
|
||||
if ($view === 'ot') {
|
||||
$user_abos = UserAbo::where('member_id', \Auth::user()->id)
|
||||
->where('status', '>', 1)
|
||||
->where('is_for', 'ot')
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
return view('user.abo.index', [
|
||||
'user_abos' => $user_abos,
|
||||
'view' => 'ot',
|
||||
'isAdmin' => false
|
||||
]);
|
||||
}
|
||||
|
||||
// Standardfall, wenn weder 'me' noch 'ot'
|
||||
return view('user.abo.index', [
|
||||
'user_abos' => [],
|
||||
'view' => 'me',
|
||||
'isAdmin' => false
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function detail($view, $id)
|
||||
{
|
||||
$data = Request::all();
|
||||
$user_abo = UserAbo::findOrFail($id);
|
||||
|
||||
|
||||
$this->checkPermissions($view, $user_abo);
|
||||
|
||||
//init Yard
|
||||
AboOrderCart::initYard($user_abo);
|
||||
//holt die aktuellen UserAccount Daten oder die Userdaten des Abo
|
||||
$customer_detail = AboOrderCart::getCustomerDetail();
|
||||
AboOrderCart::makeOrderYard($user_abo);
|
||||
|
||||
$comp_products = [];
|
||||
if ($user_abo->is_for === 'me') {
|
||||
$comp_products = Shop::getCompProducts('abo-me');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user_abo' => $user_abo,
|
||||
'isAdmin' => false,
|
||||
'customer_detail' => $customer_detail,
|
||||
'view' => $view,
|
||||
'comp_products' => $comp_products,
|
||||
];
|
||||
return view('user.abo.detail', $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function update($view, $id)
|
||||
{
|
||||
$data = Request::all();
|
||||
$user_abo = UserAbo::findOrFail($id);
|
||||
|
||||
$this->checkPermissions($view, $user_abo);
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'abo_update_settings') {
|
||||
$user_abo = UserAbo::findOrFail($data['id']);
|
||||
$this->aboRepository->setModel($user_abo);
|
||||
$this->aboRepository->update($data);
|
||||
return redirect(route('user_abos_detail', [$view, $id]));
|
||||
}
|
||||
|
||||
if (Request::ajax()) {
|
||||
$message = false;
|
||||
//addProduct
|
||||
if ($data['action'] === 'addProduct') {
|
||||
if ($product = Product::find($data['product_id'])) {
|
||||
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('product_id', $product->id)->where('comp', 0)->first()) {
|
||||
$UserAboItem->qty = $UserAboItem->qty + 1;
|
||||
$UserAboItem->save();
|
||||
} else {
|
||||
UserAboItem::create([
|
||||
'user_abo_id' => $user_abo->id,
|
||||
'product_id' => $product->id,
|
||||
'comp' => 0,
|
||||
'qty' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//updateCart
|
||||
if ($data['action'] === 'updateCart') {
|
||||
//product_id | order_item_id | cart_order_id | qty
|
||||
if (isset($data['product_id']) && $product = Product::find($data['product_id'])) {
|
||||
if (isset($data['order_item_id']) && $UserAboItem = UserAboItem::find($data['order_item_id'])) {
|
||||
if (isset($data['qty'])) {
|
||||
$qty = (int) $data['qty'];
|
||||
$qty = $qty < 1 ? 1 : $qty;
|
||||
$qty = $qty > 100 ? 100 : $qty;
|
||||
$UserAboItem->qty = $qty;
|
||||
$UserAboItem->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//removeFromCart
|
||||
if ($data['action'] === 'removeFromCart') {
|
||||
if (!isset($data['product_id']) || !($product = Product::find($data['product_id']))) {
|
||||
$message = __('abo.product_not_found');
|
||||
}
|
||||
if (!isset($data['order_item_id']) || !($userAboItem = UserAboItem::find($data['order_item_id']))) {
|
||||
$message = __('abo.abo_item_not_found');
|
||||
}
|
||||
$has_basis_product = $this->check_need_basis_product($user_abo, $product, $data['order_item_id']);
|
||||
if (!$has_basis_product) {
|
||||
$message = __('abo.need_basis_product');
|
||||
}
|
||||
if (!$message) {
|
||||
|
||||
|
||||
$userAboItem->delete();
|
||||
$user_abo->refresh(); // Abo neu laden um die aktualisierten Items zu erhalten
|
||||
}
|
||||
}
|
||||
//updateCompProduct
|
||||
if ($data['action'] === 'updateCompProduct') {
|
||||
if ($UserAboItem = UserAboItem::where('user_abo_id', $user_abo->id)->where('comp', $data['comp_num'])->first()) {
|
||||
$UserAboItem->product_id = $data['comp_product_id'];
|
||||
$UserAboItem->save();
|
||||
} else {
|
||||
UserAboItem::create([
|
||||
'user_abo_id' => $user_abo->id,
|
||||
'product_id' => $data['comp_product_id'],
|
||||
'comp' => $data['comp_num'],
|
||||
'qty' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AboOrderCart::initYard($user_abo);
|
||||
AboOrderCart::makeOrderYard($user_abo); //reCalculateShippingPrice
|
||||
AboOrderCart::checkNumOfCompProducts($user_abo); //after reCalculateShippingPrice check it and remove or add comp product
|
||||
|
||||
if ($user_abo->is_for === 'me') {
|
||||
$data['comp_products'] = Shop::getCompProducts('abo-me');
|
||||
}
|
||||
$error_message = $message ? $message : false;
|
||||
$html_cart = view("admin.abo._order_abo_show", ['user_abo' => $user_abo, 'error_message' => $error_message])->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
|
||||
$amount = $user_abo->getFormattedAmount();
|
||||
|
||||
// $html_total = view("user.homeparty.show_total_order", ['homeparty' => $homeparty])->render();
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_cart' => $html_cart, 'html_comp' => $html_comp, 'amount' => $amount]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function check_need_basis_product($user_abo, $product, $order_item_id)
|
||||
{
|
||||
// Wenn das zu entfernende Produkt kein Basis-Produkt ist, keine weitere Prüfung nötig
|
||||
if (AboHelper::getAboShowOn($product) !== 'base') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prüfe ob noch ein anderes Basis-Produkt vorhanden ist
|
||||
foreach ($user_abo->user_abo_items as $user_abo_item) {
|
||||
if ($user_abo_item->id == $order_item_id) {
|
||||
continue;
|
||||
}
|
||||
if (AboHelper::getAboShowOn($user_abo_item->product) === 'base') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function datatable($user_abo_id)
|
||||
{
|
||||
$user_abo = UserAbo::findOrFail($user_abo_id);
|
||||
if (!$user_abo) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
//$user_abo->is_for === 'me'
|
||||
|
||||
$show_on_ids = ['12', '13'];
|
||||
$query = Product::select('products.*')
|
||||
->where('active', true)
|
||||
->where(function ($q) use ($show_on_ids) {
|
||||
foreach ($show_on_ids as $id) {
|
||||
$q->orWhereJsonContains('show_on', $id);
|
||||
}
|
||||
})
|
||||
->orderByRaw(
|
||||
"CASE
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 1
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 2
|
||||
ELSE 3 END",
|
||||
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]
|
||||
);
|
||||
|
||||
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('add_card', function (Product $product) use ($user_abo) {
|
||||
$ufactor = $user_abo->is_for === 'me' ? true : false;
|
||||
$tax_free = $user_abo->is_for === 'me' ? true : Yard::instance('shopping')->getUserTaxFree();
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="' . $product->id . '">
|
||||
<strong>€ ' . $product->getFormattedPriceWith($tax_free, $ufactor, Yard::instance('shopping')->getUserCountry()) . '</strong> +<span class="ion ion-md-cart"></span>
|
||||
</button>';
|
||||
})
|
||||
->addColumn('picture', function (Product $product) {
|
||||
if (count($product->images)) {
|
||||
return '<img class="img-fluid img-extra" alt="" src="' . route('product_image', [$product->images->first()->slug]) . '">';
|
||||
}
|
||||
return "";
|
||||
})
|
||||
->addColumn('name', function (Product $product) use ($user_abo) {
|
||||
return '<strong>' . $product->getLang('name') . '</strong><br>' . get_abo_type_badge_by_product($product);
|
||||
})
|
||||
|
||||
->addColumn('price_net', function (Product $product) use ($user_abo) {
|
||||
$ufactor = $user_abo->is_for === 'me' ? true : false;
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(true, $ufactor, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
})
|
||||
->addColumn('price_gross', function (Product $product) use ($user_abo) {
|
||||
$ufactor = $user_abo->is_for === 'me' ? true : false;
|
||||
return '<span class="no-line-break">' . $product->getFormattedPriceWith(false, $ufactor, Yard::instance('shopping')->getUserCountry()) . " €</span>" . '<span class="no-line-break">' . $product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()) . '</span>';
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="' . $product->id . '" data-route="' . route('modal_load') . '"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
})
|
||||
->filterColumn('product', function ($query, $keyword) {
|
||||
if ($keyword != "") {
|
||||
$query->where('name', 'LIKE', '%' . $keyword . '%');
|
||||
}
|
||||
})
|
||||
->orderColumn('name', 'name $1')
|
||||
->orderColumn('product', 'name $1')
|
||||
->orderColumn('number', 'number $1')
|
||||
->orderColumn('points', 'points $1')
|
||||
->orderColumn('price_net', 'price_net $1')
|
||||
->orderColumn('price_gross', 'price_gross $1')
|
||||
->orderColumn('contents_total', 'contents_total $1')
|
||||
->orderColumn('weight', 'weight $1')
|
||||
|
||||
->rawColumns(['add_card', 'product', 'name', 'quantity', 'picture', 'price_net', 'price_gross', 'action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function checkPermissions($view, $user_abo)
|
||||
{
|
||||
if ($view === 'me' && $user_abo->is_for !== 'me') {
|
||||
abort(403, 'Unauthorized action. Is not for me');
|
||||
}
|
||||
if ($view === 'ot' && $user_abo->is_for !== 'ot') {
|
||||
abort(403, 'Unauthorized action. Is not your customer');
|
||||
}
|
||||
if ($view === 'me' && $user_abo->user_id !== \Auth::user()->id) {
|
||||
abort(403, 'Unauthorized action. Is not my abo');
|
||||
}
|
||||
if ($view === 'ot' && $user_abo->member_id !== \Auth::user()->id) {
|
||||
abort(403, 'Unauthorized action. Is not my customer abo');
|
||||
}
|
||||
}
|
||||
}
|
||||
322
dev/app-bak/Http/Controllers/User/CustomerController.php
Executable file
322
dev/app-bak/Http/Controllers/User/CustomerController.php
Executable file
|
|
@ -0,0 +1,322 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Repositories\CustomerRepository;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Services\ShoppingUserService;
|
||||
use App\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Request;
|
||||
use Validator;
|
||||
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
protected $customerRepository;
|
||||
|
||||
public function __construct(CustomerRepository $customerRepository)
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
$this->customerRepository = $customerRepository;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if(Request::get('reset') === 'filter'){
|
||||
// set_user_attr('filter_member_id', null);
|
||||
// set_user_attr('filter_customer_member', null);
|
||||
return redirect(route('admin_customers'));
|
||||
}
|
||||
$data = [
|
||||
|
||||
];
|
||||
return view('user.customer.index', $data);
|
||||
}
|
||||
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$shopping_user = ShoppingUser::findOrFail($id);
|
||||
if($shopping_user->member_id != \Auth::user()->id){
|
||||
abort(404);
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
];
|
||||
return view('user.customer.detail', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$shopping_user = ShoppingUser::findOrFail($id);
|
||||
if($shopping_user->member_id != \Auth::user()->id){
|
||||
abort(404);
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
|
||||
];
|
||||
return view('user.customer.edit', $data);
|
||||
}
|
||||
|
||||
public function add($id, $step=0)
|
||||
{
|
||||
if($id === "new"){
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_user->id = "new";
|
||||
}else{
|
||||
$shopping_user = ShoppingUser::findOrFail($id);
|
||||
if($shopping_user->member_id != \Auth::user()->id){
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
$billing_email = null;
|
||||
if(!session('errors')){
|
||||
if(old('email') || old('billing_email')){
|
||||
$step = 1;
|
||||
$shopping_user->same_as_billing = true;
|
||||
$billing_email = old('email');
|
||||
}
|
||||
if(old('switcher-without-email') === 'true'){
|
||||
$step = 1;
|
||||
$shopping_user->same_as_billing = true;
|
||||
$shopping_user->faker_mail = true;
|
||||
$billing_email = time()."-faker@mivita.care";
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => $step === 0 ? 'customer' : 'customer-add',
|
||||
'step' => $step,
|
||||
'billing_email' => $billing_email,
|
||||
|
||||
];
|
||||
return view('user.customer.add', $data);
|
||||
}
|
||||
|
||||
private function checkShoppingUsersEmail($email = 'email', $action = 'return', $id=null){
|
||||
|
||||
$rules = array(
|
||||
$email => 'required|string|email|max:255|unique:shopping_users,billing_email',
|
||||
);
|
||||
$messages = [
|
||||
'unique' => __('validation.custom.unique_email_client'),
|
||||
];
|
||||
$validator = Validator::make(Request::all(), $rules, $messages);
|
||||
if ($validator->fails()) {
|
||||
\Session()->flash('alert-error', __('validation.custom.unique_email_client'));
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$rules = array(
|
||||
$email => 'required|string|email|max:255|unique:users,email',
|
||||
);
|
||||
$messages = [
|
||||
'unique' => __('validation.custom.unique_email_member'),
|
||||
];
|
||||
$validator = Validator::make(Request::all(), $rules, $messages);
|
||||
if ($validator->fails()) {
|
||||
\Session()->flash('alert-error', __('validation.custom.unique_email_member'));
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
if($action === 'return'){
|
||||
return back()->withInput(Request::all());
|
||||
}
|
||||
|
||||
if($action === 'save'){
|
||||
$shopping_user = ShoppingUser::findOrFail($id);
|
||||
$shopping_user->faker_mail = false;
|
||||
$shopping_user->billing_email = Request::get($email);
|
||||
$shopping_user->save();
|
||||
return redirect(route('user_customer_detail', [$shopping_user->id]));
|
||||
}
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Request::all();
|
||||
|
||||
if($id === 'new' && $data['action'] === 'add_customer_with_email'){
|
||||
return $this->checkShoppingUsersEmail('email', 'return');
|
||||
}
|
||||
if($id === 'new' && $data['action'] === 'add_customer_without_email'){
|
||||
return back()->withInput(Request::all());
|
||||
}
|
||||
|
||||
if($id === 'new' && $data['action'] === ''){
|
||||
return back()->withInput(Request::all());
|
||||
}
|
||||
|
||||
if($id !== 'new' && $data['action'] === 'add-mail-shopping-user-store'){
|
||||
return $this->checkShoppingUsersEmail('new_email_address', 'save', $id);
|
||||
}
|
||||
|
||||
if($data['action'] === 'shopping-user-store-new' || $data['action']==='shopping-user-store'){
|
||||
$rules = array(
|
||||
'billing_salutation' => 'required',
|
||||
'billing_firstname'=>'required',
|
||||
'billing_lastname'=>'required',
|
||||
'billing_email'=>'required|email',
|
||||
'billing_address'=>'required',
|
||||
'billing_zipcode'=>'required',
|
||||
'billing_city' => 'required',
|
||||
'billing_country_id' => 'required',
|
||||
);
|
||||
|
||||
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',
|
||||
'shipping_country_id' => 'required'
|
||||
]);
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
}
|
||||
|
||||
$data['language'] = isset($data['language']) ? $data['language'] : \App::getLocale();
|
||||
$data['faker_mail'] = isset($data['faker_mail']) ? true : false;
|
||||
$data['has_buyed'] = isset($data['has_buyed']) ? true : false;
|
||||
$data['subscribed'] = isset($data['subscribed']) ? true : false;
|
||||
//subscribed can only true when has_buyed ist active
|
||||
$data['subscribed'] = $data['has_buyed'] ? $data['subscribed'] : false;
|
||||
|
||||
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
|
||||
$data['shipping_country_id'] = isset($data['shipping_country_id']) ? $data['shipping_country_id'] : $data['billing_country_id'];
|
||||
|
||||
if($id > 0 && $data['action'] === 'shopping-user-store'){
|
||||
$shopping_user = ShoppingUser::findOrFail($id);
|
||||
if($shopping_user->member_id != \Auth::user()->id){
|
||||
abort(404);
|
||||
}
|
||||
CustomerPriority::checkChangeOne($shopping_user, $data, true);
|
||||
$shopping_user->fill($data);
|
||||
$shopping_user->save();
|
||||
|
||||
}
|
||||
|
||||
if($id === 'new' && $data['action'] === 'shopping-user-store-new') {
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
$shopping_user->member_id = \Auth::user()->id;
|
||||
$shopping_user->save();
|
||||
CustomerPriority::checkNewOne($shopping_user, true);
|
||||
}
|
||||
\App\Services\Shop::newUserOrder($shopping_user->number);
|
||||
|
||||
if($shopping_user->is_like){
|
||||
\Session()->flash('custom-error', __('validation.custom.match_found'));
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect(route('user_customer_detail', [$shopping_user->id]));
|
||||
}
|
||||
|
||||
|
||||
private function checkShoppingUsersByEmail(){
|
||||
|
||||
//ist an dieser stelle nicht machbar, zu viele Datenbankzugriffe
|
||||
//siehe App\Console\Commands\SyncShoppingUserData
|
||||
/* $user = User::find(\Auth::user()->id);
|
||||
ShoppingUserService::setFakerMail($user);
|
||||
ShoppingUserService::syncNumbersByEmail($user);
|
||||
ShoppingUserService::syncOrdersByEmail($user); */
|
||||
|
||||
}
|
||||
public function getCustomers()
|
||||
{
|
||||
//$this->checkShoppingUsersByEmail();
|
||||
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
//\Log::info('Current user ID: ' . $user->id);
|
||||
|
||||
$query = ShoppingUser::select(['id', 'billing_company', 'billing_salutation', 'billing_firstname', 'billing_lastname', 'billing_email', 'faker_mail', 'billing_zipcode', 'billing_city', 'billing_country_id', 'orders', 'subscribed', 'created_at', 'number', 'mode', 'is_like', 'wp_order_number'])
|
||||
->with('billing_country')
|
||||
->whereIn('id', function($query) {
|
||||
$query->select(DB::raw('MAX(id)'))
|
||||
->from('shopping_users')
|
||||
->groupBy('billing_email');
|
||||
})->where('shopping_users.member_id', '=', $user->id)->where('shopping_users.auth_user_id', '=', NULL);
|
||||
|
||||
if(Request::get('isfor') === 'ot-member'){ //Bestellung für Kunden
|
||||
}
|
||||
if(Request::get('isfor') === 'ot-customer' || Request::get('isfor') === 'abo-ot-customer'){ //Bestellung für Kunden Zahlungslink
|
||||
$query->where(function($q) {
|
||||
$q->where('shopping_users.faker_mail', '!=', 1)
|
||||
->orWhereNull('shopping_users.faker_mail');
|
||||
});
|
||||
}
|
||||
//\Log::info('SQL Query: ' . $query->toSql());
|
||||
//\Log::info('Query Bindings: ' . print_r($query->getBindings(), true));
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('send_to', function (ShoppingUser $ShoppingUser) {
|
||||
$ot = Request::get('isfor') ? Request::get('isfor') : 'ot-member';
|
||||
if(Request::get('isfor') === 'abo-ot-customer' && AboHelper::memberHasAbo($ShoppingUser)){
|
||||
return '<span class="badge badge-pill badge-success"><i class="fa fa-check-circle"></i> '.__('abo.abo_assigned').'</span>';
|
||||
}
|
||||
return $ShoppingUser->is_like ? '<span class="badge badge-pill badge-warning"><i class="fa fa-clock"></i> '.__('customer.under_review').'</span>' : '<a href="' . route('user_order_my_delivery', [$ot, $ShoppingUser->id]) . '" class="btn btn-sm btn-secondary"><span class="fa fa-shopping-cart"></span> '.__('customer.select').'</a>';
|
||||
})
|
||||
->addColumn('billing_email', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->faker_mail ? "-" : $ShoppingUser->billing_email;
|
||||
})
|
||||
->addColumn('id', function (ShoppingUser $ShoppingUser) {
|
||||
return '<a href="' . route('user_customer_detail', [$ShoppingUser->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('billing_salutation', function (ShoppingUser $ShoppingUser) {
|
||||
return HTMLHelper::getSalutationLang($ShoppingUser->billing_salutation);
|
||||
})
|
||||
->addColumn('billing_country_id', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->billing_country ? $ShoppingUser->billing_country->getLocated() : '';
|
||||
})
|
||||
->addColumn('first_created_at', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->firstEntryByNumber()->created_at->format('d.m.Y');
|
||||
})
|
||||
->addColumn('orders', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->orders;
|
||||
})
|
||||
->addColumn('subscribed', function (ShoppingUser $ShoppingUser) {
|
||||
return get_active_badge($ShoppingUser->subscribed);
|
||||
})
|
||||
->addColumn('status', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->is_like ? '<span class="badge badge-pill badge-warning"><i class="fa fa-clock"></i> '.__('customer.under_review').'</span> ' : '<span class="badge badge-pill badge-success"><i class="fa fa-check-circle"></i> '.__('customer.assigned').'</span>';
|
||||
})
|
||||
->addColumn('extras', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->wp_order_number.($ShoppingUser->mode==='dev' ? ' <span class="badge badge-warning">dev</span>' : '');
|
||||
})
|
||||
->filterColumn('billing_email', function($query, $keyword) {
|
||||
if($keyword != ""){
|
||||
$query->where('billing_email', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('send_to', 'id $1')
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('billing_email', 'billing_email $1')
|
||||
->orderColumn('billing_country_id', 'billing_country_id $1')
|
||||
->orderColumn('billing_salutation', 'billing_salutation $1')
|
||||
->orderColumn('first_created_at', 'created_at $1')
|
||||
->orderColumn('orders', 'orders $1')
|
||||
->orderColumn('subscribed', 'subscribed $1')
|
||||
->rawColumns(['send_to', 'id', 'subscribed', 'extras', 'status'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
131
dev/app-bak/Http/Controllers/User/DocumentsController.php
Normal file
131
dev/app-bak/Http/Controllers/User/DocumentsController.php
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use Auth;
|
||||
use Request;
|
||||
use App\User;
|
||||
use Validator;
|
||||
use App\Models\File;
|
||||
use App\Mail\MailReleaseDocument;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\FileRepository;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
|
||||
|
||||
class DocumentsController extends Controller
|
||||
{
|
||||
protected $fileRepo;
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(FileRepository $fileRepo)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->fileRepo = $fileRepo;
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
||||
$data = [
|
||||
'user' => $user,
|
||||
'business_license_choose' => $user->account->getNotice('business_license'),
|
||||
];
|
||||
return view('user.documents.index', $data);
|
||||
|
||||
}
|
||||
|
||||
public function store($action){
|
||||
|
||||
|
||||
$data = Request::all();
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
|
||||
if ($action == 'verification') {
|
||||
if(Request::get('submit') === 'do'){
|
||||
if(File::whereUserId($user->id)->whereIdentifier('id_card')->count() == 0){
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('field', __('msg.no_id_card_deposited_please_upload_first'));
|
||||
$user->save();
|
||||
return redirect(route('user_documents'))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$user->save();
|
||||
return redirect(route('user_documents'));
|
||||
}
|
||||
$this->fileRepo->_set('disk', 'user');
|
||||
$this->fileRepo->_set('dir', '/'.$user->id.'/verification/');
|
||||
$this->fileRepo->_set('user_id', $user->id);
|
||||
$this->fileRepo->_set('identifier', 'id_card');
|
||||
return $this->fileRepo->uploadFile(Request::all());
|
||||
}
|
||||
|
||||
if ($action == 'business_license') {
|
||||
if(Request::get('submit') === 'do'){
|
||||
$data = Request::all();
|
||||
|
||||
if($data['business_license_choose'] === "now"){
|
||||
if(File::whereUserId($user->id)->whereIdentifier('business_license')->count() == 0){
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('field', __('msg.no_trade_licence_deposited_please_upload_first'));
|
||||
$user->save();
|
||||
return redirect(route('user_documents'))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$user->account->setNotice('business_license_reason', '');
|
||||
|
||||
}
|
||||
if($data['business_license_choose'] === "later"){
|
||||
$user->account->setNotice('business_license_reason', '');
|
||||
|
||||
}
|
||||
if($data['business_license_choose'] === "non"){
|
||||
if(!$data['non_business_license_reason'] || $data['non_business_license_reason'] == ""){
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
$validator->errors()->add('field', __('msg.please_enter_reason_why_you_not_need_trade_licence'));
|
||||
$user->save();
|
||||
return redirect(route('user_documents'))->withErrors($validator)->withInput(Request::all());
|
||||
}else{
|
||||
$user->account->setNotice('business_license_reason', $data['non_business_license_reason']);
|
||||
}
|
||||
}
|
||||
$user->account->setNotice('business_license', $data['business_license_choose']);
|
||||
$user->save();
|
||||
|
||||
if($user->isTestMode()){
|
||||
$mail = config('app.info_test_mail');
|
||||
}else{
|
||||
$mail = config('app.info_mail');
|
||||
}
|
||||
|
||||
Mail::to($mail)->locale($user->getLocale())->send(new MailReleaseDocument($user));
|
||||
|
||||
return redirect(route('user_documents'));
|
||||
}
|
||||
$this->fileRepo->_set('disk', 'user');
|
||||
$this->fileRepo->_set('dir', '/'.$user->id.'/verification/');
|
||||
$this->fileRepo->_set('user_id', $user->id);
|
||||
$this->fileRepo->_set('identifier', 'business_license');
|
||||
return $this->fileRepo->uploadFile(Request::all());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function delete($id, $relation){
|
||||
|
||||
if($relation === 'upload'){
|
||||
$user = User::findOrFail(Auth::user()->id);
|
||||
$file = $user->files()->findOrFail($id);
|
||||
//remove file
|
||||
\Storage::disk('user')->delete($file->dir.$file->filename);
|
||||
$file->delete();
|
||||
\Session()->flash('alert-success', __('msg.file_deleted'));
|
||||
}
|
||||
return back();
|
||||
}
|
||||
|
||||
}
|
||||
145
dev/app-bak/Http/Controllers/User/DownloadController.php
Normal file
145
dev/app-bak/Http/Controllers/User/DownloadController.php
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use Request;
|
||||
use App\Models\DcTag;
|
||||
use App\Models\DcFile;
|
||||
use App\Models\DcFileTag;
|
||||
use App\Models\DcCategory;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
|
||||
class DownloadController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$this->setFilterVars();
|
||||
$files = DcFile::where('active', true)->orderBy('id', 'desc')->get(); //File::all();
|
||||
|
||||
$filter_list = $this->makeFilterList();
|
||||
$data = [
|
||||
'files' => $files,
|
||||
'filter_list' => $filter_list,
|
||||
'tag_ids' => array(),
|
||||
'resTagIds' => array(),
|
||||
'search' => false,
|
||||
|
||||
];
|
||||
|
||||
return view('user.downloadcenter.index', $data);
|
||||
}
|
||||
|
||||
public function search(){
|
||||
|
||||
$request = Request::all();
|
||||
|
||||
|
||||
if(Request::ajax()){
|
||||
|
||||
$request['tagIds'] = isset($request['tagIds']) ? $request['tagIds'] : array();
|
||||
$request['searchinput'] = isset($request['searchinput']) ? $request['searchinput'] : "";
|
||||
$tag_ids = $request['tagIds'];
|
||||
$searchTags = [];
|
||||
foreach ($tag_ids as $tags) {
|
||||
if($tags != "" && $tags != "0"){
|
||||
if(is_array($tags)){
|
||||
foreach ($tags as $tag) {
|
||||
array_push($searchTags, $tag);
|
||||
}
|
||||
}else{
|
||||
array_push($searchTags, $tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
$q = DcFile::with('fileTag')->where('active', 1);
|
||||
if($request['searchinput'] != ""){
|
||||
$q->where('original_name', 'LIKE', '%'.$request['searchinput'].'%');
|
||||
}
|
||||
if(count($searchTags) > 0){
|
||||
$q->whereHas('fileTag', function ($query) use ($searchTags){
|
||||
$query->whereIn('tag_id', $searchTags);
|
||||
});
|
||||
}
|
||||
|
||||
$files = $q->orderBy('id', 'desc')->get();
|
||||
$returnContentFiles = view('user.downloadcenter.content-files')->with('files', $files)->render();
|
||||
/* if(strlen($files) < 1){
|
||||
$returnContentFiles = "Keine Einträge vorhanden";
|
||||
}*/
|
||||
/*
|
||||
$resTagIds = array();
|
||||
foreach ($files as $file) {
|
||||
foreach ($file->fileTag as $tagId) {
|
||||
if(empty($resTagIds[$tagId->tag_id])){
|
||||
$resTagIds[$tagId->tag_id] = 1;
|
||||
}else{
|
||||
$resTagIds[$tagId->tag_id]++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$categories = DcCategory::orderBy('pos')->get();
|
||||
$data = [
|
||||
'categories' => $categories,
|
||||
'tag_ids' => $tag_ids,
|
||||
'resTagIds' => $resTagIds,
|
||||
'search' => true,
|
||||
];
|
||||
$returnFilters = view('content-collapse')->with('data', $data)->render();
|
||||
*/
|
||||
$returnFilters = "";
|
||||
return response()->json( array('success' => true, 'request' => $request, 'searchTags' => $searchTags, 'content_files'=>$returnContentFiles, 'content_filter'=>$returnFilters) );
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private function setFilterVars(){
|
||||
|
||||
|
||||
/* if(!session('user_shop_api_orders_filter')){
|
||||
session(['user_shop_api_orders_filter' => 1]);
|
||||
}
|
||||
if(Request::get('user_shop_api_orders_filter')){
|
||||
session(['user_shop_api_orders_filter' => Request::get('user_shop_api_orders_filter')]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
private function makeFilterList($archive = false, $request = true)
|
||||
{
|
||||
$ret = [];
|
||||
$categories = DcCategory::where('active', true)->orderBy('pos')->get();
|
||||
foreach($categories as $category){
|
||||
$tags = DcTag::where('category_id', $category->id)->where('active', true)->orderBy('pos')->get();
|
||||
$items = [];
|
||||
foreach ($tags as $tag){
|
||||
//has file tags
|
||||
$count = DcFileTag::with('dc_file')->where('tag_id', $tag->id)->whereHas('dc_file', function ($query){
|
||||
$query->where('active', true);
|
||||
})->count();
|
||||
if($count > 0){
|
||||
$tag->count = $count;
|
||||
$items[] = $tag;
|
||||
}
|
||||
}
|
||||
if(isset($items) && count($items) > 0){
|
||||
$ret[$category->id]['items'] = $items;
|
||||
$ret[$category->id]['name'] = $category->name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
654
dev/app-bak/Http/Controllers/User/HomepartyController.php
Executable file
654
dev/app-bak/Http/Controllers/User/HomepartyController.php
Executable file
|
|
@ -0,0 +1,654 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use Auth;
|
||||
use Yard;
|
||||
use Request;
|
||||
use App\User;
|
||||
use Validator;
|
||||
use App\Services\Util;
|
||||
use App\Models\Product;
|
||||
use App\Models\Homeparty;
|
||||
use App\Models\UserHistory;
|
||||
use App\Models\HomepartyUser;
|
||||
use App\Services\UserService;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Services\HomepartyCart;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\HomepartyUserOrderItem;
|
||||
|
||||
|
||||
class HomepartyController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
'homepartys' => Homeparty::where('auth_user_id', '=', \Auth::user()->id)->orderByDesc('id')->get(),
|
||||
];
|
||||
return view('user.homeparty.index', $data);
|
||||
}
|
||||
|
||||
public function detail($id, $step = false)
|
||||
{
|
||||
if($id === 'new'){
|
||||
$homeparty = new Homeparty();
|
||||
$homeparty->id = 0;
|
||||
$step = 1;
|
||||
}else{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
if($homeparty->step < 10){
|
||||
$step = $homeparty->step;
|
||||
}else{
|
||||
if(!$step){
|
||||
$step = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($homeparty->homeparty_host){
|
||||
$homeparty_user = $homeparty->homeparty_host;
|
||||
}else{
|
||||
$homeparty_user = new HomepartyUser();
|
||||
$homeparty_user->is_host = true;
|
||||
}
|
||||
|
||||
if($homeparty->completed){
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'homeparty' => $homeparty,
|
||||
'homeparty_user' => $homeparty_user,
|
||||
'step' => $step,
|
||||
|
||||
];
|
||||
return view('user.homeparty.detail', $data);
|
||||
}
|
||||
|
||||
public function store($id = null, $step = false)
|
||||
{
|
||||
$data = Request::all();
|
||||
|
||||
if($data['action'] === 'homeparty-party-store-detail'){
|
||||
$rules = array(
|
||||
'date' => 'required',
|
||||
'name' => 'required',
|
||||
'place' => 'required',
|
||||
);
|
||||
if(!$id){
|
||||
$rules = array(
|
||||
'date' => 'required',
|
||||
'name' => 'required',
|
||||
'place' => 'required',
|
||||
'country_id' => 'required'
|
||||
);
|
||||
}
|
||||
}
|
||||
if($data['action'] === 'homeparty-party-store-address'){
|
||||
$rules = array(
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_country_id' => 'required'
|
||||
);
|
||||
}
|
||||
|
||||
if($data['action'] === 'homeparty-party-store-host'){
|
||||
$rules = array(
|
||||
'billing_salutation' => 'required',
|
||||
'billing_firstname' => 'required',
|
||||
'billing_lastname' => 'required',
|
||||
'billing_address' => 'required',
|
||||
'billing_zipcode' => 'required',
|
||||
'billing_city' => 'required',
|
||||
'billing_country_id' => 'required',
|
||||
);
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
||||
if($data['action'] === 'homeparty-party-store-detail'){
|
||||
if(!$id){
|
||||
//first save create and empty user/host
|
||||
do {
|
||||
$token = Util::uuidToken();
|
||||
} while( Homeparty::where('token', $token)->count() );
|
||||
$data['token'] = $token;
|
||||
$data['auth_user_id'] = \Auth::user()->id;
|
||||
$data['step'] = 2;
|
||||
$step = 2;
|
||||
$homeparty = Homeparty::create($data);
|
||||
$this->storeTranslations($homeparty, \App::getLocale(), $data);
|
||||
$homeparty_user = HomepartyUser::create([
|
||||
'homeparty_id' => $homeparty->id,
|
||||
'auth_user_id' => \Auth::user()->id,
|
||||
'shipping_country_id' => $homeparty->country_id,
|
||||
'billing_country_id' => $homeparty->country_id,
|
||||
'same_as_billing' => false,
|
||||
'is_host' => true,
|
||||
]);
|
||||
}else {
|
||||
$homeparty = $this->getHomparty($id);
|
||||
$homeparty->fill($data)->save();
|
||||
$this->storeTranslations($homeparty, \App::getLocale(), $data);
|
||||
$step = 10;
|
||||
}
|
||||
}
|
||||
if($data['action'] === 'homeparty-party-store-address'){
|
||||
$homeparty = $this->getHomparty($id);
|
||||
$homeparty_user = $homeparty->homeparty_host;
|
||||
$homeparty_user->fill($data)->save();
|
||||
if($homeparty->step === 2){
|
||||
$homeparty->step = 3;
|
||||
$homeparty->save();
|
||||
$step = 3;
|
||||
}else{
|
||||
$step = 12;
|
||||
}
|
||||
}
|
||||
|
||||
if($data['action'] === 'homeparty-party-store-host'){
|
||||
$homeparty = $this->getHomparty($id);
|
||||
$homeparty_user = $homeparty->homeparty_host;
|
||||
$homeparty_user->fill($data)->save();
|
||||
if($homeparty->step === 3){
|
||||
$homeparty->step = 10;
|
||||
$homeparty->save();
|
||||
$step = 10;
|
||||
}else{
|
||||
$step = 13;
|
||||
}
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('user_homeparty_detail', [$homeparty->id, $step]));
|
||||
}
|
||||
|
||||
private function storeTranslations($homeparty, $lang, $data){
|
||||
|
||||
if($lang == 'de'){
|
||||
$homeparty->description = $data['description'];
|
||||
$homeparty->save();
|
||||
return;
|
||||
}
|
||||
$trans = $homeparty->trans_description;
|
||||
$trans[$lang] = $data['description'];
|
||||
$homeparty->trans_description = $trans;
|
||||
$homeparty->save();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public function guests($id = null)
|
||||
{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
$data = [
|
||||
'homeparty' => $homeparty,
|
||||
];
|
||||
return view('user.homeparty.guests', $data);
|
||||
}
|
||||
|
||||
|
||||
public function guestDetail($id = null, $gid = null)
|
||||
{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
if($gid === 'new'){
|
||||
$homeparty_user = new HomepartyUser();
|
||||
$homeparty_user->same_as_billing = true;
|
||||
$homeparty_user->billing_country_id = $homeparty->country_id;
|
||||
$homeparty_user->shipping_country_id = $homeparty->country_id;
|
||||
}else{
|
||||
$homeparty_user = HomepartyUser::findOrFail($gid);
|
||||
if($homeparty->id !== $homeparty_user->homeparty_id){
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
if($homeparty->completed){
|
||||
abort(404);
|
||||
}
|
||||
$data = [
|
||||
'homeparty' => $homeparty,
|
||||
'homeparty_user' => $homeparty_user,
|
||||
];
|
||||
return view('user.homeparty.guest_detail', $data);
|
||||
}
|
||||
|
||||
public function guestStore($id = null, $gid = null)
|
||||
{
|
||||
$data = Request::all();
|
||||
$rules = array(
|
||||
'billing_salutation' => 'required',
|
||||
'billing_firstname' => 'required',
|
||||
'billing_lastname' => 'required',
|
||||
'billing_address' => 'required',
|
||||
'billing_zipcode' => 'required',
|
||||
'billing_city' => 'required',
|
||||
'billing_country_id' => 'required',
|
||||
);
|
||||
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',
|
||||
'shipping_country_id' => 'required'
|
||||
]);
|
||||
}
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
||||
$homeparty = $this->getHomparty($id);
|
||||
if($gid === null){
|
||||
$homeparty_user = HomepartyUser::create([
|
||||
'homeparty_id' => $homeparty->id,
|
||||
'auth_user_id' => \Auth::user()->id,
|
||||
'is_host' => false,
|
||||
]);
|
||||
}else{
|
||||
$homeparty_user = HomepartyUser::findOrFail($gid);
|
||||
}
|
||||
if($homeparty->id !== $homeparty_user->homeparty_id){
|
||||
abort(404);
|
||||
}
|
||||
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
|
||||
$data['shipping_country_id'] = isset($data['shipping_country_id']) ? $data['shipping_country_id'] : $data['billing_country_id'];
|
||||
$homeparty_user->fill($data)->save();
|
||||
\Session()->flash('alert-save', '1');
|
||||
return redirect(route('user_homeparty_guests', [$homeparty->id]));
|
||||
}
|
||||
|
||||
|
||||
public function order($id = null)
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
$homeparty = $this->getHomparty($id);
|
||||
$shipping_country_id = $this->checkShoppingCountry($homeparty->country_id);
|
||||
if(!$shipping_country_id){
|
||||
\Session()->flash('custom-error', __('validation.custom.shipping_not_found'));
|
||||
return redirect(route('user_homepartys'));
|
||||
}
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
if($this->userChangeCountry($homeparty)){
|
||||
\Session()->flash('custom-error', __('msg.country_account_has_been_changed__cost_has_been_reset'));
|
||||
return redirect(route('user_homeparty_order', [$homeparty->id]));
|
||||
}
|
||||
HomepartyCart::calculateHomeparty($homeparty);
|
||||
$homeparty->card_info = UserService::getYardInfo();
|
||||
$homeparty->save();
|
||||
$userHistoryPaymentOrder = UserHistory::whereUserId($user->id)->whereAction('payment_homeparty')->where('referenz', $homeparty->id)->get()->last();
|
||||
$data = [
|
||||
'homeparty' => $homeparty,
|
||||
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
|
||||
];
|
||||
return view('user.homeparty.order', $data);
|
||||
}
|
||||
|
||||
private function userChangeCountry($homeparty){
|
||||
if(isset($homeparty->card_info['user_country_id'])){
|
||||
if($homeparty->card_info['user_country_id'] !== UserService::$user_country->id){
|
||||
// es wurde schon eine order angelegt, aber das Rechungsland geändert
|
||||
if($homeparty->homeparty_order_items->count()){
|
||||
foreach($homeparty->homeparty_order_items as $homeparty_order_item){
|
||||
$homeparty_order_item->delete();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkShoppingCountry($country_id){
|
||||
if($country_id){
|
||||
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
|
||||
return $shipping_country->id;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//perform Request
|
||||
public function orderStore($id = null)
|
||||
{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
|
||||
if(Request::ajax()) {
|
||||
$data = Request::all();
|
||||
|
||||
if($data['action'] === 'addProduct') {
|
||||
if($data['homeparty_id'] == $homeparty->id){
|
||||
$homeparty_user = HomepartyUser::findOrFail($data['homeparty_user_id']);
|
||||
if($homeparty_user->homeparty_id !== $homeparty->id){
|
||||
abort(404);
|
||||
}
|
||||
if($product = Product::find($data['product_id'])){
|
||||
$margin = 0;
|
||||
if(\Auth::user() && \Auth::user()->user_level){
|
||||
$margin = \Auth::user()->user_level->margin;
|
||||
}
|
||||
$HomepartyUserOrderItem = HomepartyUserOrderItem::where('homeparty_user_id', $homeparty_user->id)->where('product_id', $product->id)->first();
|
||||
if($HomepartyUserOrderItem){
|
||||
$HomepartyUserOrderItem->qty = $HomepartyUserOrderItem->qty+1;
|
||||
$HomepartyUserOrderItem->save();
|
||||
}else{
|
||||
if($homeparty->getCardInfo('user_tax_free')){
|
||||
$HomepartyUserOrderItem = HomepartyUserOrderItem::create([
|
||||
'homeparty_id' => $homeparty->id,
|
||||
'homeparty_user_id' => $homeparty_user->id,
|
||||
'product_id' => $product->id,
|
||||
'qty' => 1,
|
||||
'price' => $product->getPriceWith(true, false, $homeparty->getUserCountry()),
|
||||
'price_net' => $product->getPriceWith(true, false, $homeparty->getUserCountry()),
|
||||
'tax_rate' => 0,
|
||||
'points' => $product->points,
|
||||
'margin' => $margin,
|
||||
'ek_price' => $product->getPriceWith(true, true, $homeparty->getUserCountry()),
|
||||
'ek_price_net' => $product->getPriceWith(true, true, $homeparty->getUserCountry()),
|
||||
'slug' => $product->slug
|
||||
]);
|
||||
}else{
|
||||
$HomepartyUserOrderItem = HomepartyUserOrderItem::create([
|
||||
'homeparty_id' => $homeparty->id,
|
||||
'homeparty_user_id' => $homeparty_user->id,
|
||||
'product_id' => $product->id,
|
||||
'qty' => 1,
|
||||
'price' => $product->getPriceWith(false, false, $homeparty->getUserCountry()),
|
||||
'price_net' => $product->getPriceWith(true, false, $homeparty->getUserCountry()),
|
||||
'tax_rate' => $product->getTaxWith($homeparty->getUserCountry()),
|
||||
'points' => $product->points,
|
||||
'margin' => $margin,
|
||||
'ek_price' => $product->getPriceWith(false, true, $homeparty->getUserCountry()),
|
||||
'ek_price_net' => $product->getPriceWith(true, true, $homeparty->getUserCountry()),
|
||||
'slug' => $product->slug
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$homeparty_user = HomepartyUser::findOrFail($data['homeparty_user_id']);
|
||||
HomepartyCart::calculateHomeparty($homeparty);
|
||||
$html_user_cart = view("user.homeparty.show_products_order", ['homeparty' => $homeparty, 'homeparty_guest' => $homeparty_user])->render();
|
||||
$html_bonus = view("user.homeparty.show_bonus", ['homeparty' => $homeparty])->render();
|
||||
$html_host_bonus = view("user.homeparty.show_calc_bonus_host", ['homeparty' => $homeparty])->render();
|
||||
$html_total = view("user.homeparty.show_total_order", ['homeparty' => $homeparty])->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_user_cart'=>$html_user_cart, 'html_bonus'=>$html_bonus, 'html_host_bonus'=>$html_host_bonus, 'html_total'=>$html_total]);
|
||||
}
|
||||
|
||||
if($data['action'] === 'updateCart') {
|
||||
if($data['homeparty_id'] == $homeparty->id){
|
||||
$homeparty_user = HomepartyUser::findOrFail($data['homeparty_user_id']);
|
||||
if($homeparty_user->homeparty_id !== $homeparty->id){
|
||||
abort(404);
|
||||
}
|
||||
if(isset($data['product_id']) && $product = Product::find($data['product_id'])){
|
||||
if(isset($data['order_item_id']) && $HomepartyUserOrderItem = HomepartyUserOrderItem::find($data['order_item_id'])){
|
||||
if(isset($data['qty'])){
|
||||
$qty = (int) $data['qty'];
|
||||
$qty = $qty < 1 ? 1 : $qty;
|
||||
$qty = $qty > 100 ? 100 : $qty;
|
||||
$HomepartyUserOrderItem->qty = $qty;
|
||||
$HomepartyUserOrderItem->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$homeparty_user = HomepartyUser::findOrFail($data['homeparty_user_id']);
|
||||
HomepartyCart::calculateHomeparty($homeparty);
|
||||
$html_user_cart = view("user.homeparty.show_products_order", ['homeparty' => $homeparty, 'homeparty_guest' => $homeparty_user])->render();
|
||||
$html_bonus = view("user.homeparty.show_bonus", ['homeparty' => $homeparty])->render();
|
||||
$html_host_bonus = view("user.homeparty.show_calc_bonus_host")->render();
|
||||
$html_total = view("user.homeparty.show_total_order", ['homeparty' => $homeparty])->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_user_cart'=>$html_user_cart, 'html_bonus'=>$html_bonus, 'html_host_bonus'=>$html_host_bonus, 'html_total'=>$html_total]);
|
||||
}
|
||||
|
||||
if($data['action'] === 'removeFromCart') {
|
||||
if($data['homeparty_id'] == $homeparty->id){
|
||||
$homeparty_user = HomepartyUser::findOrFail($data['homeparty_user_id']);
|
||||
if($homeparty_user->homeparty_id !== $homeparty->id){
|
||||
abort(404);
|
||||
}
|
||||
if(isset($data['product_id']) && $product = Product::find($data['product_id'])){
|
||||
if(isset($data['order_item_id']) && $HomepartyUserOrderItem = HomepartyUserOrderItem::find($data['order_item_id'])){
|
||||
$HomepartyUserOrderItem->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
$homeparty_user = HomepartyUser::findOrFail($data['homeparty_user_id']);
|
||||
HomepartyCart::calculateHomeparty($homeparty);
|
||||
$html_user_cart = view("user.homeparty.show_products_order", ['homeparty' => $homeparty, 'homeparty_guest' => $homeparty_user])->render();
|
||||
$html_bonus = view("user.homeparty.show_bonus", ['homeparty' => $homeparty])->render();
|
||||
$html_host_bonus = view("user.homeparty.show_calc_bonus_host")->render();
|
||||
$html_total = view("user.homeparty.show_total_order", ['homeparty' => $homeparty])->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_user_cart'=>$html_user_cart, 'html_bonus'=>$html_bonus, 'html_host_bonus'=>$html_host_bonus, 'html_total'=>$html_total]);
|
||||
}
|
||||
|
||||
if($data['action'] === 'updateDeliveryOption') {
|
||||
if($data['homeparty_id'] == $homeparty->id){
|
||||
$homeparty_user = HomepartyUser::findOrFail($data['homeparty_user_id']);
|
||||
if($homeparty_user->homeparty_id !== $homeparty->id){
|
||||
abort(404);
|
||||
}
|
||||
if(isset($data['delivery'])){
|
||||
$homeparty_user->delivery = $data['delivery'];
|
||||
$homeparty_user->save();
|
||||
}
|
||||
}
|
||||
$homeparty_user = HomepartyUser::findOrFail($data['homeparty_user_id']);
|
||||
HomepartyCart::calculateHomeparty($homeparty);
|
||||
$html_user_cart = view("user.homeparty.show_products_order", ['homeparty' => $homeparty, 'homeparty_guest' => $homeparty_user])->render();
|
||||
$html_bonus = view("user.homeparty.show_bonus", ['homeparty' => $homeparty])->render();
|
||||
$html_host_bonus = view("user.homeparty.show_calc_bonus_host")->render();
|
||||
$html_total = view("user.homeparty.show_total_order", ['homeparty' => $homeparty])->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_user_cart'=>$html_user_cart, 'html_bonus'=>$html_bonus, 'html_host_bonus'=>$html_host_bonus, 'html_total'=>$html_total]);
|
||||
}
|
||||
|
||||
|
||||
return response()->json(['response' => false, 'data'=>$data]);
|
||||
}
|
||||
|
||||
HomepartyCart::calculateHomeparty($homeparty);
|
||||
if(\App\Services\HomepartyCart::$price === 0){
|
||||
\Session()->flash('alert-error', __('msg.your_shopping_cart_is_empty_please_add_products_first'));
|
||||
return redirect(route('user_homeparty_order', [$homeparty->id]));
|
||||
}
|
||||
|
||||
//save the calucalte card!
|
||||
$time = time();
|
||||
$date = date('d.m.Y H:i:s', $time);
|
||||
$user = User::find(Auth::user()->id);
|
||||
Yard::instance('shopping')->destroy();
|
||||
$cartItem = Yard::instance('shopping')->add($homeparty->id, 'Bestellung Homeparty '.$date, 1, \App\Services\HomepartyCart::$ek_price, false, false, ['image' => "", 'slug' => $time, 'weight' => 0]);
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
|
||||
HomepartyCart::store($identifier, $date);
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'homeparty';
|
||||
|
||||
if($homeparty->getCardInfo('user_tax_free')){
|
||||
$data['shop_price'] = HomepartyCart::getFormattedEkPrice();
|
||||
$data['shop_price_net'] = HomepartyCart::getFormattedEkPrice();
|
||||
$data['shop_price_tax'] = 0;
|
||||
$data['user_tax_free'] = true;
|
||||
}else{
|
||||
$data['shop_price'] = HomepartyCart::getFormattedEkPrice();
|
||||
$data['shop_price_net'] = HomepartyCart::getFormattedEkPriceNet();
|
||||
$data['shop_price_tax'] = HomepartyCart::getFormattedEkPriceTax();
|
||||
$data['user_tax_free'] = false;
|
||||
}
|
||||
|
||||
$data['homeparty_id'] = $homeparty->id;
|
||||
$data['is_for'] = 'hp';
|
||||
$data['user_price_infos'] = $homeparty->card_info;
|
||||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for nuy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 5, //Berater Homeparty
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
|
||||
HomepartyCart::store($identifier, $date);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'payment_homeparty', 'status'=>1, 'referenz'=>$homeparty->id, 'identifier'=>$identifier]);
|
||||
//$path = str_replace('http', 'https', $path);
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
|
||||
|
||||
public function delete($do, $id = null, $gid=null)
|
||||
{
|
||||
$homeparty = $this->getHomparty($id);
|
||||
|
||||
if($do === 'hpu'){
|
||||
$homeparty_user = HomepartyUser::findOrFail($gid);
|
||||
if($homeparty->id !== $homeparty_user->homeparty_id){
|
||||
abort(404);
|
||||
}
|
||||
if($homeparty_user->homeparty_user_order_items){
|
||||
foreach($homeparty_user->homeparty_user_order_items as $homeparty_user_order_item){
|
||||
$homeparty_user_order_item->delete();
|
||||
}
|
||||
}
|
||||
//$homeparty_user->save();
|
||||
$homeparty_user->delete();
|
||||
\Session()->flash('alert-success', __('msg.homeparty_guest_delete'));
|
||||
return redirect(route('user_homeparty_guests', [$homeparty->id]));
|
||||
|
||||
}
|
||||
if($do === 'hp') {
|
||||
|
||||
foreach ($homeparty->homeparty_users as $homeparty_user){
|
||||
if ($homeparty->id !== $homeparty_user->homeparty_id) {
|
||||
abort(404);
|
||||
}
|
||||
if($homeparty_user->homeparty_user_order_items){
|
||||
foreach($homeparty_user->homeparty_user_order_items as $homeparty_user_order_item){
|
||||
$homeparty_user_order_item->delete();
|
||||
}
|
||||
}
|
||||
$homeparty_user->delete();
|
||||
}
|
||||
if($homeparty->homeparty_order_items){
|
||||
foreach($homeparty->homeparty_order_items as $homeparty_order_item){
|
||||
$homeparty_order_item->delete();
|
||||
}
|
||||
}
|
||||
$homeparty->delete();
|
||||
\Session()->flash('alert-success', __('msg.homeparty_delete'));
|
||||
return redirect(route('user_homepartys'));
|
||||
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
private function getHomparty($id){
|
||||
$homeparty = Homeparty::findOrFail($id);
|
||||
if($homeparty->auth_user_id !== \Auth::user()->id){
|
||||
abort(404);
|
||||
}
|
||||
return $homeparty;
|
||||
}
|
||||
|
||||
public function datatable($homeparty_id){
|
||||
|
||||
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '4');
|
||||
$homeparty = Homeparty::findOrFail($homeparty_id);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('add_card', function (Product $product) use ($homeparty) {
|
||||
if($homeparty->getCardInfo('user_tax_free')){
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'">
|
||||
<strong>€ '.$product->getFormattedPriceWith(true, false, $homeparty->getUserCountry()).'</strong> +<span class="ion ion-md-cart"></span>
|
||||
</button>';
|
||||
}else{
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'">
|
||||
<strong>€ '.$product->getFormattedPriceWith(false, false, $homeparty->getUserCountry()).'</strong> +<span class="ion ion-md-cart"></span>
|
||||
</button>';
|
||||
}
|
||||
|
||||
})
|
||||
->addColumn('picture', function (Product $product) {
|
||||
if(count($product->images)){
|
||||
return '<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">';
|
||||
}
|
||||
return "";
|
||||
})
|
||||
/*->addColumn('price_net', function (Product $product) use ($homeparty) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, true, $homeparty->getUserCountry()). " €</span>".
|
||||
'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, $homeparty->getUserCountry()).'</span>';
|
||||
})
|
||||
*/
|
||||
->addColumn('price_gross', function (Product $product) use ($homeparty) {
|
||||
if($homeparty->getCardInfo('user_tax_free')){
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, true, $homeparty->getUserCountry()). " €</span>".
|
||||
'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, $homeparty->getUserCountry()).'</span>';
|
||||
}else{
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, true, $homeparty->getUserCountry()). " €</span>".
|
||||
'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, true, $homeparty->getUserCountry()).'</span>';
|
||||
}
|
||||
})
|
||||
->addColumn('price_vk_gross', function (Product $product) use ($homeparty) {
|
||||
if($homeparty->getCardInfo('user_tax_free')){
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, false, $homeparty->getUserCountry()). " €</span>".
|
||||
'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, false, $homeparty->getUserCountry()).'</span>';
|
||||
}else{
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, false, $homeparty->getUserCountry()). " €</span>".
|
||||
'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, false, $homeparty->getUserCountry()).'</span>';
|
||||
}
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
})
|
||||
->filterColumn('product', function($query, $keyword) {
|
||||
if($keyword != ""){
|
||||
$query->where('name', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('name', 'name $1')
|
||||
->orderColumn('product', 'name $1')
|
||||
->orderColumn('number', 'number $1')
|
||||
->orderColumn('points', 'points $1')
|
||||
->orderColumn('price_net', 'price_net $1')
|
||||
->orderColumn('price_gross', 'price_gross $1')
|
||||
->orderColumn('price_vk_gross', 'price $1')
|
||||
->orderColumn('contents_total', 'contents_total $1')
|
||||
->orderColumn('weight', 'weight $1')
|
||||
|
||||
->rawColumns(['add_card', 'product', 'quantity', 'picture', 'price_net', 'price_gross', 'price_vk_gross', 'action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
}
|
||||
240
dev/app-bak/Http/Controllers/User/MembershipController.php
Executable file
240
dev/app-bak/Http/Controllers/User/MembershipController.php
Executable file
|
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use Auth;
|
||||
use Util;
|
||||
use Yard;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Mail\MailInfo;
|
||||
use App\Models\Product;
|
||||
use App\Services\Payment;
|
||||
use App\Models\UserHistory;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\UserService;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
|
||||
class MembershipController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
$diff_months = 0;
|
||||
|
||||
if($user->payment_account){
|
||||
$diff_months = Carbon::now()->diffInMonths(Carbon::parse($user->payment_account)) +1;
|
||||
}
|
||||
|
||||
$userShoppingOrders = ShoppingOrder::with('shopping_user', 'shopping_payments')->select('shopping_orders.*')
|
||||
->where('auth_user_id', '=', $user->id)
|
||||
->where('txaction', '!=', NULL)
|
||||
->whereIn('payment_for', [1, 2])
|
||||
->orderBy('created_at', 'DESC')
|
||||
->get();
|
||||
|
||||
$userHistoryPaymentOrder = null;
|
||||
$userHistoryUpgradeOrder = null;
|
||||
|
||||
/* Bezhalung ist nur 29 Tage vor ablauf möglich */
|
||||
/* isRenewalAccount payment_account date - config('mivita.renewal_days') Vertragsverlängerung */
|
||||
if($user->isRenewalAccount()){
|
||||
//Acount ist noch nicht verlängert / bezahlt
|
||||
if ($user->payment_account) {
|
||||
//Die Order muss größer als das Datum sein.
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
|
||||
$userHistoryPaymentOrder = UserHistory::whereUserId($user->id)->whereAction('payment_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
|
||||
}
|
||||
}
|
||||
if($user->isActiveAccount() && !$user->isActiveShop()){
|
||||
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
|
||||
$userHistoryUpgradeOrder = UserHistory::whereUserId($user->id)->whereAction('upgrade_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
|
||||
|
||||
}
|
||||
$userHistoryDeleteMembership = UserHistory::whereUserId($user->id)->whereAction('delete_membership')->whereStatus(50)->get()->last();
|
||||
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if(!$shipping_country_id){
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
|
||||
$data = [
|
||||
'user' => $user,
|
||||
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
|
||||
'upgrade' => Product::where('active', true)->whereJsonContains('show_on', '8')->where('identifier', 'upgrade')->get(),
|
||||
'diff_months' => $diff_months,
|
||||
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
|
||||
'userHistoryUpgradeOrder' => $userHistoryUpgradeOrder,
|
||||
'userHistoryDeleteMembership' => $userHistoryDeleteMembership,
|
||||
'yard_info' => UserService::getYardInfo(),
|
||||
'userShoppingOrders' => $userShoppingOrders,
|
||||
];
|
||||
return view('user.membership.index', $data);
|
||||
|
||||
}
|
||||
|
||||
private function checkShoppingCountry($user ){
|
||||
|
||||
$country_id = null;
|
||||
if($user->account->same_as_billing){
|
||||
$country_id = $user->account->country_id;
|
||||
}else{
|
||||
$country_id = $user->account->shipping_country_id;
|
||||
}
|
||||
if($country_id){
|
||||
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
|
||||
return $shipping_country->id;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function storePayment($action){
|
||||
|
||||
|
||||
$data = Request::all();
|
||||
|
||||
//#### remove_abo
|
||||
if($action === "remove_abo"){
|
||||
if(Request::get('abo_options_remove')){
|
||||
$user = User::find(Auth::user()->id);
|
||||
$user->abo_options = false;
|
||||
$user->save();
|
||||
$user->account->payment_data = null;
|
||||
$user->account->save();
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'abo_options_remove', 'status'=>10]);
|
||||
\Session()->flash('alert-success', __('msg.abo_deaktivert'));
|
||||
return back();
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
return back();
|
||||
}
|
||||
//#### payment order
|
||||
//#### shop upgrade
|
||||
if($action === "upgrade_order" || $action === "payment_order"){
|
||||
if(Request::get('switchers-package-wizard')){
|
||||
$user = User::find(Auth::user()->id);
|
||||
Yard::instance('shopping')->destroy();
|
||||
$product = Product::find(Request::get('switchers-package-wizard'));
|
||||
$showAboOptions = false;
|
||||
if(Request::get('abo_options')){
|
||||
$showAboOptions = false; //true Abo Option deaktivert
|
||||
$user->abo_options = false; //true Abo Option deaktivert
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$shipping_country_id = $this->checkShoppingCountry($user);
|
||||
if(!$shipping_country_id){
|
||||
abort(403, __('validation.custom.shipping_not_found'));
|
||||
}
|
||||
|
||||
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
|
||||
Yard::instance('shopping')->setUserPriceInfos(UserService::getYardInfo());
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id);
|
||||
|
||||
|
||||
if($product && $product->active){
|
||||
$image = "";
|
||||
if($product->images->count()){
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$qty = Request::get('qty') ? Request::get('qty') : 1;
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
|
||||
if(\App\Services\UserService::getTaxFree()){
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}else{
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
|
||||
}
|
||||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
|
||||
$data = [];
|
||||
$data['is_from'] = 'membership';
|
||||
$data['is_for'] = 'me';
|
||||
$data['user_price_infos'] = \App\Services\UserService::getUserPriceInfos();
|
||||
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, //is first faker shop for nuy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 3, //Berater Membership
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
//add to DB
|
||||
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>1, 'product_id'=>$product->id, 'identifier'=>$identifier, 'abo_options'=>$showAboOptions]);
|
||||
//$path = str_replace('http', 'https', $path);
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($action === "change_order"){
|
||||
if(Request::get('switchers-package-wizard')){
|
||||
$user = User::find(Auth::user()->id);
|
||||
$product = Product::find(Request::get('switchers-package-wizard'));
|
||||
if($user->payment_order_id == $product->id){
|
||||
\Session()->flash('alert-success', __('msg.no_change_made'));
|
||||
return back();
|
||||
}
|
||||
if($product && $product->active){
|
||||
$user->payment_order_id = $product->id;
|
||||
$user->save();
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>10, 'product_id'=>$product->id]);
|
||||
\Session()->flash('alert-success', __('msg.booked_package_has_been_changed'));
|
||||
return back();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if($action === "delete_membership"){
|
||||
if(Request::get('delete_membership_mivita')){
|
||||
//TODO
|
||||
$user = User::find(Auth::user()->id);
|
||||
if($user->isTestMode()){
|
||||
$mail = config('app.info_test_mail');
|
||||
}else{
|
||||
$mail = config('app.info_mail');
|
||||
}
|
||||
Mail::to($mail)->send(new MailInfo($user, 'delete_membership'));
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>50]);
|
||||
\Session()->flash('alert-success', __('msg.cancel_membership_is_requested'));
|
||||
return back();
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
return back();
|
||||
|
||||
}
|
||||
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
|
||||
return back();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
965
dev/app-bak/Http/Controllers/User/OrderController.php
Executable file
965
dev/app-bak/Http/Controllers/User/OrderController.php
Executable file
|
|
@ -0,0 +1,965 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\MailCustomPaymet;
|
||||
use App\Models\Product;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserHistory;
|
||||
use App\Services\AboHelper;
|
||||
use App\Services\OrderPaymentService;
|
||||
use App\Services\Payment;
|
||||
use App\Services\Shop;
|
||||
use App\Services\UserService;
|
||||
use App\Services\Util;
|
||||
use App\Services\MyLog;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request as IlluminateRequest;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Request;
|
||||
use Validator;
|
||||
use Yard;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
private const LOG_CHANNEL = 'order_controller';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('user.order.index');
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
$shopping_order = ShoppingOrder::findOrFail($id);
|
||||
|
||||
if ($shopping_order->auth_user_id !== $user->id) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Unauthorized access attempt to order #{$id} by user #{$user->id}");
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if ($shopping_order->payment_for === 6 || $shopping_order->payment_for === 7) {
|
||||
Log::channel(self::LOG_CHANNEL)->info("Redirecting user #{$user->id} to customer order detail for order #{$id}");
|
||||
return redirect(route('user_shop_order_detail', [$shopping_order->id]));
|
||||
}
|
||||
|
||||
$shopping_order->getLastShoppingPayment();
|
||||
|
||||
return view('user.order.detail', [
|
||||
'shopping_order' => $shopping_order,
|
||||
'isAdmin' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function ordersDatatable()
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
$query = ShoppingOrder::with('shopping_user', 'shopping_payments')
|
||||
->select('shopping_orders.*')
|
||||
->where('auth_user_id', '=', $user->id)
|
||||
->where('txaction', '!=', NULL);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<a href="'.route('user_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 '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping()." €</span>";
|
||||
})
|
||||
->addColumn('payment', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('getPaymentType');
|
||||
})
|
||||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
if ($ShoppingOrder->payment_for === 8) {
|
||||
return '<button type="button" class="btn btn-xs btn-info btn-round" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$ShoppingOrder->id.'"
|
||||
data-action="shop-user-order-shipping-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="user"
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
|
||||
}
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>';
|
||||
})
|
||||
->addColumn('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getPaymentForBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
})
|
||||
->addColumn('reference', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->getLastShoppingPayment('reference');
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('shipped', 'shipped $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
->orderColumn('payment_for', 'payment_for $1')
|
||||
->rawColumns(['id', 'txaction', 'payment_for', 'total_shipping', 'invoice', 'shipped'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/*
|
||||
$for = me, ot-member, ot-customer, abo-ot-member, abo-ot-customer, abo-me
|
||||
*/
|
||||
public function delivery($for, $id = null)
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
$shopping_user = null;
|
||||
$delivery_id = null;
|
||||
|
||||
if (strpos($for, 'ot') !== false) {
|
||||
$shopping_user = Shop::checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
|
||||
if (!Shop::checkShoppingCountry($for, $delivery_id) && !\Session()->has('custom-error')) {
|
||||
$country = Shop::getDeliveryCountry($for, $delivery_id);
|
||||
\Session()->flash('custom-error', $country.": ".__('validation.custom.shipping_not_found'));
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Shipping country not found for user #{$user->id}, country: {$country}");
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
|
||||
if ($for === 'abo-ot-customer') {
|
||||
if (AboHelper::hasAboByEmail($shopping_user->billing_email) && !\Session()->has('custom-error')) {
|
||||
\Session()->flash('custom-error', __('abo.error_email_has_abo', ['email' => $shopping_user->billing_email]));
|
||||
Log::channel(self::LOG_CHANNEL)->info("User #{$user->id} attempted to create abo for email that already has one: {$shopping_user->billing_email}");
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Request::get('action') === 'next') {
|
||||
Yard::instance('shopping')->destroy();
|
||||
if (strpos(Request::get('switchers-radio-is-for'), 'ot') !== false) {
|
||||
$delivery_id = $id;
|
||||
}
|
||||
return redirect(route('user_order_my_list', [Request::get('switchers-radio-is-for'), $delivery_id]));
|
||||
}
|
||||
|
||||
return view('user.order.delivery', [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
'for' => $for,
|
||||
'delivery_id' => $delivery_id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function list($for, $id = null)
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
||||
if ($for === 'abo-me' && AboHelper::userHasAbo($user)) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("User #{$user->id} attempted to create abo but already has one");
|
||||
abort(403, 'User has an Abo. Cannot order.');
|
||||
}
|
||||
|
||||
$shopping_user = null;
|
||||
$delivery_id = null;
|
||||
|
||||
if (strpos($for, 'ot') !== false) {
|
||||
$shopping_user = Shop::checkShoppingUser($id, $user);
|
||||
$delivery_id = $shopping_user->id;
|
||||
}
|
||||
|
||||
if ($for === 'ot-customer' || $for === 'abo-ot-customer') {
|
||||
UserService::initCustomerYard($shopping_user, $for);
|
||||
} else {
|
||||
$shipping_country_id = Shop::checkShoppingCountry($for, $id);
|
||||
if (!$shipping_country_id) {
|
||||
$country = Shop::getDeliveryCountry($for, $id);
|
||||
\Session()->flash('custom-error', $country.": ".__('validation.custom.shipping_not_found'));
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Shipping country not found for user #{$user->id}, country: {$country}");
|
||||
return redirect(route('user_order_my_delivery', [$for, $delivery_id]));
|
||||
}
|
||||
UserService::initUserYard($user, $shipping_country_id, $for);
|
||||
}
|
||||
|
||||
return view('user.order.list', [
|
||||
'shopping_user' => $shopping_user,
|
||||
'user' => $user,
|
||||
'isAdmin' => false,
|
||||
'isView' => 'customer',
|
||||
'for' => $for,
|
||||
'template' => str_replace('abo-', '', $for),
|
||||
'delivery_id' => $delivery_id,
|
||||
'is_abo' => strpos($for, 'abo') !== false,
|
||||
'comp_products' => Shop::getCompProducts($for),
|
||||
]);
|
||||
}
|
||||
|
||||
public function payment($for, $id = null)
|
||||
{
|
||||
$data = Request::all();
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
||||
$rules = [
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_state' => 'required',
|
||||
];
|
||||
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
Log::channel(self::LOG_CHANNEL)->info("Validation failed for payment form", ['errors' => $validator->errors()->toArray()]);
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
|
||||
try {
|
||||
$this->checkSendYardForPayment($data, $id);
|
||||
} catch (\Exception $e) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Error checking yard for payment: " . $e->getMessage(), [
|
||||
'user_id' => $user->id,
|
||||
'for' => $for,
|
||||
'id' => $id
|
||||
]);
|
||||
return back()->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getNumComp() > 0) {
|
||||
if (!isset($data['switchers-comp-product'])) {
|
||||
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
|
||||
Log::channel(self::LOG_CHANNEL)->info("Compensation product not selected");
|
||||
} else if (!is_array($data['switchers-comp-product'])) {
|
||||
$validator->errors()->add('switchers-comp-product', __('msg.please_select_compensation_product'));
|
||||
Log::channel(self::LOG_CHANNEL)->info("Compensation product selection is not an array");
|
||||
} else if (count($data['switchers-comp-product']) !== Yard::instance('shopping')->getNumComp()) {
|
||||
$validator->errors()->add('switchers-comp-product', __('mdg.please_select_count_compensation_products', ['count' => Yard::instance('shopping')->getNumComp()]));
|
||||
Log::channel(self::LOG_CHANNEL)->info("Incorrect number of compensation products selected", [
|
||||
'required' => Yard::instance('shopping')->getNumComp(),
|
||||
'selected' => count($data['switchers-comp-product'])
|
||||
]);
|
||||
}
|
||||
|
||||
if ($validator->errors()->count()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
}
|
||||
|
||||
// Generate unique identifier
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while (ShoppingInstance::where('identifier', $identifier)->count());
|
||||
|
||||
// Prepare common data
|
||||
$data['is_from'] = 'user_order';
|
||||
$data['is_for'] = $for;
|
||||
$data['is_abo'] = $data['is_abo'] ?? 0;
|
||||
$data['abo_interval'] = $data['abo_interval'] ?? 0;
|
||||
$data['shopping_user_id'] = $id;
|
||||
$data['user_price_infos'] = Yard::instance('shopping')->getUserPriceInfos();
|
||||
$data['mode'] = config('app.mode') === 'test' ? 'test' : 'live';
|
||||
|
||||
// Remove unnecessary data
|
||||
unset($data['quantity']);
|
||||
unset($data['_token']);
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->info("Processing payment for user #{$user->id}", [
|
||||
'for' => $for,
|
||||
'identifier' => $identifier,
|
||||
'is_abo' => $data['is_abo']
|
||||
]);
|
||||
|
||||
if ($for === 'ot-customer' || $for === 'abo-ot-customer') {
|
||||
return $this->processCustomerPayment($user, $identifier, $data, $id, $for);
|
||||
} else {
|
||||
return $this->processUserPayment($user, $identifier, $data, $id, $for);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process payment for customer orders
|
||||
*/
|
||||
private function processCustomerPayment($user, $identifier, $data, $id, $for)
|
||||
{
|
||||
$shopping_instance = ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => $user->shop->id,
|
||||
'payment' => 6, // Berater Shop to Customer Shop
|
||||
'subdomain' => $user->shop->getSubdomain(),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'status' => 0,
|
||||
'shopping_user_id' => $id,
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
]);
|
||||
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$yard_shopping_items = OrderPaymentService::getRestoredYardShoppingItems($shopping_instance);
|
||||
|
||||
// Send Mail to Customer
|
||||
try {
|
||||
$this->customPaymentSendMail($user, $identifier, $yard_shopping_items, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->info("Custom payment email sent successfully", [
|
||||
'identifier' => $identifier,
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Failed to send custom payment email: " . $e->getMessage(), [
|
||||
'identifier' => $identifier,
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
}
|
||||
|
||||
UserHistory::create([
|
||||
'user_id' => $user->id,
|
||||
'action' => 'user_order_customer',
|
||||
'status' => 1,
|
||||
'product_id' => null,
|
||||
'identifier' => $identifier,
|
||||
'is_abo' => $data['is_abo']
|
||||
]);
|
||||
|
||||
return redirect(route('user_order_my_custom_payment', ['identifier' => $identifier]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process payment for user orders
|
||||
*/
|
||||
private function processUserPayment($user, $identifier, $data, $id, $for)
|
||||
{
|
||||
Shop::deleteCheckoutInstance();
|
||||
ShoppingInstance::create([
|
||||
'identifier' => $identifier,
|
||||
'user_shop_id' => 1, // is first faker shop for buy intern
|
||||
'auth_user_id' => Auth::user()->id,
|
||||
'payment' => 2, // Berater Shop
|
||||
'subdomain' => url('/'),
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),
|
||||
'status' => 0,
|
||||
'shopping_user_id' => $id,
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
]);
|
||||
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
|
||||
UserHistory::create([
|
||||
'user_id' => $user->id,
|
||||
'action' => 'user_order_payment',
|
||||
'status' => 1,
|
||||
'product_id' => null,
|
||||
'identifier' => $identifier,
|
||||
'is_abo' => $data['is_abo']
|
||||
]);
|
||||
|
||||
$path = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
return redirect()->secure($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the yard before payment
|
||||
*/
|
||||
private function checkSendYardForPayment($data, $id)
|
||||
{
|
||||
$user = User::find(Auth::user()->id);
|
||||
$shopping_user = null;
|
||||
|
||||
if (strpos($data['shipping_is_for'], 'ot') !== false) {
|
||||
$shopping_user = Shop::checkShoppingUser($id, $user);
|
||||
}
|
||||
|
||||
$shipping_country_id = Shop::checkShoppingCountry($data['shipping_is_for'], $id);
|
||||
if (!$shipping_country_id) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'no shipping_country_id found | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping country not found", $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_country_was_not_found'));
|
||||
}
|
||||
|
||||
// Must be the same shipping country
|
||||
if ($shipping_country_id != Yard::instance('shopping')->getShippingCountryId()) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_country_id,
|
||||
'actual' => Yard::instance('shopping')->getShippingCountryId()
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'shipping_country_id is not the same from Yard | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping country mismatch", $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_country_was_not_correctly'));
|
||||
}
|
||||
|
||||
if ($data['shipping_is_for'] !== 'ot-customer') {
|
||||
if (Yard::instance('shopping')->shipping_free) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard can by not shipping_free | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Yard cannot be shipping free", $logData);
|
||||
|
||||
throw new \Exception(__('msg.shopping_cart_was_shipping_free'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($data['shipping_is_for'] === 'ot-customer') {
|
||||
if (!$user->shop) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'User has no Shop for an User to Customer order| Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("User has no shop for customer order", $logData);
|
||||
|
||||
throw new \Exception(__('msg.shopping_cart_was_not_user_shop'));
|
||||
}
|
||||
}
|
||||
|
||||
$shipping_price = Shop::getShippingPriceByShippingCountryId($shipping_country_id, Yard::instance('shopping')->weight());
|
||||
|
||||
// For other and has weight - check
|
||||
if (strpos($data['shipping_is_for'], 'ot') !== false && $data['shipping_is_for'] !== 'ot-customer' && Yard::instance('shopping')->weight() > 0) {
|
||||
if (!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight()
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is 0 | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price cannot be zero for order with weight", $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->price,
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice()
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard OT shipping_price is not the same from shipping_price | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price mismatch", $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
}
|
||||
|
||||
if (($data['shipping_is_for'] == 'me' || $data['shipping_is_for'] == 'abo-me') && Yard::instance('shopping')->weight() > 0) {
|
||||
if (!Yard::instance('shopping')->getShippingPrice() || Yard::instance('shopping')->getShippingPrice() == 0) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'weight' => Yard::instance('shopping')->weight()
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is 0 | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price cannot be zero for personal order with weight", $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_cost_cannot_be_0'));
|
||||
}
|
||||
|
||||
if(Shop::isCompProducts($data['shipping_is_for'])){
|
||||
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price_comp) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->price_comp,
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice()
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price with comp products | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price mismatch for personal order", $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getNumComp() != $shipping_price->num_comp) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->num_comp,
|
||||
'actual' => Yard::instance('shopping')->getNumComp()
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard num_comp is not correct | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Compensation product count mismatch", $logData);
|
||||
|
||||
throw new \Exception(__('msg.compensation_products_cannot_be_0'));
|
||||
}
|
||||
}else{
|
||||
if (Yard::instance('shopping')->getShippingPrice() != $shipping_price->price) {
|
||||
$identifier = 'error-' . time() . mt_rand(1000000, 9999999);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
$logData = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'shopping_user_id' => $id,
|
||||
'yard_identifier' => $identifier,
|
||||
'expected' => $shipping_price->price,
|
||||
'actual' => Yard::instance('shopping')->getShippingPrice()
|
||||
];
|
||||
|
||||
MyLog::writeLog('payment', 'error', 'Yard ME shipping_price is not the same from shipping_price without comp products | Yard identifier: ' . $identifier, $data);
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shipping price mismatch for personal order", $logData);
|
||||
|
||||
throw new \Exception(__('msg.shipping_costs_were_not_calculated_correctly'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable()
|
||||
{
|
||||
$isAbo = Request::get('is_abo');
|
||||
$shippingIsFor = Request::get('shipping_is_for');
|
||||
|
||||
if ($shippingIsFor === 'me' || $shippingIsFor === 'abo-me') {
|
||||
$show_on_ids = $isAbo ? ['12', '13'] : ['2'];
|
||||
|
||||
$query = Product::with('product_buyings')
|
||||
->select('products.*')
|
||||
->where('products.active', true)
|
||||
->where(function($q) use ($show_on_ids) {
|
||||
foreach ($show_on_ids as $id) {
|
||||
$q->orWhereJsonContains('show_on', $id);
|
||||
}
|
||||
})
|
||||
->orderByRaw("CASE
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 1
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 2
|
||||
ELSE 3 END",
|
||||
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]);
|
||||
} else {
|
||||
$show_on_ids = $isAbo ? ['12', '13'] : ['3'];
|
||||
|
||||
$query = Product::select('products.*')
|
||||
->where('active', true)
|
||||
->where(function($q) use ($show_on_ids) {
|
||||
foreach ($show_on_ids as $id) {
|
||||
$q->orWhereJsonContains('show_on', $id);
|
||||
}
|
||||
})
|
||||
->orderByRaw("CASE
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 1
|
||||
WHEN JSON_CONTAINS(show_on, ?, '$') THEN 2
|
||||
ELSE 3 END",
|
||||
[$show_on_ids[0], isset($show_on_ids[1]) ? $show_on_ids[1] : $show_on_ids[0]]);
|
||||
}
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->info("Datatable query executed", [
|
||||
'is_abo' => $isAbo,
|
||||
'shipping_is_for' => $shippingIsFor,
|
||||
'show_on_ids' => $show_on_ids
|
||||
]);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('product', function (Product $product) {
|
||||
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
|
||||
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
|
||||
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
|
||||
return '<strong>'.$product->getLang('name').'</strong><br>
|
||||
<div class="no-line-break input-group-min-w">
|
||||
<div class="input-group d-inline-flex w-auto">
|
||||
<span class="input-group-prepend">
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra remove-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">-</button>
|
||||
</span>
|
||||
<input type="text" class="form-control text-center input-extra table-input-event-onchange" name="product_qty_'.$product->id.'" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'" value="'.$qty.'">
|
||||
<span class="input-group-append">
|
||||
<button type="button" class="btn btn-secondary icon-btn md-btn-extra add-product-basket" data-row-id="'.$rowId.'" data-product-id="'.$product->id.'">+</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>';
|
||||
})
|
||||
->addColumn('abo', function (Product $product) {
|
||||
return AboHelper::getAboTypeBadge(AboHelper::getAboShowOn($product));
|
||||
})
|
||||
->addColumn('picture', function (Product $product) {
|
||||
if(count($product->images)){
|
||||
return '<img class="img-fluid img-extra" alt="" src="'.route('product_image', [$product->images->first()->slug]).'">';
|
||||
}
|
||||
return "";
|
||||
})
|
||||
->addColumn('price_net', function (Product $product) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, true, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('price_gross', function (Product $product) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, true, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, true, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('price_vk_gross', function (Product $product) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('customer_price_net', function (Product $product) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('customer_price_gross', function (Product $product) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(false, false, Yard::instance('shopping')->getUserCountry()). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(false, false, Yard::instance('shopping')->getUserCountry()).'</span>';
|
||||
})
|
||||
->addColumn('my_commission_net', function (Product $product) {
|
||||
return '<span class="no-line-break">'.$product->getFormattedPriceWith(true, false, Yard::instance('shopping')->getUserCountry(), true). " €</span>".'<span class="no-line-break">'.$product->getFormattedPriceCurrencyWith(true, false, Yard::instance('shopping')->getUserCountry(), true).'</span>';
|
||||
})
|
||||
->addColumn('action', function (Product $product) {
|
||||
return '<button class="btn btn-default btn-sm icon-btn md-btn-flat product-tooltip" title="details" data-modal="modal-lg"
|
||||
data-toggle="modal" data-target="#modals-load-content" data-id="'.$product->id.'" data-route="'.route('modal_load').'"
|
||||
data-action="user-order-show-product" data-view="customer"><i class="ion ion-md-eye"></i></button>';
|
||||
})
|
||||
->filterColumn('product', function($query, $keyword) {
|
||||
if($keyword != ""){
|
||||
$query->where('name', 'LIKE', '%'.$keyword.'%');
|
||||
}
|
||||
})
|
||||
->orderColumn('name', 'name $1')
|
||||
->orderColumn('product', 'name $1')
|
||||
->orderColumn('number', 'number $1')
|
||||
->orderColumn('points', 'points $1')
|
||||
->orderColumn('price_net', 'price_net $1')
|
||||
->orderColumn('price_gross', 'price_gross $1')
|
||||
->orderColumn('price_vk_gross', 'price $1')
|
||||
->orderColumn('customer_price_net', 'price $1')
|
||||
->orderColumn('customer_price_gross', 'price $1')
|
||||
->orderColumn('my_commission_net', 'price $1')
|
||||
->orderColumn('contents_total', 'contents_total $1')
|
||||
->orderColumn('weight', 'weight $1')
|
||||
->orderColumn('abo', 'show_on $1')
|
||||
->rawColumns(['add_card', 'price_net', 'price_gross', 'price_vk_gross', 'customer_price_net', 'customer_price_gross', 'my_commission_net', 'product', 'quantity', 'picture', 'abo', 'action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle AJAX requests for cart operations
|
||||
*/
|
||||
public function performRequest()
|
||||
{
|
||||
if (!Request::ajax()) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Non-AJAX request to performRequest method");
|
||||
return response()->json(['response' => false, 'message' => 'Only AJAX requests are allowed']);
|
||||
}
|
||||
|
||||
$data = Request::all();
|
||||
$is_for = isset($data['shipping_is_for']) ? $data['shipping_is_for'] : 'ot-member';
|
||||
$data['for'] = $is_for;
|
||||
$data['comp_products'] = Shop::getCompProducts($is_for);
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->info("Performing cart action", [
|
||||
'action' => $data['action'] ?? 'unknown',
|
||||
'is_for' => $is_for
|
||||
]);
|
||||
|
||||
if ($data['action'] === 'updateCart' && isset($data['product_id'])) {
|
||||
return $this->handleUpdateCart($data, $is_for);
|
||||
}
|
||||
|
||||
if ($data['action'] === 'clearCart') {
|
||||
Yard::instance('shopping')->destroy();
|
||||
Log::channel(self::LOG_CHANNEL)->info("Cart cleared");
|
||||
return response()->json(['response' => true, 'data' => Yard::instance('shopping')->count(), 'html_card' => '', 'html_comp' => '']);
|
||||
}
|
||||
|
||||
if ($data['action'] === 'updateShippingCountry') {
|
||||
return $this->handleUpdateShippingCountry($data, $is_for);
|
||||
}
|
||||
|
||||
if ($data['action'] === 'updateCompProduct') {
|
||||
return $this->handleUpdateCompProduct($data, $is_for);
|
||||
}
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Unknown action in performRequest", ['action' => $data['action'] ?? 'not set']);
|
||||
return response()->json(['response' => false, 'data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle updating cart items
|
||||
*/
|
||||
private function handleUpdateCart($data, $is_for)
|
||||
{
|
||||
$product = Product::find($data['product_id']);
|
||||
if (!$product) {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Product not found for cart update", ['product_id' => $data['product_id']]);
|
||||
return response()->json(['response' => false, 'message' => 'Product not found']);
|
||||
}
|
||||
|
||||
$image = "";
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
|
||||
// Get the cart item
|
||||
if ($is_for === 'ot-customer' || $is_for === 'abo-ot-customer') {
|
||||
$cartItem = Yard::instance('shopping')
|
||||
->add($product->id, $product->getLang('name'), 1,
|
||||
round($product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), false, Yard::instance('shopping')->getUserCountry()), 1), false, false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
|
||||
} else {
|
||||
$cartItem = Yard::instance('shopping')
|
||||
->add($product->id, $product->getLang('name'), 1,
|
||||
$product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), true, Yard::instance('shopping')->getUserCountry()), false, false,
|
||||
['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
|
||||
}
|
||||
|
||||
if (Yard::instance('shopping')->getUserTaxFree()) {
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
} else {
|
||||
Yard::setTax($cartItem->rowId, $product->getTaxWith(Yard::instance('shopping')->getUserCountry()));
|
||||
}
|
||||
|
||||
if (isset($data['qty']) && $data['qty'] > 0) {
|
||||
Yard::instance('shopping')->update($cartItem->rowId, $data['qty']);
|
||||
Log::channel(self::LOG_CHANNEL)->info("Cart item updated", [
|
||||
'product_id' => $product->id,
|
||||
'product_name' => $product->getLang('name'),
|
||||
'qty' => $data['qty']
|
||||
]);
|
||||
} else {
|
||||
// If 0 get the item by qty:1 and remove it
|
||||
Yard::instance('shopping')->remove($cartItem->rowId);
|
||||
Log::channel(self::LOG_CHANNEL)->info("Cart item removed", [
|
||||
'product_id' => $product->id,
|
||||
'product_name' => $product->getLang('name')
|
||||
]);
|
||||
}
|
||||
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
|
||||
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle updating shipping country
|
||||
*/
|
||||
private function handleUpdateShippingCountry($data, $is_for)
|
||||
{
|
||||
if (isset($data['shipping_country_id'])) {
|
||||
$shipping_country = ShippingCountry::find($data['shipping_country_id']);
|
||||
if ($shipping_country) {
|
||||
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for);
|
||||
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->info("Shipping country updated", [
|
||||
'shipping_country_id' => $shipping_country->id,
|
||||
'shipping_country_name' => $shipping_country->name ?? 'unknown'
|
||||
]);
|
||||
} else {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Shipping country not found", [
|
||||
'shipping_country_id' => $data['shipping_country_id']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle updating compensation products
|
||||
*/
|
||||
private function handleUpdateCompProduct($data, $is_for)
|
||||
{
|
||||
$this->updateCompProduct($data);
|
||||
Yard::instance('shopping')->reCalculateShippingPrice();
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->info("Compensation product updated", [
|
||||
'comp_product_id' => $data['comp_product_id'] ?? null,
|
||||
'comp_num' => $data['comp_num'] ?? null,
|
||||
'count_comp_products' => $data['count_comp_products'] ?? null
|
||||
]);
|
||||
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
|
||||
return response()->json(['response' => true, 'data' => $data, 'html_card' => $html_card, 'html_comp' => $html_comp]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and remove compensation products if needed
|
||||
*/
|
||||
private function checkCompProduct($count_comp_products)
|
||||
{
|
||||
foreach (Yard::instance('shopping')->content() as $row) {
|
||||
// If equal or greater, delete due to new shipping costs
|
||||
if ($row->options->comp && $row->options->comp > intval($count_comp_products)) {
|
||||
Yard::instance('shopping')->remove($row->rowId);
|
||||
Log::channel(self::LOG_CHANNEL)->info("Compensation product removed due to count change", [
|
||||
'product_id' => $row->id,
|
||||
'product_name' => $row->name,
|
||||
'comp_value' => $row->options->comp,
|
||||
'required_comp' => $count_comp_products
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update compensation products
|
||||
*/
|
||||
private function updateCompProduct($data)
|
||||
{
|
||||
// Clear old
|
||||
foreach (Yard::instance('shopping')->content() as $row) {
|
||||
// If count_comp_products is smaller, the product was removed due to quantity
|
||||
// if comp_num equals the comp product, the product was removed due to new shipping costs
|
||||
//count_comp_products wie viele comp products werden gebraucht
|
||||
//comp_num welches comp product wird hinzugefügt
|
||||
if ($row->options->comp && ($row->options->comp == intval($data['comp_num']) || $row->options->comp > intval($data['count_comp_products']))) {
|
||||
Yard::instance('shopping')->remove($row->rowId);
|
||||
Log::channel(self::LOG_CHANNEL)->info("Compensation product removed during update", [
|
||||
'product_id' => $row->id,
|
||||
'product_name' => $row->name,
|
||||
'comp_value' => $row->options->comp,
|
||||
'comp_num' => $data['comp_num'],
|
||||
'count_comp_products' => $data['count_comp_products']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['comp_product_id'])) {
|
||||
$product = Product::find($data['comp_product_id']);
|
||||
if ($product) {
|
||||
$image = "";
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, false, false, [
|
||||
'image' => $image,
|
||||
'slug' => $product->slug,
|
||||
'weight' => 0,
|
||||
'points' => 0,
|
||||
'comp' => intval($data['comp_num']),
|
||||
'product_id' => $product->id
|
||||
]
|
||||
);
|
||||
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->info("Compensation product added", [
|
||||
'product_id' => $product->id,
|
||||
'product_name' => $product->getLang('name'),
|
||||
'comp_num' => $data['comp_num']
|
||||
]);
|
||||
} else {
|
||||
Log::channel(self::LOG_CHANNEL)->warning("Compensation product not found", [
|
||||
'comp_product_id' => $data['comp_product_id']
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display custom payment page
|
||||
*/
|
||||
public function customPayment($identifier)
|
||||
{
|
||||
try {
|
||||
$data = OrderPaymentService::getCustomPayment($identifier);
|
||||
Log::channel(self::LOG_CHANNEL)->info("Custom payment page accessed", ['identifier' => $identifier]);
|
||||
return view('user.order.payment.custom_payment', $data);
|
||||
} catch (\Exception $e) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Error accessing custom payment: " . $e->getMessage(), ['identifier' => $identifier]);
|
||||
abort(404, 'Custom payment not found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send custom payment email
|
||||
*/
|
||||
private function customPaymentSendMail($user, $identifier, $yard_shopping_items, $data)
|
||||
{
|
||||
$bcc = [];
|
||||
$shopping_instance = ShoppingInstance::where('identifier', $identifier)->first();
|
||||
|
||||
if (!$shopping_instance) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shopping instance not found for email", ['identifier' => $identifier]);
|
||||
throw new \Exception(__('msg.shopping_instance_not_found'));
|
||||
}
|
||||
|
||||
$shopping_user = $data['shopping_user_id'] ? ShoppingUser::find($data['shopping_user_id']) : null;
|
||||
|
||||
if (!$shopping_user) {
|
||||
Log::channel(self::LOG_CHANNEL)->error("Shopping user not found for email", ['shopping_user_id' => $data['shopping_user_id']]);
|
||||
throw new \Exception(__('msg.shopping_user_not_found'));
|
||||
}
|
||||
|
||||
$route = route('checkout.checkout_card', ['identifier' => $identifier]);
|
||||
|
||||
$billing_email = $shopping_user->billing_email;
|
||||
if (!$billing_email) {
|
||||
$billing_email = $data['mode'] === 'test' ? config('app.checkout_test_mail') : config('app.checkout_mail');
|
||||
}
|
||||
|
||||
$bcc[] = $data['mode'] === 'test' ? config('app.checkout_test_mail') : config('app.checkout_mail');
|
||||
$bcc[] = $shopping_user->member ? $shopping_user->member->email : $user->email;
|
||||
|
||||
Log::channel(self::LOG_CHANNEL)->info("Sending custom payment email", [
|
||||
'to' => $billing_email,
|
||||
'bcc' => $bcc,
|
||||
'identifier' => $identifier
|
||||
]);
|
||||
|
||||
Mail::to($billing_email)
|
||||
->bcc($bcc)
|
||||
->locale(\App::getLocale())
|
||||
->send(new MailCustomPaymet($route, $shopping_user, $shopping_instance, $yard_shopping_items, $data['mode']));
|
||||
}
|
||||
}
|
||||
97
dev/app-bak/Http/Controllers/User/OrderPaymentController.php
Normal file
97
dev/app-bak/Http/Controllers/User/OrderPaymentController.php
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Models\ShoppingInstance;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\OrderPaymentService;
|
||||
|
||||
class OrderPaymentController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
];
|
||||
return view('user.order.payment.index', $data);
|
||||
}
|
||||
|
||||
public function detail($identifier)
|
||||
{
|
||||
$data = OrderPaymentService::getCustomPayment($identifier);
|
||||
$data['backlink'] = route('user_order_payment_links');
|
||||
return view('user.order.payment.custom_payment', $data);
|
||||
}
|
||||
|
||||
public function delete($identifier){
|
||||
OrderPaymentService::deleteInstance($identifier);
|
||||
return redirect(route('user_order_payment_links'));
|
||||
}
|
||||
|
||||
public function datatable(){
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$user_shop_id = $user->shop ? $user->shop->id : null;
|
||||
$query = ShoppingInstance::select('*')
|
||||
->where('user_shop_id', '=', $user_shop_id)
|
||||
->where('payment', 6);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingInstance $shoppingInstance) {
|
||||
return '<a href="'.route('user_order_payment_links_detail', [$shoppingInstance->identifier]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingInstance $shoppingInstance) {
|
||||
return $shoppingInstance->created_at->format("d.m.Y");
|
||||
})
|
||||
->addColumn('status', function (ShoppingInstance $shoppingInstance) {
|
||||
return OrderPaymentService::getStatusBadge($shoppingInstance);
|
||||
})
|
||||
->addColumn('payment_method', function (ShoppingInstance $shoppingInstance) {
|
||||
return $shoppingInstance->payment_method ? $shoppingInstance->payment_method->name : '-';
|
||||
})
|
||||
->addColumn('total', function (ShoppingInstance $shoppingInstance) {
|
||||
if($shoppingInstance->amount > 0){
|
||||
return '<span class="no-line-break">'.$shoppingInstance->getAmountFormatted()." €</span>";
|
||||
}else{
|
||||
return '-';
|
||||
}
|
||||
})
|
||||
->addColumn('type', function (ShoppingInstance $shoppingInstance) {
|
||||
return OrderPaymentService::getTypeBadge($shoppingInstance);
|
||||
})
|
||||
->addColumn('billing_firstname', function (ShoppingInstance $shoppingInstance) {
|
||||
return $shoppingInstance->shopping_data['billing_firstname'] ?? '-';
|
||||
})
|
||||
->addColumn('billing_lastname', function (ShoppingInstance $shoppingInstance) {
|
||||
return $shoppingInstance->shopping_data['billing_lastname'] ?? '-';
|
||||
})
|
||||
->addColumn('billing_email', function (ShoppingInstance $shoppingInstance) {
|
||||
return $shoppingInstance->shopping_data['billing_email'] ?? '-';
|
||||
})
|
||||
->addColumn('delete', function (ShoppingInstance $shoppingInstance) {
|
||||
return '<a onclick="return confirm(\''.__('confirm_delete').'\');" href="'.route('user_order_payment_links_delete', [$shoppingInstance->identifier]).'" class="btn icon-btn btn-sm btn-danger"><span class="fa fa-trash"></span></a>';
|
||||
})
|
||||
|
||||
->orderColumn('id', 'identifier $1')
|
||||
->orderColumn('created_at', 'created_at $1')
|
||||
->orderColumn('status', 'status $1')
|
||||
->orderColumn('total', 'total $1')
|
||||
->orderColumn('type', 'type $1')
|
||||
->orderColumn('billing_firstname', 'billing_firstname $1')
|
||||
->orderColumn('billing_lastname', 'billing_lastname $1')
|
||||
->orderColumn('billing_email', 'billing_email $1')
|
||||
->rawColumns(['id', 'status', 'type', 'total', 'invoice', 'delete'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
137
dev/app-bak/Http/Controllers/User/PaymentController.php
Normal file
137
dev/app-bak/Http/Controllers/User/PaymentController.php
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\Credit;
|
||||
use App\Models\UserCredit;
|
||||
use App\Models\UserPayCredit;
|
||||
use App\Models\UserCreditItem;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
|
||||
private $startYear;
|
||||
private $endYear;
|
||||
private $rangeYears;
|
||||
private $activeYear;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
/* $this->startYear = 2021;
|
||||
$this->endYear = date('Y');
|
||||
$this->rangeYears = range($this->startYear, $this->endYear);
|
||||
$this->activeYear = $this->endYear;*/
|
||||
}
|
||||
|
||||
public function credit()
|
||||
{
|
||||
$user = \Auth::user();
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return view('user.payment.credit', $data);
|
||||
}
|
||||
|
||||
|
||||
public function credit_datatable(){
|
||||
|
||||
$user = \Auth::user();
|
||||
$query = UserCredit::with('user', 'user.account')->select('user_credits.*')->where('user_id', $user->id);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('view', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if(Credit::isCredit($UserCredit)){
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a><br>';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'html']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-eye"></i></a> ';
|
||||
$ret .= '<a href="'.route('storage_file', [$UserCredit->id, 'credit_detail', 'pdf']).'" target="_blank" class="btn btn-secondary btn-xs mt-2"><i class="fa fa-file-pdf" style="min-width:13.5px"></i></a> ';
|
||||
|
||||
}else{
|
||||
$ret = "-";
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('total', function (UserCredit $UserCredit) {
|
||||
return $UserCredit->getFormattedTotal()." €";
|
||||
})
|
||||
->addColumn('credits', function (UserCredit $UserCredit) {
|
||||
$ret = "";
|
||||
if($UserCredit->user_credit_items){
|
||||
foreach($UserCredit->user_credit_items as $user_credit_item){
|
||||
$ret .= nl2br($user_credit_item->getTransMessage())." / ".$user_credit_item->created_at->format('d.m.Y')."<br>";
|
||||
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
})
|
||||
->addColumn('status', function (UserCredit $UserCredit) {
|
||||
return '<span class="badge badge-pill badge-'.$UserCredit->getStatusColor().'">'.$UserCredit->getStatusType().' <span class="ion ion-md-cash"></span></span>';
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('status', 'status $1')
|
||||
->orderColumn('total', 'total $1')
|
||||
->rawColumns(['total', 'credits', 'status', 'view'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function credit_item_datatable(){
|
||||
|
||||
$user = \Auth::user();
|
||||
$query = UserCreditItem::select('user_credit_items.*')->where('user_id', $user->id);
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('message', function (UserCreditItem $user_credit_item) {
|
||||
return nl2br($user_credit_item->getTransMessage());
|
||||
})
|
||||
->addColumn('credit', function (UserCreditItem $user_credit_item) {
|
||||
return formatNumber($user_credit_item->credit)." €";
|
||||
})
|
||||
->addColumn('created_at', function (UserCreditItem $user_credit_item) {
|
||||
return formatDate($user_credit_item->created_at);
|
||||
})
|
||||
->addColumn('status', function (UserCreditItem $user_credit_item) {
|
||||
return '<span class="badge badge-pill badge-'.$user_credit_item->getStatusColor().'">'.$user_credit_item->getStatusType().'</span> ';
|
||||
})
|
||||
->addColumn('paid', function (UserCreditItem $user_credit_item) {
|
||||
return ($user_credit_item->paid && $user_credit_item->user_credit) ?
|
||||
'<span class="badge badge-pill badge-success"><i class="fa fa-check"></i> '.$user_credit_item->user_credit->full_number.'</span>'
|
||||
: '<span class="badge badge-pill badge-warning"><i class="fa fa-times"></i></span>';
|
||||
})
|
||||
|
||||
->orderColumn('message', 'message $1')
|
||||
->orderColumn('credit', 'credit $1')
|
||||
->orderColumn('created_at', 'created_at $1')
|
||||
->orderColumn('status', 'status $1')
|
||||
->rawColumns(['message', 'status', 'paid'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
/*private function setActiveYears(){
|
||||
if(Request::get('filter_year')){
|
||||
$this->activeYear = Request::get('filter_year');
|
||||
}
|
||||
}
|
||||
|
||||
public function revenue()
|
||||
{
|
||||
$this->setActiveYears();
|
||||
|
||||
$user = \Auth::user();
|
||||
$data = [
|
||||
'user' => $user,
|
||||
'years' => $this->rangeYears,
|
||||
'active_year' => $this->activeYear,
|
||||
'months' => range(1, 12),
|
||||
];
|
||||
return view('user.payment.revenue', $data);
|
||||
}*/
|
||||
}
|
||||
171
dev/app-bak/Http/Controllers/User/ShopApiController.php
Normal file
171
dev/app-bak/Http/Controllers/User/ShopApiController.php
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use Request;
|
||||
use App\User;
|
||||
use App\Services\Payment;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\ShopApiRepository;
|
||||
|
||||
|
||||
|
||||
|
||||
class ShopApiController extends Controller
|
||||
{
|
||||
|
||||
private $api_action = [0 => 'bitte wählen', 'order' => 'markierte bezahlen', 'remove' => 'markierte entfernen', 'reset' => 'markierte zurücksetzen/bestellt'];
|
||||
private $filter_show = [10 => 'alle anzeigen', 1 => 'bestellt', 2 => 'bezahlt', 5 => 'entfernt'];
|
||||
protected $shopApiRepository;
|
||||
|
||||
public function __construct(ShopApiRepository $shopApiRepository)
|
||||
{
|
||||
$this->middleware('active.shop');
|
||||
$this->shopApiRepository = $shopApiRepository;
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
$this->setFilterVars();
|
||||
$data = [
|
||||
'api_action' => $this->api_action,
|
||||
'filter_show' => $this->filter_show,
|
||||
];
|
||||
return view('user.shop.sales.api_orders', $data);
|
||||
}
|
||||
|
||||
public function action(){
|
||||
$data = Request::all();
|
||||
|
||||
if(isset($data['user_shop_api_orders_action'])){
|
||||
switch($data['user_shop_api_orders_action']){
|
||||
case 'order':
|
||||
$shopApiOrderCart = $this->shopApiRepository->order($data);
|
||||
return view('user.shop.sales.api_order_list', compact('shopApiOrderCart', 'data'));
|
||||
break;
|
||||
case 'remove':
|
||||
$this->shopApiRepository->remove($data);
|
||||
break;
|
||||
case 'reset':
|
||||
$this->shopApiRepository->reset($data);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
return redirect(route('user_shop_api_orders'));
|
||||
}
|
||||
|
||||
public function checkout(){
|
||||
|
||||
$data = Request::all();
|
||||
return $this->shopApiRepository->checkout($data);
|
||||
}
|
||||
|
||||
|
||||
private function setFilterVars(){
|
||||
|
||||
if(!session('user_shop_api_orders_filter')){
|
||||
session(['user_shop_api_orders_filter' => 1]);
|
||||
}
|
||||
if(Request::get('user_shop_api_orders_filter')){
|
||||
session(['user_shop_api_orders_filter' => Request::get('user_shop_api_orders_filter')]);
|
||||
}
|
||||
}
|
||||
|
||||
private function initSearch($archive = false, $request = true)
|
||||
{
|
||||
$this->setFilterVars();
|
||||
|
||||
$user = User::find(\Auth::user()->id);
|
||||
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')
|
||||
->where('shopping_orders.member_id', $user->id)
|
||||
->where('shopping_orders.payment_for', 7); //7 payment for extern
|
||||
|
||||
|
||||
if(Request::get('user_shop_api_orders_filter')){
|
||||
if(Request::get('user_shop_api_orders_filter') < 10){
|
||||
if(Request::get('user_shop_api_orders_filter') == 1){
|
||||
$query->where(function($query) {
|
||||
return $query->where('shopping_orders.api_status', 0)
|
||||
->orWhere('shopping_orders.api_status', 1)
|
||||
->orWhereNull('shopping_orders.api_status');
|
||||
});
|
||||
}else{
|
||||
$query->where('shopping_orders.api_status', Request::get('user_shop_api_orders_filter'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function ordersDatatable(){
|
||||
|
||||
$query = $this->initSearch();
|
||||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<button type="button" class="btn icon-btn btn-sm btn-secondary" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$ShoppingOrder->id.'"
|
||||
data-action="shop-user-order-detail"
|
||||
data-back=""
|
||||
data-modal="modal-xl"
|
||||
data-init_from="user"
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-eye"></span></button>';
|
||||
})
|
||||
->addColumn('api_status', function (ShoppingOrder $ShoppingOrder) {
|
||||
if($ShoppingOrder->api_status === 2){
|
||||
$shopping_oder_id = isset($ShoppingOrder->api_notice['shopping_order_id']) ? $ShoppingOrder->api_notice['shopping_order_id'] : null;
|
||||
if($shopping_oder_id){
|
||||
return '<a class="btn btn-sm btn-secondary btn-round" href="'.route('user_order_detail', [$shopping_oder_id]).'"><i class="fa fa-check fa-check-circle-o"> '.$shopping_oder_id.'</a>';
|
||||
}
|
||||
}
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getAPIStatusColor().'">'.$ShoppingOrder->getAPIStatusType().'</span>';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->created_at->format("d.m.Y");
|
||||
})
|
||||
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getShoppingOrderBadge($ShoppingOrder);
|
||||
})
|
||||
|
||||
->addColumn('api_action', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<label class="custom-control custom-checkbox m-0">
|
||||
<input type="checkbox" class="custom-control-input" name="api_action_list['.$ShoppingOrder->id.']" id="api_action_list_'.$ShoppingOrder->id.'">
|
||||
<span class="custom-control-label"></span>
|
||||
</label>';
|
||||
})
|
||||
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping()." €</span>";
|
||||
})
|
||||
->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('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getPaymentForBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>
|
||||
';
|
||||
})
|
||||
|
||||
->orderColumn('payment_for', 'payment_for $1')
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('api_action', 'id $1')
|
||||
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('user_shop_id', 'user_shop_id $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
|
||||
->rawColumns(['id', 'api_status', 'txaction', 'user_shop_id', 'api_action', 'shipped', 'total_shipping', 'payment_for'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
92
dev/app-bak/Http/Controllers/User/ShopSalesController.php
Executable file
92
dev/app-bak/Http/Controllers/User/ShopSalesController.php
Executable file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Services\Payment;
|
||||
use App\User;
|
||||
|
||||
|
||||
class ShopSalesController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('active.shop');
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
$data = [
|
||||
];
|
||||
return view('user.shop.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(403, 'Unauthorized action. User ID does not match.');
|
||||
}
|
||||
if( $shopping_order->payment_for !== 6 && $shopping_order->payment_for !== 7){
|
||||
return redirect(route('user_order_detail', [$shopping_order->id]));
|
||||
abort(403, 'Beraterbestellung');
|
||||
}
|
||||
$data = [
|
||||
'shopping_order' => $shopping_order,
|
||||
'isAdmin' => false,
|
||||
];
|
||||
|
||||
return view('user.shop.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_shop_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 '<span class="no-line-break">'.$ShoppingOrder->getFormattedTotalShipping()." €</span>";
|
||||
})
|
||||
->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('payment_for', function (ShoppingOrder $ShoppingOrder) {
|
||||
return Payment::getPaymentForBadge($ShoppingOrder);
|
||||
})
|
||||
->addColumn('shipped', function (ShoppingOrder $ShoppingOrder) {
|
||||
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getShippedColor().'">'.$ShoppingOrder->getShippedType().'</span>
|
||||
';
|
||||
})
|
||||
->addColumn('invoice', function (ShoppingOrder $ShoppingOrder) {
|
||||
return $ShoppingOrder->isInvoice() ? '<span class="no-line-break"><a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'download']).'" class="btn btn-primary btn-xs"><i class="fa fa-download"></i></a>
|
||||
<a href="'.route('storage_file', [$ShoppingOrder->id, 'invoice', 'stream']).'" target="_blank" class="btn btn-warning btn-xs"><i class="fa fa-eye"></i></a></span>' : '-';
|
||||
})
|
||||
->orderColumn('payment_for', 'payment_for $1')
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('txaction', 'txaction $1')
|
||||
->orderColumn('user_shop_id', 'user_shop_id $1')
|
||||
->orderColumn('total_shipping', 'total_shipping $1')
|
||||
|
||||
->rawColumns(['id', 'txaction', 'user_shop_id', 'total_shipping', 'invoice', 'shipped', 'payment_for'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
1137
dev/app-bak/Http/Controllers/User/TeamController.php
Executable file
1137
dev/app-bak/Http/Controllers/User/TeamController.php
Executable file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue