Promotion Backend v1
This commit is contained in:
parent
0ed47d3553
commit
f0da981737
43 changed files with 2765 additions and 45 deletions
189
app/Http/Controllers/AdminPromotionController.php
Executable file
189
app/Http/Controllers/AdminPromotionController.php
Executable file
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Request;
|
||||
use Validator;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\PromotionAdmin;
|
||||
use App\Models\PromotionAdminProduct;
|
||||
use App\Repositories\AdminPromotionRepository;
|
||||
|
||||
|
||||
|
||||
class AdminPromotionController extends Controller
|
||||
{
|
||||
protected $promoRepo;
|
||||
|
||||
public function __construct(AdminPromotionRepository $promoRepo)
|
||||
{
|
||||
$this->middleware('admin');
|
||||
$this->promoRepo = $promoRepo;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
'values' => PromotionAdmin::all(),
|
||||
];
|
||||
return view('admin.promotion.index', $data);
|
||||
}
|
||||
|
||||
public function detail($id){
|
||||
if($id == 0 || $id === 'new'){
|
||||
$promotion = new PromotionAdmin();
|
||||
$promotion->id = 0;
|
||||
|
||||
$promotion->active = true;
|
||||
}else{
|
||||
$promotion = PromotionAdmin::findOrFail($id);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'promotion' => $promotion,
|
||||
|
||||
];
|
||||
return view('admin.promotion.detail', $data);
|
||||
}
|
||||
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Request::all();
|
||||
if(isset($data['action']) && $data['action'] === 'save-promotion_product'){
|
||||
$model = $this->promoRepo->updateProduct($id, Request::all());
|
||||
}
|
||||
|
||||
if(isset($data['action']) && $data['action'] === 'save-promotion'){
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
'type' => 'required',
|
||||
);
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return redirect(route('admin_promotion_detail', [$id]))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$model = $this->promoRepo->update($id, Request::all());
|
||||
}
|
||||
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect(route('admin_promotion_detail', [$model->id]));
|
||||
}
|
||||
|
||||
public function delete($id, $del = false)
|
||||
{
|
||||
if($del === 'promotion_admin_product'){
|
||||
$PromotionAdminProduct = PromotionAdminProduct::findOrFail($id);
|
||||
$PromotionAdmin = $PromotionAdminProduct->promotion_admin;
|
||||
if($PromotionAdminProduct->canDelete()){
|
||||
\Session()->flash('alert-success', "Promotion Produkt gelöscht");
|
||||
$PromotionAdminProduct->delete();
|
||||
}else{
|
||||
\Session()->flash('alert-error', "Promotion Produkt kann nicht gelöscht werden, schon in Verwendung.");
|
||||
}
|
||||
return redirect(route('admin_promotion_detail', [$PromotionAdmin->id]));
|
||||
}
|
||||
|
||||
if($del === 'admin_promotion'){
|
||||
$PromotionAdmin = PromotionAdmin::findOrFail($id);
|
||||
if($PromotionAdmin->canDelete()){
|
||||
foreach($PromotionAdmin->promotion_admin_products as $promotion_admin_product){
|
||||
$promotion_admin_product->delete();
|
||||
}
|
||||
$PromotionAdmin->delete();
|
||||
\Session()->flash('alert-success', "Promotion gelöscht");
|
||||
}else{
|
||||
\Session()->flash('alert-error', "Promotion kann nicht gelöscht werden, schon in Verwendung.");
|
||||
}
|
||||
return redirect(route('admin_promotions'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function show($by, $id = null){
|
||||
|
||||
$data = [
|
||||
'id' => $id,
|
||||
'by' => $by,
|
||||
];
|
||||
|
||||
if($by === 'promotion'){
|
||||
$data['promotion'] = PromotionAdmin::findOrFail($id);
|
||||
}
|
||||
if($by === 'all'){
|
||||
$data['promotion'] = null;
|
||||
|
||||
}
|
||||
return view('admin.promotion.show', $data);
|
||||
}
|
||||
|
||||
public function datatable($by, $id = null){
|
||||
|
||||
$query = PromotionUser::with('promotion_user_products', 'user')->select('promotion_users.*');
|
||||
if($by === 'promotion'){
|
||||
// $query->where('promotion_admin_id', $id);
|
||||
}
|
||||
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (PromotionUser $PromotionUser) {
|
||||
return $PromotionUser->id; //'<a href="" class="btn icon-btn btn-sm btn-primary">'.$PromotionUser->id.'</a>';
|
||||
})
|
||||
->addColumn('user', function (PromotionUser $PromotionUser) {
|
||||
if($PromotionUser->user){
|
||||
return $PromotionUser->user->getFullName();
|
||||
}
|
||||
return "";
|
||||
})
|
||||
->addColumn('name', function (PromotionUser $PromotionUser) {
|
||||
if(strlen($PromotionUser->name) > 30){
|
||||
return substr($PromotionUser->name, 0, 30)."...";
|
||||
}
|
||||
return $PromotionUser->name;
|
||||
})
|
||||
->addColumn('products_active', function (PromotionUser $PromotionUser) {
|
||||
return $PromotionUser->promotion_user_products_active->count();
|
||||
})
|
||||
->addColumn('count_open_items', function (PromotionUser $PromotionUser) {
|
||||
return $PromotionUser->getCountOpenItems();
|
||||
})
|
||||
->addColumn('count_sell_items', function (PromotionUser $PromotionUser) {
|
||||
return $PromotionUser->getCountSellItems();
|
||||
})
|
||||
->addColumn('user_promotion_cart_price', function (PromotionUser $PromotionUser) {
|
||||
$back = $PromotionUser->calculateCart();
|
||||
return formatNumber($back['price'])." €";
|
||||
})
|
||||
->addColumn('user_promotion_sell_price', function (PromotionUser $PromotionUser) {
|
||||
$back = $PromotionUser->calculateSell();
|
||||
return formatNumber($back['price'])." €";
|
||||
})
|
||||
->addColumn('user_credit', function (PromotionUser $PromotionUser) {
|
||||
return formatNumber($PromotionUser->user->payment_credit)." €";;
|
||||
})
|
||||
->addColumn('active', function (PromotionUser $PromotionUser) {
|
||||
return get_active_badge($PromotionUser->active);
|
||||
})
|
||||
->addColumn('pick_up', function (PromotionUser $PromotionUser) {
|
||||
return get_active_badge($PromotionUser->pick_up);
|
||||
})
|
||||
->addColumn('user_delete', function (PromotionUser $PromotionUser) {
|
||||
return get_active_badge(($PromotionUser->user_deleted_at != null));
|
||||
})
|
||||
|
||||
|
||||
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('name', 'name $1')
|
||||
//->orderColumn('status', 'status $1')
|
||||
->orderColumn('active', 'active $1')
|
||||
->orderColumn('pick_up', 'pick_up $1')
|
||||
// ->orderColumn('user_delete', 'user_delete $1')
|
||||
|
||||
|
||||
->rawColumns(['id', 'status', 'active', 'pick_up', 'user_delete'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ class LeadController extends Controller
|
|||
$user->account = new UserAccount();
|
||||
}
|
||||
}
|
||||
$next_account_id = UserAccount::max('m_account') +1;
|
||||
$next_account_id = UserAccount::withTrashed()->max('m_account') +1;
|
||||
if($user->account->m_account === null){
|
||||
$user->account->m_account = $next_account_id;
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ class LeadController extends Controller
|
|||
|
||||
$data = Request::all();
|
||||
$show = Request::get('show');
|
||||
|
||||
dd($data);
|
||||
if ($data['user_id'] === "new" || $data['user_id'] == 0) {
|
||||
$rules = array(
|
||||
'salutation' => 'required',
|
||||
|
|
@ -237,7 +237,7 @@ class LeadController extends Controller
|
|||
}
|
||||
|
||||
if(!$user->account->m_account){
|
||||
$user->account->m_account = UserAccount::max('m_account') +1;
|
||||
$user->account->m_account = UserAccount::withTrashed()->max('m_account') +1;
|
||||
$user->account->save();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||
use App\Models\Homeparty;
|
||||
use App\Models\HomepartyUser;
|
||||
use App\Models\Product;
|
||||
use App\Models\PromotionAdminProduct;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserCredit;
|
||||
|
|
@ -82,17 +83,18 @@ class ModalController extends Controller
|
|||
$ret = view("admin.modal.user-credit-status", compact('value', 'data'))->render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*if($data['action'] === 'homeparty-add-product') {
|
||||
$homeparty = Homeparty::find($data['id']);
|
||||
$homeparty_user = HomepartyUser::find($data['user_id']);
|
||||
$data['homeparty'] = $homeparty;
|
||||
$ret = view("user.homeparty.modal_show_products", compact( 'data', 'homeparty', 'homeparty_user'))->render();
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
if($data['action'] === 'save-promotion_product'){
|
||||
if($data['id'] === 'new'){
|
||||
$value = new PromotionAdminProduct();
|
||||
$value->calcu_commission = true;
|
||||
$value->shipping = true;
|
||||
$value->active = true;
|
||||
}else{
|
||||
$value = PromotionAdminProduct::find($data['id']);
|
||||
}
|
||||
$ret = view("admin.modal.promotion-product", compact('value', 'data'))->render();
|
||||
}
|
||||
}
|
||||
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,17 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Models\Setting;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\UserShop;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Services\Payment;
|
||||
use Request;
|
||||
use App\Models\Setting;
|
||||
use App\Models\UserShop;
|
||||
use App\Services\Payment;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserPayCredit;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
|
||||
class SalesController extends Controller
|
||||
{
|
||||
|
|
@ -307,6 +308,19 @@ class SalesController extends Controller
|
|||
$shopping_order = ShoppingOrder::findOrFail($data['id']);
|
||||
$shopping_payment = ShoppingPayment::findOrFail($data['payment_id']);
|
||||
|
||||
if($shopping_order->shopping_order_margin->from_payment_credit > 0){
|
||||
$last_UserPayCredit = UserPayCredit::where('shopping_order_id', $shopping_order->id)->whereIn('status', [2, 4])->orderBy('id', 'DESC')->first();
|
||||
//Status Keine Zahlung, Guthaben zurückführen, wenn status 2 / deduction from payment
|
||||
if($data['txaction'] === 'non' && $last_UserPayCredit->status === 2){
|
||||
Payment::handelUserPayCredits($shopping_order, 'return');
|
||||
}
|
||||
//Status Zahlung, voher gab es eine Storno, Guthaben abziehen wenn status 4 / return from order
|
||||
if($last_UserPayCredit->status === 4 && ($data['txaction'] === 'open' || $data['txaction'] === 'paid')){
|
||||
Payment::handelUserPayCredits($shopping_order, 'deduction');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$payt = PaymentTransaction::create([
|
||||
'shopping_payment_id' => $shopping_payment->id,
|
||||
'request' => 'transaction',
|
||||
|
|
@ -327,6 +341,7 @@ class SalesController extends Controller
|
|||
if($payt->status === 'vor' && $payt->txaction === 'paid'){
|
||||
$send_link = Payment::paymentStatusPaidAction($shopping_order, true);
|
||||
}
|
||||
|
||||
$edata = [
|
||||
'mode' => $payt->mode,
|
||||
'txaction' => $payt->txaction,
|
||||
|
|
|
|||
|
|
@ -555,6 +555,8 @@ class CheckoutController extends Controller
|
|||
|
||||
if($shopping_payment){
|
||||
|
||||
Payment::handelUserPayCredits($shopping_order, 'deduction');
|
||||
|
||||
if($payt->status === 'vor'){
|
||||
$shopping_payment->txaction = 'open';
|
||||
$shopping_order->txaction = 'open';
|
||||
|
|
|
|||
|
|
@ -367,10 +367,10 @@ class OrderController extends Controller
|
|||
return "";
|
||||
})
|
||||
->addColumn('price_net', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(true, true). "€";
|
||||
return $product->getFormattedPriceWith(true, false). "€";
|
||||
})
|
||||
->addColumn('price_gross', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(false, true). "€";
|
||||
return $product->getFormattedPriceWith(false, false). "€";
|
||||
})
|
||||
->addColumn('price_vk_gross', function (Product $product) {
|
||||
return $product->getFormattedPriceWith(false, false). "€";
|
||||
|
|
|
|||
147
app/Http/Controllers/User/PromotionController.php
Normal file
147
app/Http/Controllers/User/PromotionController.php
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use Request;
|
||||
use Validator;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\PromotionAdmin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\PromotionAdminProduct;
|
||||
use App\Repositories\UserPromotionRepository;
|
||||
use App\Services\Util;
|
||||
|
||||
class PromotionController extends Controller
|
||||
{
|
||||
protected $promoRepo;
|
||||
|
||||
public function __construct(UserPromotionRepository $promoRepo)
|
||||
{
|
||||
$this->middleware('active.account');
|
||||
$this->promoRepo = $promoRepo;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
'values' => PromotionUser::where('user_id', Auth::user()->id)->whereNull('user_deleted_at')->get(),
|
||||
];
|
||||
return view('user.promotion.index', $data);
|
||||
}
|
||||
|
||||
public function detail($id){
|
||||
|
||||
|
||||
$user_promotion = PromotionUser::findOrFail($id);
|
||||
if($user_promotion->user_id != Auth::user()->id){
|
||||
abort(404);
|
||||
}
|
||||
$data = [
|
||||
'checkPaymentCredit' => $user_promotion->checkPaymentCredit(),
|
||||
'user_promotion_cart' => PromotionUser::preCalculateCart($user_promotion, 'user_promotion'),
|
||||
'user_promotion' => $user_promotion,
|
||||
];
|
||||
return view('user.promotion.detail', $data);
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Request::all();
|
||||
|
||||
if(isset($data['action']) && $data['action'] === 'new-user-promotion'){
|
||||
$model = $this->promoRepo->create(Request::all());
|
||||
\Session()->flash('alert-save', true);
|
||||
}
|
||||
|
||||
if(isset($data['action']) && $data['action'] === 'save-user-promotion'){
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
'user_promotion_url' => ' required|alpha_dash|profanity|unique:promotion_users,url,'.\Auth::user()->id.'|min:4|max:20',
|
||||
);
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return redirect(route('user_promotion_detail', [$id]))->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
$model = $this->promoRepo->update($id, Request::all());
|
||||
|
||||
}
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect(route('user_promotion_detail', [$model->id]));
|
||||
}
|
||||
|
||||
public function delete($id, $del = false)
|
||||
{
|
||||
|
||||
if($del === 'user_promotion'){
|
||||
$PromotionUser = PromotionUser::findOrFail($id);
|
||||
if($PromotionUser->canDelete()){
|
||||
$PromotionUser->user_deleted_at = now();
|
||||
$PromotionUser->save();
|
||||
\Session()->flash('alert-success', "Promotion gelöscht");
|
||||
}else{
|
||||
\Session()->flash('alert-error', "Promotion kann nicht gelöscht werden, schon in Verwendung.");
|
||||
}
|
||||
return redirect(route('user_promotions'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function load(){
|
||||
$data = Request::all();
|
||||
|
||||
if(Request::ajax()) {
|
||||
if(isset($data['action']) && $data['action'] === 'validate_url'){
|
||||
$rules = array(
|
||||
//'user_promotion_url' => ' required|alpha_dash|profanity|unique:user_shops,name|min:4|max:20|full_word_check',
|
||||
'user_promotion_url' => ' required|alpha_dash|profanity|unique:promotion_users,url,'.\Auth::user()->id.'|min:4|max:20',
|
||||
);
|
||||
/*Validator::extend('full_word_check', function ($attribute, $value, $parameters, $validator) {
|
||||
if(in_array($value, config('profanity.full_word_check'))){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});*/
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
//$messages = $validator->messages();
|
||||
return Response::json(array(
|
||||
'success' => false,
|
||||
'errors' => $validator->getMessageBag()->toArray()
|
||||
|
||||
));
|
||||
}
|
||||
//$slug = SlugService::createSlug(UserShop::class, 'slug', Request::get('user_promotion_url'));
|
||||
$name = Util::sanitize(Request::get('user_promotion_url'), true, false, true, true);
|
||||
|
||||
return Response::json(array(
|
||||
'success' => true,
|
||||
'preview_user_promotion_url' => config('app.promo_url').$name,
|
||||
));
|
||||
}
|
||||
if(isset($data['action']) && $data['action'] === 'updateCart'){
|
||||
|
||||
$fill = [
|
||||
'user_promotion_cart' => ['price' => 0, 'price_net' => 0],
|
||||
];
|
||||
|
||||
if(isset($data['products'])){
|
||||
$fill['user_promotion_cart'] = PromotionUser::preCalculateCart($data['products'], 'products');
|
||||
$fill['checkPaymentCredit'] = PromotionUser::preCheckPaymentCredit($fill['user_promotion_cart']);
|
||||
|
||||
}
|
||||
/*if(isset($data['user_promotion_id']) && $user_promotion = PromotionUser::find($data['user_promotion_id'])){
|
||||
}*/
|
||||
$html_cart = view("user.promotion.cart", $fill)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_cart'=>$html_cart]);
|
||||
}
|
||||
return response()->json(['success' => false, 'data'=>$data]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -221,6 +221,10 @@ class WizardController extends Controller
|
|||
}
|
||||
$data = Request::all();
|
||||
$data['same_as_billing'] = Request::get('same_as_billing') == NULL ? 0 : 1;
|
||||
$data['birthday_day'] = isset($data['birthday_day']) ? $data['birthday_day'] : 1;
|
||||
$data['birthday_month'] = isset($data['birthday_month']) ? $data['birthday_month'] : 1;
|
||||
$data['birthday_year'] = isset($data['birthday_year']) ? $data['birthday_year'] : 1970;
|
||||
$data['birthday'] = $data['birthday_day'].".".$data['birthday_month'].".".$data['birthday_year'];
|
||||
$user->account->fill($data)->save();
|
||||
$user->wizard = 2;
|
||||
$user->save();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue