Updates to 03-2025
This commit is contained in:
parent
6167273a48
commit
9b54eb0512
348 changed files with 34535 additions and 5774 deletions
|
|
@ -5,21 +5,24 @@ namespace App\Repositories;
|
|||
use Yard;
|
||||
use App\Services\Shop;
|
||||
use App\Services\Util;
|
||||
use App\Models\UserShop;
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\ShoppingOrder;
|
||||
use App\Models\ShoppingOrderItem;
|
||||
use App\Services\CustomerPriority;
|
||||
use Illuminate\Support\Collection;
|
||||
use App\Models\ShoppingOrderMargin;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use App\Http\Controllers\Pay\PayController;
|
||||
|
||||
|
||||
|
||||
class CheckoutRepository {
|
||||
|
||||
private $payment_for;
|
||||
private $PromotionUser;
|
||||
private $UserShop;
|
||||
|
||||
private $is_for;
|
||||
private $session;
|
||||
private $instance;
|
||||
private $shopping_user;
|
||||
|
|
@ -38,6 +41,14 @@ class CheckoutRepository {
|
|||
{
|
||||
$this->payment_for = $payment_for;
|
||||
$this->PromotionUser = $PromotionUser;
|
||||
$this->is_for = 'pr';
|
||||
}
|
||||
|
||||
public function setUserShop($payment_for, UserShop $UserShop)
|
||||
{
|
||||
$this->payment_for = $payment_for;
|
||||
$this->UserShop = $UserShop;
|
||||
$this->is_for = 'shop';
|
||||
}
|
||||
|
||||
public function init($identifier, $data)
|
||||
|
|
@ -51,7 +62,7 @@ class CheckoutRepository {
|
|||
|
||||
$shopping_data = Yard::instance('shopping')->getYardExtra('shopping_data');
|
||||
$this->data['is_from'] = isset($shopping_data['is_from']) ? $shopping_data['is_from'] : 'shopping'; //shopping
|
||||
$this->data['is_from'] = isset($shopping_data['is_for']) ? $shopping_data['is_for'] : 'pr'; //promotion
|
||||
$this->data['is_for'] = isset($shopping_data['is_for']) ? $shopping_data['is_for'] : 'pr'; //promotion //us shop
|
||||
|
||||
$this->shopping_user = $this->makeShoppingUser($data);
|
||||
$this->shopping_order = $this->makeShoppingOrder($this->shopping_user);
|
||||
|
|
@ -94,7 +105,7 @@ class CheckoutRepository {
|
|||
$data['accepted_data'] = isset($data['accepted_data']) ? true : false;
|
||||
$data['billing_country_id'] = Shop::getShippingCountryCountryId($data['billing_state']);
|
||||
$data['shipping_country_id'] = $data['billing_country_id'];
|
||||
$data['member_id'] = $this->PromotionUser->user_id;
|
||||
$data['member_id'] = $this->is_for === 'shop' ? $this->UserShop->user_id : $this->PromotionUser->user_id; //pr
|
||||
|
||||
if(isset($data['shipping_state'])){
|
||||
$data['shipping_country_id'] = Shop::getShippingCountryCountryId($data['shipping_state']);
|
||||
|
|
@ -119,7 +130,8 @@ class CheckoutRepository {
|
|||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'auth_user_id' => $shopping_user->auth_user_id,
|
||||
'promotion_user_id' => $this->PromotionUser->id,
|
||||
'promotion_user_id' => $this->is_for === 'pr' ? $this->PromotionUser->id : null,
|
||||
'user_shop_id' => $this->is_for === 'shop' ? $this->UserShop->id : null,
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'payment_for' => $this->payment_for,
|
||||
'total' => Yard::instance('shopping')->total(2, '.', ''),
|
||||
|
|
@ -152,7 +164,7 @@ class CheckoutRepository {
|
|||
if(!$shopping_order){
|
||||
$shopping_order = ShoppingOrder::create($data);
|
||||
}
|
||||
//$this->makeOrderMargin($shopping_order);
|
||||
$this->makeOrderMargin($shopping_order);
|
||||
|
||||
$this->putPayments('shopping_order_id', $shopping_order->id);
|
||||
$items = Yard::instance('shopping')->getContentByOrder();
|
||||
|
|
@ -197,6 +209,43 @@ class CheckoutRepository {
|
|||
return $shopping_order;
|
||||
}
|
||||
|
||||
private function makeOrderMargin(ShoppingOrder $shopping_order)
|
||||
{
|
||||
if ($this->is_for === 'pr' || $this->is_for === 'shop' ) {
|
||||
|
||||
$userMargin = Shop::calculateUserShopMargins($this->UserShop, $this->PromotionUser);
|
||||
$data = [
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'user_id' => $shopping_order->shopping_user->member_id,
|
||||
'net_price' => $userMargin->yard_margin->net_price,
|
||||
'net_discount' => $userMargin->yard_margin->net_discount,
|
||||
'net_amount' => $userMargin->yard_margin->net_amount,
|
||||
'from_payment_credit' =>0,
|
||||
'from' => now(),
|
||||
'status' => $this->payment_for, //7 => 'from promotion', 8 => 'from shop',
|
||||
'content' => serialize($userMargin->yard_margin->toArray())
|
||||
];
|
||||
if($userMargin->yard_margin->net_partner_commission > 0){
|
||||
if(isset($shopping_order->auth_user->m_sponsor)){
|
||||
if($shopping_order->auth_user->user_sponsor && $shopping_order->auth_user->user_sponsor->isActiveAccount())
|
||||
$data['m_sponsor_id'] = $shopping_order->auth_user->m_sponsor;
|
||||
$data['net_partner_commission'] = $userMargin->yard_margin->net_partner_commission;
|
||||
}
|
||||
}
|
||||
$shopping_order_margin = false;
|
||||
if ($this->getPayments('shopping_order_margin_id')) {
|
||||
$shopping_order_margin = ShoppingOrderMargin::find($this->getPayments('shopping_order_margin_id'));
|
||||
if ($shopping_order_margin) {
|
||||
$shopping_order_margin->fill($data);
|
||||
$shopping_order_margin->save();}
|
||||
}
|
||||
if (!$shopping_order_margin) {
|
||||
$shopping_order_margin = ShoppingOrderMargin::create($data);
|
||||
}
|
||||
$this->putPayments('shopping_order_margin_id', $shopping_order_margin->id);
|
||||
}
|
||||
}
|
||||
|
||||
private function putPayments($key, $value){
|
||||
$content = $this->getContent();
|
||||
$content->put($key, $value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue