added assets into stream
This commit is contained in:
@@ -24,6 +24,7 @@ use App\Models\TransactionsAdmin;
|
||||
use App\Services\BalanceReportService;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\WalletBalanceService;
|
||||
use App\Services\WalletBroadcastService;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
|
||||
|
||||
@@ -154,6 +155,8 @@ class WalletController extends Controller
|
||||
. "\n"
|
||||
. $this->Config('name_fa');
|
||||
$this->Send($customer->mobile, $message);
|
||||
$this->broadcastCustomerWalletAssets($customer);
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
public function charge_gold(Request $request)
|
||||
@@ -224,6 +227,8 @@ class WalletController extends Controller
|
||||
. $data['note']
|
||||
. $this->Config('name_fa');
|
||||
$this->Send($customer->mobile, $message);
|
||||
$this->broadcastCustomerWalletAssets($customer);
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
|
||||
@@ -367,6 +372,7 @@ class WalletController extends Controller
|
||||
. "\n"
|
||||
. $this->Config('name_fa');
|
||||
$this->Send($customer->mobile, $message);
|
||||
$this->broadcastCustomerWalletAssets($customer);
|
||||
|
||||
return response()->json(true);
|
||||
}
|
||||
@@ -467,6 +473,10 @@ class WalletController extends Controller
|
||||
$transaction->save();
|
||||
$message = 'تراکنش با موفقیت بهروزرسانی شد.';
|
||||
|
||||
$customer = Customer::find($transaction->customer_id);
|
||||
if ($customer) {
|
||||
$this->broadcastCustomerWalletAssets($customer);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => $message,
|
||||
@@ -660,4 +670,12 @@ class WalletController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
private function broadcastCustomerWalletAssets(Customer $customer): void
|
||||
{
|
||||
app(WalletBroadcastService::class)->broadcastForCustomer(
|
||||
(int) $customer->id,
|
||||
(int) $customer->type
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ use App\Models\Setting;
|
||||
use App\Models\Cnt;
|
||||
use App\Services\MontzarService;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\WalletBroadcastService;
|
||||
|
||||
|
||||
class SingleOrderController extends Controller
|
||||
@@ -221,6 +222,14 @@ class SingleOrderController extends Controller
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
if ($customer) {
|
||||
app(WalletBroadcastService::class)->broadcastForCustomer(
|
||||
(int) $customer->id,
|
||||
$ownerType
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json([$response, $data]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Site;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\AssetSummaryService;
|
||||
use App\Services\LivePriceCacheService;
|
||||
use App\Services\PriceBroadcastService;
|
||||
use App\Services\PriceStreamService;
|
||||
@@ -19,7 +20,11 @@ class PriceStreamController extends Controller
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return response()->stream(function () use ($service) {
|
||||
$customer = auth('customer')->user();
|
||||
$customerId = $customer ? (int) $customer->id : 0;
|
||||
$customerOwnerType = $customer ? (int) $customer->type : 0;
|
||||
|
||||
return response()->stream(function () use ($service, $customerId, $customerOwnerType) {
|
||||
@set_time_limit(0);
|
||||
|
||||
if (function_exists('apache_setenv')) {
|
||||
@@ -50,6 +55,18 @@ class PriceStreamController extends Controller
|
||||
$send('list', $list);
|
||||
}
|
||||
|
||||
$customerLastId = 0;
|
||||
if ($customerId > 0) {
|
||||
$assets = app(AssetSummaryService::class)->buildForCustomer(
|
||||
$customerId,
|
||||
$customerOwnerType > 0 ? $customerOwnerType : 2
|
||||
);
|
||||
if ($assets !== []) {
|
||||
$send('assets', $assets);
|
||||
}
|
||||
$customerLastId = $service->currentCustomerSeq($customerId);
|
||||
}
|
||||
|
||||
$lastId = $service->currentSeq();
|
||||
$heartbeatTicks = 0;
|
||||
|
||||
@@ -62,6 +79,13 @@ class PriceStreamController extends Controller
|
||||
$lastId = (int) $event['id'];
|
||||
}
|
||||
|
||||
if ($customerId > 0) {
|
||||
foreach ($service->consumeCustomerSince($customerId, $customerLastId) as $event) {
|
||||
$send((string) $event['event'], $event['data']);
|
||||
$customerLastId = (int) $event['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$heartbeatTicks++;
|
||||
// هر ۵ ثانیه — LiteSpeed/پروکسی اتصال بیکار را نمیبندد
|
||||
if ($heartbeatTicks >= 10) {
|
||||
|
||||
Reference in New Issue
Block a user