refactor(membership): mengubah total_points menjadi tier points

- menambahkan kolom baru yaitu reward point
- menambahkan tier baru di seeder yaitu "Bronze"
This commit is contained in:
Yoga Pangestu 2025-11-04 21:28:16 +07:00
parent be4ff665df
commit 4067882f8a
4 changed files with 14 additions and 5 deletions

View File

@ -36,7 +36,7 @@ public function mount()
->map(function ($tier) { ->map(function ($tier) {
$topMembership = $tier->memberships() $topMembership = $tier->memberships()
->with(['user.customer.orders.items', 'user.customer.orders.payments']) ->with(['user.customer.orders.items', 'user.customer.orders.payments'])
->orderByDesc('total_points') ->orderByDesc('tier_points')
->first(); ->first();
$topMemberStats = null; $topMemberStats = null;
@ -49,7 +49,7 @@ public function mount()
$topMemberStats = [ $topMemberStats = [
'name' => $topMembership->user->customer->name, 'name' => $topMembership->user->customer->name,
'points' => currency($topMembership->total_points), 'points' => currency($topMembership->tier_points),
'total_orders' => currency($totalOrders), 'total_orders' => currency($totalOrders),
'total_items' => currency($totalItems), 'total_items' => currency($totalItems),
'total_amount' => currency($totalAmount), 'total_amount' => currency($totalAmount),
@ -57,6 +57,7 @@ public function mount()
} }
return [ return [
'id' => $tier->id,
'hash' => $tier->hash, 'hash' => $tier->hash,
'name' => $tier->name, 'name' => $tier->name,
'min_points' => currency($tier->min_points), 'min_points' => currency($tier->min_points),

View File

@ -15,7 +15,8 @@ class Membership extends Model
protected function casts(): array protected function casts(): array
{ {
return [ return [
'total_points' => 'int', 'tier_points' => 'int',
'reward_points' => 'int',
]; ];
} }

View File

@ -15,7 +15,9 @@ public function up(): void
$table->id(); $table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('tier_id')->constrained()->cascadeOnDelete(); $table->foreignId('tier_id')->constrained()->cascadeOnDelete();
$table->unsignedInteger('total_points')->default(0); $table->unsignedInteger('tier_points')->default(0);
$table->unsignedInteger('reward_points')->default(0);
$table->timestamp('last_transaction_at')->nullable();
$table->timestamp('created_at')->useCurrent(); $table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate(); $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
$table->softDeletes(); $table->softDeletes();

View File

@ -11,8 +11,13 @@ public function run(): void
{ {
$tiers = [ $tiers = [
[ [
'name' => 'Silver', 'name' => 'Bronze',
'min_points' => 0, 'min_points' => 0,
'max_points' => 49,
],
[
'name' => 'Silver',
'min_points' => 50,
'max_points' => 99, 'max_points' => 99,
], ],
[ [