product time changed 4
This commit is contained in:
@@ -764,6 +764,8 @@ class WalletController extends Controller
|
|||||||
foreach ($rows as $record) {
|
foreach ($rows as $record) {
|
||||||
$row = $record instanceof Transaction ? $record->toArray() : (array) $record;
|
$row = $record instanceof Transaction ? $record->toArray() : (array) $record;
|
||||||
|
|
||||||
|
$this->attachMissingOrderForApi($row);
|
||||||
|
|
||||||
if ($this->isShopRialTransaction($record)) {
|
if ($this->isShopRialTransaction($record)) {
|
||||||
$row['withdraw'] = ['sts_str' => 'برداشت ریالی توسط فروشگاه'];
|
$row['withdraw'] = ['sts_str' => 'برداشت ریالی توسط فروشگاه'];
|
||||||
}
|
}
|
||||||
@@ -899,4 +901,52 @@ class WalletController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* بعضی تراکنشهای قدیمی order_id دارند ولی ردیف orders حذف شده — برای UI وضعیت/قیمت را بازسازی میکنیم.
|
||||||
|
*/
|
||||||
|
private function attachMissingOrderForApi(array &$row): void
|
||||||
|
{
|
||||||
|
$orderId = (int) ($row['order_id'] ?? 0);
|
||||||
|
if ($orderId <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$order = $row['order'] ?? null;
|
||||||
|
if (is_array($order) && !empty($order['id'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$loaded = Order::query()->find($orderId);
|
||||||
|
if ($loaded) {
|
||||||
|
$row['order'] = $loaded->toArray();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = (int) ($row['type'] ?? 0);
|
||||||
|
if (!in_array($type, [1, 2, 10], true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row['order'] = [
|
||||||
|
'id' => $orderId,
|
||||||
|
'sts' => 2,
|
||||||
|
'payment_sts' => 4,
|
||||||
|
'sts_str' => 'موفق',
|
||||||
|
'price' => $this->inferTradePriceFromTransactionRow($row),
|
||||||
|
'amount' => abs((float) ($row['gold'] ?? 0)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function inferTradePriceFromTransactionRow(array $row): int
|
||||||
|
{
|
||||||
|
$cash = abs((int) ($row['cash'] ?? 0));
|
||||||
|
$gold = abs((float) ($row['gold'] ?? 0));
|
||||||
|
if ($gold > 0 && $cash > 0) {
|
||||||
|
return (int) round($cash / $gold);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user