testemich Promotion
This commit is contained in:
parent
38e7fd504a
commit
a0f4eda6ea
83 changed files with 1690 additions and 504 deletions
|
|
@ -39,16 +39,24 @@ class Invoice
|
|||
return isset($shopping_order->invoice['filename']) ? true : false;
|
||||
}
|
||||
|
||||
public static function getFilename(ShoppingOrder $shopping_order){
|
||||
public static function getFilename($shopping_order){
|
||||
return isset($shopping_order->invoice['filename']) ? $shopping_order->invoice['filename'] : false;
|
||||
}
|
||||
|
||||
public static function getDir(ShoppingOrder $shopping_order){
|
||||
public static function getDir($shopping_order){
|
||||
return isset($shopping_order->invoice['dir']) ? $shopping_order->invoice['dir'] : false;
|
||||
}
|
||||
|
||||
public static function getDate($shopping_order){
|
||||
return isset($shopping_order->invoice['invoice_date']) ? $shopping_order->invoice['invoice_date'] : false;
|
||||
}
|
||||
|
||||
public static function getNumber($shopping_order){
|
||||
return isset($shopping_order->invoice['invoice_number']) ? $shopping_order->invoice['invoice_number'] : false;
|
||||
}
|
||||
|
||||
public static function getDownloadURL(ShoppingOrder $shopping_order, $do = false){
|
||||
return route('storage_file', [$shopping_order->id, 'cms_download_file', $do]);
|
||||
// return route('storage_file', [$shopping_order->id, 'cms_download_file', $do]);
|
||||
}
|
||||
public static function getDownloadPath(ShoppingOrder $shopping_order, $full = false){
|
||||
$dir = self::getDir($shopping_order);
|
||||
|
|
|
|||
|
|
@ -165,15 +165,24 @@ class Payment
|
|||
$date = \Carbon::parse($user->payment_account)->modify('1 year');
|
||||
}
|
||||
foreach ($shopping_order_item->product->action as $do){
|
||||
if($shopping_order_item->product->getActionName($do) === 'payment_for_account'){
|
||||
if($shopping_order_item->product->getActionName($do) === 'payment_for_account' && !$shopping_order_item->handle){
|
||||
// $user->payment_order_id = $shopping_order_item->product->id; //34
|
||||
$user->payment_account = $date;
|
||||
$user->wizard = 100;
|
||||
$user->save();
|
||||
self::addUserPayCredits($user, $shopping_order_item->product->price, 1, 'payment_for_account', $shopping_order->id);
|
||||
self::addUserPayCredits($user, $shopping_order_item->product->price, 1, 'payment_for_account', $shopping_order->id);
|
||||
$shopping_order_item->handle = true;
|
||||
$shopping_order_item->save();
|
||||
$shopping_order->setUserHistoryValue(['status' => 9]);
|
||||
|
||||
}
|
||||
if($shopping_order_item->product->getActionName($do) === 'charging_credits' && !$shopping_order_item->handle){
|
||||
self::addUserPayCredits($user, ($shopping_order_item->product->price * $shopping_order_item->qty), 7, 'charging_credits_add', $shopping_order->id);
|
||||
$shopping_order_item->handle = true;
|
||||
$shopping_order_item->save();
|
||||
$shopping_order->setUserHistoryValue(['status' => 9]);
|
||||
}
|
||||
|
||||
/*if($shopping_order_item->product->getActionName($do) === 'payment_for_shop'){
|
||||
$user->payment_order_id = $shopping_order_item->product->id; //35
|
||||
$user->payment_shop = $date;
|
||||
|
|
@ -199,7 +208,7 @@ class Payment
|
|||
|
||||
}
|
||||
//if the order has action
|
||||
if($shopping_order->shopping_user->is_from === 'user_order'){
|
||||
if($shopping_order->shopping_user->is_from === 'user_order' && $shopping_order->shopping_order_margin){
|
||||
//is margin -> set paid
|
||||
$shopping_order->shopping_order_margin->paid = true;
|
||||
$shopping_order->shopping_order_margin->save();
|
||||
|
|
@ -228,23 +237,54 @@ class Payment
|
|||
'price' => $promotion_admin_product->getPriceWith(false),
|
||||
'price_net' => $promotion_admin_product->getPriceWith(true),
|
||||
'tax_rate' => $promotion_admin_product->product->tax,
|
||||
'status' => 0,
|
||||
'pick_up' => $shopping_order->isPickUp()
|
||||
]);
|
||||
|
||||
$promotion_user_product->open_items -= $PromotionUserOrder->qty;
|
||||
$promotion_user_product->sell_items += $PromotionUserOrder->qty;
|
||||
$promotion_user_product->used_budget_total += $PromotionUserOrder->price;
|
||||
$promotion_user_product->save();
|
||||
|
||||
//TODO Guthaben abziehen
|
||||
self::addUserPayCredits($promotion_user_product->promotion_user->user, ($PromotionUserOrder->price*-1), 5, 'promotion_order_deduction', $shopping_order->id);
|
||||
|
||||
//Guthaben abziehen wenn nicht abholung
|
||||
if(!$shopping_order->isPickUp()){
|
||||
self::addUserPayCredits($promotion_user_product->promotion_user->user, ($PromotionUserOrder->price*-1), 5, 'promotion_order_deduction', $shopping_order->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//remove or add form credit, is from Charging credits, handle is true (by paymentStatusPaidAction first action by paid)
|
||||
public static function handelUserPayChargingCredits(ShoppingOrder $shopping_order, $action){
|
||||
//only from cr <- credit Charging
|
||||
if($shopping_order->shopping_user->is_for !== 'cr'){
|
||||
return;
|
||||
}
|
||||
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){
|
||||
$user = User::findOrFail($shopping_order->auth_user_id);
|
||||
//product action
|
||||
if($shopping_order_item->product->action){
|
||||
foreach ($shopping_order_item->product->action as $do){
|
||||
if($shopping_order_item->product->getActionName($do) === 'charging_credits' && $shopping_order_item->handle){
|
||||
if($action === 'remove'){
|
||||
self::addUserPayCredits($user, ($shopping_order_item->product->price*-1), 8, 'charging_credits_remove', $shopping_order->id);
|
||||
}
|
||||
if($action === 'add'){
|
||||
self::addUserPayCredits($user, $shopping_order_item->product->price, 7, 'charging_credits_add', $shopping_order->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//remove form credit, every sale fnc / vor / etc from CheckoutController
|
||||
//when stone, put it back SalesController
|
||||
//when done, put it back SalesController
|
||||
public static function handelUserPayCredits(ShoppingOrder $shopping_order, $do){
|
||||
//is payment credit, deduction or return
|
||||
if(!$shopping_order->shopping_order_margin){
|
||||
|
|
@ -261,8 +301,51 @@ class Payment
|
|||
$credit = $shopping_order->shopping_order_margin->from_payment_credit;
|
||||
self::addUserPayCredits($shopping_order->auth_user, $credit, 4, 'user_order_return', $shopping_order->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function handelUserPromotionOrder(ShoppingOrder $shopping_order){
|
||||
//no user promotion
|
||||
if($shopping_order->payment_for !== 7 || !$shopping_order->promotion_user){
|
||||
return;
|
||||
}
|
||||
|
||||
if($shopping_order->promotion_user->promotion_user_orders){
|
||||
foreach($shopping_order->promotion_user->getPromotionUserOrders($shopping_order->id) as $promotion_user_order){
|
||||
$promotion_user_order->setStatusShipped($shopping_order->getAPIShippedType());
|
||||
if(!$promotion_user_order->pick_up){ // keine abholung handel credit
|
||||
$last_UserPayCredit = UserPayCredit::where('shopping_order_id', $shopping_order->id)->whereIn('status', [5, 6])->orderBy('id', 'DESC')->first();
|
||||
if($last_UserPayCredit && $promotion_user_order->status === 10 && $last_UserPayCredit->status === 5){
|
||||
Payment::handelUserPayCreditsPromotion($promotion_user_order, 'return');
|
||||
}
|
||||
//Status Zahlung, voher gab es eine Storno, Guthaben abziehen wenn status 6 / return from order
|
||||
if($last_UserPayCredit && $promotion_user_order->status === 0 && $last_UserPayCredit->status === 6){
|
||||
Payment::handelUserPayCreditsPromotion($promotion_user_order, 'deduction');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//add or remove form credit,
|
||||
//when done, put it back SalesController
|
||||
public static function handelUserPayCreditsPromotion(PromotionUserOrder $promotion_user_order, $do){
|
||||
//is promotion pick up, dont
|
||||
if($promotion_user_order->pick_up){
|
||||
return;
|
||||
}
|
||||
if($do === 'deduction'){
|
||||
if($promotion_user_order->price > 0){
|
||||
$credit = $promotion_user_order->price * -1;
|
||||
self::addUserPayCredits($promotion_user_order->promotion_user->user, $credit, 5, 'promotion_order_deduction', $promotion_user_order->shopping_order->id);
|
||||
}
|
||||
}
|
||||
if($do === 'return'){
|
||||
if($promotion_user_order->price > 0){
|
||||
$credit = $promotion_user_order->price;
|
||||
self::addUserPayCredits($promotion_user_order->promotion_user->user, $credit, 6, 'promotion_order_return', $promotion_user_order->shopping_order->id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function paymentStatusSendMail(ShoppingOrder $shopping_order, $shopping_payment, $data){
|
||||
|
|
@ -284,6 +367,7 @@ class Payment
|
|||
if(!$shopping_order->shopping_user->is_like && $shopping_order->shopping_user->member){
|
||||
$bcc[] = $shopping_order->shopping_user->member->email;
|
||||
}
|
||||
|
||||
Mail::to($billing_email)->bcc($bcc)->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment, $data['send_link'], $data['mode']));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,16 @@ class PromotionCart
|
|||
Yard::instance('shopping')->setShippingCountryWithPrice($id, 'shop');
|
||||
}
|
||||
|
||||
public static function getLowestShippingPrice($shipping_for = 2)
|
||||
public static function getCurrentShippingPrice($shipping_for = 2) //shipping_for === microsite
|
||||
{
|
||||
$shipping = Yard::instance('shopping')->shipping();
|
||||
if($shipping > 0){
|
||||
return $shipping;
|
||||
}
|
||||
$shipping = Yard::instance('shopping')->preCalcuShippingPrice();
|
||||
if($shipping > 0){
|
||||
return formatNumber($shipping);
|
||||
}
|
||||
if($ShippingCountry = ShippingCountry::all()->first()){
|
||||
if($ShippingCountry->shipping){
|
||||
if($ShippingPrices = $ShippingCountry->shipping->getShippingPricesFirstBy($shipping_for)){
|
||||
|
|
@ -85,7 +93,6 @@ class PromotionCart
|
|||
Yard::instance('shopping')->remove($cartItem->rowId);
|
||||
}
|
||||
}
|
||||
|
||||
Yard::instance('shopping')->reCalculate();
|
||||
return $cartItem->qty;
|
||||
}
|
||||
|
|
@ -118,6 +125,8 @@ class PromotionCart
|
|||
'product_id' => $product->id
|
||||
]);
|
||||
Yard::setTax($cartItem->rowId, 0);
|
||||
Yard::instance('shopping')->reCalculate();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Type
|
|||
3 => 'Registrierung / Mitgliedschaft Vertriebspartner',
|
||||
4 => 'Nur Mitgliedschaft Vertriebspartner',
|
||||
//5 => 'Onboarding Vertriebspartner',
|
||||
//6 => 'Onboarding Vertriebspartner + Vertriebspartner Shop',
|
||||
6 => 'Guthaben aufladen',
|
||||
7 => 'zur internen Berechnung',
|
||||
|
||||
];
|
||||
|
|
@ -24,7 +24,7 @@ class Type
|
|||
3 => 'Microsite',
|
||||
4 => 'Registrierung Vertriebspartner',
|
||||
5 => 'Mitgliedschaft Vertriebspartner',
|
||||
//6 => 'Onboarding Berater',
|
||||
6 => 'Guthaben aufladen',
|
||||
10 => 'zur internen Berechnung',
|
||||
];
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ class Type
|
|||
3 => 'Microsite',
|
||||
4 => 'Registrierung Vertriebspartner',
|
||||
5 => 'Mitgliedschaft Vertriebspartner',
|
||||
//6 => 'Onboarding Berater',
|
||||
6 => 'Guthaben aufladen',
|
||||
10 => 'überall',
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ use Yard;
|
|||
class Util
|
||||
{
|
||||
|
||||
|
||||
|
||||
private static $postRoute = 'base.';
|
||||
|
||||
public static function getToken()
|
||||
|
|
|
|||
|
|
@ -121,6 +121,11 @@ class Yard extends Cart
|
|||
$this->putYardExtra('global_tax_rate', $this->global_tax_rate);
|
||||
}
|
||||
|
||||
public function getGlobalTaxRate(){
|
||||
$this->global_tax_rate;
|
||||
|
||||
}
|
||||
|
||||
public function setShippingOption($value){
|
||||
$this->shipping_option = $value;
|
||||
$this->putYardExtra('shipping_option', $this->shipping_option);
|
||||
|
|
@ -199,6 +204,10 @@ class Yard extends Cart
|
|||
/* * ***** */
|
||||
|
||||
public function calculateMargins(){
|
||||
|
||||
if($this->shipping_is_for === 'cr'){
|
||||
return;
|
||||
}
|
||||
//get user monthy amount
|
||||
$monthy_amount = UserMarign::getMontlyAmount($this->user);
|
||||
|
||||
|
|
@ -288,7 +297,6 @@ class Yard extends Cart
|
|||
|
||||
$margin->setCommission($this->yard_commission);
|
||||
$margin->calculate();
|
||||
|
||||
$this->yard_margin = $margin;
|
||||
$this->putYardExtra('yard_margin', $this->yard_margin);
|
||||
|
||||
|
|
@ -319,18 +327,17 @@ class Yard extends Cart
|
|||
$this->payment_credit = $payment_credit;
|
||||
$this->putYardExtra('user', $user);
|
||||
$this->putYardExtra('payment_credit', $payment_credit);
|
||||
|
||||
}
|
||||
|
||||
public function getPaymentCredit(){
|
||||
if($this->payment_credit && $this->user->payment_credit > 0){
|
||||
return $this->user->payment_credit;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
private function calculateShippingPrice(){
|
||||
|
||||
//keine Verandkosten
|
||||
if($this->shipping_option && $this->shipping_option === 'pick_up'){
|
||||
$this->shipping_price = 0;
|
||||
$this->shipping_tax_rate = 0;
|
||||
|
|
@ -339,6 +346,15 @@ class Yard extends Cart
|
|||
$this->putShippingPrices();
|
||||
return;
|
||||
}
|
||||
//keine Verandkosten
|
||||
if($this->shipping_is_for === 'cr' || $this->shipping_is_for === 'mp'){
|
||||
$this->shipping_price = 0;
|
||||
$this->shipping_tax_rate = 0;
|
||||
$this->shipping_price_net = 0;
|
||||
$this->shipping_tax = 0;
|
||||
$this->putShippingPrices();
|
||||
return;
|
||||
}
|
||||
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if(!$shippingCountry){
|
||||
|
|
@ -396,6 +412,42 @@ class Yard extends Cart
|
|||
}
|
||||
}
|
||||
|
||||
public function preCalcuShippingPrice(){
|
||||
$shippingCountry = ShippingCountry::find($this->shipping_country_id);
|
||||
if(!$shippingCountry){
|
||||
return false;
|
||||
}
|
||||
$shipping = $shippingCountry->shipping;
|
||||
$shipping_price_for = 1;
|
||||
if($this->shipping_is_for === 'shop'){
|
||||
$shipping_price_for = 2;
|
||||
}
|
||||
if($this->weight() == 0){
|
||||
$shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first();
|
||||
if(!$shipping_price){
|
||||
$shipping_price = new \App\Models\ShippingPrice();
|
||||
}
|
||||
$shipping_price->price = 0;
|
||||
}else{
|
||||
//first by price
|
||||
$shipping_price = $this->shippingPriceBySubTotal($shipping->getShippingPricesBy($shipping_price_for), $this->subtotal(2, '.', ''));
|
||||
//sec by weight
|
||||
if(!$shipping_price){
|
||||
$shipping_price = $this->shippingPriceByWeight($shipping->getShippingPricesBy($shipping_price_for), $this->weight());
|
||||
}
|
||||
//default
|
||||
if(!$shipping_price){
|
||||
$shipping_price = $shipping->getShippingPricesBy($shipping_price_for)->first();
|
||||
}
|
||||
|
||||
}
|
||||
if($shipping_price){
|
||||
return $shipping_price->price;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private function putShippingPrices(){
|
||||
$this->putYardExtra('num_comp', $this->num_comp);
|
||||
$this->putYardExtra('shipping_price', $this->shipping_price);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue