feat(tahesab,colleague): push app balance to Tahesab and always wait callback

Add admin decision to write app wallet onto Tahesab even when zero, always await colleague callback regardless of the wait switch, and SMS admins on colleague reject.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-05 22:30:56 +03:30
co-authored by Cursor
parent 8cee34bfba
commit 00b23ac404
6 changed files with 176 additions and 15 deletions
@@ -32,6 +32,7 @@ use App\Services\ReferralGiftService;
use App\Services\WalletBalanceService;
use App\Services\WalletBroadcastService;
use App\Services\ColleagueOrderCallbackService;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
@@ -1010,9 +1011,8 @@ class SingleOrderController extends Controller
$this->assertProviderOrderAccepted($data);
$this->finalizeProviderOrder($data);
$order->refresh();
if (app(ColleagueOrderCallbackService::class)->waitEnabled()) {
$data['_awaiting_callback'] = true;
}
// همیشه تا کالبک/استعلام همکار در انتظار می‌ماند (حتی اگر سوییچ خاموش باشد)
$data['_awaiting_callback'] = true;
} catch (\Throwable $e) {
$this->markOrderFailed($order, $e->getMessage());
throw $e instanceof UnprocessableEntityHttpException
@@ -2093,6 +2093,44 @@ class SingleOrderController extends Controller
public function rejectColleaguePendingOrder(Order $order, string $message): void
{
$this->markOrderFailed($order, $message);
$this->notifyAdminsColleagueOrderRejected($order, $message);
}
/**
* SMS ادمین وقتی سفارش در اپ ثبت شده ولی همکار رد کرده است.
*/
private function notifyAdminsColleagueOrderRejected(Order $order, string $rejectMessage): void
{
if (! self::isSmsNotifEnabled('sms_notif_order_admin')) {
return;
}
try {
$customer = Customer::query()->find((int) $order->customer_id);
$name = trim((string) ($customer->name ?? '')) ?: 'بدون نام';
$mobile = trim((string) ($customer->mobile ?? '')) ?: '—';
$dir = ((int) ($order->direction ?? 0) === 2) ? 'فروش' : 'خرید';
$amount = self::formatSmsGoldWeight((float) ($order->amount ?? 0));
$company = (string) ($this->Config('name_fa') ?: '');
$reason = trim($rejectMessage);
if ($reason === '') {
$reason = 'رد شده توسط همکار';
}
$message = "سفارش {$dir} کاربر {$name} ({$mobile}) به مقدار {$amount} گرم در اپ ثبت شد ولی از سمت همکار رد شد. علت: {$reason}";
if ($company !== '') {
$message .= " — {$company}";
}
User::where('send_sms', 1)->get()->each(function ($admin) use ($message) {
$this->send($admin->mobile, $message);
});
} catch (\Throwable $e) {
Log::warning('Colleague reject admin SMS failed', [
'order_id' => $order->id,
'error' => $e->getMessage(),
]);
}
}
public function finalizeColleaguePendingOrder(Order $order): void