#10 Promotion Modul, Kommentar 2

This commit is contained in:
Kevin Adametz 2021-11-09 18:40:18 +01:00
parent f0da981737
commit c9e1545693
128 changed files with 8194 additions and 637 deletions

View file

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

View file

@ -45,8 +45,8 @@ class MembershipController extends Controller
$userHistoryDeleteMembership = UserHistory::whereUserId($user->id)->whereAction('delete_membership')->whereStatus(50)->get()->last();
$data = [
'user' => $user,
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
'upgrade' => Product::where('active', true)->where('show_at', '=', 4)->where('identifier', 'upgrade')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'upgrade' => Product::where('active', true)->whereJsonContains('show_on', '5')->where('identifier', 'upgrade')->get(),
'diff_months' => $diff_months,
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
'userHistoryUpgradeOrder' => $userHistoryUpgradeOrder,
@ -93,7 +93,7 @@ class MembershipController extends Controller
$user->abo_options = true;
$user->save();
}*/
if($product && $product->active && $product->show_at >= 3){
if($product && $product->active){
$image = "";
if($product->images->count()){
$image = $product->images->first()->slug;
@ -146,7 +146,7 @@ class MembershipController extends Controller
\Session()->flash('alert-success', "keine Änderung vorgenommen.");
return back();
}
if($product && $product->active && $product->show_at >= 3){
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]);

View file

@ -35,7 +35,7 @@ class PaymentMethodController extends Controller
'name' => $data['name'],
'short' => $data['short'],
'pos' => $data['pos'],
'show_at' => $data['show_at'],
'show_on' => isset($data['show_on']) ? $data['show_on'] : null,
'max_price' => $data['max_price'],
'default' => isset($data['default']) ? true : false,
'active' => isset($data['active']) ? true : false,
@ -46,7 +46,7 @@ class PaymentMethodController extends Controller
$model->short = $data['short'];
$model->pos = $data['pos'];
$model->max_price = $data['max_price'];
$model->show_at = $data['show_at'];
$model->show_on = isset($data['show_on']) ? $data['show_on'] : null;
$model->default = isset($data['default']) ? true : false;
$model->active = isset($data['active']) ? true : false;
$model->save();

View file

@ -20,7 +20,6 @@ class ProductController extends Controller
{
$this->middleware('admin');
$this->productRepo = $productRepo;
}
public function index()
@ -104,17 +103,11 @@ class ProductController extends Controller
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_show'));
}
public function copy($id){
$model = Product::findOrFail($id);
$product = $this->productRepo->copy($model);
\Session()->flash('alert-success', 'Eintrag kopiert');
return redirect(route('admin_product_show'));
}
@ -140,9 +133,7 @@ class ProductController extends Controller
}
// Upload FILE -----------------------------------------------------------------------------------------------------------------------
public function imageUpload(){
$product_id = Request::get('product_id');
@ -191,7 +182,7 @@ class ProductController extends Controller
return redirect(route('admin_product_edit', [$product->id]));
}
catch (Exception $e) {
catch (\Exception $e) {
\Session()->flash('alert-danger', "Fehler".$e);
return redirect(route('admin_product_edit', [$product->id]));
}

View file

@ -308,14 +308,14 @@ 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){
if($shopping_order->shopping_order_margin && $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){
if($last_UserPayCredit && $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')){
if($last_UserPayCredit && $last_UserPayCredit->status === 4 && ($data['txaction'] === 'open' || $data['txaction'] === 'paid')){
Payment::handelUserPayCredits($shopping_order, 'deduction');
}

View file

@ -105,6 +105,8 @@ class CheckoutController extends Controller
$shopping_user = ShoppingUser::findOrFail($this->getPayments('shopping_user_id'));
$shopping_user->billing_state = Shop::getCountryShippingCountryId($shopping_user->billing_country_id);
$shopping_user->shipping_state = Shop::getCountryShippingCountryId($shopping_user->shipping_country_id);
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; //reinvert
}
if($shopping_user->same_as_billing === NULL){
$shopping_user->same_as_billing = false;
@ -552,7 +554,7 @@ class CheckoutController extends Controller
$shopping_order->txaction = 'open';
$shopping_order->save();
if($shopping_payment){
Payment::handelUserPayCredits($shopping_order, 'deduction');

View file

@ -438,19 +438,16 @@ class HomepartyController extends Controller
abort(404);
}
private function getHomparty($id){
/*private function getHomparty($id){
$homeparty = Homeparty::findOrFail($id);
if($homeparty->auth_user_id !== \Auth::user()->id){
abort(404);
}
return $homeparty;
}
}*/
public function datatable(){
$query = Product::select('products.*')->where('active', true)->where(function ($q) {
$q->where('show_at', '=', 0)
->orWhere('show_at', '=', 1);
});
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '3');
return \DataTables::eloquent($query)

View file

@ -278,33 +278,17 @@ class OrderController extends Controller
public function datatable(){
$show_at = 1;
$not_show_pids = ProductBuy::getNotShowProductIDs(Auth::user()->id);
if(Request::get('shipping_is_for') === 'me'){
$query = Product::with('categories')->select('products.*')->where('active', true)->where(function ($q) {
$q->where('show_at', '=', 1)
->orWhere('show_at', '=', 2)
->orWhere('show_at', '=', 6);
});
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '2');
}else{
$query = Product::with('categories')->select('products.*')->where('active', true)->where(function ($q) {
$q->where('show_at', '=', 0)
->orWhere('show_at', '=', 1);
});
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '1');
}
foreach($not_show_pids as $not_show_pid){
$query->where('id', '!=', $not_show_pid);
}
//Kunden und Vertriebspartner
//->orWhere('show_at', '=', 2); // Nur Vertriebspartner
//->orderBy('pos', 'DESC')
//->orderBy('id', 'DESC');
return \DataTables::eloquent($query)
->addColumn('product', function (Product $product) {
@ -540,10 +524,10 @@ class OrderController extends Controller
private function getCompProducts($for){
if($for === 'me' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_me')){
return Product::whereActive(true)->where('show_at', '=', 1)->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
return Product::whereActive(true)->whereJsonContains('show_on', ['2'])->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
}
if($for === 'ot' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_ot')){
return Product::whereActive(true)->where('show_at', '=', 1)->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
return Product::whereActive(true)->whereJsonContains('show_on', ['1'])->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
}
return null;
}

View file

@ -34,11 +34,11 @@ class PromotionController extends Controller
public function detail($id){
$user_promotion = PromotionUser::findOrFail($id);
if($user_promotion->user_id != Auth::user()->id){
abort(404);
}
$user_promotion->about_you = !$user_promotion->about_you ? $user_promotion->user->account->about_you : $user_promotion->about_you;
$data = [
'checkPaymentCredit' => $user_promotion->checkPaymentCredit(),
'user_promotion_cart' => PromotionUser::preCalculateCart($user_promotion, 'user_promotion'),
@ -59,7 +59,7 @@ class PromotionController extends Controller
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',
'user_promotion_url' => ' required|alpha_dash|profanity|unique:promotion_users,url,'.\Auth::user()->id.',user_id|min:4|max:20',
);
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
@ -96,7 +96,7 @@ class PromotionController extends Controller
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',
'user_promotion_url' => ' required|alpha_dash|profanity|unique:promotion_users,url,'.\Auth::user()->id.',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'))){
@ -119,7 +119,7 @@ class PromotionController extends Controller
return Response::json(array(
'success' => true,
'preview_user_promotion_url' => config('app.promo_url').$name,
'preview_user_promotion_url' => config('app.promo_url')."/".$name,
));
}
if(isset($data['action']) && $data['action'] === 'updateCart'){
@ -130,7 +130,7 @@ class PromotionController extends Controller
if(isset($data['products'])){
$fill['user_promotion_cart'] = PromotionUser::preCalculateCart($data['products'], 'products');
$fill['checkPaymentCredit'] = PromotionUser::preCheckPaymentCredit($fill['user_promotion_cart']);
$fill['checkPaymentCredit'] = PromotionUser::preCheckPaymentCredit($fill['user_promotion_cart'], Auth::user());
}
/*if(isset($data['user_promotion_id']) && $user_promotion = PromotionUser::find($data['user_promotion_id'])){

View file

@ -21,7 +21,6 @@ class UserDataController extends Controller
$this->userRepo = $userRepo;
}
public function userEdit(){
$user = Auth::user();
@ -34,7 +33,6 @@ class UserDataController extends Controller
return view('user.edit', $data);
}
public function userEditStore(){
$user = Auth::user();
@ -86,10 +84,7 @@ class UserDataController extends Controller
}
/**
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function userDataStore(){
$user = User::findOrFail(Auth::user()->id);
@ -150,10 +145,7 @@ class UserDataController extends Controller
return redirect('/home');
}
}
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function userDataAcceptedForm(){
$user = Auth::user();
@ -168,10 +160,6 @@ class UserDataController extends Controller
return redirect('/home');
}
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function userDataFree(){
$user = Auth::user();
$user->active = 1;
@ -181,9 +169,6 @@ class UserDataController extends Controller
}
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function userDataFreeForm(){
$user = Auth::user();
@ -220,7 +205,76 @@ class UserDataController extends Controller
}
return redirect('/home');
}
public function userProfile(){
$user = Auth::user();
$data = [
'user' => $user,
];
return view('user.profile', $data);
}
public function userProfileStore(){
$user = Auth::user();
$data = Request::all();
if($account = $user->account){
$account->about_you = $data['about_you'] ? $data['about_you'] : null;
$account->save();
}
\Session()->flash('alert-save', true);
return redirect(route('user_profile'));
}
// Upload FILE -----------------------------------------------------------------------------------------------------------------------
public function imageUpload(){
$user = Auth::user();
try {
$image = \App\Services\Slim::getImages('avatar')[0];
if ( isset($image['output']['data']) )
{
// Original file name
$name = $image['output']['name'];
// Base64 of the image
$data = $image['output']['data'];
$file_ex = array( 'image/jpeg' => 'jpg', 'image/png' => 'png');
if (!isset($file_ex[$image['output']['type']])) {
\Session()->flash('alert-danger', 'File is not jpg or png!');
return redirect()->back();
}
$ext = $file_ex[$image['output']['type']];
$data = \Storage::disk('user')->put(
$user->id.'/avatar.'.$ext,
$data
);
\Session()->flash('alert-success', "Datei hochgeladen");
return redirect()->back();
}
\Session()->flash('alert-danger', "Datei leer");
return redirect()->back();
}
catch (\Exception $e) {
\Session()->flash('alert-danger', "Fehler".$e);
return redirect()->back();
}
}
public function imageDelete($delete){
$user = Auth::user();
if($delete === 'avatar'){
if($user->hasProfileImage()){
\Storage::disk('user')->delete(str_replace('_', '/', $user->getProfileImage()));
\Session()->flash('alert-success', "Datei gelöscht");
return redirect()->back();
}
}
}
}

View file

@ -0,0 +1,99 @@
<?php
namespace App\Http\Controllers\Web;
use Request;
use Response;
use Validator;
use App\Services\Util;
use App\Models\Product;
use App\Models\PaymentMethod;
use App\Models\PromotionUser;
use App\Http\Controllers\Controller;
class PromotionController extends Controller
{
public function __construct()
{
}
public function serve($path = null)
{
if(!isset($path)){
abort(402);
}
//search for promo
$PromotionUser = PromotionUser::where('url', trim($path))->whereNull('user_deleted_at')->first();
if(!$PromotionUser){
abort(402);
}
if($PromotionUser->checkOutOfStock()){
$data = [
'promotion_user' => $PromotionUser,
];
return view('web.promotion.outofstock', $data);
}
$data = [
'promotion_user' => $PromotionUser,
'shop_products' => Product::where('active', true)->whereJsonContains('show_on', ['1', '2', '3'])->orderBy('pos', 'ASC')->get(),
'user_payment_methods' => PaymentMethod::getDefaultAsArray()->toArray(),
];
return view('web.promotion.index', $data);
}
public function goto($load, $id){
$PromotionUser = PromotionUser::findOrFail($id);
$data = [
'promotion_user' => $PromotionUser,
];
if($load === 'thanksreminder'){
return view('web.promotion.thanksreminder', $data);
}
if($load === 'thanksorder'){
return view('web.promotion.thanksorder', $data);
}
if($load === 'notactive'){
return view('web.promotion.notactive', $data);
}
}
public function store($id){
$PromotionUser = PromotionUser::findOrFail($id);
$data = Request::all();
if(!isset($data['action'])){
abort(402);
}
if($data['action'] === 'submit-reminder-service'){
return redirect(route('web_promotion_goto', ['thanksreminder', $PromotionUser->id]));
}
if($data['action'] === 'submit-promotion-order'){
return redirect(route('web_promotion_goto', ['thanksorder', $PromotionUser->id]));
}
dd($PromotionUser);
}
public function load(){
$data = Request::all();
$ret = "";
$status = false;
if(Request::ajax()){
if($data['action'] === 'web-show-product'){
$product = Product::find($data['id']); //current user form order
$ret = view("web.promotion.show_product", compact('product', 'data'))->render();
}
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
}
}
}

View file

@ -60,8 +60,8 @@ class WizardController extends Controller
$data = [
'user' => Auth::user(),
'step' => $step,
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
'userHistoryWizardPayment' => $userHistoryWizardPayment,
];
@ -96,8 +96,9 @@ class WizardController extends Controller
'user' => Auth::user(),
'step' => $step,
'user_levels' => UserLevel::where('active', true)->get(),
//'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
//'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
//'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
//'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
];
if($step == 5){
return view('user.wizard.register_release', $data);
@ -125,8 +126,8 @@ class WizardController extends Controller
$data = [
'user' => Auth::user(),
'step' => 0,
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
'userHistoryWizardPayment' => $userHistoryWizardPayment,
];
@ -161,8 +162,8 @@ class WizardController extends Controller
'user' => Auth::user(),
'step' => $step,
'user_levels' => UserLevel::where('active', true)->get(),
//'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
//'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
//'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
//'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),,
];
$user->wizard = 0;
$user->save();
@ -342,8 +343,8 @@ class WizardController extends Controller
$data = [
'user' => Auth::user(),
'step' => $step,
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
];
$user->wizard = 10;
$user->save();
@ -381,8 +382,8 @@ class WizardController extends Controller
$data = [
'user' => Auth::user(),
'step' => $step,
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
];
return view('user.wizard.create', $data)->withErrors($validator);
}
@ -457,7 +458,7 @@ class WizardController extends Controller
$user->abo_options = true;
$user->save();
}*/
if($product && $product->active && $product->show_at == 3){
if($product && $product->active){
//set membership product
$image = "";
if($product->images->count()){

View file

@ -45,6 +45,7 @@ use Cviebrock\EloquentSluggable\Sluggable;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Category whereTransHeadline($value)
* @property-read \App\Models\IqImage|null $iq_image
* @property-read int|null $product_categories_count
* @method static \Illuminate\Database\Eloquent\Builder|Category withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
*/
class Category extends Model
{

View file

@ -38,6 +38,7 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage query()
* @property int|null $pos
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IqImage wherePos($value)
* @method static \Illuminate\Database\Eloquent\Builder|IqImage withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
*/
class IqImage extends Model
{

View file

@ -38,6 +38,8 @@ use Illuminate\Database\Eloquent\Model;
* @mixin \Eloquent
* @property string|null $max_price
* @method static \Illuminate\Database\Eloquent\Builder|PaymentMethod whereMaxPrice($value)
* @property array $show_on
* @method static \Illuminate\Database\Eloquent\Builder|PaymentMethod whereShowOn($value)
*/
class PaymentMethod extends Model
{
@ -49,12 +51,14 @@ class PaymentMethod extends Model
'pos' => 'int',
'active' => 'bool',
'default' => 'bool',
'show_on' => 'array',
];
protected $fillable = [
'name',
'short',
'show_at',
'show_on',
'max_price',
'pos',
'default',
@ -71,10 +75,30 @@ class PaymentMethod extends Model
9 => 'überall',
];
public static $showONs = [
1 => 'Kunden Bestellungen',
2 => 'Vertriebspartner Bestellungen',
3 => 'Microsite',
4 => 'Registrierung Vertriebspartner',
5 => 'Mitgliedschaft Vertriebspartner',
//6 => 'Onboarding Berater',
10 => 'überall',
];
public function getShowAtType(){
return isset(self::$showATs[$this->show_at]) ? self::$showATs[$this->show_at] : '-';
}
public function getShowOnTypes(){
$ret = [];
if($this->show_on){
foreach($this->show_on as $show){
$ret[] = isset(self::$showONs[$show]) ? self::$showONs[$show] : '-';
}
}
return $ret;
}
public static function getDefaultAsArray($short=false){
return PaymentMethod::where('active', true)->where('default', true)->pluck('id');
}
@ -100,7 +124,7 @@ class PaymentMethod extends Model
if($payment_method && $payment_method->active){
if(in_array($payment_method->id, $user_payment_methods)){
if($payment_method->max_price > 0){
if($total > 0 && $payment_method->max_price > 0){
if($payment_method->max_price >= $total){
return true;
}

View file

@ -124,6 +124,11 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @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)
* @method static \Illuminate\Database\Eloquent\Builder|Product withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
* @property string|null $short_copy
* @property array|null $show_on
* @method static \Illuminate\Database\Eloquent\Builder|Product whereShortCopy($value)
* @method static \Illuminate\Database\Eloquent\Builder|Product whereShowOn($value)
*/
class Product extends Model
{
@ -144,6 +149,7 @@ class Product extends Model
'trans_description' => 'array',
'trans_usage' => 'array',
'trans_ingredients' => 'array',
'show_on' => 'array',
'action' => 'array',
'wp_number' => 'int',
'single_commission' => 'bool',
@ -163,6 +169,7 @@ class Product extends Model
'name',
'title',
'copy',
'short_copy',
'price',
'price_ek',
'tax',
@ -182,6 +189,7 @@ class Product extends Model
'amount',
'active',
'show_at',
'show_on',
'single_commission',
'amount_commission',
'value_commission',
@ -201,8 +209,6 @@ class Product extends Model
'upgrade' => 'Produktupgrade zur Produkt ID',
'upgrade_member' => 'Vertriebspartnerupgrade zur Karriere ID',
//'proportional_voucher' => 'Anteiliger Gutschein Vertriebspartner',
];
public $unitTypes = [
0 => '',
@ -224,6 +230,17 @@ class Product extends Model
];
public $showONs = [
1 => 'Kunden Bestellungen',
2 => 'Vertriebspartner Bestellungen',
3 => 'Microsite',
4 => 'Registrierung Vertriebspartner',
5 => 'Mitgliedschaft Vertriebspartner',
//6 => 'Onboarding Berater',
10 => 'zur internen Berechnung',
];
public $actions = [
0 => 'payment_for_account',
// 1 => 'payment_for_shop',
@ -419,6 +436,14 @@ class Product extends Model
return isset($this->showATs[$this->show_at]) ? $this->showATs[$this->show_at] : '-';
}
public function getShowOnTypes(){
$ret = [];
foreach($this->show_on as $show){
$ret[] = isset($this->showONs[$show]) ? $this->showONs[$show] : '-';
}
return $ret;
}
public function setPosAttribute($value){
$this->attributes['pos'] = is_numeric($value) ? $value : null;

View file

@ -11,17 +11,27 @@ use Illuminate\Database\Eloquent\Model;
/**
* Class ProductBuy
*
*
* @property int $id
* @property int $auth_user_id
* @property int $product_id
* @property int $num
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property Product $product
*
* @package App\Models
* @property-read \App\User $auth_user
* @property-read \App\User $user
* @method static \Illuminate\Database\Eloquent\Builder|ProductBuy newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ProductBuy newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ProductBuy query()
* @method static \Illuminate\Database\Eloquent\Builder|ProductBuy whereAuthUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBuy whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBuy whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBuy whereNum($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBuy whereProductId($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductBuy whereUpdatedAt($value)
* @mixin \Eloquent
*/
class ProductBuy extends Model
{

View file

@ -38,6 +38,7 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage query()
* @property int|null $pos
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ProductImage wherePos($value)
* @method static \Illuminate\Database\Eloquent\Builder|ProductImage withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
*/
class ProductImage extends Model
{

View file

@ -45,6 +45,14 @@ use Illuminate\Database\Eloquent\Collection;
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereTo($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereUpdatedAt($value)
* @mixin \Eloquent
* @property int|null $type
* @property bool $shop
* @property-read Collection|\App\Models\PromotionAdminProduct[] $promotion_admin_products
* @property-read int|null $promotion_admin_products_count
* @property-read Collection|\App\Models\PromotionAdminProduct[] $promotion_admin_products_active
* @property-read int|null $promotion_admin_products_active_count
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereShop($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionAdmin whereType($value)
*/
class PromotionAdmin extends Model
{
@ -167,15 +175,22 @@ class PromotionAdmin extends Model
public static function getActiveAdminPromotionsAsArray(){
$query = PromotionAdmin::where('active', true)
->where(function ($query) {
$PromotionAdmins = PromotionAdmin::where('active', true)->get();
$ret = [];
foreach($PromotionAdmins as $PromotionAdmin){
$temp = $PromotionAdmin->name;
$temp .= $PromotionAdmin->from ? " | vom: ".$PromotionAdmin->from : '';
$temp .= $PromotionAdmin->to ? " | bis: ".$PromotionAdmin->to : '';
$ret[$PromotionAdmin->id] = $temp;
}
/*->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();
});*/
return $ret;
}
}

View file

@ -45,6 +45,21 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUsedBudgetTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUserDeletedAt($value)
* @mixin \Eloquent
* @property int $user_id
* @property string|null $user_address
* @property-read Collection|\App\Models\PromotionUserProduct[] $promotion_user_products
* @property-read int|null $promotion_user_products_count
* @property-read Collection|\App\Models\PromotionUserProduct[] $promotion_user_products_active
* @property-read int|null $promotion_user_products_active_count
* @property-read \App\User $user
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUserAddress($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereUserId($value)
* @property string|null $about_you
* @property string|null $internal_name
* @property string|null $internal_description
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereAboutYou($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereInternalDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|PromotionUser whereInternalName($value)
*/
class PromotionUser extends Model
{
@ -68,8 +83,12 @@ class PromotionUser extends Model
'user_id',
'name',
'description',
'about_you',
'internal_name',
'internal_description',
'url',
'pick_up',
'user_address',
'used_budget_total',
'sell_items_total',
'active',
@ -97,7 +116,6 @@ class PromotionUser extends Model
{
return $this->hasMany(PromotionUserProduct::class);
}
public function promotion_user_products_active()
{
return $this->hasMany(PromotionUserProduct::class)->where('active', 1);
@ -106,7 +124,7 @@ class PromotionUser extends Model
public function getUrlPreview()
{
return $this->url ? config('app.promo_url').$this->url : "";
return $this->url ? config('app.promo_url')."/".$this->url : "";
}
public function canDelete(){
@ -164,7 +182,7 @@ class PromotionUser extends Model
public function checkPaymentCredit()
{
if($this->promotion_user_products_active->count() > 0 && $this->getCountOpenItems() > 0){
$payment_credit = \Auth::user()->payment_credit;
$payment_credit = $this->user->payment_credit;
if($payment_credit <= 0){
return "empty";
}
@ -179,9 +197,23 @@ class PromotionUser extends Model
}
return false;
}
public static function preCheckPaymentCredit($values){
public function checkOutOfStock(){
if(!$this->active){
return true;
}
if($this->getCountOpenItems() < 1){
return true;
}
if($this->checkPaymentCredit() !== 'okay'){
return true;
}
return false;
}
public static function preCheckPaymentCredit($values, $user){
if($values['count_items'] > 0 && $values['sum_items'] > 0){
$payment_credit = \Auth::user()->payment_credit;
$payment_credit = $user->payment_credit;
if($payment_credit <= 0){
return "empty";
}

View file

@ -89,4 +89,11 @@ class PromotionUserProduct extends Model
{
return $this->belongsTo(PromotionUser::class);
}
public function isShow(){
if($this->active && $this->product && $this->open_items > 0){
return true;
}
return false;
}
}

View file

@ -46,6 +46,7 @@ use Illuminate\Database\Eloquent\Model;
* @mixin \Eloquent
* @property int|null $int
* @method static \Illuminate\Database\Eloquent\Builder|Setting whereInt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Setting withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
*/
class Setting extends Model
{

View file

@ -37,6 +37,7 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SySetting whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\SySetting whereUpdatedAt($value)
* @mixin \Eloquent
* @method static \Illuminate\Database\Eloquent\Builder|SySetting withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
*/
class SySetting extends Model
{

View file

@ -119,6 +119,8 @@ use Carbon\Carbon;
* @property array|null $notice
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAccount whereAcceptedContract($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAccount whereNotice($value)
* @property string|null $about_you
* @method static \Illuminate\Database\Eloquent\Builder|UserAccount whereAboutYou($value)
*/
class UserAccount extends Model
{
@ -127,7 +129,7 @@ class UserAccount extends Model
'm_account', 'm_salutation', 'm_first_name', 'm_last_name', 'm_notes', 'company', 'salutation', 'first_name', 'last_name', 'address', 'address_2', 'zipcode', 'city', 'country_id', 'pre_phone_id', 'phone', 'pre_mobil_id', 'mobil',
'tax_number', 'tax_identification_number', 'taxable_sales', 'same_as_billing',
'shipping_salutation', 'shipping_company', 'shipping_firstname', 'shipping_lastname', 'shipping_address', 'shipping_address_2', 'shipping_zipcode', 'shipping_city', 'shipping_country_id', 'shipping_pre_phone_id', 'shipping_phone',
'birthday', 'website', 'facebook', 'facebook_fanpage', 'instagram', 'notice', 'payment_data'
'birthday', 'about_you', 'website', 'facebook', 'facebook_fanpage', 'instagram', 'notice', 'payment_data'
];
protected $casts = [

View file

@ -49,6 +49,8 @@ use Illuminate\Database\Eloquent\Model;
* @property string|null $date
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereCreditNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereDate($value)
* @property object|null $user_credits
* @method static \Illuminate\Database\Eloquent\Builder|UserCredit whereUserCredits($value)
*/
class UserCredit extends Model
{

View file

@ -34,6 +34,8 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|UserCreditMargin whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserCreditMargin whereUserId($value)
* @mixin \Eloquent
* @property int|null $user_credit_id
* @method static \Illuminate\Database\Eloquent\Builder|UserCreditMargin whereUserCreditId($value)
*/
class UserCreditMargin extends Model
{

View file

@ -31,7 +31,7 @@ class ProductRepository extends BaseRepository {
$data['amount_commission'] = isset($data['amount_commission']) ? 1 : 0;
$data['shipping_addon'] = isset($data['shipping_addon']) ? 1 : 0;
$data['max_buy'] = isset($data['max_buy']) ? 1 : 0;
$data['show_on'] = isset($data['show_on']) ? $data['show_on'] : null;
if($data['id'] === "new"){
$this->model = Product::create($data);

View file

@ -67,9 +67,11 @@ class UserPromotionRepository extends BaseRepository {
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,
'user_address' => Auth::user()->getFullAddress()
]);
return $this->model;
}

View file

@ -213,6 +213,9 @@ class Payment
//when stone, put it back SalesController
public static function handelUserPayCredits(ShoppingOrder $shopping_order, $do){
//is payment credit, reduce Sae
if(!$shopping_order->shopping_order_margin){
return;
}
if($do === 'deduction'){
if($shopping_order->shopping_order_margin->from_payment_credit > 0){
$credit = $shopping_order->shopping_order_margin->from_payment_credit * -1;

View file

@ -222,6 +222,18 @@ class Util
}
return url($uri);
}
public static function substr_ellipsis($str, $len=100, $clean, $ell="..."){
if($clean){
$str = strip_tags($str);
}
if(strlen($str) > $len){
$lastPos = ($len - 3) - strlen($str);
$str = substr($str, 0, strrpos($str, ' ', $lastPos)) ." ".$ell;
}
return $str;
}
public static function sanitize($string, $force_lowercase = true, $anal = false, $substr = false, $anCon = false)
{
$strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "=", "+", "[", "{", "]",

View file

@ -101,6 +101,10 @@ use Util;
* @method static \Illuminate\Database\Eloquent\Builder|User wherePaymentCredit($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserPayCredit[] $user_pay_credits
* @property-read int|null $user_pay_credits_count
* @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Client[] $clients
* @property-read int|null $clients_count
* @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Token[] $tokens
* @property-read int|null $tokens_count
*/
class User extends Authenticatable
{
@ -135,6 +139,9 @@ class User extends Authenticatable
'payment_methods' => 'array'
];
private $userImage = false;
private $userImageLink = false;
public function account(){
return $this->belongsTo('App\Models\UserAccount', 'account_id');
}
@ -194,6 +201,25 @@ class User extends Authenticatable
return $ret;
}
public function getFullAddress($email=true){
$ret = "";
if($this->account){
$ret .= $this->account->first_name." ".$this->account->last_name."\n";
$ret .= $this->account->address."\n";
$ret .= $this->account->address_2 ? $this->account->address_2."\n" : "";
$ret .= $this->account->zipcode." ".$this->account->city."\n";
$ret .= $email ? $this->email."\n" : "";
$pre = $this->account->pre_phone_id != "" ? $this->account->pre_phone->phone." " : "";
$ret .= $this->account->phone ? $pre.$this->account->phone."\n" : "";
$pre = $this->account->pre_mobil_id != "" ? $this->account->pre_mobil->phone." " : "";
$ret .= $this->account->mobil ? $pre.$this->account->mobil."\n" : "";
}
return $ret;
}
/**
* @return bool
*/
@ -414,6 +440,27 @@ class User extends Authenticatable
return null;
}
public function hasProfileImage(){
if($this->userImage){
return $this->userImage;
}
if(\Storage::disk('user')->has($this->id.'/avatar.jpg')){
$this->userImage = $this->id.'/avatar.jpg';
}
if(\Storage::disk('user')->has($this->id.'/avatar.png')){
$this->userImage = $this->id.'/avatar.jpg';
}
return $this->userImage;
}
public function getProfileImage(){
if($this->hasProfileImage()){
return str_replace('/', '_', $this->userImage);
}
return null;
}
/**
* Send the password reset notification.
*

View file

@ -83,3 +83,11 @@ if (! function_exists('formatPlural')) {
}
if (! function_exists('substr_ellipsis')) {
function substr_ellipsis($str, $len=100, $clean, $ell="...")
{
return Util::substr_ellipsis($str, $len, $clean, $ell);
}
}