6
0
Fork 0

钱包和钱包流水表

release
李静 2021-12-23 17:49:41 +08:00
parent 4c75464780
commit 45b446d253
4 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Wallet extends Model
{
/**
* @var array
*/
protected $attributes = [
'withdrawable' => true,
];
/**
* @var array
*/
protected $fillable = [
'user_id',
'balance',
'total_expenses',
'total_revenue',
'withdrawable',
];
/**
* @var array
*/
protected $casts = [
'withdrawable' => 'bool',
];
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class WalletLog extends Model
{
use HasFactory;
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateWalletsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('wallets', function (Blueprint $table) {
$table->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');
}
}

View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateWalletLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('wallet_logs', function (Blueprint $table) {
$table->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');
}
}