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();
|
||||
|
|
|
|||
|
|
@ -117,6 +117,13 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|Product wherePartnerCommission($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereSingleCommission($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereValueCommission($value)
|
||||
* @property bool|null $shipping_addon
|
||||
* @property bool|null $max_buy
|
||||
* @property int|null $max_buy_num
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProductBuy[] $product_buys
|
||||
* @property-read int|null $product_buys_count
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereMaxBuy($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Product whereMaxBuyNum($value)
|
||||
*/
|
||||
class Product extends Model
|
||||
{
|
||||
|
|
@ -340,10 +347,13 @@ class Product extends Model
|
|||
|
||||
/*price by user Factor*/
|
||||
private function calcPriceUserFactor($price){
|
||||
/*
|
||||
Nicht in benutzung, die margin errechnet sich im Warenkorb, wegen der Staffelprovision
|
||||
if(\Auth::user() && \Auth::user()->user_level){
|
||||
$margin = ((\Auth::user()->user_level->margin -100)*-1) / 100;
|
||||
$price = $price * $margin;
|
||||
}
|
||||
*/
|
||||
return $price;
|
||||
}
|
||||
/*price net*/
|
||||
|
|
|
|||
181
app/Models/PromotionAdmin.php
Normal file
181
app/Models/PromotionAdmin.php
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Services\Util;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* Class PromotionAdmin
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string|null $description
|
||||
* @property Carbon|null $from
|
||||
* @property Carbon|null $to
|
||||
* @property float|null $max_bugdet
|
||||
* @property int|null $max_items
|
||||
* @property bool $active
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property Collection|Product[] $products
|
||||
* @property Collection|PromotionUserProduct[] $promotion_user_products
|
||||
* @property Collection|PromotionUser[] $promotion_users
|
||||
* @package App\Models
|
||||
* @property-read int|null $products_count
|
||||
* @property-read int|null $promotion_user_products_count
|
||||
* @property-read int|null $promotion_users_count
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereActive($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereDescription($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereFrom($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereMaxBugdet($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereMaxItems($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereTo($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereUpdatedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class PromotionAdmin extends Model
|
||||
{
|
||||
protected $table = 'promotion_admins';
|
||||
|
||||
protected $casts = [
|
||||
'max_bugdet' => 'float',
|
||||
'max_items' => 'int',
|
||||
'active' => 'bool',
|
||||
'type' => 'int',
|
||||
'shop' => 'bool',
|
||||
|
||||
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'from',
|
||||
'to'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'type',
|
||||
'name',
|
||||
'description',
|
||||
'from',
|
||||
'to',
|
||||
'shop',
|
||||
'max_bugdet',
|
||||
'max_items',
|
||||
'active'
|
||||
];
|
||||
|
||||
public $promotionType = [
|
||||
1 => 'verschenken',
|
||||
2 => 'Nachlass (not built in!)',
|
||||
3 => 'Gewinnspiel (not built in!)',
|
||||
];
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'promotion_admin_products')
|
||||
->withPivot('id', 'own_price', 'price', 'tax', 'price_old', 'calcu_commission', 'max_items', 'used_items', 'shipping', 'active')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
|
||||
public function promotion_admin_products()
|
||||
{
|
||||
return $this->hasMany(PromotionAdminProduct::class);
|
||||
}
|
||||
|
||||
public function promotion_admin_products_active()
|
||||
{
|
||||
return $this->hasMany(PromotionAdminProduct::class)->where('active', 1);
|
||||
}
|
||||
|
||||
public function promotion_user_products()
|
||||
{
|
||||
return $this->hasMany(PromotionUserProduct::class);
|
||||
}
|
||||
|
||||
public function promotion_users()
|
||||
{
|
||||
return $this->hasMany(PromotionUser::class);
|
||||
}
|
||||
|
||||
public function getPromotionType(){
|
||||
if(isset($this->promotionType[$this->type])){
|
||||
return $this->promotionType[$this->type];
|
||||
}
|
||||
}
|
||||
|
||||
public function getFromAttribute($value)
|
||||
{
|
||||
if(!$value){ return ""; }
|
||||
return Carbon::parse($value)->format(\Util::formatDateDB());
|
||||
}
|
||||
|
||||
public function getFromRaw(){
|
||||
return isset($this->attributes['from']) ? $this->attributes['from'] : NULL;
|
||||
}
|
||||
|
||||
public function setFromAttribute( $value ) {
|
||||
$this->attributes['from'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
||||
}
|
||||
|
||||
public function getToAttribute($value)
|
||||
{
|
||||
if(!$value){ return ""; }
|
||||
return Carbon::parse($value)->format(\Util::formatDateDB());
|
||||
}
|
||||
|
||||
public function getToRaw(){
|
||||
return isset($this->attributes['to']) ? $this->attributes['to'] : NULL;
|
||||
}
|
||||
|
||||
public function setToAttribute( $value ) {
|
||||
$this->attributes['to'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : NULL;
|
||||
}
|
||||
|
||||
|
||||
public function setMaxBugdetAttribute( $value ) {
|
||||
|
||||
$this->attributes['max_bugdet'] = $value ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function getFormattedMaxBugdet()
|
||||
{
|
||||
return isset($this->attributes['max_bugdet']) ? Util::formatNumber($this->attributes['max_bugdet']) : "";
|
||||
}
|
||||
|
||||
|
||||
public function canDelete(){
|
||||
|
||||
if($this->promotion_users->count() === 0 && $this->promotion_user_products->count() === 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function getActiveAdminPromotionsAsArray(){
|
||||
$query = PromotionAdmin::where('active', true)
|
||||
->where(function ($query) {
|
||||
$query->where('from', '<', Carbon::now())
|
||||
->orWhereNull('from');
|
||||
})
|
||||
->where(function ($query) {
|
||||
$query->where('to', '>=', Carbon::now())
|
||||
->orWhereNull('to');
|
||||
});
|
||||
return $query->pluck('name', 'id')->toArray();
|
||||
}
|
||||
}
|
||||
194
app/Models/PromotionAdminProduct.php
Normal file
194
app/Models/PromotionAdminProduct.php
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Services\Util;
|
||||
use Auth;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* Class PromotionAdminProduct
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $promotion_admin_id
|
||||
* @property int $product_id
|
||||
* @property bool $own_price
|
||||
* @property float|null $price
|
||||
* @property float|null $tax
|
||||
* @property float|null $price_old
|
||||
* @property bool $calcu_commission
|
||||
* @property int|null $max_items
|
||||
* @property int|null $used_items
|
||||
* @property bool $shipping
|
||||
* @property bool $active
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property Product $product
|
||||
* @property PromotionAdmin $promotion_admin
|
||||
* @property Collection|PromotionUserProduct[] $promotion_user_products
|
||||
* @package App\Models
|
||||
* @property-read int|null $promotion_user_products_count
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereActive($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereCalcuCommission($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereMaxItems($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereOwnPrice($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct wherePrice($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct wherePriceOld($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereProductId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct wherePromotionAdminId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereShipping($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereTax($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdminProduct whereUsedItems($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class PromotionAdminProduct extends Model
|
||||
{
|
||||
protected $table = 'promotion_admin_products';
|
||||
|
||||
protected $casts = [
|
||||
'promotion_admin_id' => 'int',
|
||||
'product_id' => 'int',
|
||||
'own_price' => 'bool',
|
||||
'price' => 'float',
|
||||
'tax' => 'float',
|
||||
'price_old' => 'float',
|
||||
'calcu_commission' => 'bool',
|
||||
'max_items' => 'int',
|
||||
'used_items' => 'int',
|
||||
'shipping' => 'bool',
|
||||
'active' => 'bool'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'promotion_admin_id',
|
||||
'product_id',
|
||||
'own_price',
|
||||
'price',
|
||||
'tax',
|
||||
'price_old',
|
||||
'calcu_commission',
|
||||
'max_items',
|
||||
'used_items',
|
||||
'shipping',
|
||||
'active'
|
||||
];
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function promotion_admin()
|
||||
{
|
||||
return $this->belongsTo(PromotionAdmin::class);
|
||||
}
|
||||
|
||||
public function promotion_user_products()
|
||||
{
|
||||
return $this->hasMany(PromotionUserProduct::class);
|
||||
}
|
||||
|
||||
public function setPriceAttribute( $value ) {
|
||||
|
||||
$this->attributes['price'] = $value ? Util::reFormatNumber($value) : null;
|
||||
}
|
||||
|
||||
public function getFormattedPrice()
|
||||
{
|
||||
return isset($this->attributes['price']) ? Util::formatNumber($this->attributes['price']) : "";
|
||||
}
|
||||
|
||||
public function getRealPrice()
|
||||
{
|
||||
if($this->own_price && $this->price){
|
||||
return $this->price;
|
||||
}
|
||||
if($this->product && $this->product->price){
|
||||
return $this->product->price;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getFormattedRealPrice()
|
||||
{
|
||||
return Util::formatNumber($this->getRealPrice());
|
||||
}
|
||||
|
||||
/*price calcu Marign single_commission Factor*/
|
||||
private function calcPriceCommissionFactor($price){
|
||||
//einzelrabatt aus produkt
|
||||
$margin = 100;
|
||||
if(isset($this->product) && $this->product->single_commission){
|
||||
$margin = $this->product->value_commission;
|
||||
}else{
|
||||
//rabatt aus user level
|
||||
$user = Auth::user();
|
||||
if($user && $user->user_level && $user->user_level->user_level_margins){
|
||||
if($user_level_margin = $user->user_level->user_level_margins_re->first()){
|
||||
$margin = $user_level_margin->trading_margin;
|
||||
}
|
||||
}
|
||||
}
|
||||
$margin = (100 - $margin) / 100;
|
||||
$price = $price * $margin;
|
||||
return $price;
|
||||
}
|
||||
/*price net*/
|
||||
private function calcPriceNet($price){
|
||||
$tax = isset($this->product->tax) ? $this->product->tax : 0;
|
||||
$tax_rate = ($tax + 100) / 100;
|
||||
return $price / $tax_rate;
|
||||
}
|
||||
//price calu with
|
||||
public function getPriceWith(Bool $net = true){
|
||||
$price = $this->getRealPrice();
|
||||
$price = $net ? $this->calcPriceNet($price) : $price;
|
||||
$price = $this->calcu_commission ? $this->calcPriceCommissionFactor($price) : $price;
|
||||
return round($price, 2);
|
||||
}
|
||||
/*out*/
|
||||
public function getFormattedPriceWith(Bool $net = true)
|
||||
{
|
||||
return Util::formatNumber($this->getPriceWith($net));
|
||||
}
|
||||
|
||||
public function canDelete(){
|
||||
if($this->promotion_user_products->count() === 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public function getPromotionUserProducts($user_promotion, $key = false)
|
||||
{
|
||||
$user_promotion_product = $user_promotion->hasPromotionUserProducts($this->id);
|
||||
if($user_promotion_product){
|
||||
if(!$key){
|
||||
return $user_promotion_product;
|
||||
}
|
||||
if(isset($user_promotion_product->{$key})){
|
||||
return $user_promotion_product->{$key};
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
//return $this->hasMany(PromotionUserProduct::class)->where('promotion_admin_product_id', $promotion_admin_product->id)->first();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
222
app/Models/PromotionUser.php
Normal file
222
app/Models/PromotionUser.php
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class PromotionUser
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $promotion_admin_id
|
||||
* @property string $name
|
||||
* @property string|null $description
|
||||
* @property string|null $url
|
||||
* @property bool $pick_up
|
||||
* @property float|null $used_budget_total
|
||||
* @property int|null $sell_items_total
|
||||
* @property bool $active
|
||||
* @property Carbon|null $user_deleted_at
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property PromotionAdmin $promotion_admin
|
||||
* @property Collection|Product[] $products
|
||||
* @package App\Models
|
||||
* @property-read int|null $products_count
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereActive($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereDescription($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser wherePickUp($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser wherePromotionAdminId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereSellItemsTotal($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUrl($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUsedBudgetTotal($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUserDeletedAt($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class PromotionUser extends Model
|
||||
{
|
||||
protected $table = 'promotion_users';
|
||||
|
||||
protected $casts = [
|
||||
'promotion_admin_id' => 'int',
|
||||
'user_id' => 'int',
|
||||
'pick_up' => 'bool',
|
||||
'used_budget_total' => 'float',
|
||||
'sell_items_total' => 'int',
|
||||
'active' => 'bool'
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'user_deleted_at'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'promotion_admin_id',
|
||||
'user_id',
|
||||
'name',
|
||||
'description',
|
||||
'url',
|
||||
'pick_up',
|
||||
'used_budget_total',
|
||||
'sell_items_total',
|
||||
'active',
|
||||
'user_deleted_at'
|
||||
];
|
||||
|
||||
public function promotion_admin()
|
||||
{
|
||||
return $this->belongsTo(PromotionAdmin::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(\App\User::class);
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'promotion_user_products')
|
||||
->withPivot('id', 'promotion_admin_id', 'promotion_admin_product_id', 'open_items', 'sell_items', 'used_budget_total', 'active')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function promotion_user_products()
|
||||
{
|
||||
return $this->hasMany(PromotionUserProduct::class);
|
||||
}
|
||||
|
||||
public function promotion_user_products_active()
|
||||
{
|
||||
return $this->hasMany(PromotionUserProduct::class)->where('active', 1);
|
||||
}
|
||||
|
||||
|
||||
public function getUrlPreview()
|
||||
{
|
||||
return $this->url ? config('app.promo_url').$this->url : "";
|
||||
}
|
||||
|
||||
public function canDelete(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasPromotionUserProducts($promotion_admin_product_id)
|
||||
{
|
||||
return $this->hasMany(PromotionUserProduct::class)->where('promotion_admin_product_id', $promotion_admin_product_id)->first();
|
||||
}
|
||||
public function calculateSell(){
|
||||
$price = 0;
|
||||
$price_net = 0;
|
||||
//used_budget_total
|
||||
//von den user produkte, inkl. der nicht aktiven!
|
||||
//ToDo der Preis vom verkauf muss eingesetzt werden, wird gespeichert beim Sale
|
||||
if($this->promotion_user_products){
|
||||
foreach($this->promotion_user_products as $promotion_user_product){
|
||||
$qty = $promotion_user_product->sell_items;
|
||||
$price += $promotion_user_product->promotion_admin_product->getPriceWith(false) * intval($qty);
|
||||
$price_net += $promotion_user_product->promotion_admin_product->getPriceWith(true) * intval($qty);
|
||||
|
||||
}
|
||||
}
|
||||
return ['price' => $price, 'price_net' => $price_net];
|
||||
}
|
||||
|
||||
public function calculateCart(){
|
||||
$price = 0;
|
||||
$price_net = 0;
|
||||
if(isset($this->promotion_admin->promotion_admin_products_active)){
|
||||
foreach($this->promotion_admin->promotion_admin_products_active as $promotion_admin_product){
|
||||
if($promotion_user_product = $this->hasPromotionUserProducts($promotion_admin_product->id)){
|
||||
if($promotion_user_product->active){
|
||||
$qty = $promotion_user_product->open_items;
|
||||
$price += $promotion_admin_product->getPriceWith(false) * intval($qty);
|
||||
$price_net += $promotion_admin_product->getPriceWith(true) * intval($qty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['price' => $price, 'price_net' => $price_net];
|
||||
}
|
||||
|
||||
public function getCountOpenItems(){
|
||||
//hier die aktiven
|
||||
return $this->promotion_user_products_active->sum('open_items');
|
||||
}
|
||||
|
||||
public function getCountSellItems(){
|
||||
//hier alle zusammenziehen
|
||||
return $this->promotion_user_products->sum('sell_items');
|
||||
}
|
||||
|
||||
public function checkPaymentCredit()
|
||||
{
|
||||
if($this->promotion_user_products_active->count() > 0 && $this->getCountOpenItems() > 0){
|
||||
$payment_credit = \Auth::user()->payment_credit;
|
||||
if($payment_credit <= 0){
|
||||
return "empty";
|
||||
}
|
||||
|
||||
$prices = $this->calculateCart();
|
||||
if(isset($prices['price']) && $prices['price'] > 0){
|
||||
if($payment_credit >= $prices['price']){
|
||||
return "okay";
|
||||
}
|
||||
}
|
||||
return 'not';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static function preCheckPaymentCredit($values){
|
||||
if($values['count_items'] > 0 && $values['sum_items'] > 0){
|
||||
$payment_credit = \Auth::user()->payment_credit;
|
||||
if($payment_credit <= 0){
|
||||
return "empty";
|
||||
}
|
||||
if(isset($values['price']) && $values['price'] > 0){
|
||||
if($payment_credit >= $values['price']){
|
||||
return "okay";
|
||||
}
|
||||
}
|
||||
return 'not';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function preCalculateCart($value, $by = ''){
|
||||
$price = 0;
|
||||
$price_net = 0;
|
||||
$count_items = 0;
|
||||
$sum_items = 0;
|
||||
if($by === 'products'){
|
||||
foreach($value as $product){
|
||||
if(isset($product['product_id']) && isset($product['qty'])){
|
||||
if($promotion_admin_product = PromotionAdminProduct::find($product['product_id'])){
|
||||
$count_items ++;
|
||||
$sum_items += intval($product['qty']);
|
||||
$price += $promotion_admin_product->getPriceWith(false) * intval($product['qty']);
|
||||
$price_net += $promotion_admin_product->getPriceWith(true) * intval($product['qty']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($by === 'user_promotion'){
|
||||
return $value->calculateCart();
|
||||
}
|
||||
return ['price' => $price, 'price_net' => $price_net, 'count_items' => $count_items, 'sum_items' => $sum_items];
|
||||
|
||||
}
|
||||
}
|
||||
92
app/Models/PromotionUserProduct.php
Normal file
92
app/Models/PromotionUserProduct.php
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class PromotionUserProduct
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $promotion_admin_id
|
||||
* @property int $promotion_user_id
|
||||
* @property int $promotion_admin_product_id
|
||||
* @property int $product_id
|
||||
* @property int|null $open_items
|
||||
* @property int|null $sell_items
|
||||
* @property float|null $used_budget_total
|
||||
* @property bool $active
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property Product $product
|
||||
* @property PromotionAdmin $promotion_admin
|
||||
* @property PromotionAdminProduct $promotion_admin_product
|
||||
* @property PromotionUser $promotion_user
|
||||
* @package App\Models
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereActive($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereOpenItems($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereProductId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct wherePromotionAdminId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct wherePromotionAdminProductId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct wherePromotionUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereSellItems($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUserProduct whereUsedBudgetTotal($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class PromotionUserProduct extends Model
|
||||
{
|
||||
protected $table = 'promotion_user_products';
|
||||
|
||||
protected $casts = [
|
||||
'promotion_admin_id' => 'int',
|
||||
'promotion_user_id' => 'int',
|
||||
'promotion_admin_product_id' => 'int',
|
||||
'product_id' => 'int',
|
||||
'open_items' => 'int',
|
||||
'sell_items' => 'int',
|
||||
'used_budget_total' => 'float',
|
||||
'active' => 'bool'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'promotion_admin_id',
|
||||
'promotion_user_id',
|
||||
'promotion_admin_product_id',
|
||||
'product_id',
|
||||
'open_items',
|
||||
'sell_items',
|
||||
'used_budget_total',
|
||||
'active'
|
||||
];
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function promotion_admin()
|
||||
{
|
||||
return $this->belongsTo(PromotionAdmin::class);
|
||||
}
|
||||
|
||||
public function promotion_admin_product()
|
||||
{
|
||||
return $this->belongsTo(PromotionAdminProduct::class);
|
||||
}
|
||||
|
||||
public function promotion_user()
|
||||
{
|
||||
return $this->belongsTo(PromotionUser::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -47,6 +47,7 @@ class UserPayCredit extends Model
|
|||
1 => 'add from payment',
|
||||
2 => 'deduction from payment',
|
||||
3 => 'manually added credit',
|
||||
4 => 'return from order',
|
||||
|
||||
];
|
||||
protected $table = 'user_pay_credits';
|
||||
|
|
|
|||
62
app/Repositories/AdminPromotionRepository.php
Normal file
62
app/Repositories/AdminPromotionRepository.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\PromotionAdmin;
|
||||
use App\Models\PromotionAdminProduct;
|
||||
|
||||
class AdminPromotionRepository extends BaseRepository {
|
||||
|
||||
|
||||
public function __construct(PromotionAdmin $model){
|
||||
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function update($id, $data)
|
||||
{
|
||||
|
||||
$data['active'] = isset($data['active']) ? 1 : 0;
|
||||
$data['shop'] = isset($data['shop']) ? 1 : 0;
|
||||
|
||||
if($id == 0 || $id === 'new'){
|
||||
$this->model = PromotionAdmin::create($data);
|
||||
}
|
||||
else{
|
||||
$this->model = $this->getById($id);
|
||||
$this->model->fill($data);
|
||||
$this->model->save();
|
||||
}
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
public function updateProduct($id, $data){
|
||||
$this->model = $this->getById($id);
|
||||
|
||||
$data['own_price'] = isset($data['own_price']) ? 1 : 0;
|
||||
$data['calcu_commission'] = isset($data['calcu_commission']) ? 1 : 0;
|
||||
$data['shipping'] = isset($data['shipping']) ? 1 : 0;
|
||||
$data['active'] = isset($data['active']) ? 1 : 0;
|
||||
|
||||
if($data['id'] === 'new'){
|
||||
$data['promotion_admin_id'] = $this->model->id;
|
||||
$product = PromotionAdminProduct::create($data);
|
||||
}
|
||||
else{
|
||||
$product = PromotionAdminProduct::findOrFail($data['id']);
|
||||
$product->fill($data);
|
||||
$product->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function create($data){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
81
app/Repositories/UserPromotionRepository.php
Normal file
81
app/Repositories/UserPromotionRepository.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Services\Util;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\PromotionAdmin;
|
||||
use App\Models\PromotionUserProduct;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\PromotionAdminProduct;
|
||||
|
||||
class UserPromotionRepository extends BaseRepository {
|
||||
|
||||
|
||||
public function __construct(PromotionUser $model){
|
||||
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function update($id, $data)
|
||||
{
|
||||
|
||||
$data['active'] = isset($data['active']) ? 1 : 0;
|
||||
$data['pick_up'] = isset($data['pick_up']) ? 1 : 0;
|
||||
$data['url'] = Util::sanitize($data['user_promotion_url'], true, false, true, true);
|
||||
|
||||
$this->model = $this->getById($id);
|
||||
$this->model->fill($data);
|
||||
$this->model->save();
|
||||
|
||||
$this->updateProducts($id, $data);
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function updateProducts($id, $data){
|
||||
|
||||
$this->model = $this->getById($id);
|
||||
if(isset($data['products_qty'])){
|
||||
foreach($data['products_qty'] as $pa_id => $qty){
|
||||
$PromotionAdminProduct = PromotionAdminProduct::findOrFail($pa_id);
|
||||
$PromotionUserProduct = $PromotionAdminProduct->getPromotionUserProducts($this->model);
|
||||
|
||||
if(isset($data['products_user'][$pa_id]) && $data['products_user'][$pa_id] > 0 && $PromotionUserProduct){
|
||||
$PromotionUserProduct->fill([
|
||||
'open_items' => intval($qty),
|
||||
'active' => isset($data['products_active'][$pa_id]) ? 1 : 0,
|
||||
]);
|
||||
$PromotionUserProduct->save();
|
||||
}else{
|
||||
$user_product = PromotionUserProduct::create([
|
||||
'promotion_admin_id' => $PromotionAdminProduct->promotion_admin_id,
|
||||
'promotion_user_id' => $this->model->id,
|
||||
'promotion_admin_product_id' => $PromotionAdminProduct->id,
|
||||
'product_id' => $PromotionAdminProduct->product_id,
|
||||
'open_items' => intval($qty),
|
||||
'active' => isset($data['products_active'][$pa_id]) ? 1 : 0,
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function create($data){
|
||||
|
||||
if(isset($data['promotion_admin_id'])){
|
||||
$PromotionAdmin = PromotionAdmin::findOrFail($data['promotion_admin_id']);
|
||||
$this->model = PromotionUser::create([
|
||||
'promotion_admin_id' => $PromotionAdmin->id,
|
||||
'user_id' => Auth::user()->id,
|
||||
]);
|
||||
return $this->model;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -197,22 +197,35 @@ class Payment
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
//if the order has action
|
||||
if($shopping_order->shopping_user->is_from === 'user_order'){
|
||||
//is margin -> set paid
|
||||
$shopping_order->shopping_order_margin->paid = true;
|
||||
$shopping_order->shopping_order_margin->save();
|
||||
}
|
||||
|
||||
}
|
||||
//if the order has action
|
||||
if($shopping_order->shopping_user->is_from === 'user_order'){
|
||||
//is margin -> set paid
|
||||
$shopping_order->shopping_order_margin->paid = true;
|
||||
$shopping_order->shopping_order_margin->save();
|
||||
//is payment credit, reduce
|
||||
return $send_link;
|
||||
}
|
||||
|
||||
//remove form credit, every sale fnc / vor / etc from CheckoutController
|
||||
//when stone, put it back SalesController
|
||||
public static function handelUserPayCredits(ShoppingOrder $shopping_order, $do){
|
||||
//is payment credit, reduce Sae
|
||||
if($do === 'deduction'){
|
||||
if($shopping_order->shopping_order_margin->from_payment_credit > 0){
|
||||
$credit = $shopping_order->shopping_order_margin->from_payment_credit * -1;
|
||||
self::addUserPayCredits($shopping_order->auth_user, $credit, 2, 'user_order_deduction', $shopping_order->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $send_link;
|
||||
if($do === 'return'){
|
||||
if($shopping_order->shopping_order_margin->from_payment_credit > 0){
|
||||
$credit = $shopping_order->shopping_order_margin->from_payment_credit;
|
||||
self::addUserPayCredits($shopping_order->auth_user, $credit, 4, 'user_order_return', $shopping_order->id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function paymentStatusSendMail(ShoppingOrder $shopping_order, $shopping_payment, $data){
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ class Util
|
|||
return number_format($value, $dec, ',', '.');
|
||||
}
|
||||
|
||||
public static function formatPlural($count, $singular, $plural){
|
||||
return ($count === 1) ? $singular : $singular.$plural;
|
||||
}
|
||||
|
||||
public static function utf8ize( $mixed ) {
|
||||
if (is_array($mixed)) {
|
||||
foreach ($mixed as $key => $value) {
|
||||
|
|
@ -218,15 +222,27 @@ class Util
|
|||
}
|
||||
return url($uri);
|
||||
}
|
||||
public static function sanitize($string, $force_lowercase = true, $anal = false, $substr = false)
|
||||
public static function sanitize($string, $force_lowercase = true, $anal = false, $substr = false, $anCon = false)
|
||||
{
|
||||
$strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]",
|
||||
$strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "=", "+", "[", "{", "]",
|
||||
"}", "\\", "|", ";", ":", "\"", "'", "‘", "’", "“", "”", "–", "—",
|
||||
"—", "–", ",", "<", ".", ">", "/", "?");
|
||||
$clean = trim(str_replace($strip, "", strip_tags($string)));
|
||||
$clean = preg_replace('/\s+/', "_", $clean);
|
||||
$clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean ;
|
||||
$clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean;
|
||||
|
||||
if($anCon){
|
||||
$ers = array(
|
||||
'Ä' => 'Ae',
|
||||
'Ö' => 'Oe',
|
||||
'Ü' => 'Ue',
|
||||
'ä' => 'ae',
|
||||
'ö' => 'oe',
|
||||
'ü' => 'ue',
|
||||
'ß' => 'ss'
|
||||
);
|
||||
$clean = strtr($clean,$ers);
|
||||
}
|
||||
if($substr){
|
||||
$clean = (strlen($clean) > 20) ? substr($clean,-20) : $clean;
|
||||
|
||||
|
|
|
|||
|
|
@ -75,4 +75,11 @@ if (! function_exists('reFormatNumber')) {
|
|||
}
|
||||
}
|
||||
|
||||
if (! function_exists('formatPlural')) {
|
||||
function formatPlural($count, $singular, $plural)
|
||||
{
|
||||
return Util::formatPlural($count, $singular, $plural);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue