From 45b446d25307432270baa8f92e76b3ba33e96541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Thu, 23 Dec 2021 17:49:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=92=8C=E9=92=B1=E5=8C=85?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Wallet.php | 33 +++++++++++++++ app/Models/WalletLog.php | 11 +++++ ...2021_12_23_171645_create_wallets_table.php | 36 ++++++++++++++++ ..._12_23_171714_create_wallet_logs_table.php | 41 +++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 app/Models/Wallet.php create mode 100644 app/Models/WalletLog.php create mode 100644 database/migrations/2021_12_23_171645_create_wallets_table.php create mode 100644 database/migrations/2021_12_23_171714_create_wallet_logs_table.php diff --git a/app/Models/Wallet.php b/app/Models/Wallet.php new file mode 100644 index 00000000..70542aad --- /dev/null +++ b/app/Models/Wallet.php @@ -0,0 +1,33 @@ + true, + ]; + + /** + * @var array + */ + protected $fillable = [ + 'user_id', + 'balance', + 'total_expenses', + 'total_revenue', + 'withdrawable', + ]; + + /** + * @var array + */ + protected $casts = [ + 'withdrawable' => 'bool', + ]; +} diff --git a/app/Models/WalletLog.php b/app/Models/WalletLog.php new file mode 100644 index 00000000..56815e5a --- /dev/null +++ b/app/Models/WalletLog.php @@ -0,0 +1,11 @@ +id(); + $table->unsignedBigInteger('user_id')->unique()->comment('用户ID'); + $table->unsignedBigInteger('balance')->default(0)->comment('余额(分)'); + $table->unsignedBigInteger('total_expenses')->default(0)->comment('总支出(分)'); + $table->unsignedBigInteger('total_revenue')->default(0)->comment('总收入(分)'); + $table->boolean('withdrawable')->default(true)->comment('是否可提现'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('wallets'); + } +} diff --git a/database/migrations/2021_12_23_171714_create_wallet_logs_table.php b/database/migrations/2021_12_23_171714_create_wallet_logs_table.php new file mode 100644 index 00000000..e014d1e7 --- /dev/null +++ b/database/migrations/2021_12_23_171714_create_wallet_logs_table.php @@ -0,0 +1,41 @@ +id(); + $table->unsignedBigInteger('user_id')->comment('用户ID'); + $table->unsignedBigInteger('wallet_id')->comment('钱包ID'); + $table->nullableMorphs('loggable'); + $table->tinyInteger('action')->comment('操作类型'); + $table->unsignedBigInteger('before_balance')->default(0)->comment('变更前的余额'); + $table->bigInteger('fee')->default(0)->comment('变动金额(分)'); + $table->string('remarks')->nullable()->comment('备注'); + $table->timestamps(); + + $table->index('user_id'); + $table->index('wallet_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('wallet_logs'); + } +}