zarbox added 11

This commit is contained in:
2026-06-04 19:22:01 +03:30
parent c13222055b
commit 577e2f3400
2 changed files with 72 additions and 39 deletions
@@ -85,6 +85,15 @@ class WalletController extends Controller
}
foreach ($records['rows'] as &$record) {
if ($this->isShopGoldTransaction($record)) {
$this->applyShopTransactionPresentation($record);
$this->applyMetalTypeTransactionTitle($record);
$this->applyProductTransactionTitle($record);
$this->applyProductOrderDisplayFields($record);
$this->applyProductTransactionUnit($record);
continue;
}
// بقیه رکوردها فقط اگر title ندارند یا تعریف نشده هستند اصلاح شوند
if (empty($record->title) || $record->title == "تعریف نشده") {
@@ -118,9 +127,10 @@ class WalletController extends Controller
$this->applyProductTransactionTitle($record);
$this->applyProductOrderDisplayFields($record);
$this->applyProductTransactionUnit($record);
$this->applyTransactionDisplayStatus($record);
}
$records['rows'] = $this->serializeTransactionRowsForApi($records['rows']);
return response()->json($records);
}
@@ -448,45 +458,73 @@ class WalletController extends Controller
}
/**
* متن وضعیت آبی UI — کلاینت: order.sts_str ?? withdraw.sts_str (بدون تغییر اپ).
* عنوان/وضعیت تراکنش‌های API فروشگاه — فقط نمایش؛ واریز/برداشت عادی دست نخورده.
*/
private function applyTransactionDisplayStatus($record): void
private function applyShopTransactionPresentation($record): void
{
if ($this->isShopRialTransaction($record)) {
$this->setWithdrawStsStr($record, 'برداشت ریالی توسط فروشگاه');
return;
}
if ($this->isShopGoldTransaction($record)) {
$this->setOrderStsStr($record, 'برداشت طلایی توسط فروشگاه');
return;
if (empty($record->title) || $record->title === 'تعریف نشده') {
$record->title = 'برداشت طلایی';
}
}
}
/** برداشت ریال از API خارجی — بدون رکورد withdraw در DB */
/**
* خروجی JSON — withdraw/order را صریحاً می‌گذارد (setRelation گاهی در JSON نمی‌آید).
*/
private function serializeTransactionRowsForApi($rows): array
{
$out = [];
foreach ($rows as $record) {
$row = $record instanceof Transaction ? $record->toArray() : (array) $record;
if ($this->isShopRialTransaction($record)) {
$row['withdraw'] = ['sts_str' => 'برداشت ریالی توسط فروشگاه'];
}
if ($this->isShopGoldTransaction($record)) {
$order = $row['order'] ?? [];
if (!is_array($order)) {
$order = $order instanceof Order ? $order->toArray() : [];
}
$order['sts_str'] = 'برداشت طلایی توسط فروشگاه';
if (empty($order['id']) && !empty($record->order_id)) {
$order['id'] = $record->order_id;
}
$row['order'] = $order;
$row['title'] = 'برداشت طلایی';
$row['type_str'] = 'برداشت طلایی';
}
$out[] = $row;
}
return $out;
}
/** برداشت ریال API فروشگاه — type=4، بدون withdraw_id، مبلغ منفی */
private function isShopRialTransaction($record): bool
{
if ((int) $record->type !== 4) {
if ((int) $record->type !== 4 || !empty($record->withdraw_id)) {
return false;
}
if (!empty($record->withdraw_id) || !empty($record->withdraw)) {
return false;
}
return true;
return (int) ($record->cash ?? 0) < 0;
}
/** برداشت طلا از API خارجی (RequestsController::processGoldTransaction) */
/** برداشت طلا API فروشگاه — type=10 + order_id، بدون withdraw */
private function isShopGoldTransaction($record): bool
{
if ((int) $record->type !== 10 || empty($record->order_id) || empty($record->order)) {
if ((int) $record->type !== 10 || empty($record->order_id) || !empty($record->withdraw_id)) {
return false;
}
$order = $record->order;
$order = $this->resolveOrderForTransaction($record);
if (!$order) {
return true;
}
if ((int) ($order->direction ?? 0) !== 2) {
return false;
}
@@ -496,28 +534,22 @@ class WalletController extends Controller
return true;
}
return (int) ($order->sts ?? 0) === 2
&& (int) ($order->payment_sts ?? 0) === 4
&& empty($record->withdraw_id);
return (int) ($order->sts ?? 0) === 2 && (int) ($order->payment_sts ?? 0) === 4;
}
private function setWithdrawStsStr($record, string $label): void
private function resolveOrderForTransaction($record): ?Order
{
// آرایه — stdClass در toArray()/JSON نمی‌آید و UI خالی می‌ماند
$record->setRelation('withdraw', ['sts_str' => $label]);
}
private function setOrderStsStr($record, string $label): void
{
if (empty($record->order)) {
return;
if ($record->order instanceof Order) {
return $record->order;
}
$order = $record->order instanceof Order
? $record->order->toArray()
: (array) $record->order;
$order['sts_str'] = $label;
$record->setRelation('order', $order);
if (empty($record->order_id)) {
return null;
}
return Order::query()
->select(['*', Order::$SELECT_STS_STR])
->find($record->order_id);
}
private function resolveMainWalletBalanceCashForOrder($record): ?int
@@ -25,6 +25,7 @@ class Transaction extends Model
6 => 'برداشت',
8 => ' پاداش بابت معرفی',
9 => 'سود زیر مجموعه',
10 => 'برداشت طلایی',
];
public function customer()
{