From a557725c912389c8420172926cc75b0dd29204eb Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 7 Mar 2022 09:47:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=90=8E=E5=8F=B0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=80=81=E9=85=8D=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Forms/QuotaV1Deduction.php | 2 +- app/Admin/Forms/QuotaV1Recharge.php | 2 +- app/Models/QuotaV1Log.php | 13 ++++++++ app/Models/User.php | 8 +++++ app/Services/QuotaV1Service.php | 2 +- ..._before_balance_to_quota_v1_logs_table.php | 33 +++++++++++++++++++ 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2022_03_04_180530_change_before_balance_to_quota_v1_logs_table.php diff --git a/app/Admin/Forms/QuotaV1Deduction.php b/app/Admin/Forms/QuotaV1Deduction.php index d3cf0096..acfd94ff 100644 --- a/app/Admin/Forms/QuotaV1Deduction.php +++ b/app/Admin/Forms/QuotaV1Deduction.php @@ -63,7 +63,7 @@ class QuotaV1Deduction extends Form implements LazyRenderable public function form() { $this->select('user_id', '用户手机号')->ajax(admin_route('api.users'))->required(); - $this->currency('change_balance', '扣减配额')->symbol('¥')->required(); + $this->currency('change_balance', '扣减配额')->digits(3)->symbol('¥')->required(); $this->confirm('是否确认扣减?', '提交后该动作无法逆转'); } } diff --git a/app/Admin/Forms/QuotaV1Recharge.php b/app/Admin/Forms/QuotaV1Recharge.php index ecd0f1c8..9e84af27 100644 --- a/app/Admin/Forms/QuotaV1Recharge.php +++ b/app/Admin/Forms/QuotaV1Recharge.php @@ -63,7 +63,7 @@ class QuotaV1Recharge extends Form implements LazyRenderable public function form() { $this->select('user_id', '用户手机号')->ajax(admin_route('api.users'))->required(); - $this->currency('change_balance', '增加配额')->symbol('¥')->required(); + $this->currency('change_balance', '增加配额')->digits(3)->required(); $this->confirm('是否确认增加老配额?', '提交后该动作无法逆转'); } } diff --git a/app/Models/QuotaV1Log.php b/app/Models/QuotaV1Log.php index 6271df3d..e8440b3c 100644 --- a/app/Models/QuotaV1Log.php +++ b/app/Models/QuotaV1Log.php @@ -11,4 +11,17 @@ class QuotaV1Log extends Model public const ACTION_ADMIN_RECHARGE = 7; public const ACTION_ADMIN_DEDUCTION = 8; + + /** + * @var array + */ + protected $fillable = [ + 'user_id', + 'loggable_id', + 'loggable_type', + 'action', + 'before_balance', + 'change_balance', + 'remarks', + ]; } diff --git a/app/Models/User.php b/app/Models/User.php index fe8e0d74..f793e61f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -368,6 +368,14 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac return $this->hasMany(QuotaLog::class); } + /** + * 用户的配额日志 + */ + public function quotaV1Logs() + { + return $this->hasMany(QuotaV1Log::class); + } + /** * 属于此用户的团队销售值(含自己的销售值) */ diff --git a/app/Services/QuotaV1Service.php b/app/Services/QuotaV1Service.php index 1e905b5e..922ab5a8 100644 --- a/app/Services/QuotaV1Service.php +++ b/app/Services/QuotaV1Service.php @@ -45,7 +45,7 @@ class QuotaV1Service $user->userInfo()->decrement('quota_v1', $_changeBalance); } - $user->walletLogs()->create([ + $user->quotaV1Logs()->create([ 'loggable_id' => $loggable?->id, 'loggable_type' => $loggable?->getMorphClass(), 'before_balance' => $beforeBalance, diff --git a/database/migrations/2022_03_04_180530_change_before_balance_to_quota_v1_logs_table.php b/database/migrations/2022_03_04_180530_change_before_balance_to_quota_v1_logs_table.php new file mode 100644 index 00000000..4391ca78 --- /dev/null +++ b/database/migrations/2022_03_04_180530_change_before_balance_to_quota_v1_logs_table.php @@ -0,0 +1,33 @@ +string('before_balance', 12, 3)->change(); + $table->decimal('change_balance', 12, 3)->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('quota_v1_logs', function (Blueprint $table) { + // + }); + } +}