feat: nạp tiền thủ công mã 30 phút, gia hạn trừ số dư, đồng bộ domain từ Plesk

- Nạp tiền: mã thanh toán sống 30 phút (ManualDepositDraft), khôi phục/huỷ mã, lệnh dọn mã hết hạn; total_pending chỉ tính giao dịch đã nộp chứng từ, admin duyệt/từ chối/xoá giao dịch
- Gia hạn dịch vụ: phát hành invoice gia hạn trên order gốc và trừ số dư ngay
- Đồng bộ domain từ Plesk theo server, ServiceOrderRecorder tạo order/invoice cho dịch vụ admin dựng
- Danh sách dịch vụ trả field theo loại (service_plan, dns_records_count), đếm dịch vụ theo loại

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
baodev0
2026-10-11 23:07:51 +07:00
co-authored by Claude Opus 5.5
parent 10af41c5cf
commit c5115b52dd
53 changed files with 1887 additions and 613 deletions
@@ -0,0 +1,69 @@
<?php
use App\Services\Domain\CustomerDomainServiceSync;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
return new class extends Migration
{
public function up(): void
{
DB::table('dns_domain_user')
->join('dns_manager_domain', 'dns_manager_domain.id', '=', 'dns_domain_user.domain_id')
->select([
'dns_domain_user.user_id as customer_id',
'dns_manager_domain.domain_name',
'dns_manager_domain.is_created',
'dns_manager_domain.created_at',
])
->orderBy('dns_domain_user.domain_id')
->each(function ($assignment): void {
$existing = DB::table('services')
->where('customer_id', $assignment->customer_id)
->where('type', 'domain')
->whereRaw('LOWER(TRIM(server_name)) = ?', [mb_strtolower(trim($assignment->domain_name))])
->orderBy('id')
->first();
if ($existing) {
if ($existing->deleted_at !== null) {
DB::table('services')->where('id', $existing->id)->update([
'deleted_at' => null,
'updated_at' => now(),
]);
}
return;
}
DB::table('services')->insert([
'uuid' => (string) Str::uuid(),
'customer_id' => $assignment->customer_id,
'type' => 'domain',
'server_name' => $assignment->domain_name,
'status' => match ((int) $assignment->is_created) {
1 => 'active',
2 => 'suspended',
3 => 'cancelled',
default => 'pending',
},
'auto_renew' => false,
'started_at' => $assignment->created_at,
'note' => CustomerDomainServiceSync::AUTO_CREATED_NOTE,
'created_at' => now(),
'updated_at' => now(),
]);
});
}
public function down(): void
{
DB::table('services')
->where('type', 'domain')
->where('note', CustomerDomainServiceSync::AUTO_CREATED_NOTE)
->whereNull('product_id')
->whereNull('order_item_id')
->whereNull('invoice_id')
->delete();
}
};
@@ -0,0 +1,25 @@
<?php
use App\Enums\TransactionStatus;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
$submittedPending = DB::table('transactions')
->selectRaw('COALESCE(SUM(amount), 0)')
->whereColumn('transactions.customer_id', 'customers.id')
->where('type', 'manual')
->where('status', TransactionStatus::PENDING->value)
->whereNotNull('proof_image')
->whereNull('deleted_at');
DB::table('customers')->update(['total_pending' => DB::raw('(' . $submittedPending->toRawSql() . ')')]);
}
public function down(): void
{
}
};