Komp / Max Produkt,

This commit is contained in:
Kevin Adametz 2021-06-18 15:01:01 +02:00
parent a4c76d06fa
commit 78f43169c8
19 changed files with 347 additions and 51 deletions

View file

@ -34,10 +34,10 @@ class SettingController extends Controller
{
$data = Request::all();
if(isset($data['action'])){
if(isset($data['settings'])){
foreach ($data['settings'] as $key=>$value){
$value['val'] = isset($value['val']) ? $value['val'] : false;
Setting::setContentBySlug($key, $value['val'], $value['type']);
}
}

View file

@ -479,6 +479,7 @@ class CheckoutController extends Controller
];
$shopping_order_item = ShoppingOrderItem::create($data);
}
}
return $shopping_order;
}

View file

@ -18,7 +18,7 @@ use App\Models\ProductCategory;
use App\Models\ShippingCountry;
use App\Models\ShoppingInstance;
use App\Http\Controllers\Controller;
use App\Models\ProductBuy;
class OrderController extends Controller
{
@ -153,7 +153,6 @@ class OrderController extends Controller
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id, $for);
Yard::instance('shopping')->setShoppingUser($user, true);
$data = [
'shopping_user' => $shopping_user,
'user' => $user,
@ -161,7 +160,7 @@ class OrderController extends Controller
'isView' => 'customer',
'for' => $for,
'delivery_id' => $delivery_id,
//'comp_products' => $this->getCompProducts($for),
'comp_products' => $this->getCompProducts($for),
];
return view('user.order.list', $data);
}
@ -184,7 +183,7 @@ class OrderController extends Controller
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{
@ -200,7 +199,7 @@ class OrderController extends Controller
return back()->withErrors($validator)->withInput(Request::all());
}
}
*/
/*do {
$identifier = Util::getToken();
} while( ShoppingInstance::where('identifier', $identifier)->count() );*/
@ -280,6 +279,7 @@ 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)
@ -294,6 +294,12 @@ class OrderController extends Controller
->orWhere('show_at', '=', 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')
@ -418,7 +424,7 @@ class OrderController extends Controller
$data = Request::all();
$is_for = isset($data['shipping_is_for']) ? $data['shipping_is_for'] : 'ot';
// $data['comp_products'] = $this->getCompProducts($is_for);
$data['comp_products'] = $this->getCompProducts($is_for);
if($data['action'] === 'updateCart' && isset($data['product_id'])){
if($product = Product::find($data['product_id'])){
@ -448,9 +454,12 @@ class OrderController extends Controller
}
//
Yard::instance('shopping')->reCalculate();
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
$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'=>'']);
return response()->json(['response' => true, 'data'=>$data, 'html_card'=>$html_card, 'html_comp'=>$html_comp]);
}
}
if($data['action'] === 'clearCart') {
@ -462,18 +471,30 @@ class OrderController extends Controller
if(isset($data['shipping_country_id'])){
if($shipping_country = ShippingCountry::find($data['shipping_country_id'])){
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country->id, $is_for);
//$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
$this->checkCompProduct(Yard::instance('shopping')->getNumComp());
}
}
$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 = 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'] === 'updateCompProduct'){
// $data['comp_product_id']
// $data['comp_num']
//count_comp_products
$this->updateCompProduct($data);
Yard::instance('shopping')->reCalculateShippingPrice();
$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]);
}
return response()->json(['response' => false, 'data'=>$data]);
}
}
/* private function checkCompProduct($count_comp_products){
private function checkCompProduct($count_comp_products){
foreach (Yard::instance('shopping')->content() as $row) {
//wenn gleich löschen, da neue Versandkosten
if($row->options->comp > $count_comp_products) {
@ -486,8 +507,10 @@ class OrderController extends Controller
foreach (Yard::instance('shopping')->content() as $row) {
//wenn kleiner wurde ein produkt entfernt aufgrund der Anzahl
//wenn gleich löschen, da neue Versandkosten
if($row->options->comp === $data['comp_num'] || $row->options->comp > $data['count_comp_products']) {
Yard::instance('shopping')->remove($row->rowId);
Yard::instance('shopping')->remove($row->rowId);
}
}
@ -497,13 +520,33 @@ class OrderController extends Controller
if ($product->images->count()) {
$image = $product->images->first()->slug;
}
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, 0,
['image' => $image, 'slug' => $product->slug, 'weight' => 0, 'points' => 0,
'comp' => $data['comp_num'], 'product_id' => $product->id]);
$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){
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();
}
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 null;
}
}

View file

@ -141,7 +141,10 @@ class Product extends Model
'wp_number' => 'int',
'single_commission' => 'bool',
'amount_commission' => 'bool',
'active' => 'bool'
'active' => 'bool',
'shipping_addon' => 'bool',
'max_buy' => 'bool',
'max_buy_num' => 'int'
];
use Sluggable;
@ -178,7 +181,10 @@ class Product extends Model
'partner_commission',
'identifier',
'action',
'upgrade_to_id'
'upgrade_to_id',
'shipping_addon',
'max_buy',
'max_buy_num'
];
public $identifiers_types = [
@ -249,6 +255,10 @@ class Product extends Model
return $this->hasMany(CountryPrice::class, 'product_id');
}
public function product_buys()
{
return $this->hasMany(ProductBuy::class, 'product_id');
}
public function p_ingredients()
{

72
app/Models/ProductBuy.php Normal file
View file

@ -0,0 +1,72 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
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
*/
class ProductBuy extends Model
{
protected $table = 'product_buys';
protected $casts = [
'auth_user_id' => 'int',
'product_id' => 'int',
'num' => 'int'
];
protected $fillable = [
'auth_user_id',
'product_id',
'num'
];
public function product()
{
return $this->belongsTo(Product::class);
}
public function user()
{
return $this->belongsTo('App\User','auth_user_id');
}
public function auth_user()
{
return $this->belongsTo('App\User','auth_user_id');
}
public static function getNotShowProductIDs($user_id){
$ret = [];
$ProductBuys = ProductBuy::where('auth_user_id', $user_id)->get();
if($ProductBuys){
foreach($ProductBuys as $ProductBuy){
if($ProductBuy->product){
if($ProductBuy->product->max_buy && $ProductBuy->num >= $ProductBuy->product->max_buy_num){
$ret[] = $ProductBuy->product->id;
}
}
}
}
return $ret;
}
}

View file

@ -77,6 +77,10 @@ class Setting extends Model
'object' => 'Object',
'full_text' => 'Full Text',
'text' => 'Text',
'int' => 'Zahl',
'bool' => 'Bool',
];
public function sluggable()
@ -103,6 +107,9 @@ class Setting extends Model
case 'int':
return $content->int;
break;
case 'bool':
return $content->int === 1 ? true : false;
break;
}
}
return false;
@ -120,17 +127,20 @@ class Setting extends Model
$content->type = $type;
switch ($content->type){
case 'object':
$content->object = $value;
$content->object = $value ? $value : null;;
break;
case 'full_text':
$content->full_text = $value;
$content->full_text = $value ? $value : null;;
break;
case 'text':
$content->text = $value;
$content->text = $value ? $value : null;;
break;
case 'int':
$content->int = (int) $value;
break;
case 'bool':
$content->int = $value ? 1 : 0;
break;
}
$content->save();

View file

@ -29,6 +29,9 @@ class ProductRepository extends BaseRepository {
$data['active'] = isset($data['active']) ? 1 : 0;
$data['single_commission'] = isset($data['single_commission']) ? 1 : 0;
$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;
if($data['id'] === "new"){
$this->model = Product::create($data);

View file

@ -2,13 +2,15 @@
namespace App\Services;
use App\Mail\MailCheckout;
use App\User;
use App\Models\Product;
use App\Models\Setting;
use App\Mail\MailCheckout;
use App\Models\ProductBuy;
use App\Models\ShoppingOrder;
use App\Models\UserPayCredit;
use App\Models\ShoppingPayment;
use App\Models\UserCreditMargin;
use App\Models\UserPayCredit;
use App\User;
use Illuminate\Support\Facades\Mail;
class Payment
@ -117,6 +119,23 @@ class Payment
]);
}
public static function addProductBuy(User $user, Product $product){
if($product->max_buy && $product->max_buy_num > 0){
$ProductBuy = ProductBuy::where('auth_user_id', $user->id)->where('product_id', $product->id)->first();
if(!$ProductBuy){
ProductBuy::create([
'auth_user_id' => $user->id,
'product_id' => $product->id,
'num' => 1,
]);
}else{
$ProductBuy->num = $ProductBuy->num+1;
$ProductBuy->save();
}
}
}
public static function paymentStatusPaidAction(ShoppingOrder $shopping_order, $paid){
$send_link = false;
@ -129,8 +148,14 @@ class Payment
if($shopping_order->shopping_order_items && $shopping_order->auth_user_id){
foreach($shopping_order->shopping_order_items as $shopping_order_item){
if($shopping_order_item->product){
//add product when buy
$user = User::findOrFail($shopping_order->auth_user_id);
if($shopping_order_item->product->max_buy && $shopping_order_item->product->max_buy_num > 0){
self::addProductBuy($user, $shopping_order_item->product);
}
//product action
if($shopping_order_item->product->action){
$user = User::findOrFail($shopping_order->auth_user_id);
$user->save();
$send_link = true;
//new date

View file

@ -22,7 +22,7 @@ class Yard extends Cart
private $shipping_tax = 0;
private $shipping_country_id = 0; //default de
private $shipping_is_for;
//private $num_comp;
private $num_comp;
private $ysession;
private $yinstance;
private $shopping_data = [];
@ -87,9 +87,9 @@ class Yard extends Cart
$this->global_tax_rate = config('cart.tax');
}
/*if($this->getYardExtra('num_comp')){
if($this->getYardExtra('num_comp')){
$this->num_comp = $this->getYardExtra('num_comp');
}*/
}
parent::__construct($session, $events);
@ -164,7 +164,10 @@ class Yard extends Cart
return $this->ysession->get($this->yinstance);
}
public function reCalculateShippingPrice(){
$this->calculateShippingPrice();
}
public function reCalculate(){
$this->calculateShippingPrice();
}
@ -328,18 +331,23 @@ class Yard extends Cart
}
if($shipping_price){
$price = $shipping_price->price;
/*$this->num_comp = 0;
if($this->shipping_is_for === 'me'){
$this->num_comp = 0;
if($this->shipping_is_for === 'me' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_me')){
$price = $shipping_price->price_comp;
$this->num_comp = $shipping_price->num_comp;
}
if($this->shipping_is_for === 'ot' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_ot')){
$price = $shipping_price->price_comp;
$this->num_comp = $shipping_price->num_comp;
}
}*/
$this->shipping_price = $price;
$this->shipping_tax_rate = $shipping_price->tax_rate;
$this->shipping_price_net = round($price / ((100+$shipping_price->tax_rate) / 100), 2);
$this->shipping_tax = round($price / (100+$shipping_price->tax_rate) * 100, 2);
//$this->putYardExtra('num_comp', $this->num_comp);
$this->putYardExtra('num_comp', $this->num_comp);
$this->putYardExtra('shipping_price', $this->shipping_price);
$this->putYardExtra('shipping_tax_rate', $this->shipping_tax_rate);
$this->putYardExtra('shipping_tax', $this->shipping_tax);
@ -627,7 +635,7 @@ class Yard extends Cart
}
public function getNumComp(){
return 0; //$this->num_comp;
return $this->num_comp;
}
public function getCompProductBy($comp, $product_id=false){