handle transactions
This commit is contained in:
@@ -209,6 +209,7 @@ class SingleOrderController extends Controller
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'start_at' => now(),
|
||||
'title' => self::meltedGoldBuyTitle(),
|
||||
], 1, true, false);
|
||||
$response['1'] = 2;
|
||||
//send to provider
|
||||
@@ -253,6 +254,7 @@ class SingleOrderController extends Controller
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'start_at' => now(),
|
||||
'title' => self::productBuyTitle($data['product']['title'] ?? ''),
|
||||
], 1, true, false);
|
||||
|
||||
|
||||
@@ -285,7 +287,7 @@ class SingleOrderController extends Controller
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'title' => $this->goldWithdrawTitle()
|
||||
'title' => self::productBuyTitle($data['product']['title'] ?? '')
|
||||
], 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);
|
||||
@@ -297,6 +299,7 @@ class SingleOrderController extends Controller
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'start_at' => now(),
|
||||
'title' => self::productBuyTitle($data['product']['title'] ?? ''),
|
||||
], 1, true, false);
|
||||
|
||||
}
|
||||
@@ -319,7 +322,8 @@ class SingleOrderController extends Controller
|
||||
"cash" => $data['total_price'],
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id
|
||||
'order_id' => $order->id,
|
||||
'title' => self::meltedGoldSellTitle(),
|
||||
], 2, false, true);
|
||||
|
||||
//send to Goldir
|
||||
@@ -355,6 +359,7 @@ class SingleOrderController extends Controller
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'start_at' => now(),
|
||||
'title' => self::productSellTitle($data['product']['title'] ?? ''),
|
||||
], 1, false, false);
|
||||
$data['transaction'][] = new TransactionInterface($wallet_interface, $_inp = [
|
||||
"number" => $data['number'],
|
||||
@@ -393,7 +398,7 @@ class SingleOrderController extends Controller
|
||||
'expire_at' => now(),
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'title' => $this->goldDepositTitle()
|
||||
'title' => self::productSellTitle($data['product']['title'] ?? '')
|
||||
], 12, true, false);
|
||||
$wallet_interface_product->wallet->gold = intval($wallet_interface_product->wallet->gold);
|
||||
$wallet_interface_product->wallet->save();
|
||||
@@ -404,6 +409,7 @@ class SingleOrderController extends Controller
|
||||
'active' => true,
|
||||
'order_id' => $order->id,
|
||||
'start_at' => now(),
|
||||
'title' => self::productSellTitle($data['product']['title'] ?? ''),
|
||||
], 1, false, false);
|
||||
}
|
||||
|
||||
@@ -477,20 +483,20 @@ class SingleOrderController extends Controller
|
||||
: 0
|
||||
);
|
||||
$totalPrice = $data['total_price'] ?? ($data['payment_amount'] ?? 0);
|
||||
$productTitle = $data['product']['title'] ?? self::metalTypeLabel();
|
||||
$subjectTitle = $this->transactionSubjectTitle($data);
|
||||
|
||||
$message = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType {$productTitle} به مقدار " .
|
||||
$message = "کاربر {$customer->name} با شماره موبایل {$customer->mobile} اقدام به $transactionType {$subjectTitle} به مقدار " .
|
||||
"{$amount} گرم به مبلغ " . number_format($totalPrice) .
|
||||
" ریال کرد. با تشکر، $companyName";
|
||||
User::where('send_sms', 1)->get()->each(function ($admin) use ($message, $data, $transactionType, $companyName) {
|
||||
$this->send($admin->mobile, $message);
|
||||
});
|
||||
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
|
||||
$metalLabel = self::metalTypeLabel();
|
||||
$balanceLabel = self::metalTypeLabel();
|
||||
// $pricePerGram = $totalPrice / $amount;
|
||||
$customerMessage = "$companyName\n$transactionType {$metalLabel}\nگرم: {$amount}\n" .
|
||||
$customerMessage = "$companyName\n$transactionType {$subjectTitle}\nگرم: {$amount}\n" .
|
||||
"مبلغ کل: " . number_format($totalPrice) . "\n\n" .
|
||||
"موجودی {$metalLabel}: {$wallet->gold}\n" .
|
||||
"موجودی {$balanceLabel}: {$wallet->gold}\n" .
|
||||
"مانده ریالی: " . number_format($wallet->cash) . "\n" .
|
||||
$this->Config('app_url');
|
||||
|
||||
@@ -672,14 +678,18 @@ class SingleOrderController extends Controller
|
||||
->count() < (int)$count;
|
||||
}
|
||||
|
||||
private function goldDepositTitle(): string
|
||||
private function isProductOrder(array $data): bool
|
||||
{
|
||||
return 'موجودی ' . self::metalTypeLabel();
|
||||
return !empty($data['product_id']) && !empty($data['product']['title']);
|
||||
}
|
||||
|
||||
private function goldWithdrawTitle(): string
|
||||
private function transactionSubjectTitle(array $data): string
|
||||
{
|
||||
return 'برداشت ' . self::metalTypeLabel();
|
||||
if ($this->isProductOrder($data)) {
|
||||
return $data['product']['title'];
|
||||
}
|
||||
|
||||
return self::meltedGoldLabel();
|
||||
}
|
||||
|
||||
private function insufficientGoldBalanceMessage(array $data): string
|
||||
|
||||
Reference in New Issue
Block a user