06 2022
This commit is contained in:
parent
9b0b5feb7e
commit
7a040c3e19
106 changed files with 4074 additions and 1349 deletions
304
app/Services/SyS/Correction.php
Normal file
304
app/Services/SyS/Correction.php
Normal file
|
|
@ -0,0 +1,304 @@
|
|||
<?php
|
||||
namespace App\Services\SyS;
|
||||
|
||||
use Carbon;
|
||||
use Request;
|
||||
use App\Models\Product;
|
||||
use App\Models\Homeparty;
|
||||
use App\Models\SySetting;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Repositories\ImportRepository;
|
||||
|
||||
class Correction
|
||||
{
|
||||
|
||||
private static function userSalesVolume($order){
|
||||
/*
|
||||
status
|
||||
1 => 'hinzugefügt aus Bestellung',
|
||||
2 => 'hinzugefügt aus Shop',
|
||||
3 => 'hinzugefügt aus Shop / pending',
|
||||
|
||||
*/
|
||||
$status = UserSalesVolume::getStatusByOrder($order);
|
||||
$user_id = $order->auth_user_id ? $order->auth_user_id : $order->member_id;
|
||||
//akuteller tag / Monat.
|
||||
$month = $order->created_at->format('m');
|
||||
$year = $order->created_at->format('Y');
|
||||
$date = $order->created_at->format('d.m.Y');
|
||||
|
||||
|
||||
if($status === 3){ //shop bestellung User pending
|
||||
$user_id = $order->auth_user_id ? $order->auth_user_id : $order->member_id;
|
||||
$month_points = 0;
|
||||
$month_total_net = 0;
|
||||
$month_shop_points = 0;
|
||||
$month_shop_total_net = 0;
|
||||
}else{
|
||||
$month_points = UserSalesVolume::where('user_id', $user_id)->where('status', 1)->where('month', $month)->where('year', $year)->sum('points');
|
||||
$month_total_net = UserSalesVolume::where('user_id', $user_id)->where('status', 1)->where('month', $month)->where('year', $year)->sum('total_net');
|
||||
$month_shop_points = UserSalesVolume::where('user_id', $user_id)->where('status', 2)->where('month', $month)->where('year', $year)->sum('points');
|
||||
$month_shop_total_net = UserSalesVolume::where('user_id', $user_id)->where('status', 2)->where('month', $month)->where('year', $year)->sum('total_net');
|
||||
}
|
||||
switch ($status) {
|
||||
case 1: //Bestellung
|
||||
$month_points += $order->points;
|
||||
$month_total_net += $order->subtotal;
|
||||
break;
|
||||
case 2: //Shop
|
||||
$month_shop_points += $order->points;
|
||||
$month_shop_total_net += $order->subtotal;
|
||||
break;
|
||||
}
|
||||
|
||||
return UserSalesVolume::create([
|
||||
'user_id' => $user_id,
|
||||
'shopping_order_id' => $order->id,
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
'date' => $date,
|
||||
'points' => $order->points,
|
||||
'month_points' => $month_points,
|
||||
'month_shop_points' => $month_shop_points,
|
||||
'total_net' => $order->subtotal,
|
||||
'month_total_net' => $month_total_net,
|
||||
'month_shop_total_net' => $month_shop_total_net,
|
||||
'message' => '',
|
||||
'status' => $status,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function show()
|
||||
{
|
||||
// abort(403, 'STOP funtion not online');
|
||||
|
||||
$c = 0;
|
||||
|
||||
if(true){ //11
|
||||
dump("calculate user_sales_volumes from Orders");
|
||||
//dd('check function');
|
||||
$year = 21;
|
||||
$months = range(1, 12);
|
||||
foreach($months as $month){
|
||||
$ShoppingOrders = ShoppingOrder::where('txaction', 'paid')->where('created_at', '>=', $year.'-'.$month.'-01 00:00:00')->where('created_at', '<=', $year.'-'.$month.'-31 23:59:59')->get();
|
||||
foreach($ShoppingOrders as $item){
|
||||
|
||||
if(UserSalesVolume::whereShoppingOrderId($item->id)->count() === 0){
|
||||
dump($item->id);
|
||||
self::userSalesVolume($item);
|
||||
}
|
||||
$c ++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
dump("counter");
|
||||
dd($c);
|
||||
}
|
||||
|
||||
if(false){ //11
|
||||
dump("set Discount to Order Items");
|
||||
dd('check function');
|
||||
$ShoppingOrderItems = ShoppingOrderItem::where('discount', null)
|
||||
//$ShoppingOrderItems = ShoppingOrderItem::where('discount', 0)->get();
|
||||
->skip(0)->take(1000)->get();
|
||||
//->skip(2000)->take(2000)->get();
|
||||
foreach($ShoppingOrderItems as $item){
|
||||
$no_commission = $item->product ? $item->product->no_commission : false;
|
||||
$item->discount = $no_commission ? 0 : $item->shopping_order->getUserDiscount();
|
||||
$item->save();
|
||||
//dump($item->discount);
|
||||
|
||||
$c ++;
|
||||
}
|
||||
dump("counter");
|
||||
dd($c);
|
||||
}
|
||||
|
||||
|
||||
if(false){ //10
|
||||
dump("set ProduktPoints to Order Items");
|
||||
dd('check function');
|
||||
$ShoppingOrderItems = ShoppingOrderItem::where('points', null)->get();
|
||||
$ShoppingOrderItems = ShoppingOrderItem::where('points', 0)->get();
|
||||
//->skip(0)->take(500)->get();
|
||||
//->skip(500)->take(500)->get();
|
||||
foreach($ShoppingOrderItems as $item){
|
||||
if($item->product){
|
||||
$item->points = $item->product->points;
|
||||
$item->save();
|
||||
}else{
|
||||
|
||||
}
|
||||
$c ++;
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
|
||||
if(false){ //9
|
||||
dump("make homeparty tax_split in shopping_order");
|
||||
dd('check function');
|
||||
$ShoppingOrders = ShoppingOrder::where('payment_for', '=', NULL)->get();
|
||||
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
dump($ShoppingOrder->id);
|
||||
dump($ShoppingOrder->shopping_user->getOrderPaymentFor());
|
||||
$ShoppingOrder->payment_for = $ShoppingOrder->shopping_user->getOrderPaymentFor();
|
||||
$ShoppingOrder->save();
|
||||
|
||||
$c ++;
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
|
||||
|
||||
if(false){ //8
|
||||
dump("make homeparty tax_split in shopping_order");
|
||||
dd('check function');
|
||||
$ShoppingOrders = ShoppingOrder::where('homeparty_id', '!=', NULL)->get();
|
||||
//->skip(0)->take(500)->get();
|
||||
//->skip(500)->take(500)->get();
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
$ShoppingOrder->makeHomepartyTaxSplit();
|
||||
$c ++;
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
|
||||
if(false){ //7
|
||||
dump("make homeparty shipping_tax in homeparty order user_cart");
|
||||
dd('check function');
|
||||
$ShoppingOrders = ShoppingOrder::where('homeparty_id', '!=', NULL)->get();
|
||||
//->skip(0)->take(500)->get();
|
||||
//->skip(500)->take(500)->get();
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
if(isset($ShoppingOrder->homeparty->order['user_carts'])){
|
||||
$user_carts = [];
|
||||
foreach($ShoppingOrder->homeparty->order['user_carts'] as $id => $values){
|
||||
$values['shipping_tax'] = round($values['shipping_price'] - $values['shipping_price_net'], 2);
|
||||
dump($values['shipping_tax']);
|
||||
$user_carts[$id] = $values;
|
||||
}
|
||||
$order = $ShoppingOrder->homeparty->order;
|
||||
$order['user_carts'] = $user_carts;
|
||||
$ShoppingOrder->homeparty->order = $order;
|
||||
$ShoppingOrder->homeparty->save();
|
||||
|
||||
}
|
||||
$c ++;
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
|
||||
if(false){ //6
|
||||
dump("make tax_split in shopping_order");
|
||||
dd('check function');
|
||||
$ShoppingOrders = ShoppingOrder::where('homeparty_id', '=', NULL)->get();
|
||||
//->skip(0)->take(500)->get();
|
||||
//->skip(500)->take(500)->get();
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
$ShoppingOrder->makeTaxSplit();
|
||||
$c ++;
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
|
||||
if(false){ //5
|
||||
//run after make points etc.
|
||||
dump("correction shopping_order homeparty");
|
||||
dd('check function');
|
||||
$ShoppingOrders = ShoppingOrder::where('payment_for', 5)->get();
|
||||
//->skip(0)->take(500)->get();
|
||||
//->skip(500)->take(500)->get();
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
$homeparty = Homeparty::find($ShoppingOrder->homeparty_id);
|
||||
if($homeparty && $homeparty->completed && $homeparty->step > 10){
|
||||
$ShoppingOrder->subtotal = $homeparty->order['ek_price_net'];
|
||||
$ShoppingOrder->subtotal_ws = 0;
|
||||
$ShoppingOrder->tax = $ShoppingOrder->total - $homeparty->order['ek_price_net'];
|
||||
$ShoppingOrder->points = $homeparty->order['points'] - $homeparty->order['bonus_points_diff'];
|
||||
$ShoppingOrder->save();
|
||||
$c ++;
|
||||
}
|
||||
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
|
||||
if(false){ //4
|
||||
dump("make tax in ShoppingOrderItem");
|
||||
dd('check function');
|
||||
$ShoppingOrderItems = ShoppingOrderItem::all();
|
||||
//->skip(0)->take(500)->get();
|
||||
//->skip(500)->take(500)->get();
|
||||
foreach($ShoppingOrderItems as $item){
|
||||
$item->tax = $item->price - $item->price_net;
|
||||
$item->save();
|
||||
$c ++;
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(false){ //3
|
||||
dump("make price_net in ShoppingOrderItem");
|
||||
dd('check function');
|
||||
$ShoppingOrderItems = ShoppingOrderItem::where('price_net', '=', NULL)->get();
|
||||
//->skip(0)->take(500)->get();
|
||||
//->skip(500)->take(500)->get();
|
||||
foreach($ShoppingOrderItems as $item){
|
||||
$item->price_net = $item->price / (100 + $item->tax_rate) * 100;
|
||||
$item->save();
|
||||
$c ++;
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
|
||||
if(false){ //2
|
||||
dump("add payment_for in shopping_order");
|
||||
dd('check function');
|
||||
$ShoppingUsers = ShoppingUser::all();
|
||||
foreach($ShoppingUsers as $ShoppingUser){
|
||||
if($ShoppingUser->shopping_order){
|
||||
$ShoppingUser->shopping_order->payment_for = $ShoppingUser->getOrderPaymentFor();
|
||||
$ShoppingUser->shopping_order->save();
|
||||
$c ++;
|
||||
}
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
|
||||
if(false){ //1
|
||||
dump("make points in shopping_order_item and total in ShoppingOrder");
|
||||
dd('check function');
|
||||
$ShoppingOrders = ShoppingOrder::all();
|
||||
//->skip(0)->take(500)->get();
|
||||
//->skip(500)->take(500)->get();
|
||||
foreach($ShoppingOrders as $ShoppingOrder){
|
||||
$points_total = 0;
|
||||
foreach($ShoppingOrder->shopping_order_items as $shopping_order_item){
|
||||
$points = $shopping_order_item->product ? $shopping_order_item->product->points : 0;
|
||||
$points_total += $points;
|
||||
$shopping_order_item->points = $points;
|
||||
$shopping_order_item->save();
|
||||
$c ++;
|
||||
}
|
||||
$ShoppingOrder->points = $points_total;
|
||||
$ShoppingOrder->save();
|
||||
}
|
||||
dd($c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function store()
|
||||
{
|
||||
abort(403, 'STOP funtion not online');
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue