Cron Jobs, Reminder, Fonts, Members / Wizard / Price, Credit and Promotion
This commit is contained in:
parent
a0f4eda6ea
commit
6167273a48
204 changed files with 8746 additions and 215 deletions
120
app/Console/Commands/PaymentsAccounts.php
Normal file
120
app/Console/Commands/PaymentsAccounts.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Cron\UserCheckPaymentsAccounts;
|
||||
|
||||
class PaymentsAccounts extends Command
|
||||
{
|
||||
/**
|
||||
* ln -sfv /usr/bin/php73 /usr/bin/php
|
||||
* php artisan payments:accounts
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'payments:accounts';
|
||||
protected $description = 'Check Payments Accounts';
|
||||
|
||||
private $timeStart;
|
||||
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('RUN Command Payments Account: '.date('d.m.Y H:i'));
|
||||
$this->timeStart = microtime(true);
|
||||
|
||||
$this->updateUserNextLevel();
|
||||
$this->updatePaymentsAccountsFree();
|
||||
$this->reminderPaymentsAccounts();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
private function updateUserNextLevel(){
|
||||
// now date - renewal_days
|
||||
$count = 0;
|
||||
$renewalDate = Carbon::now()->modify('+'.(config('main.renewal_days')).' days');
|
||||
$users = User::where('payment_account', '!=', NULL)
|
||||
->where('active', '=', 1)
|
||||
->where('blocked', '!=', 1)
|
||||
->where('payment_account', '<', $renewalDate)
|
||||
->whereColumn('m_level', '!=', 'next_m_level')
|
||||
->get();
|
||||
|
||||
foreach($users as $user){
|
||||
$user->m_level = $user->next_m_level;
|
||||
$user->save();
|
||||
$count ++;
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command updateUserNextLevel: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
}
|
||||
|
||||
|
||||
private function updatePaymentsAccountsFree(){
|
||||
// now date - renewal_days -1 / user_levels.payment_year false is no payment
|
||||
$count = 0;
|
||||
$renewalDate = Carbon::now()->modify('+'.(config('main.renewal_days')-1).' days');
|
||||
$users = User::join('user_levels', 'm_level', '=', 'user_levels.id')->select('users.*')
|
||||
->where('users.payment_account', '!=', NULL)
|
||||
->where('users.active', '=', 1)
|
||||
->where('users.blocked', '!=', 1)
|
||||
->where('users.payment_account', '<', $renewalDate)
|
||||
->where('user_levels.payment_year', '=', 0)
|
||||
->get();
|
||||
|
||||
foreach($users as $user){
|
||||
$user->payment_account = Carbon::parse($user->payment_account)->modify('1 year');
|
||||
$user->save();
|
||||
$count ++;
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command updatePaymentsAccountsFree: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
}
|
||||
|
||||
private function reminderPaymentsAccounts()
|
||||
{
|
||||
|
||||
$count = 0;
|
||||
$max_reminder_date = Carbon::now()->modify('+'.(config('main.remind_first_days')).' days');
|
||||
$users = User::where('payment_account', '!=', NULL)
|
||||
->where('active', '=', 1)
|
||||
->where('blocked', '!=', 1)
|
||||
->where('payment_account', '<', $max_reminder_date)
|
||||
->get();
|
||||
|
||||
foreach ($users as $user){
|
||||
$status = UserCheckPaymentsAccounts::userReminderPayments($user);
|
||||
$this->info('reminderPaymentsAccounts Status: '.$status.' | User: '.$user->id.' '.$user->email.' | Date :' . $user->getPaymentAccountDateFormat() . "");
|
||||
$count ++;
|
||||
}
|
||||
|
||||
$diff = microtime(true) - $this->timeStart;
|
||||
$sec = intval($diff);
|
||||
$micro = $diff - $sec;
|
||||
$this->info('END Command reminderPaymentsAccounts: '.$count.' | Time: '.$sec. 'sec :' . round($micro * 1000, 4) . " ms");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -24,8 +24,10 @@ class Kernel extends ConsoleKernel
|
|||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
$schedule->command('payments:accounts')
|
||||
->sendOutputTo("cron.log");
|
||||
//->hourly();
|
||||
// ->emailOutputTo('kevin@adametz.media');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
87
app/Cron/CronController.php
Normal file
87
app/Cron/CronController.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
namespace App\Cron;
|
||||
|
||||
use App\User;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\UserCreditItem;
|
||||
use App\Repositories\CreditRepository;
|
||||
|
||||
class UserCheckPaymentsAccounts
|
||||
{
|
||||
private $month;
|
||||
private $year;
|
||||
|
||||
|
||||
public function __construct($month, $year)
|
||||
{
|
||||
$this->month = $month;
|
||||
$this->year = $year;
|
||||
}
|
||||
|
||||
|
||||
public function getUserBusinessByMonthYear(){
|
||||
return UserBusiness::select('user_businesses.*')
|
||||
->where('user_businesses.month', '=', $this->month)
|
||||
->where('user_businesses.year', '=', $this->year)
|
||||
->where(function($q) {
|
||||
return $q->where('user_businesses.commission_team_total', '>', 0)
|
||||
->orWhere('user_businesses.commission_shop_sales', '>', 0);
|
||||
})
|
||||
->get();
|
||||
}
|
||||
|
||||
public function addUserCreditItem($userBusiness)
|
||||
{
|
||||
$date = HTMLHelper::getMonth($userBusiness->month).' '.$userBusiness->year;
|
||||
|
||||
if($userBusiness->commission_shop_sales > 0){
|
||||
if($this->hasNotUserCreditItem($userBusiness, 1)){
|
||||
UserCreditItem::create([
|
||||
'user_id' => $userBusiness->user_id,
|
||||
'user_business_id' => $userBusiness->id,
|
||||
'credit' => $userBusiness->commission_shop_sales,
|
||||
'message' => 'Provision Shop '.$date,
|
||||
'status' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
if($userBusiness->commission_team_total > 0){
|
||||
if($this->hasNotUserCreditItem($userBusiness, 2)){
|
||||
UserCreditItem::create([
|
||||
'user_id' => $userBusiness->user_id,
|
||||
'user_business_id' => $userBusiness->id,
|
||||
'credit' => $userBusiness->commission_team_total,
|
||||
'message' => 'Provision Team '.$date,
|
||||
'status' => 2,
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $userBusiness;
|
||||
|
||||
}
|
||||
|
||||
public function getUserCreditItemUsersByMonthYear(){
|
||||
return UserCreditItem::select('user_credit_items.*')
|
||||
->where('paid', '=', false)
|
||||
->groupBy('user_id')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function makeCreditPaymentPDF($user_id, $credit_send_mail)
|
||||
{
|
||||
//$user_id = 2;
|
||||
$user = User::findOrFail($user_id);
|
||||
$data = [];
|
||||
if($credit_send_mail){
|
||||
$data['credit_send_mail'] = true;
|
||||
}
|
||||
$credit_repo = new CreditRepository($user);
|
||||
return $credit_repo->create($data);
|
||||
}
|
||||
|
||||
private function hasNotUserCreditItem($userBusiness, $status){
|
||||
return (UserCreditItem::where('user_business_id', $userBusiness->id)
|
||||
->where('user_id', $userBusiness->user_id)->where('status', $status)->count() > 0) ? false : true;
|
||||
}
|
||||
}
|
||||
154
app/Cron/UserCheckPaymentsAccounts.php
Normal file
154
app/Cron/UserCheckPaymentsAccounts.php
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
<?php
|
||||
namespace App\Cron;
|
||||
|
||||
use App\User;
|
||||
use App\Models\UserBusiness;
|
||||
use App\Services\HTMLHelper;
|
||||
use App\Models\UserCreditItem;
|
||||
use App\Repositories\CreditRepository;
|
||||
use App\Mail\MailCustomMessage;
|
||||
use App\Mail\MailVerifyAccount;
|
||||
use App\Models\UserHistory;
|
||||
use App\Models\UserMessage;
|
||||
use Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class UserCheckPaymentsAccounts
|
||||
{
|
||||
|
||||
/*RULES
|
||||
reminders
|
||||
> 29 renewal_days > set next_m_level to m_level
|
||||
> 29 renewal_days $user->user_level->payment_year = 0 / false + 1 year
|
||||
|
||||
> 21 remind_first_days = reminder_first //status 31
|
||||
> 14 remind_sec_days = reminder_sec //status 33
|
||||
> 2 remind_last_days = reminder_last //status 34
|
||||
> 0 deaktiv = reminder_deaktiv //status 35
|
||||
*/
|
||||
|
||||
public static function userReminderPayments(User $user){
|
||||
//35 reminder_deaktiv
|
||||
if(!$user->isActiveAccount()){ // payment_account gt now
|
||||
return self::checkIsReminderSend($user, 35);
|
||||
}
|
||||
//34 reminder_last
|
||||
if($user->daysActiveAccount() <= config('main.remind_last_days')){
|
||||
return self::checkIsReminderSend($user, 34);
|
||||
}
|
||||
//33 reminder_sec
|
||||
if($user->daysActiveAccount() <= config('main.remind_sec_days')){
|
||||
return self::checkIsReminderSend($user, 33);
|
||||
}
|
||||
//31 reminder_first
|
||||
if($user->daysActiveAccount() > config('main.remind_sec_days')){
|
||||
return self::checkIsReminderSend($user, 31);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function checkIsReminderSend(User $user, $status){
|
||||
|
||||
$isSend = UserHistory::whereUserId($user->id)
|
||||
->whereAction('reminder_payments')
|
||||
->whereIdentifier($user->payment_account)
|
||||
->whereStatus($status)
|
||||
->get()->last();
|
||||
|
||||
if($isSend){
|
||||
return 0;
|
||||
}
|
||||
$referenz = self::sendReminderMail($user, $status);
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'reminder_payments', 'referenz'=>$referenz, 'identifier'=>$user->payment_account, 'status'=>$status]);
|
||||
return $status;
|
||||
|
||||
}
|
||||
|
||||
private function sendReminderMail(User $user, $status){
|
||||
|
||||
$days = $user->daysActiveAccount();
|
||||
if($days < 0){
|
||||
$days = $days*-1;
|
||||
}
|
||||
$datetime = $user->getPaymentAccountDateFormat();
|
||||
|
||||
$pay_date = 0;
|
||||
$price = 0;
|
||||
/*$pay_date = Carbon::parse($user->payment_account)->modify('- '.config('main.abo_booking_days').' days')->format('d.m.Y');
|
||||
$price = "";
|
||||
if($user->payment_order_id && isset($user->payment_order_product->price)){
|
||||
$price = 'von '.$user->payment_order_product->getFormattedPrice().' EUR';
|
||||
}*/
|
||||
|
||||
$message = __('reminder.copy_first_'.$status, ['days'=>$days, 'datetime'=>$datetime, 'price' =>$price, 'pay_date'=>$pay_date]);
|
||||
$message_last = __('reminder.copy_last_'.$status, ['days'=>$days, 'datetime'=>$datetime, 'price' =>$price, 'pay_date'=>$pay_date]);
|
||||
$button = __('reminder.button_'.$status);
|
||||
|
||||
$message = preg_replace("/[\n\r]/","",$message);
|
||||
$message_last = preg_replace("/[\n\r]/","",$message_last);
|
||||
|
||||
$data = [
|
||||
'subject' => __('reminder.subject')." | ID: ".$status,
|
||||
'message' => $message,
|
||||
'message_last' => $message_last,
|
||||
'url' => route('user_membership'),
|
||||
'button' => $button,
|
||||
];
|
||||
//dump($data);
|
||||
$sender = User::find(1);
|
||||
$customer_mail = UserMessage::create([
|
||||
'user_id' => $user->id,
|
||||
'send_user_id' => $sender->id,
|
||||
'email' => $user->email,
|
||||
'subject' => $data['subject'],
|
||||
'message' => $data['message']." ".$data['message_last'],
|
||||
]);
|
||||
try{
|
||||
if($status >= 34){
|
||||
Mail::to($user->email)->bcc(config('app.info_mail'))->send(new MailCustomMessage($user, $data, $sender, false));
|
||||
}else{
|
||||
Mail::to($user->email)->send(new MailCustomMessage($user, $data, $sender, false));
|
||||
}
|
||||
}
|
||||
catch(\Exception $e){
|
||||
\Log::channel('cron')->error('Mail Error: '.$e->getMessage());
|
||||
// Never reached
|
||||
$customer_mail->fail = true;
|
||||
$customer_mail->error = $e->getMessage();
|
||||
$customer_mail->save();
|
||||
return 0;
|
||||
}
|
||||
$customer_mail->send = true;
|
||||
$customer_mail->sent_at = now();
|
||||
$customer_mail->save();
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*public function checkConfirmation()
|
||||
{
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$next = date('Y-m-d H:i:s', strtotime('+3 week'));
|
||||
|
||||
$users = User::where('confirmed', '=', 0)->where('confirmation_code_to', '<', $now)->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
||||
//delete user
|
||||
if ($user->confirmation_code_remider == 1) {
|
||||
$this->userRepo->deleteUser($user);
|
||||
|
||||
}
|
||||
//send new remider
|
||||
if ($user->confirmation_code_remider == 0) {
|
||||
Mail::to($user->email)->bcc(config('app.info_mail'))->send(new MailVerifyAccount($user->confirmation_code, $user));
|
||||
$user->confirmation_code_to = $next;
|
||||
$user->confirmation_code_remider = 1;
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
return "TOSK";
|
||||
}*/
|
||||
|
||||
|
|
@ -20,6 +20,11 @@ class AuthController extends Controller
|
|||
|
||||
public $successStatus = 200;
|
||||
|
||||
public function test(Request $request)
|
||||
{
|
||||
var_dump("testing");
|
||||
die("test");
|
||||
}
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -230,7 +230,9 @@ class LeadController extends Controller
|
|||
if(!$user->account->m_last_name){
|
||||
$validator->errors()->add('m_last_name', __('Vertriebspartner hat keinen Nachnamen.'));
|
||||
}
|
||||
|
||||
if(!$user->m_level){
|
||||
$validator->errors()->add('m_level', __('Vertriebspartner hat keine Rolle'));
|
||||
}
|
||||
if ($validator->errors()->count()) {
|
||||
return back()->withErrors($validator)->withRequest(Request::all());
|
||||
}
|
||||
|
|
@ -248,14 +250,8 @@ class LeadController extends Controller
|
|||
$pdf->_set('identifier', 'contract');
|
||||
$pdf->createContractPDF();
|
||||
|
||||
//set wizard tp payments
|
||||
$user->wizard = 20;
|
||||
$user->active = 1;
|
||||
$user->active_date = now();
|
||||
$user->confirmation_code = null;
|
||||
$user->confirmation_code_to = null;
|
||||
$user->confirmation_code_remider = 0;
|
||||
$user->save();
|
||||
//set wizard to payments / activate
|
||||
$this->activeAccountPayment($user);
|
||||
|
||||
//mail with code to user?
|
||||
try {
|
||||
|
|
@ -274,8 +270,6 @@ class LeadController extends Controller
|
|||
}
|
||||
|
||||
if($action === 'incomplete'){
|
||||
|
||||
|
||||
//reset release
|
||||
$confirmation_code = UserService::createConfirmationCode();
|
||||
$user->confirmation_code = $confirmation_code;
|
||||
|
|
@ -303,9 +297,58 @@ class LeadController extends Controller
|
|||
}
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'released_incomplete', 'status'=>0]);
|
||||
\Session()->flash('alert-success', "E-Mail an Vertriebspartner gesendet.");
|
||||
}
|
||||
if($action === 'reset_switch'){
|
||||
$user->wizard = 4;
|
||||
$user->save();
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'reset_switch', 'status'=>0]);
|
||||
\Session()->flash('alert-success', "Vertriebspartner zurückgesetzt!");
|
||||
}
|
||||
if($action === 'unlock'){
|
||||
$validator = Validator::make(Request::all(), []);
|
||||
/*if(!$user->m_sponsor){
|
||||
$validator->errors()->add('m_sponsor', __('Vertriebspartner hat keinen Sponsor.'));
|
||||
}*/
|
||||
if(!$user->account->m_first_name){
|
||||
$validator->errors()->add('m_first_name', __('Vertriebspartner hat keinen Vornamen.'));
|
||||
}
|
||||
if(!$user->account->m_last_name){
|
||||
$validator->errors()->add('m_last_name', __('Vertriebspartner hat keinen Nachnamen.'));
|
||||
}
|
||||
if(!$user->m_level){
|
||||
$validator->errors()->add('m_level', __('Vertriebspartner hat keine Rolle'));
|
||||
}
|
||||
|
||||
if ($validator->errors()->count()) {
|
||||
return back()->withErrors($validator)->withRequest(Request::all());
|
||||
}
|
||||
|
||||
if(!$user->account->m_account){
|
||||
$user->account->m_account = UserAccount::withTrashed()->max('m_account') +1;
|
||||
$user->account->save();
|
||||
}
|
||||
|
||||
//set wizard to payments / activate
|
||||
$this->activeAccountPayment($user);
|
||||
|
||||
//mail with code to user?
|
||||
try {
|
||||
Mail::to($user->email)->bcc(config('app.info_mail'))->send(new MailAccountActive($user));
|
||||
}
|
||||
catch(\Exception $e){
|
||||
SysLog::action('unlock', 'admin_lead', 5)
|
||||
->setUserId($user->id)
|
||||
->setModel($user->id, User::class)
|
||||
->setMessage('Error send released E-Mail: '.$e->getMessage())
|
||||
->save();
|
||||
}
|
||||
|
||||
UserHistory::create(['user_id' => $user->id, 'action'=>'unlock_completed', 'status'=>0]);
|
||||
\Session()->flash('alert-success', "Vertriebspartner erneut freigeschaltet!");
|
||||
}
|
||||
return redirect(route('admin_lead_edit', [$user->id]));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -350,7 +393,6 @@ class LeadController extends Controller
|
|||
return back();
|
||||
}
|
||||
|
||||
|
||||
public function getLeads()
|
||||
{
|
||||
|
||||
|
|
@ -409,4 +451,30 @@ class LeadController extends Controller
|
|||
->rawColumns(['id', 'confirmed', 'active', 'agreement', 'payment_account'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
private function activeAccountPayment($user){
|
||||
|
||||
if($user->user_level){
|
||||
if($user->user_level->payment_year){
|
||||
//if true = payments
|
||||
$user->wizard = 20;
|
||||
$user->active = 1;
|
||||
$user->active_date = now();
|
||||
$user->confirmation_code = null;
|
||||
$user->confirmation_code_to = null;
|
||||
$user->confirmation_code_remider = 0;
|
||||
$user->save();
|
||||
}else{
|
||||
//if false = no payments for 1 year
|
||||
$user->wizard = 100;
|
||||
$user->payment_account = \Carbon::now()->modify('1 year');
|
||||
$user->active = 1;
|
||||
$user->active_date = now();
|
||||
$user->confirmation_code = null;
|
||||
$user->confirmation_code_to = null;
|
||||
$user->confirmation_code_remider = 0;
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ class MembershipController extends Controller
|
|||
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
|
||||
'userHistoryUpgradeOrder' => $userHistoryUpgradeOrder,
|
||||
'userHistoryDeleteMembership' => $userHistoryDeleteMembership,
|
||||
'user_levels' => UserLevel::where('active', true)->get(),
|
||||
'user_levels' => UserLevel::where('active', true)->orderBy('pos')->get(),
|
||||
|
||||
];
|
||||
return view('user.membership.index', $data);
|
||||
|
|
|
|||
|
|
@ -167,21 +167,24 @@ class OrderController extends Controller
|
|||
|
||||
$data = Request::all();
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
||||
$rules = array(
|
||||
'shipping_salutation' => 'required',
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_firstname' => 'required',
|
||||
'shipping_lastname' => 'required',
|
||||
'shipping_address' => 'required',
|
||||
'shipping_zipcode' => 'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_state' => 'required',
|
||||
);
|
||||
|
||||
$validator = Validator::make(Request::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withInput(Request::all());
|
||||
}
|
||||
if(Yard::instance('shopping')->getNumComp() > 0){
|
||||
|
||||
if(Yard::instance('shopping')->getNumComp() > 0){
|
||||
if(!isset($data['switchers-comp-product'])){
|
||||
$validator->errors()->add('switchers-comp-product', __('Bitte wähle ein Kompensationsprodukt aus'));
|
||||
}else{
|
||||
|
|
@ -198,9 +201,12 @@ class OrderController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
/*do {
|
||||
/*
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );*/
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
*/
|
||||
|
||||
$identifier = Util::getToken();
|
||||
$data['is_from'] = 'user_order';
|
||||
$data['is_for'] = $for;
|
||||
|
|
@ -219,7 +225,6 @@ class OrderController extends Controller
|
|||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'shopping_data' => $data,
|
||||
'back' => url()->previous(),
|
||||
|
||||
]);
|
||||
Yard::instance('shopping')->store($identifier);
|
||||
*/
|
||||
|
|
@ -301,7 +306,6 @@ class OrderController extends Controller
|
|||
return \DataTables::eloquent($query)
|
||||
|
||||
->addColumn('product', function (Product $product) {
|
||||
|
||||
$cartItem = Yard::instance('shopping')->getCartItemByProduct($product->id);
|
||||
$qty = isset($cartItem->qty) ? $cartItem->qty : 0;
|
||||
$rowId = isset($cartItem->rowId) ? $cartItem->rowId : '';
|
||||
|
|
@ -318,7 +322,6 @@ class OrderController extends Controller
|
|||
</div>';
|
||||
})
|
||||
/*
|
||||
|
||||
->addColumn('add_card', function (Product $product) {
|
||||
return '<button type="button" class="btn btn-sm btn-md-extra btn-secondary add-product-basket" data-product-id="'.$product->id.'">
|
||||
<strong>€ '.$product->getFormattedPriceWith().'</strong> +<span class="ion ion-md-cart"></span>
|
||||
|
|
@ -455,6 +458,16 @@ class OrderController extends Controller
|
|||
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
|
||||
}
|
||||
}
|
||||
if($data['action'] === 'reCalculateCart') {
|
||||
//set use_payment_credit
|
||||
$data['reduce_payment_credit'] = $data['reduce_payment_credit'] == 'true' ? true: false;
|
||||
Yard::instance('shopping')->setReducePaymentCredit($data['reduce_payment_credit']);
|
||||
Yard::instance('shopping')->reCalculate();
|
||||
$html_card = view("user.order.yard_view_form", $data)->render();
|
||||
$html_comp = view("user.order.comp_product", $data)->render();
|
||||
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
|
||||
}
|
||||
|
||||
if($data['action'] === 'clearCart') {
|
||||
Yard::instance('shopping')->destroy();
|
||||
return response()->json(['response' => true, 'data'=>Yard::instance('shopping')->count(), 'html_card'=>'', 'html_comp'=>'']);
|
||||
|
|
@ -507,27 +520,27 @@ class OrderController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
if(isset($data['comp_product_id'])) {
|
||||
if ($product = Product::find($data['comp_product_id'])) {
|
||||
$image = "";
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, 0,
|
||||
[
|
||||
'image' => $image,
|
||||
'slug' => $product->slug,
|
||||
'weight' => 0,
|
||||
'single_commission' => 0,
|
||||
'amount_commission' => 0,
|
||||
'value_commission' => 0,
|
||||
'partner_commission' => 0,
|
||||
'comp' => $data['comp_num'],
|
||||
'product_id' => $product->id
|
||||
]);
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
if(isset($data['comp_product_id'])) {
|
||||
if ($product = Product::find($data['comp_product_id'])) {
|
||||
$image = "";
|
||||
if ($product->images->count()) {
|
||||
$image = $product->images->first()->slug;
|
||||
}
|
||||
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0, 0,
|
||||
[
|
||||
'image' => $image,
|
||||
'slug' => $product->slug,
|
||||
'weight' => 0,
|
||||
'single_commission' => 0,
|
||||
'amount_commission' => 0,
|
||||
'value_commission' => 0,
|
||||
'partner_commission' => 0,
|
||||
'comp' => $data['comp_num'],
|
||||
'product_id' => $product->id
|
||||
]);
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getCompProducts($for){
|
||||
|
|
|
|||
|
|
@ -3,15 +3,14 @@
|
|||
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 Validator;
|
||||
use App\Services\Util;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Services\UserService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Repositories\UserPromotionRepository;
|
||||
|
||||
class PromotionController extends Controller
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class UserLevelController extends Controller
|
|||
{
|
||||
|
||||
$data = [
|
||||
'values' => UserLevel::all(),
|
||||
'values' => UserLevel::orderBy('pos')->get(),
|
||||
'trans' => array_keys(config('localization.supportedLocales')),
|
||||
];
|
||||
return view('admin.level.index', $data);
|
||||
|
|
@ -57,6 +57,7 @@ class UserLevelController extends Controller
|
|||
$user_level = UserLevel::create([
|
||||
'name' => $data['name'],
|
||||
'pos' => $data['pos'],
|
||||
'payment_year' => isset($data['payment_year']) ? true : false,
|
||||
'content' => $data['content'],
|
||||
'partner_provision' => isset($data['partner_provision']) ? true : false,
|
||||
'active' => isset($data['active']) ? true : false,
|
||||
|
|
@ -65,6 +66,7 @@ class UserLevelController extends Controller
|
|||
$user_level = UserLevel::find($data['id']);
|
||||
$user_level->name = $data['name'];
|
||||
$user_level->pos = $data['pos'];
|
||||
$user_level->payment_year =isset($data['payment_year']) ? true : false;
|
||||
$user_level->content = $data['content'];
|
||||
$user_level->partner_provision = isset($data['partner_provision']) ? true : false;
|
||||
$user_level->active = isset($data['active']) ? true : false;
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class WizardController extends Controller
|
|||
$data = [
|
||||
'user' => Auth::user(),
|
||||
'step' => $step,
|
||||
'user_levels' => UserLevel::where('active', true)->get(),
|
||||
'user_levels' => UserLevel::where('active', true)->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(),
|
||||
|
||||
|
|
@ -161,7 +161,7 @@ class WizardController extends Controller
|
|||
$data = [
|
||||
'user' => Auth::user(),
|
||||
'step' => $step,
|
||||
'user_levels' => UserLevel::where('active', true)->get(),
|
||||
'user_levels' => UserLevel::where('active', true)->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(),,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -42,19 +42,17 @@ class UserLevel extends Model
|
|||
{
|
||||
protected $table = 'user_levels';
|
||||
|
||||
protected $casts = ['trans_name' => 'array', 'trans_content' => 'array', 'partner_provision'=>'bool'];
|
||||
protected $casts = ['trans_name' => 'array',
|
||||
'trans_content' => 'array',
|
||||
'partner_provision'=>'bool',
|
||||
'payment_year' => 'bool',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'content', 'pos', 'active', 'partner_provision',
|
||||
'name', 'content', 'pos', 'payment_year', 'active', 'partner_provision',
|
||||
];
|
||||
|
||||
|
||||
/* public function childrens()
|
||||
{
|
||||
return $this->hasMany('App\Models\Attribute', 'parent_id', 'id');
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public function user_level_margins()
|
||||
{
|
||||
|
|
@ -71,7 +69,6 @@ class UserLevel extends Model
|
|||
|
||||
}
|
||||
|
||||
|
||||
public function _format_number($value){
|
||||
return preg_replace("/[^0-9,]/", "", $value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ namespace App\Services;
|
|||
|
||||
|
||||
use App\User;
|
||||
use App\Models\PromotionUser;
|
||||
|
||||
class UserService
|
||||
{
|
||||
|
|
@ -18,4 +19,15 @@ class UserService
|
|||
return $confirmation_code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function hasActivePromotion($user) {
|
||||
$promotion_users = PromotionUser::where('user_id', $user->id)->where('active', 1)->whereNull('user_deleted_at')->get();
|
||||
foreach($promotion_users as $promotion_user){
|
||||
if($promotion_user->promotion_admin->isActive()){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,16 +2,17 @@
|
|||
namespace App\Services;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Services\UserService;
|
||||
use App\Services\Yard\Margin;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Services\Yard\Commission;
|
||||
use App\Services\Yard\Margin;
|
||||
use App\Services\Yard\MarginItems;
|
||||
use Gloudemans\Shoppingcart\Cart;
|
||||
use App\Services\Yard\MarginItems;
|
||||
use Illuminate\Support\Collection;
|
||||
use Gloudemans\Shoppingcart\CartItem;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
use Gloudemans\Shoppingcart\Contracts\Buyable;
|
||||
|
||||
/*
|
||||
|
||||
|
|
@ -38,7 +39,9 @@ class Yard extends Cart
|
|||
private $yinstance;
|
||||
private $shopping_data = [];
|
||||
private $user;
|
||||
private $payment_credit;
|
||||
private $use_payment_credit;
|
||||
private $has_active_promotion;
|
||||
private $reduce_payment_credit;
|
||||
|
||||
private $yard_commission;
|
||||
private $yard_margin;
|
||||
|
|
@ -75,8 +78,14 @@ class Yard extends Cart
|
|||
if($this->getYardExtra('user')){
|
||||
$this->user = $this->getYardExtra('user');
|
||||
}
|
||||
if($this->getYardExtra('payment_credit')){
|
||||
$this->payment_credit = $this->getYardExtra('payment_credit');
|
||||
if($this->getYardExtra('use_payment_credit')){
|
||||
$this->use_payment_credit = $this->getYardExtra('use_payment_credit');
|
||||
}
|
||||
if($this->getYardExtra('has_active_promotion')){
|
||||
$this->has_active_promotion = $this->getYardExtra('has_active_promotion');
|
||||
}
|
||||
if($this->getYardExtra('reduce_payment_credit')){
|
||||
$this->reduce_payment_credit = $this->getYardExtra('reduce_payment_credit');
|
||||
}
|
||||
if($this->getYardExtra('yard_commission')){
|
||||
$this->yard_commission = $this->getYardExtra('yard_commission');
|
||||
|
|
@ -268,14 +277,17 @@ class Yard extends Cart
|
|||
$rest_amount = $end_monthy_amount - ($start_monthy_amount + $balance);
|
||||
}
|
||||
}else{
|
||||
$range = $last_limit-$user_level_margin->price_from;
|
||||
if($rest_amount >= $range){
|
||||
$balance = $range;
|
||||
}else{
|
||||
$balance = $rest_amount;
|
||||
if(isset($last_limit)){
|
||||
$range = $last_limit - $user_level_margin->price_from;
|
||||
if($rest_amount >= $range){
|
||||
$balance = $range;
|
||||
}else{
|
||||
$balance = $rest_amount;
|
||||
}
|
||||
$rest_amount = $rest_amount - $balance;
|
||||
}
|
||||
$rest_amount = $rest_amount-$balance;
|
||||
}
|
||||
|
||||
$last_limit = $user_level_margin->price_from;
|
||||
if($balance != 0){
|
||||
$commission = 0;
|
||||
|
|
@ -287,8 +299,8 @@ class Yard extends Cart
|
|||
'range' => $range,
|
||||
'rest_amount' => $rest_amount,
|
||||
'balance' => $balance,
|
||||
'trading_margin'=> $user_level_margin->trading_margin,
|
||||
'commission'=> $commission,
|
||||
'trading_margin' => $user_level_margin->trading_margin,
|
||||
'commission' => $commission,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -299,7 +311,6 @@ class Yard extends Cart
|
|||
$margin->calculate();
|
||||
$this->yard_margin = $margin;
|
||||
$this->putYardExtra('yard_margin', $this->yard_margin);
|
||||
|
||||
//dump($margin);
|
||||
}
|
||||
|
||||
|
|
@ -322,20 +333,49 @@ class Yard extends Cart
|
|||
|
||||
}
|
||||
|
||||
public function setShoppingUser($user, $payment_credit = false){
|
||||
public function setShoppingUser($user, $use_payment_credit = false){
|
||||
$this->user = $user;
|
||||
$this->payment_credit = $payment_credit;
|
||||
$this->use_payment_credit = $use_payment_credit;
|
||||
$this->has_active_promotion = UserService::hasActivePromotion($user);
|
||||
$this->reduce_payment_credit = true; //default set true, checkbox on yard_view_from ist checked
|
||||
$this->putYardExtra('user', $user);
|
||||
$this->putYardExtra('payment_credit', $payment_credit);
|
||||
$this->putYardExtra('use_payment_credit', $use_payment_credit);
|
||||
$this->putYardExtra('has_active_promotion', $this->has_active_promotion);
|
||||
$this->putYardExtra('reduce_payment_credit', $this->reduce_payment_credit);
|
||||
|
||||
}
|
||||
|
||||
public function setReducePaymentCredit($reduce_payment_credit){
|
||||
$this->reduce_payment_credit = $reduce_payment_credit;
|
||||
$this->putYardExtra('reduce_payment_credit', $reduce_payment_credit);
|
||||
}
|
||||
|
||||
public function getReducePaymentCredit(){
|
||||
return $this->reduce_payment_credit;
|
||||
}
|
||||
|
||||
|
||||
public function getPaymentCredit(){
|
||||
if($this->payment_credit && $this->user->payment_credit > 0){
|
||||
if($this->use_payment_credit && $this->user->payment_credit > 0){
|
||||
return $this->user->payment_credit;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasActivePromotion(){
|
||||
return $this->has_active_promotion;
|
||||
}
|
||||
|
||||
public function reducePaymentCredit(){
|
||||
if(!$this->reduce_payment_credit){
|
||||
return false;
|
||||
}
|
||||
if($this->has_active_promotion){
|
||||
return false;
|
||||
}
|
||||
return $this->getPaymentCredit();
|
||||
}
|
||||
|
||||
private function calculateShippingPrice(){
|
||||
//keine Verandkosten
|
||||
if($this->shipping_option && $this->shipping_option === 'pick_up'){
|
||||
|
|
@ -527,7 +567,7 @@ class Yard extends Cart
|
|||
$subtotal_shipping = $this->subtotalWithShipping(2, '.', '');
|
||||
$tax = $subtotal_shipping / 100 * $this->global_tax_rate;
|
||||
$total = ($subtotal_shipping + $tax);
|
||||
if($PaymentCredit = $this->getPaymentCredit()){
|
||||
if($PaymentCredit = $this->reducePaymentCredit()){
|
||||
$total = $total - $PaymentCredit;
|
||||
if($total < 0){
|
||||
$total = 0;
|
||||
|
|
@ -549,7 +589,7 @@ class Yard extends Cart
|
|||
public function totalfromCredit($decimals = null, $decimalPoint = null, $thousandSeperator = null)
|
||||
{
|
||||
$rest = 0;
|
||||
if ($PaymentCredit = $this->getPaymentCredit()) {
|
||||
if ($PaymentCredit = $this->reducePaymentCredit()) {
|
||||
$subtotal_shipping= $this->subtotalWithShipping(2, '.', '');
|
||||
$tax = $subtotal_shipping/ 100 * $this->global_tax_rate;
|
||||
$total = ($subtotal_shipping+ $tax);
|
||||
|
|
|
|||
15
app/User.php
15
app/User.php
|
|
@ -230,6 +230,17 @@ class User extends Authenticatable
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isPasswort(){
|
||||
if($this->password == env('APP_KEY')){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
|
@ -305,7 +316,7 @@ class User extends Authenticatable
|
|||
|
||||
public function isRenewalAccount(){
|
||||
if ($this->payment_account) {
|
||||
return Carbon::parse($this->payment_account)->modify('-'.(config('main.renewal_days')+1).' days')->lt(Carbon::now());
|
||||
return Carbon::parse($this->payment_account)->modify('-'.(config('main.renewal_days')).' days')->lt(Carbon::now());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -459,7 +470,7 @@ class User extends Authenticatable
|
|||
$this->userImage = $this->id.'/avatar.jpg';
|
||||
}
|
||||
if(\Storage::disk('user')->has($this->id.'/avatar.png')){
|
||||
$this->userImage = $this->id.'/avatar.jpg';
|
||||
$this->userImage = $this->id.'/avatar.png';
|
||||
}
|
||||
return $this->userImage;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue