mirror of
https://github.com/henry4682/finance_app.git
synced 2026-07-16 00:10:00 +00:00
feat: 前端分離+功能api化
1. 新增資產管理CRUD、googleOAuth登入 2. 更改原記帳controller
This commit is contained in:
@@ -14,6 +14,7 @@ return new class extends Migration
|
||||
Schema::create('expenses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->onDelete('cascade');
|
||||
$table->unsignedBigInteger('account_id')->nullable()->after('user_id');
|
||||
$table->foreignId('category_id')->nullable()->constrained()->onDelete('set null');
|
||||
$table->decimal('amount', 10, 2);
|
||||
$table->string('note')->nullable();
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('google_id')->nullable()->unique()->after('id');
|
||||
$table->string('avatar')->nullable()->after('google_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->morphs('tokenable');
|
||||
$table->text('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable()->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('accounts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('type', 20);
|
||||
$table->string('currency', 10)->default('TWD');
|
||||
$table->decimal('balance', 15, 2)->default(0);
|
||||
$table->string('note')->nullable();
|
||||
$table->integer('billing_day')->nullable();
|
||||
$table->integer('payment_day')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('accounts');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('investment_holdings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('account_id')->constrained()->cascadeOnDelete();
|
||||
$table->enum('type', ['stock', 'fund']);
|
||||
$table->string('symbol');
|
||||
$table->string('name');
|
||||
$table->decimal('shares', 10, 2)->default(0);
|
||||
$table->decimal('avg_cost', 10, 2)->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('investment_holdings');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('investment_transactions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('holding_id')->constrained('investment_holdings')->cascadeOnDelete();
|
||||
$table->enum('action', ['buy', 'sell']);
|
||||
$table->decimal('shares', 10, 2)->nullable();
|
||||
$table->decimal('price', 10, 2)->nullable();
|
||||
$table->decimal('amount', 15, 2)->nullable();
|
||||
$table->decimal('nav', 10, 4)->nullable();
|
||||
$table->decimal('fee', 10, 2)->default(0);
|
||||
$table->decimal('tax', 10, 2)->default(0);
|
||||
$table->date('traded_at');
|
||||
$table->string('note')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('investment_transactions');
|
||||
}
|
||||
};
|
||||
@@ -12,14 +12,14 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->dropColumn('external_id');
|
||||
$table->dropForeign(['account_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
39
database/migrations/2026_06_16_183426_securities.php
Normal file
39
database/migrations/2026_06_16_183426_securities.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('securities', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('code', 20);
|
||||
$table->enum('type', ['stock', 'etf', 'fund']);
|
||||
$table->string('source', 20); // twse, tpex, cnyes
|
||||
$table->string('name'); // 中文名稱/簡稱
|
||||
|
||||
$table->decimal('latest_price', 15, 4)->nullable(); // 最新報價/淨值
|
||||
$table->timestamp('latest_price_at')->nullable(); // 最新報價/淨值時間
|
||||
$table->decimal('change_amount', 15, 4)->nullable(); // 漲跌
|
||||
$table->decimal('change_rate', 8, 4)->nullable(); // 漲跌幅(%)
|
||||
|
||||
$table->jsonb('meta')->nullable(); // 基金專屬額外資訊(category、riskLevel、isinCode...)
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['code', 'type']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('securities');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('security_price_histories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignId('security_id')
|
||||
->constrained('securities')
|
||||
->cascadeOnDelete();
|
||||
|
||||
$table->date('price_date'); // 該筆報價/淨值所屬日期
|
||||
$table->decimal('price', 15, 4); // 收盤價/淨值
|
||||
$table->decimal('change_amount', 15, 4)->nullable(); // 漲跌
|
||||
$table->decimal('change_rate', 8, 4)->nullable(); // 漲跌幅(%)
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['security_id', 'price_date']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('security_price_histories');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->text('google_access_token')->nullable();
|
||||
$table->text('google_refresh_token')->nullable();
|
||||
$table->timestamp('google_token_expires_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -12,15 +12,17 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->foreignId('subcategory_id')->nullable()->after('category_id')
|
||||
->constrained('categories')->onDelete('set null');
|
||||
// 🟢 新增分攤控制欄位
|
||||
$table->boolean('is_amortized')->default(false); // 是否開啟分攤
|
||||
$table->date('period_start')->nullable(); // 費用歸屬開始日期
|
||||
$table->date('period_end')->nullable(); // 費用歸屬結束日期
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('expenses', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('subcategory_id');
|
||||
$table->dropColumn(['is_amortized', 'period_start', 'period_end']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('account_rules', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->onDelete('cascade');
|
||||
$table->string('keyword'); // 🔍 關鍵字,例如: 'cathaybk' 或 '國泰' 或 '永豐'
|
||||
$table->string('match_type'); // 💡 類型,例如: 'email_from' (比對寄件者) 或 'subject' (比對主旨)
|
||||
$table->foreignId('account_id')->constrained('accounts')->onDelete('cascade'); // 🎯 要掛勾的資產帳戶ID
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('account_rules');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user