Kundenhoheit
This commit is contained in:
parent
d8b5206031
commit
dc63fa9fb2
52 changed files with 2436 additions and 557 deletions
201
app/Services/CustomerPriority.php
Normal file
201
app/Services/CustomerPriority.php
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Mail\MailCheckout;
|
||||
use App\Mail\MailInfo;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Services\Shop;
|
||||
use App\User;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
|
||||
|
||||
class CustomerPriority
|
||||
{
|
||||
|
||||
protected static $start_number = 1000;
|
||||
protected static $user_notice_key = 'like';
|
||||
|
||||
public static function checkForAll(){
|
||||
//only extern no members with no numbers
|
||||
$shopping_users = ShoppingUser::where('auth_user_id', '=', NULL)->where('number', '=', NULL)->orderBy('created_at', 'ASC')->get();
|
||||
foreach ($shopping_users as $shopping_user){
|
||||
if($shopping_user->shopping_order && $shopping_user->shopping_order->user_shop){
|
||||
self::checkOne($shopping_user);
|
||||
}
|
||||
}
|
||||
return $shopping_users;
|
||||
}
|
||||
|
||||
public static function checkOne($shopping_user, $mail=false){
|
||||
//look for entry
|
||||
if(self::entryExists($shopping_user)){
|
||||
return 'exists';
|
||||
}
|
||||
if(self::entryLike($shopping_user)){
|
||||
if($mail){ //send mail
|
||||
Mail::to(config('app.info_mail'))->send(new MailInfo($shopping_user, 'check_is_like_customer'));
|
||||
}
|
||||
return 'like';
|
||||
}
|
||||
self::newCustomer($shopping_user);
|
||||
return 'update';
|
||||
|
||||
}
|
||||
|
||||
public static function setIsLike($shopping_user, $set_like_shopping_user, $send_member_mail)
|
||||
{
|
||||
if ($shopping_user->id === $set_like_shopping_user->id) {
|
||||
//set new customer for shopping_user
|
||||
self::newCustomer($shopping_user);
|
||||
} else {
|
||||
//set existing customer for shopping_user
|
||||
self::existingCustomer($shopping_user, $set_like_shopping_user);
|
||||
}
|
||||
self::clearIsLike($shopping_user);
|
||||
//SEND MAIL TO MEMBER
|
||||
if ($send_member_mail){
|
||||
if ($shopping_user->shopping_order && $shopping_user->shopping_order->shopping_payments) {
|
||||
Mail::to($shopping_user->member->email)->send(new MailCheckout($shopping_user->shopping_order->txaction, $shopping_user->shopping_order, $shopping_user->shopping_order->shopping_payments->last(), false, $shopping_user->shopping_order->mode));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function newMemberForOrder($shopping_order, $member_id, Bool $all = false){
|
||||
if($all){
|
||||
if($shopping_order->shopping_user && $shopping_order->shopping_user->number){
|
||||
$shopping_users = ShoppingUser::where('number', '=', $shopping_order->shopping_user->number)->get();
|
||||
$new_number = self::nextNumber();
|
||||
foreach ($shopping_users as $shopping_user) {
|
||||
self::changeCustomer($shopping_user, $member_id, $new_number);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$shopping_order->member_id = $member_id;
|
||||
$shopping_order->save();
|
||||
if($shopping_order->shopping_user){
|
||||
$shopping_order->shopping_user->member_id = $member_id;
|
||||
$shopping_order->shopping_user->number = self::nextNumber();
|
||||
$shopping_order->shopping_user->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function newMemberForCustomer($shopping_user, $member_id, Bool $all = false){
|
||||
if($all){
|
||||
if($shopping_user && $shopping_user->number){
|
||||
$shopping_users = ShoppingUser::where('number', '=', $shopping_user->number)->get();
|
||||
$new_number = self::nextNumber();
|
||||
foreach ($shopping_users as $s_user) {
|
||||
self::changeCustomer($s_user, $member_id, $new_number);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$shopping_user->member_id = $member_id;
|
||||
$shopping_user->number = self::nextNumber();
|
||||
$shopping_user->save();
|
||||
if($shopping_user->shopping_order){
|
||||
$shopping_user->shopping_order->member_id = $member_id;
|
||||
$shopping_user->shopping_order->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function entryExists($shopping_user){
|
||||
//check same email
|
||||
$matches = ShoppingUser::where('auth_user_id', '=', NULL)
|
||||
->where('number', '!=', NULL) //has number
|
||||
->where('id', '!=', $shopping_user->id)
|
||||
->where('billing_email', '=', $shopping_user->billing_email)->get();
|
||||
|
||||
if($matches && count($matches)){
|
||||
$match = $matches->last();
|
||||
$shopping_user->member_id = $match->member_id;
|
||||
$shopping_user->number = $match->number;
|
||||
$shopping_user->save();
|
||||
//has order
|
||||
if($shopping_user->shopping_order){
|
||||
$shopping_user->shopping_order->member_id = $match->member_id;
|
||||
$shopping_user->shopping_order->save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function entryLike($shopping_user){
|
||||
//check same last name und PLZ
|
||||
$matches = ShoppingUser::select('*')
|
||||
->where('auth_user_id', '=', NULL)
|
||||
->where('number', '!=', NULL) //has number
|
||||
->where('id', '!=', $shopping_user->id)
|
||||
->where('billing_lastname', '=', $shopping_user->billing_lastname)
|
||||
->where('billing_zipcode', '=', $shopping_user->billing_zipcode)
|
||||
->get()->pluck('number', 'id')->unique()->toArray();
|
||||
if($matches && count($matches)){
|
||||
$shopping_user->is_like = true;
|
||||
$shopping_user->setNotice(self::$user_notice_key, $matches);
|
||||
$shopping_user->save();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function newCustomer($shopping_user){
|
||||
if($shopping_user->shopping_order && $shopping_user->shopping_order->user_shop) {
|
||||
$member_id = $shopping_user->shopping_order->user_shop->user_id;
|
||||
$shopping_user->member_id = $member_id;
|
||||
$shopping_user->number = self::nextNumber();
|
||||
$shopping_user->save();
|
||||
$shopping_user->shopping_order->member_id = $member_id;
|
||||
$shopping_user->shopping_order->save();
|
||||
}
|
||||
}
|
||||
|
||||
private static function changeCustomer($shopping_user, $member_id, $number){
|
||||
|
||||
$old_number = $shopping_user->number;
|
||||
$shopping_user->member_id = $member_id;
|
||||
$shopping_user->number = $number;
|
||||
$shopping_user->save();
|
||||
if($shopping_user->shopping_order) {
|
||||
$shopping_user->shopping_order->member_id = $member_id;
|
||||
$shopping_user->shopping_order->save();
|
||||
}
|
||||
\App\Services\Shop::newUserOrder($old_number);
|
||||
\App\Services\Shop::newUserOrder($number);
|
||||
|
||||
}
|
||||
|
||||
private static function existingCustomer($shopping_user, $set_like_shopping_user){
|
||||
$old_number = $shopping_user->number;
|
||||
|
||||
$shopping_user->member_id = $set_like_shopping_user->member_id;
|
||||
$shopping_user->number = $set_like_shopping_user->number;
|
||||
$shopping_user->save();
|
||||
if($shopping_user->shopping_order) {
|
||||
$shopping_user->shopping_order->member_id = $set_like_shopping_user->member_id;
|
||||
$shopping_user->shopping_order->save();
|
||||
}
|
||||
\App\Services\Shop::newUserOrder($old_number);
|
||||
\App\Services\Shop::newUserOrder($set_like_shopping_user->number);
|
||||
}
|
||||
|
||||
private static function clearIsLike($shopping_user){
|
||||
$shopping_user->is_like = false;
|
||||
$shopping_user->removeNotice(self::$user_notice_key);
|
||||
$shopping_user->save();
|
||||
|
||||
}
|
||||
|
||||
private static function nextNumber (){
|
||||
if(!$number = ShoppingUser::max('number')){
|
||||
$number = self::$start_number;
|
||||
}
|
||||
return $number+1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -282,8 +282,8 @@ class HTMLHelper
|
|||
return $ret;
|
||||
}
|
||||
|
||||
public static function getSponsorOptions($id, $all=false){
|
||||
$values = User::all();
|
||||
public static function getMembersOptions($id, $all=false){
|
||||
$values = User::where('active', '=', true)->where('blocked', '=', false)->where('payment_account', '>=', now())->get();
|
||||
$ret = "";
|
||||
if($all){
|
||||
$ret .= '<option value="">'.__('please select').'</option>\n';
|
||||
|
|
@ -294,36 +294,9 @@ class HTMLHelper
|
|||
if($value->account){
|
||||
$to = $value->account->first_name." ".$value->account->last_name." | ";
|
||||
}
|
||||
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$to.$value->email.'</option>\n';
|
||||
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$to.$value->email.' #'.$value->number.'</option>\n';
|
||||
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*public static function getIndustrySectorsWithoutParents($id = false, $sameId = false, $all = true){
|
||||
$values = IndustrySector::where('parent_id', null)->get();
|
||||
$ret = "";
|
||||
if($all){
|
||||
$ret .= '<option value="">'.__('no').'</option>\n';
|
||||
}
|
||||
foreach ($values as $value){
|
||||
if($sameId == $value->id){
|
||||
continue;
|
||||
}
|
||||
$attr = ($value->id == $id) ? 'selected="selected"' : '';
|
||||
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
55
app/Services/Payment.php
Normal file
55
app/Services/Payment.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingPayment;
|
||||
use App\User;
|
||||
|
||||
class Payment
|
||||
{
|
||||
|
||||
public static $txaction_text = [
|
||||
'paid' => "bezahlt",
|
||||
'appointed' => "offen",
|
||||
'failed' => "abbruch",
|
||||
'NULL' => 'keine Zahlung',
|
||||
];
|
||||
|
||||
public static $txaction_color = [
|
||||
'paid' => "success",
|
||||
'appointed' => "warning",
|
||||
'failed' => "danger",
|
||||
];
|
||||
|
||||
|
||||
public static function getFormattedTxaction($txaction){
|
||||
if($txaction && isset(self::$txaction_text[$txaction])){
|
||||
return self::$txaction_text[$txaction];
|
||||
}
|
||||
return self::$txaction_text['NULL'];
|
||||
}
|
||||
|
||||
public static function getFormattedTxactionColor($txaction){
|
||||
if($txaction && isset(self::$txaction_color[$txaction])){
|
||||
return self::$txaction_color[$txaction];
|
||||
}
|
||||
return "warning";
|
||||
}
|
||||
|
||||
public static function getShoppingOrderBadge(ShoppingOrder $shopping_order){
|
||||
if($shopping_order->mode === 'test'){
|
||||
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_order->mode).' - '.self::getFormattedTxaction($shopping_order->txaction).'</span>';
|
||||
}
|
||||
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_order->txaction).'">'.self::getFormattedTxaction($shopping_order->txaction).'</span>';
|
||||
}
|
||||
|
||||
public static function getShoppingPaymentBadge(ShoppingPayment $shopping_payment){
|
||||
if($shopping_payment->mode === 'test'){
|
||||
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_payment->mode).' - '.self::getFormattedTxaction($shopping_payment->txaction).'</span>';
|
||||
}
|
||||
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_payment->txaction).'">'.self::getFormattedTxaction($shopping_payment->txaction).'</span>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
40
app/Services/Shop.php
Normal file
40
app/Services/Shop.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
|
||||
use App\Models\ShoppingUser;
|
||||
|
||||
class Shop
|
||||
{
|
||||
public static function userOrders() {
|
||||
$shopping_users = ShoppingUser::whereHas('shopping_order', function($q) {
|
||||
$q->where('txaction', 'paid')->OrWhere('txaction', 'appointed');
|
||||
})->where('orders', '=', NULL)->get();
|
||||
foreach ($shopping_users as $shopping_user) {
|
||||
if ($shopping_user->number) {
|
||||
$orders = ShoppingUser::where('number', '=', $shopping_user->number)->max('orders');
|
||||
$orders = $orders + 1;
|
||||
} else {
|
||||
$orders = ShoppingUser::where('billing_email', '=', $shopping_user->billing_email)->max('orders');
|
||||
$orders = $orders + 1;
|
||||
}
|
||||
$shopping_user->orders = $orders;
|
||||
$shopping_user->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function newUserOrder($number){
|
||||
$shopping_users = ShoppingUser::where('number', '=', $number)->get();
|
||||
$orders = 1;
|
||||
foreach ($shopping_users as $shopping_user) {
|
||||
if($shopping_user->shopping_order && ($shopping_user->shopping_order->txaction === 'paid' || $shopping_user->shopping_order->txaction === 'appointed')){
|
||||
$shopping_user->orders = $orders++;
|
||||
|
||||
}else{
|
||||
$shopping_user->orders = NULL;
|
||||
}
|
||||
$shopping_user->save();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ use App\User;
|
|||
|
||||
class UserService
|
||||
{
|
||||
|
||||
public static function createConfirmationCode() {
|
||||
$unique = false;
|
||||
do{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue