zarbox added 11
This commit is contained in:
@@ -85,6 +85,15 @@ class WalletController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($records['rows'] as &$record) {
|
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 ندارند یا تعریف نشده هستند اصلاح شوند
|
// بقیه رکوردها فقط اگر title ندارند یا تعریف نشده هستند اصلاح شوند
|
||||||
if (empty($record->title) || $record->title == "تعریف نشده") {
|
if (empty($record->title) || $record->title == "تعریف نشده") {
|
||||||
|
|
||||||
@@ -118,9 +127,10 @@ class WalletController extends Controller
|
|||||||
$this->applyProductTransactionTitle($record);
|
$this->applyProductTransactionTitle($record);
|
||||||
$this->applyProductOrderDisplayFields($record);
|
$this->applyProductOrderDisplayFields($record);
|
||||||
$this->applyProductTransactionUnit($record);
|
$this->applyProductTransactionUnit($record);
|
||||||
$this->applyTransactionDisplayStatus($record);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$records['rows'] = $this->serializeTransactionRowsForApi($records['rows']);
|
||||||
|
|
||||||
return response()->json($records);
|
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)) {
|
if ($this->isShopGoldTransaction($record)) {
|
||||||
$this->setOrderStsStr($record, 'برداشت طلایی توسط فروشگاه');
|
if (empty($record->title) || $record->title === 'تعریف نشده') {
|
||||||
|
$record->title = 'برداشت طلایی';
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** برداشت ریال از 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
|
private function isShopRialTransaction($record): bool
|
||||||
{
|
{
|
||||||
if ((int) $record->type !== 4) {
|
if ((int) $record->type !== 4 || !empty($record->withdraw_id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($record->withdraw_id) || !empty($record->withdraw)) {
|
return (int) ($record->cash ?? 0) < 0;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** برداشت طلا از API خارجی (RequestsController::processGoldTransaction) */
|
/** برداشت طلا API فروشگاه — type=10 + order_id، بدون withdraw */
|
||||||
private function isShopGoldTransaction($record): bool
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$order = $record->order;
|
$order = $this->resolveOrderForTransaction($record);
|
||||||
|
if (!$order) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ((int) ($order->direction ?? 0) !== 2) {
|
if ((int) ($order->direction ?? 0) !== 2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -496,28 +534,22 @@ class WalletController extends Controller
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) ($order->sts ?? 0) === 2
|
return (int) ($order->sts ?? 0) === 2 && (int) ($order->payment_sts ?? 0) === 4;
|
||||||
&& (int) ($order->payment_sts ?? 0) === 4
|
|
||||||
&& empty($record->withdraw_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setWithdrawStsStr($record, string $label): void
|
private function resolveOrderForTransaction($record): ?Order
|
||||||
{
|
{
|
||||||
// آرایه — stdClass در toArray()/JSON نمیآید و UI خالی میماند
|
if ($record->order instanceof Order) {
|
||||||
$record->setRelation('withdraw', ['sts_str' => $label]);
|
return $record->order;
|
||||||
}
|
|
||||||
|
|
||||||
private function setOrderStsStr($record, string $label): void
|
|
||||||
{
|
|
||||||
if (empty($record->order)) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$order = $record->order instanceof Order
|
if (empty($record->order_id)) {
|
||||||
? $record->order->toArray()
|
return null;
|
||||||
: (array) $record->order;
|
}
|
||||||
$order['sts_str'] = $label;
|
|
||||||
$record->setRelation('order', $order);
|
return Order::query()
|
||||||
|
->select(['*', Order::$SELECT_STS_STR])
|
||||||
|
->find($record->order_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function resolveMainWalletBalanceCashForOrder($record): ?int
|
private function resolveMainWalletBalanceCashForOrder($record): ?int
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class Transaction extends Model
|
|||||||
6 => 'برداشت',
|
6 => 'برداشت',
|
||||||
8 => ' پاداش بابت معرفی',
|
8 => ' پاداش بابت معرفی',
|
||||||
9 => 'سود زیر مجموعه',
|
9 => 'سود زیر مجموعه',
|
||||||
|
10 => 'برداشت طلایی',
|
||||||
];
|
];
|
||||||
public function customer()
|
public function customer()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user