testemich Promotion
This commit is contained in:
parent
38e7fd504a
commit
a0f4eda6ea
83 changed files with 1690 additions and 504 deletions
|
|
@ -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']));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue