Merge remote-tracking branch 'origin/Abshode_Khanegi' into Abshode_Khanegi

This commit is contained in:
2026-06-15 11:35:05 +03:30
5 changed files with 30 additions and 22 deletions
@@ -33,14 +33,14 @@ class WalletController extends Controller
if ($data['value'] > 0) {
$deposit = true;
}
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
$wallet_interface = new WalletInterface($data['customer_id'], (int) $customer->type);
$wallet = $wallet_interface->wallet;
if (is_null($wallet) && !$deposit) {
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
}
if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit) {
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
}
$wallet_interface = new WalletInterface($data['customer_id'], $customer->type);
$orders = Order::where('customer_id', $data['customer_id'])->where('sts', 1)->get();
$gold_block = 0;
if (count($orders) > 0) {
@@ -91,14 +91,14 @@ class WalletController extends Controller
if ($data['value'] > 0) {
$deposit = true;
}
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
$wallet_interface = new WalletInterface($data['customer_id'], (int) $customer->type);
$wallet = $wallet_interface->wallet;
if (is_null($wallet) && !$deposit) {
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
}
if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit) {
throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
}
$wallet_interface = new WalletInterface($data['customer_id'], $customer->type);
$orders = Order::where('customer_id', $data['customer_id'])->where('sts', 1)->get();
$gold_block = 0;
@@ -160,14 +160,14 @@ class WalletController extends Controller
$deposit = true;
}
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
$wallet_interface = new WalletInterface($data['customer_id'], (int) $customer->type);
$wallet = $wallet_interface->wallet;
// if (is_null($wallet) && !$deposit) {
// throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
// }
// if (!is_null($wallet) && $wallet->cash < abs($data['value']) && !$deposit) {
// throw new UnprocessableEntityHttpException('مقدار موجودی کمتر از درخواست شماست');
// }
$wallet_interface = new WalletInterface($data['customer_id'], $customer->type);
$gold_block = 0;
$user = auth()->user();
$customer = Customer::findOrFail($data["customer_id"]);
@@ -42,9 +42,8 @@ class OrderController extends Controller
throw new UnprocessableEntityHttpException('امکان سفارش برای شما غیرفعال است.');
}
app(ConfigService::class)->assertTradingOpen();
$wallet = Wallet::where('owner',auth('customer')->id())->whereNull('fund_id')
->first();
$wallet_interface = new WalletInterface($data['customer_id'], 1);
$wallet_interface = new WalletInterface($data['customer_id'], (int) $customer->type);
$wallet = $wallet_interface->wallet;
if ($data['direction'] == 1){
// $order = Order::where('customer_id',auth('customer')->id())->where('sts',1)->first();
// if (!is_null($order)){
@@ -111,8 +111,9 @@ class SingleOrderController extends Controller
$data['price_original'] = $data['price'];
$data['payment_remind'] = 0;
$data['fee'] = $data['difference'];
$wallet_interface = new WalletInterface($data['customer_id'], 2);
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
$ownerType = (int) ($customer?->type ?? 2);
$wallet_interface = new WalletInterface($data['customer_id'], $ownerType);
$wallet = $wallet_interface->wallet;
if (!$wallet) {
throw new UnprocessableEntityHttpException('کیف پول یافت نشد.');
}
@@ -668,8 +669,9 @@ class SingleOrderController extends Controller
$data['payment_sts'] = 4;
$data['price_original'] = $data['price'];
$add_sell_price = config('add_sell_price.single');
$wallet_interface = new WalletInterface($data['customer_id'], 2);
$wallet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
$customer = Customer::findOrFail($data['customer_id']);
$wallet_interface = new WalletInterface($data['customer_id'], (int) $customer->type);
$wallet = $wallet_interface->wallet;
$data['total_price_original'] = $data['amount'] * $data['price_original'];
$data['payment_remind'] = 0;
$data['fee'] = $add_sell_price;
@@ -732,16 +734,16 @@ class SingleOrderController extends Controller
$this->Send($admin->mobile, $message);
});
$Walet = Wallet::where('owner', $data['customer_id'])->whereNull('fund_id')->first();
$companyName = $this->Config('name_fa');
$mainWallet = Wallet::where('owner', $data['customer_id'])
->where('owner_type', $customer->type)
->main()
->first();
$companyurl = $this->Config('app_url');
$weight = $data['amount'];
$totalAmount = $data['total_price'];
$pricePerGram = $totalAmount / $weight;
$goldBalance = $Walet->gold;
$remainingBalance = $Walet->cash;
$pricePerGram = $weight > 0 ? $totalAmount / $weight : 0;
$goldBalance = $mainWallet->gold ?? 0;
$remainingBalance = $mainWallet->cash ?? 0;
$message = "$companyName\n";
$message .= "خرید آبشده\n";
@@ -47,8 +47,9 @@ class RequestsController extends Controller
$data['total_fee'] = $data['amount'] * $data['difference'];
$myCustomer = Customer::find($customer_id);
$wallet_interface = new WalletInterface($customer_id, 2);
$wallet = Wallet::where('owner', $customer_id)->whereNull('fund_id')->first();
$ownerType = (int) ($myCustomer?->type ?? 2);
$wallet_interface = new WalletInterface($customer_id, $ownerType);
$wallet = $wallet_interface->wallet;
$response = [];
@@ -24,4 +24,10 @@ class Wallet extends Model
{
return $this->belongsTo('App\Models\Product','product_id');
}
/** کیف اصلی مشتری — بدون fund و بدون product */
public function scopeMain($query)
{
return $query->whereNull('fund_id')->whereNull('product_id');
}
}