added merge wallet 2
This commit is contained in:
@@ -300,9 +300,8 @@ class SingleOrderController extends Controller
|
||||
'order_id' => $order->id,
|
||||
'title' => "برداشت وجه نقد"
|
||||
], 12, false, false);
|
||||
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
|
||||
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
|
||||
$wallet_interface_product->wallet->save();
|
||||
$wallet_interface_product = $this->productWalletInterface((int) $data["product_id"]);
|
||||
$this->normalizeProductWalletGold($wallet_interface_product);
|
||||
new TransactionInterface($wallet_interface_product, [
|
||||
"gold" => $data['number'],
|
||||
"product_id" => $data["product_id"],
|
||||
@@ -346,9 +345,8 @@ class SingleOrderController extends Controller
|
||||
'order_id' => $order->id,
|
||||
'title' => self::mainMetalSellTitle(),
|
||||
], 12, false, true);
|
||||
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
|
||||
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
|
||||
$wallet_interface_product->wallet->save();
|
||||
$wallet_interface_product = $this->productWalletInterface((int) $data["product_id"]);
|
||||
$this->normalizeProductWalletGold($wallet_interface_product);
|
||||
new TransactionInterface($wallet_interface_product, [
|
||||
"gold" => $data['number'],
|
||||
"product_id" => $data["product_id"],
|
||||
@@ -410,7 +408,7 @@ class SingleOrderController extends Controller
|
||||
$this->enforceProductOrderLimits($data, $grossTotal);
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
|
||||
$wallet_interface_product = $this->productWalletInterface((int) $data["product_id"]);
|
||||
|
||||
if ($wallet_interface_product->wallet->gold < $data['number']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
@@ -419,8 +417,7 @@ class SingleOrderController extends Controller
|
||||
throw new UnprocessableEntityHttpException('فروش این محصول در این لحظه مقدور نمیباشد');
|
||||
}
|
||||
$data['order'] = $order = Order::create($data);
|
||||
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
|
||||
$wallet_interface_product->wallet->save();
|
||||
$this->normalizeProductWalletGold($wallet_interface_product);
|
||||
new TransactionInterface($wallet_interface_product, [
|
||||
"gold" => $data['number'],
|
||||
"product_id" => $data["product_id"],
|
||||
@@ -454,7 +451,7 @@ class SingleOrderController extends Controller
|
||||
$data['service_charge'] = isset($data['fee_free']) && $data['fee_free'] === true ? 0 : ($data['product']['percent_fee_sell'] * $data['amount']);
|
||||
$data['total_fee'] = 0;
|
||||
$data['service_charge_price'] = $data['service_charge'] * $data['price_original'];
|
||||
$wallet_interface_product = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type, null, $data["product_id"]);
|
||||
$wallet_interface_product = $this->productWalletInterface((int) $data["product_id"]);
|
||||
if ($wallet_interface_product->wallet->gold < $data['number']) {
|
||||
throw new UnprocessableEntityHttpException('موجودی شما کمتر از میزان سفارش است');
|
||||
}
|
||||
@@ -471,8 +468,7 @@ class SingleOrderController extends Controller
|
||||
'order_id' => $order->id,
|
||||
'title' => self::mainMetalBuyTitle(),
|
||||
], 12, true, false);
|
||||
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
|
||||
$wallet_interface_product->wallet->save();
|
||||
$this->normalizeProductWalletGold($wallet_interface_product);
|
||||
new TransactionInterface($wallet_interface_product, [
|
||||
"gold" => $data['number'],
|
||||
"product_id" => $data["product_id"],
|
||||
@@ -484,6 +480,31 @@ class SingleOrderController extends Controller
|
||||
], 1, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* کیف مؤثر محصول برای تراکنش سفارش.
|
||||
* محصولات متصل به کیف اصلی (main_wallet_products) مستقیماً روی کیف اصلی مینشینند.
|
||||
*/
|
||||
private function productWalletInterface(int $productId): WalletInterface
|
||||
{
|
||||
return new WalletInterface(
|
||||
auth('customer')->id(),
|
||||
auth('customer')->user()->type,
|
||||
null,
|
||||
self::effectiveProductWalletId($productId)
|
||||
);
|
||||
}
|
||||
|
||||
/** رفتار قدیمیِ رُند کردن موجودی فقط برای کیف خود محصول؛ کیف اصلی هرگز رُند نمیشود */
|
||||
private function normalizeProductWalletGold(WalletInterface $walletInterface): void
|
||||
{
|
||||
if ($walletInterface->wallet->product_id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$walletInterface->wallet->gold = intval($walletInterface->wallet->gold);
|
||||
$walletInterface->wallet->save();
|
||||
}
|
||||
|
||||
private function give_order_reward(&$data, $wallet, $wallet_interface)
|
||||
{
|
||||
$data['aCustomers'] = [];
|
||||
|
||||
Reference in New Issue
Block a user