6
0
Fork 0

钱包优化

release
李静 2021-12-23 19:25:59 +08:00
parent 2a3a943963
commit 527b4537ee
4 changed files with 11 additions and 7 deletions

View File

@ -6,6 +6,16 @@ use Illuminate\Database\Eloquent\Model;
class Wallet extends Model
{
/**
* @var string
*/
protected $primaryKey = 'user_id';
/**
* @var bool
*/
public $incrementing = false;
/**
* @var array
*/
@ -17,7 +27,6 @@ class Wallet extends Model
* @var array
*/
protected $fillable = [
'user_id',
'balance',
'total_expenses',
'total_revenue',

View File

@ -2,10 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class WalletLog extends Model
{
use HasFactory;
}

View File

@ -14,8 +14,7 @@ class CreateWalletsTable extends Migration
public function up()
{
Schema::create('wallets', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id')->unique()->comment('用户ID');
$table->unsignedBigInteger('user_id')->primary()->comment('用户ID');
$table->unsignedBigInteger('balance')->default(0)->comment('余额(分)');
$table->unsignedBigInteger('total_expenses')->default(0)->comment('总支出(分)');
$table->unsignedBigInteger('total_revenue')->default(0)->comment('总收入(分)');

View File

@ -16,7 +16,6 @@ class CreateWalletLogsTable extends Migration
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('变更前的余额');
@ -25,7 +24,6 @@ class CreateWalletLogsTable extends Migration
$table->timestamps();
$table->index('user_id');
$table->index('wallet_id');
});
}