diff --git a/app/Http/Controllers/Admin/WalletController.php b/app/Http/Controllers/Admin/WalletController.php index 0d1fbb4..ddc76d6 100644 --- a/app/Http/Controllers/Admin/WalletController.php +++ b/app/Http/Controllers/Admin/WalletController.php @@ -691,7 +691,7 @@ class WalletController extends Controller public function indexWithdraw(Request $request) { - $records = Withdraw::with(['customer', 'bank_account', 'Address', "Transaction"]); + $records = Withdraw::with(['customer', 'bank_account', 'address', "Transaction"]); Withdraw::applyFlowFilter($records, $request->input('flow_type', 'all')); TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) @@ -874,7 +874,7 @@ class WalletController extends Controller public function getWithdraw(Request $request, $id) { - $withdraw = Withdraw::with(['customer', 'bank_account', 'Address', "Transaction"])->find($id); + $withdraw = Withdraw::with(['customer', 'bank_account', 'address', "Transaction"])->find($id); if (!$withdraw) { return response()->json(['error' => 'Withdraw not found'], 404); } @@ -883,7 +883,7 @@ class WalletController extends Controller public function indexPhysicalWithdraw(Request $request) { - $records = Withdraw::with(['customer', 'Address', 'Transaction.product']); + $records = Withdraw::with(['customer', 'address', 'Transaction.product']); Withdraw::scopePhysicalWithdrawals($records); TableEngine::create($records, $request->all()) diff --git a/app/Http/Controllers/Customer/WalletController.php b/app/Http/Controllers/Customer/WalletController.php index a28d7b8..d017bdd 100644 --- a/app/Http/Controllers/Customer/WalletController.php +++ b/app/Http/Controllers/Customer/WalletController.php @@ -473,14 +473,19 @@ class WalletController extends Controller $data['customer'] = Customer::with([/*"wallet"*/])->where('id', auth('customer')->id())->first(); $data['customer']['wallet_interface'] = new WalletInterface(auth('customer')->id(), auth('customer')->user()->type); - if (!isset($data['address_id'])) { + if (!isset($data['address_id']) || (int) $data['address_id'] <= 0) { return response()->json(['message' => 'آدرس انتخاب نشده است'], 422); } - $data['adress'] = Address::find($data['address_id']); - if (!$data['adress'] || $data['adress']->customer_id != $data['customer']->id) { + $addressId = (int) $data['address_id']; + $data['adress'] = Address::query() + ->where('id', $addressId) + ->where('customer_id', $data['customer']->id) + ->first(); + if (! $data['adress']) { return response()->json(['message' => 'آدرس معتبر نیست یا متعلق به شما نمی‌باشد'], 403); } + $data['address_id'] = $addressId; $assetSummaryService = app(AssetSummaryService::class); foreach ($data['wallets'] as $key => $wallet) { $data['wallets'][$key]['wallet'] = Wallet::with(["product"])->find($wallet['wallet_id']); @@ -580,7 +585,7 @@ class WalletController extends Controller return response()->json($data['withdraw']['id']); } public function indexWithdraw(Request $request){ - $records = Withdraw::with(['customer','bank_account','Address',"Transaction"])->where("customer_id",auth('customer')->id()); + $records = Withdraw::with(['customer','bank_account','address',"Transaction"])->where("customer_id",auth('customer')->id()); TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) ->select([ @@ -589,7 +594,7 @@ class WalletController extends Controller return response()->json($records); } public function index_withdraw_physical(Request $request){ - $records = Withdraw::with(['customer','bank_account','Address',"Transaction.product.file"])->where("customer_id",auth('customer')->id())->whereBetween('sts', [49, 70]); + $records = Withdraw::with(['customer','bank_account','address',"Transaction.product.file"])->where("customer_id",auth('customer')->id())->whereBetween('sts', [49, 70]); TableEngine::create($records, $request->all()) ->initSearch(['customer.name']) ->select([ diff --git a/app/Models/Withdraw.php b/app/Models/Withdraw.php index 4e13092..38735d6 100644 --- a/app/Models/Withdraw.php +++ b/app/Models/Withdraw.php @@ -19,6 +19,7 @@ class Withdraw extends Model 'extra_note', 'tracked_number', 'bank_account_id', + 'address_id', 'date_at', 'sts', 'type', @@ -42,9 +43,9 @@ class Withdraw extends Model return $this->belongsTo('App\Models\Customer')->select(['id', 'name', 'mobile']); } - public function Address() + public function address() { - return $this->belongsTo('App\Models\Address'); + return $this->belongsTo(Address::class, 'address_id'); } public function Transaction()