Introduce a comprehensive set of commercial features including a multi-step order approval workflow, customer credit management, and specialized import service invoicing. Key changes: - Implement `pending_approval` and `approved` shipment statuses to allow staff verification before customer payment. - Add a credit system to `User` model with `credit_limit` and `credit_used` to manage customer balances and debts. - Develop a new `importInvoice` PDF generation service following the "Sheet ENG Invoice" specification for import services. - Add Filament resources for managing Audit Logs, Commitment Forms, Customer Credits, and Shipment Checklists. - Implement staff-specific APIs for order approval/rejection and customer financial status monitoring. - Integrate Kavenegar SMS service for mobile verification and notifications. - Add bulk tracking import functionality via CSV/Excel. - Update WordPress bridge assets (CSS/JS) to support the new multi-step order form UI and updated redirection logic. - Update deployment configurations and documentation to reflect new production domains and feature sets.
105 lines
3.1 KiB
PHP
105 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\KavenegarSmsService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class MobileVerificationController extends Controller
|
|
{
|
|
private KavenegarSmsService $smsService;
|
|
|
|
public function __construct(KavenegarSmsService $smsService)
|
|
{
|
|
$this->smsService = $smsService;
|
|
}
|
|
|
|
/**
|
|
* ارسال کد تأیید به شماره موبایل
|
|
* POST /api/v1/verify/send-code
|
|
*/
|
|
public function sendCode(Request $request): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'phone' => ['required', 'string', 'regex:/^09[0-9]{9}$/'],
|
|
]);
|
|
|
|
$result = $this->smsService->sendVerificationCode($validated['phone']);
|
|
|
|
if ($result['success']) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'کد تأیید با موفقیت ارسال شد',
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => $result['message'],
|
|
], 400);
|
|
}
|
|
|
|
/**
|
|
* بررسی کد تأیید
|
|
* POST /api/v1/verify/check-code
|
|
*/
|
|
public function checkCode(Request $request): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'phone' => ['required', 'string', 'regex:/^09[0-9]{9}$/'],
|
|
'code' => ['required', 'string', 'size:5'],
|
|
]);
|
|
|
|
$isValid = $this->smsService->verifyCode($validated['phone'], $validated['code']);
|
|
|
|
if ($isValid) {
|
|
// بهروزرسانی شماره موبایل کاربر (اختیاری)
|
|
$user = Auth::user();
|
|
if ($user && $user->phone !== $validated['phone']) {
|
|
$user->update(['phone' => $validated['phone']]);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'کد تأیید صحیح است',
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'کد تأیید نادرست است یا منقضی شده است',
|
|
], 400);
|
|
}
|
|
|
|
/**
|
|
* ارسال پیامک به شماره موبایل (برای استفاده داخلی)
|
|
* POST /api/v1/verify/send-sms
|
|
*/
|
|
public function sendSms(Request $request): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'phone' => ['required', 'string', 'regex:/^09[0-9]{9}$/'],
|
|
'message' => ['required', 'string', 'max:500'],
|
|
]);
|
|
|
|
$result = $this->smsService->send($validated['phone'], $validated['message']);
|
|
|
|
if ($result['success']) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'پیامک با موفقیت ارسال شد',
|
|
'cost' => $result['cost'] ?? 0,
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => $result['message'],
|
|
], 400);
|
|
}
|
|
}
|