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'); + } +}