From 4140f5aeacf3b1d6c63dab94ebb3089031d4c05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Tue, 25 Jan 2022 13:47:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=8F=E9=94=80=E5=95=86=E4=BD=99=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Enums/DealerWalletAction.php | 6 +++ app/Models/DealerWallet.php | 36 ++++++++++++++++++ app/Models/DealerWalletLog.php | 37 +++++++++++++++++++ app/Models/User.php | 18 ++++++++- ..._25_131329_create_dealer_wallets_table.php | 36 ++++++++++++++++++ ...131739_create_dealer_wallet_logs_table.php | 37 +++++++++++++++++++ 6 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 app/Enums/DealerWalletAction.php create mode 100644 app/Models/DealerWallet.php create mode 100644 app/Models/DealerWalletLog.php create mode 100644 database/migrations/2022_01_25_131329_create_dealer_wallets_table.php create mode 100644 database/migrations/2022_01_25_131739_create_dealer_wallet_logs_table.php diff --git a/app/Enums/DealerWalletAction.php b/app/Enums/DealerWalletAction.php new file mode 100644 index 00000000..a166ae6b --- /dev/null +++ b/app/Enums/DealerWalletAction.php @@ -0,0 +1,6 @@ + 0, + 'total_revenue' => 0, + 'total_expenses' => 0, + 'withdrawable' => false, + ]; + + /** + * @var array + */ + protected $casts = [ + 'withdrawable' => 'bool', + ]; + + /** + * @var array + */ + protected $fillable = [ + 'user_id', + 'balance', + 'total_expenses', + 'total_revenue', + 'withdrawable', + ]; +} diff --git a/app/Models/DealerWalletLog.php b/app/Models/DealerWalletLog.php new file mode 100644 index 00000000..828094a8 --- /dev/null +++ b/app/Models/DealerWalletLog.php @@ -0,0 +1,37 @@ + DealerWalletAction::class, + ]; + + /** + * @var array + */ + protected $fillable = [ + 'user_id', + 'loggable_id', + 'loggable_type', + 'action', + 'before_balance', + 'change_balance', + 'remarks', + ]; + + /** + * 此余额日志关联的用户 + */ + public function user() + { + return $this->belongsTo(User::class); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 182ca8f5..f9e251b2 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -143,7 +143,7 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac } /** - * 属于次用户得经销商身份 + * 属于此用户得经销商身份 * * @return void */ @@ -152,6 +152,22 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac return $this->hasOne(Dealer::class, 'user_id'); } + /** + * 属于此用户得经销商余额 + */ + public function dealerWallet() + { + return $this->hasOne(DealerWallet::class, 'user_id'); + } + + /** + * 属于此用户得经销商余额日志 + */ + public function dealerWalletLogs() + { + return $this->hasMany(DealerWalletLog::class, 'user_id'); + } + /** * 经销商订购订单 * diff --git a/database/migrations/2022_01_25_131329_create_dealer_wallets_table.php b/database/migrations/2022_01_25_131329_create_dealer_wallets_table.php new file mode 100644 index 00000000..5599195a --- /dev/null +++ b/database/migrations/2022_01_25_131329_create_dealer_wallets_table.php @@ -0,0 +1,36 @@ +id(); + $table->unsignedBigInteger('user_id')->unique()->comment('用户ID'); + $table->unsignedDecimal('balance', 12, 2)->default(0)->comment('余额'); + $table->unsignedDecimal('total_expenses', 12, 2)->default(0)->comment('总支出'); + $table->unsignedDecimal('total_revenue', 12, 2)->default(0)->comment('总收入'); + $table->boolean('withdrawable')->default(true)->comment('是否可提现'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('dealer_wallets'); + } +} diff --git a/database/migrations/2022_01_25_131739_create_dealer_wallet_logs_table.php b/database/migrations/2022_01_25_131739_create_dealer_wallet_logs_table.php new file mode 100644 index 00000000..e7550655 --- /dev/null +++ b/database/migrations/2022_01_25_131739_create_dealer_wallet_logs_table.php @@ -0,0 +1,37 @@ +id(); + $table->unsignedBigInteger('user_id')->comment('用户ID'); + $table->nullableMorphs('loggable'); + $table->tinyInteger('action')->comment('操作类型'); + $table->decimal('before_balance', 12, 2)->default(0)->comment('变更前的余额'); + $table->decimal('change_balance', 12, 2)->default(0)->comment('变动余额'); + $table->string('remarks')->nullable()->comment('备注'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('dealer_wallet_logs'); + } +}