钱包优化
parent
2a3a943963
commit
527b4537ee
|
|
@ -6,6 +6,16 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Wallet extends Model
|
class Wallet extends Model
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'user_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
|
@ -17,7 +27,6 @@ class Wallet extends Model
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'user_id',
|
|
||||||
'balance',
|
'balance',
|
||||||
'total_expenses',
|
'total_expenses',
|
||||||
'total_revenue',
|
'total_revenue',
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class WalletLog extends Model
|
class WalletLog extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,7 @@ class CreateWalletsTable extends Migration
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::create('wallets', function (Blueprint $table) {
|
Schema::create('wallets', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->unsignedBigInteger('user_id')->primary()->comment('用户ID');
|
||||||
$table->unsignedBigInteger('user_id')->unique()->comment('用户ID');
|
|
||||||
$table->unsignedBigInteger('balance')->default(0)->comment('余额(分)');
|
$table->unsignedBigInteger('balance')->default(0)->comment('余额(分)');
|
||||||
$table->unsignedBigInteger('total_expenses')->default(0)->comment('总支出(分)');
|
$table->unsignedBigInteger('total_expenses')->default(0)->comment('总支出(分)');
|
||||||
$table->unsignedBigInteger('total_revenue')->default(0)->comment('总收入(分)');
|
$table->unsignedBigInteger('total_revenue')->default(0)->comment('总收入(分)');
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ class CreateWalletLogsTable extends Migration
|
||||||
Schema::create('wallet_logs', function (Blueprint $table) {
|
Schema::create('wallet_logs', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->unsignedBigInteger('user_id')->comment('用户ID');
|
$table->unsignedBigInteger('user_id')->comment('用户ID');
|
||||||
$table->unsignedBigInteger('wallet_id')->comment('钱包ID');
|
|
||||||
$table->nullableMorphs('loggable');
|
$table->nullableMorphs('loggable');
|
||||||
$table->tinyInteger('action')->comment('操作类型');
|
$table->tinyInteger('action')->comment('操作类型');
|
||||||
$table->unsignedBigInteger('before_balance')->default(0)->comment('变更前的余额');
|
$table->unsignedBigInteger('before_balance')->default(0)->comment('变更前的余额');
|
||||||
|
|
@ -25,7 +24,6 @@ class CreateWalletLogsTable extends Migration
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
||||||
$table->index('user_id');
|
$table->index('user_id');
|
||||||
$table->index('wallet_id');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue