fix title in transacrion
This commit is contained in:
@@ -324,6 +324,46 @@ class Controller extends BaseController
|
|||||||
return in_array($title, self::genericMetalTransactionTitles(), true);
|
return in_array($title, self::genericMetalTransactionTitles(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function rialDepositTitle(): string
|
||||||
|
{
|
||||||
|
return 'واریز ریالی';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function rialWithdrawTitle(): string
|
||||||
|
{
|
||||||
|
return 'برداشت ریالی';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* type و title تراکنش ریالی — بر اساس علامت cash (دادههای قدیمی گاهی type=4 با cash مثبت دارند).
|
||||||
|
*/
|
||||||
|
public static function normalizeRialTransactionPresentation($record, bool $persist = true): void
|
||||||
|
{
|
||||||
|
$type = (int) ($record->type ?? 0);
|
||||||
|
if (!in_array($type, [3, 4], true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cash = (float) ($record->cash ?? 0);
|
||||||
|
$correctType = $cash >= 0 ? 3 : 4;
|
||||||
|
$correctTitle = $correctType === 3 ? self::rialDepositTitle() : self::rialWithdrawTitle();
|
||||||
|
|
||||||
|
$dirty = false;
|
||||||
|
if ($correctType !== $type) {
|
||||||
|
$record->type = $correctType;
|
||||||
|
$dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trim((string) ($record->title ?? '')) !== $correctTitle) {
|
||||||
|
$record->title = $correctTitle;
|
||||||
|
$dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($dirty && $persist && $record instanceof \Rooyesh\Wallet\models\Transaction) {
|
||||||
|
$record->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function productBuyTitle(string $productTitle): string
|
public static function productBuyTitle(string $productTitle): string
|
||||||
{
|
{
|
||||||
return 'خرید ' . $productTitle;
|
return 'خرید ' . $productTitle;
|
||||||
|
|||||||
@@ -81,6 +81,9 @@ class WalletController extends Controller
|
|||||||
|
|
||||||
public function transactionTable(Request $request)
|
public function transactionTable(Request $request)
|
||||||
{
|
{
|
||||||
|
$customerId = (int) auth('customer')->id();
|
||||||
|
$this->repairMisclassifiedRialTransactions($customerId);
|
||||||
|
|
||||||
if (isset($request->wallet_id)){
|
if (isset($request->wallet_id)){
|
||||||
$wallet = Wallet::with('product')->where('id', $request->wallet_id)->where('owner', auth('customer')->id())->get();
|
$wallet = Wallet::with('product')->where('id', $request->wallet_id)->where('owner', auth('customer')->id())->get();
|
||||||
}else{
|
}else{
|
||||||
@@ -116,6 +119,7 @@ class WalletController extends Controller
|
|||||||
$this->applyProductTransactionTitle($record);
|
$this->applyProductTransactionTitle($record);
|
||||||
$this->applyProductOrderDisplayFields($record);
|
$this->applyProductOrderDisplayFields($record);
|
||||||
$this->applyProductTransactionUnit($record);
|
$this->applyProductTransactionUnit($record);
|
||||||
|
self::normalizeRialTransactionPresentation($record);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +157,7 @@ class WalletController extends Controller
|
|||||||
$this->applyProductTransactionTitle($record);
|
$this->applyProductTransactionTitle($record);
|
||||||
$this->applyProductOrderDisplayFields($record);
|
$this->applyProductOrderDisplayFields($record);
|
||||||
$this->applyProductTransactionUnit($record);
|
$this->applyProductTransactionUnit($record);
|
||||||
|
self::normalizeRialTransactionPresentation($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
$records['rows'] = $this->serializeTransactionRowsForApi($records['rows']);
|
$records['rows'] = $this->serializeTransactionRowsForApi($records['rows']);
|
||||||
@@ -160,6 +165,36 @@ class WalletController extends Controller
|
|||||||
return response()->json($records);
|
return response()->json($records);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* دادهٔ قدیمی: type=4 با cash مثبت (واریز ادمین) — قبل از فیلتر جدول اصلاح میشود.
|
||||||
|
*/
|
||||||
|
private function repairMisclassifiedRialTransactions(int $customerId): void
|
||||||
|
{
|
||||||
|
if ($customerId <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Transaction::query()
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->whereNull('fund_id')
|
||||||
|
->where('type', 4)
|
||||||
|
->where('cash', '>', 0)
|
||||||
|
->update([
|
||||||
|
'type' => 3,
|
||||||
|
'title' => self::rialDepositTitle(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Transaction::query()
|
||||||
|
->where('customer_id', $customerId)
|
||||||
|
->whereNull('fund_id')
|
||||||
|
->where('type', 3)
|
||||||
|
->where('cash', '<', 0)
|
||||||
|
->update([
|
||||||
|
'type' => 4,
|
||||||
|
'title' => self::rialWithdrawTitle(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function transactionTableb(Request $request)
|
public function transactionTableb(Request $request)
|
||||||
{
|
{
|
||||||
$wallet = Wallet::with('product')->where('owner', auth('customer')->id())->whereNull('fund_id')->get();
|
$wallet = Wallet::with('product')->where('owner', auth('customer')->id())->whereNull('fund_id')->get();
|
||||||
|
|||||||
Reference in New Issue
Block a user